mirror of https://git.wuffs.org/MWCC
99 lines
2.4 KiB
C
99 lines
2.4 KiB
C
#ifndef COMPILER_LOOPDETECTION_H
|
|
#define COMPILER_LOOPDETECTION_H
|
|
|
|
#include "compiler/common.h"
|
|
#include "compiler/BitVector.h"
|
|
|
|
#ifdef __MWERKS__
|
|
#pragma options align=mac68k
|
|
#endif
|
|
typedef struct BlockList {
|
|
struct BlockList *next;
|
|
PCodeBlock *block;
|
|
} BlockList;
|
|
|
|
typedef struct InstrList {
|
|
struct InstrList *next;
|
|
PCode *instr;
|
|
} InstrList;
|
|
|
|
typedef enum LoopBound {
|
|
LOOP_BOUND_INDETERMINATE,
|
|
LOOP_BOUND_CONSTANT,
|
|
LOOP_BOUND_VARIABLE
|
|
} LoopBound;
|
|
|
|
typedef struct Loop {
|
|
struct Loop *parent;
|
|
struct Loop *nextSibling;
|
|
struct Loop *children;
|
|
PCodeBlock *body; // repeated block
|
|
PCodeBlock *preheader; // block at the start of the loop
|
|
PCodeBlock *footer; // block at the end of the loop
|
|
PCode *pc18;
|
|
BlockList *blocks;
|
|
UInt32 *memberblocks;
|
|
UInt32 *vec24;
|
|
UInt32 *vec28;
|
|
UInt32 *vec2C;
|
|
struct BasicInductionVar *basicInductionVars;
|
|
int loopWeight;
|
|
int bodySize; // amount of instructions in the body
|
|
SInt32 iterationCount;
|
|
SInt32 lower;
|
|
SInt32 upper;
|
|
SInt32 step; // value added in each iteration
|
|
unsigned char unknownCondition;
|
|
Boolean x4D;
|
|
Boolean x4E;
|
|
Boolean x4F;
|
|
Boolean isUnknownCountingLoop; // is a counting loop with non-constant iteration count
|
|
Boolean isKnownCountingLoop;
|
|
Boolean x52;
|
|
Boolean x53;
|
|
Boolean x54;
|
|
LoopBound lowerType;
|
|
LoopBound upperType;
|
|
Boolean x57;
|
|
} Loop;
|
|
|
|
typedef struct BasicInductionVar {
|
|
struct BasicInductionVar *next;
|
|
Loop *loop;
|
|
struct InductionVar *inductionVars;
|
|
InstrList *instrsC;
|
|
PCode *initializer;
|
|
SInt32 step;
|
|
short reg;
|
|
} BasicInductionVar;
|
|
|
|
typedef struct InductionVar {
|
|
struct InductionVar *next;
|
|
BasicInductionVar *basicVar;
|
|
PCode *instr;
|
|
PCode *instrC;
|
|
Loop *someloop;
|
|
SInt32 step;
|
|
short x18; // arg index within instr
|
|
short x1A; // arg index within instr
|
|
short x1C; // reg
|
|
short x1E; // reg
|
|
} InductionVar;
|
|
#ifdef __MWERKS__
|
|
#pragma options align=reset
|
|
#endif
|
|
|
|
extern Loop *loopsinflowgraph;
|
|
extern int loopdetection_nblocks;
|
|
extern BitVector *LoopTemp;
|
|
extern void *LoopList_First;
|
|
|
|
extern void addblocktoloop(Loop *loop, PCodeBlock *block);
|
|
extern void insertpreheaderblock(Loop *loop);
|
|
extern void findloopsinflowgraph(void);
|
|
extern void analyzeForCountableLoops(Loop *loop);
|
|
extern void analyzeloop(Loop *loop);
|
|
extern void analyzeloopsinflowgraph(void);
|
|
|
|
#endif
|