2022-11-20 05:07:22 +00:00
|
|
|
#ifndef COMPILER_LOOPDETECTION_H
|
|
|
|
#define COMPILER_LOOPDETECTION_H
|
|
|
|
|
|
|
|
#include "compiler/common.h"
|
2023-01-26 11:30:47 +00:00
|
|
|
#include "../../compiler_and_linker/FrontEnd/Optimizer/BitVector.h"
|
2022-12-14 00:16:59 +00:00
|
|
|
|
|
|
|
#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;
|
2023-01-10 11:05:21 +00:00
|
|
|
extern struct LoopList *LoopList_First;
|
2022-12-14 00:16:59 +00:00
|
|
|
|
|
|
|
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);
|
2022-11-20 05:07:22 +00:00
|
|
|
|
|
|
|
#endif
|