1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
#ifndef COMPILER_PCODE_H
#define COMPILER_PCODE_H
#include "compiler/common.h"
#include "compiler/PCodeInfo.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
#define FLAG_SET_T(flags) (((flags) & (fIsBranch | fIsCall)) ? (flags) : 0)
#define FLAG_SET_F(flags) (((flags) & (fIsBranch | fIsCall)) ? 0 : (flags))
#define PCODE_FLAG_SET_T(pcode) ((((PCode *) (pcode))->flags & (fIsBranch | fIsCall)) ? ((PCode *) (pcode))->flags : 0)
#define PCODE_FLAG_SET_F(pcode) ((((PCode *) (pcode))->flags & (fIsBranch | fIsCall)) ? 0 : ((PCode *) (pcode))->flags)
enum {
EffectRead = 1,
EffectWrite = 2,
Effect4 = 4,
Effect8 = 8,
Effect40 = 0x40 // spilled register?
};
typedef enum {
RefType_0,
RefType_1, // like D, but 32-bit?
RefType_2, // matches MW_RELOC_3?
RefType_3, // matches MW_RELOC_4?
RefType_4,
RefType_5,
RefType_6, // LO16?
RefType_7, // HI16?
RefType_8, // HA16?
RefType_9,
RefType_A, // another LO
RefType_B, // another HA
RefType_C, // another HA
RefType_D // another LO
} PCRefType;
struct PCodeArg {
PCOpKind kind;
RegClass arg;
union {
struct {
unsigned short effect;
short reg;
} reg;
struct {
SInt32 value;
Object *obj;
} imm;
struct {
SInt32 offset;
Object *obj;
} mem;
struct {
PCodeLabel *label;
} label;
struct {
SInt16 offset;
PCodeLabel *labelA;
PCodeLabel *labelB;
} labeldiff;
unsigned char placeholder[10]; // keep the size
} data;
};
#define PC_OP_IS_REGISTER(_op, _rclass, _reg) \
((_op)->kind == PCOp_REGISTER && \
(_op)->arg == (_rclass) && \
(_op)->data.reg.reg == (_reg))
#define PC_OP_IS_READ_REGISTER(_op, _rclass, _reg) \
((_op)->kind == PCOp_REGISTER && \
(_op)->arg == (_rclass) && \
(_op)->data.reg.reg == (_reg) && \
((_op)->data.reg.effect & EffectRead))
#define PC_OP_IS_WRITE_REGISTER(_op, _rclass, _reg) \
((_op)->kind == PCOp_REGISTER && \
(_op)->arg == (_rclass) && \
(_op)->data.reg.reg == (_reg) && \
((_op)->data.reg.effect & EffectWrite))
#define PC_OP_IS_R_OR_W_REGISTER(_op, _rclass, _reg) \
((_op)->kind == PCOp_REGISTER && \
(_op)->arg == (_rclass) && \
(_op)->data.reg.reg == (_reg) && \
((_op)->data.reg.effect & (EffectRead | EffectWrite)))
#define PC_OP_IS_ANY_REGISTER(_op, _rclass) \
((_op)->kind == PCOp_REGISTER && \
(_op)->arg == (_rclass))
#define PC_OP_IS_READ_ANY_REGISTER(_op, _rclass) \
((_op)->kind == PCOp_REGISTER && \
(_op)->arg == (_rclass) && \
((_op)->data.reg.effect & EffectRead))
#define PC_OP_IS_WRITE_ANY_REGISTER(_op, _rclass) \
((_op)->kind == PCOp_REGISTER && \
(_op)->arg == (_rclass) && \
((_op)->data.reg.effect & EffectWrite))
struct PCode {
PCode *nextPCode;
PCode *prevPCode;
PCodeBlock *block;
int useID;
int defID;
UInt32 flags;
struct Alias *alias;
SInt32 sourceoffset;
short op;
short argCount;
PCodeArg args[0];
};
struct PCodeLabel {
PCodeLabel *nextLabel;
PCodeBlock *block;
short resolved;
unsigned short index;
};
typedef struct _PCLink {
struct _PCLink *nextLink;
struct PCodeBlock *block;
} PCLink;
struct PCodeBlock {
struct PCodeBlock *nextBlock;
struct PCodeBlock *prevBlock;
PCodeLabel *labels;
PCLink *predecessors;
PCLink *successors;
PCode *firstPCode;
PCode *lastPCode;
int blockIndex;
int codeOffset; // in bytes
int loopWeight;
short pcodeCount;
unsigned short flags;
};
/* PCode Flags */
enum {
fIsBranch = 1,
fIsRead = 2, // read from memory
fIsWrite = 4, // write to memory
fIsCall = 8,
fIsMove = 0x10, // moves register (mcrf, mr, fmr, vmr, vmrp)
// Always valid
fIsConst = 0x40,
fIsVolatile = 0x80,
fSideEffects = 0x100, // instructions that do weird stuff with PPC state
fPCodeFlag200 = 0x200, // ?
fPCodeFlag400 = 0x400, // ?
fPCodeFlag800 = 0x800, // ?
fPCodeFlag1000 = 0x1000, // ?
fCommutative = 0x2000,
fIsCSE = 0x4000,
fIsArgInit = 0x8000, // instruction that stores varargs from GPRs to the stack
fPCodeFlag20000 = 0x20000, // some kinda load?
fPCodeFlag40000 = 0x40000, // some kinda store?
// Set 1 (branches) only
fLink = 0x1000000,
fCanLink = 0x2000000, // is capable of being a link branch
fBranchNotTaken = 0x4000000,
fBranchTaken = 0x8000000,
fAbsolute = 0x10000000,
fCanBeAbsolute = 0x20000000, // is capable of having fAbsolute set
// Set 2 (non-branches) only
fIsPtrOp = 0x20,
fPCodeFlag200000 = 0x200000,
fPCodeFlag400000 = 0x400000,
fOverflow = 0x800000,
fUpdatesPtr = 0x2000000, // lbzu, lbzux, lwzu, stbu, stbux, etc
fCanSetCarry = 0x4000000, // is capable of having fSetsCarry set
fCanSetRecordBit = 0x8000000, // is capable of having fRecordBit set
fSetsCarry = 0x10000000,
fRecordBit = 0x20000000,
fOpTypeFPR = 0x40000000,
fOpTypeGPR = 0x80000000,
fOpTypeVR = 0xC0000000,
fOpTypeMask = 0xC0000000
};
enum {
fIsProlog = 1, // fIsProlog
fIsEpilogue = 2, // fIsEpilogue
fVisited = 4, // fVisited
fScheduled = 8, // fScheduled
fPCBlockFlag10 = 0x10, // maybe fIsSwitch based off v3?
fDeleted = 0x20,
fPCBlockFlag2000 = 0x2000,
fPCBlockFlag4000 = 0x4000,
fPCBlockFlag6000 = 0x6000,
fPCBlockFlag8000 = 0x8000
};
// v3 has fCCisLiveOnExit, fUnrolled, fAlignBlock
extern PCodeBlock *pcbasicblocks;
extern PCodeBlock *pclastblock;
extern PCodeBlock *prologue;
extern PCodeBlock *epilogue;
extern PCodeBlock **depthfirstordering;
extern int pcblockcount;
extern int pcloopweight;
extern void initpcode(void);
extern PCode *makepcode(Opcode op, ...);
extern void emitpcode(Opcode op, ...);
extern PCode *copypcode(PCode *pcode);
extern PCodeLabel *makepclabel(void);
extern PCodeBlock *makepcblock(void);
extern void pclabel(PCodeBlock *block, PCodeLabel *label);
extern void pcbranch(PCodeBlock *block, PCodeLabel *label);
extern void pccomputepredecessors(void);
extern void deleteblock(PCodeBlock *block);
extern void deleteunreachableblocks(void);
extern void appendpcode(PCodeBlock *block, PCode *pcode);
extern void deletepcode(PCode *pcode);
extern void insertpcodebefore(PCode *anchor, PCode *newpcode);
extern void insertpcodeafter(PCode *anchor, PCode *newpcode);
extern void setpcodeflags(int flags);
extern void clearpcodeflags(int flags);
extern int pccomputeoffsets(void);
extern void computedepthfirstordering(void);
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif
|