-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcompiler_info.ac
More file actions
256 lines (217 loc) · 7.68 KB
/
compiler_info.ac
File metadata and controls
256 lines (217 loc) · 7.68 KB
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
// PowerPC C Compiler Backend Information File
// Part of PowerPC ArchC Model
//====================-- Machine specific rules --============================//
// compu is a compare operator which forces unsigned comparisons
// and produces signed flags
define operator compu as arity 2;
(cjump const:cond:ult (comp aa:any bb:any) cc:any) =>
(cjump const:cond:lt (compu aa:any bb:any) cc:any);
(cjump const:cond:ugt (comp aa:any bb:any) cc:any) =>
(cjump const:cond:gt (compu aa:any bb:any) cc:any);
(cjump const:cond:uge (comp aa:any bb:any) cc:any) =>
(cjump const:cond:ge (compu aa:any bb:any) cc:any);
(cjump const:cond:ule (comp aa:any bb:any) cc:any) =>
(cjump const:cond:le (compu aa:any bb:any) cc:any);
(nop) =>
(transfer AReg:regs (or AReg:regs AReg:regs const:byte:0));
(transfer a:regs b:regs) =>
(transfer a:regs (or b:regs b:regs));
//=====================-- Registers definitions --============================//
define registers GPR:regs as (
r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 r16
r17 r18 r19 r20 r21 r22 r23 r24 r25 r26 r27 r28 r29 r30 r31
);
define operand spec as size 32 like int;
define registers SPECIAL:spec as (
CR CTR LR
);
//===========================-- ABI stuff --==================================//
redefine operand tgtimm size to 16;
define abi as (
define callee save registers as (r14 r15 r16 r17 r18 r19 r20 r21 r22 r23
r24 r25 r26 r27 r28 r29 r30 r31);
define reserved registers as (r1 r2 r13);
define auxiliar registers as (r11 r12);
//define calling convention for int as stack size 4 alignment 4;
define calling convention for int as (r3 r4 r5 r6 r7 r8 r9 r10);
define calling convention for int as stack size 4 alignment 4;
define return convention for int as (r3 r4);
//define programcounter register as PC;
define stackpointer register as r13;
define framepointer register as r14;
define return register as LR;
define stack grows down alignment 8;
define pcoffset -8;
);
//==================-- Instruction semantic fragments --======================//
//=======================-- Instructions definitions --=======================//
// * DATA PROCESSING - FIXED POINT INSTRUCTIONS *
/* Logical */
define instruction ande semantic as (
(transfer Op1:GPR (and Op2:GPR Op3:GPR));
) cost 1;
define instruction andi_ semantic as (
(transfer Op1:GPR (and Op2:GPR imm:Op3:tgtimm));
) cost 1;
define instruction ore semantic as (
(transfer Op1:GPR (or Op2:GPR Op3:GPR));
) cost 1;
define instruction ori semantic as (
//let Op1 = "r0", Op2 = "r0", Op3 = "0" in
//(nop);
(transfer Op1:GPR (or Op2:GPR imm:Op3:tgtimm));
) cost 1;
define instruction xxor semantic as (
(transfer Op1:GPR (xor Op2:GPR Op3:GPR));
) cost 1;
define instruction xori semantic as (
(transfer Op1:GPR (xor Op2:GPR imm:Op3:tgtimm));
) cost 1;
// Shift
define instruction rlwinm semantic as (
let Op4 = "0", Op5 = "31" in
(transfer Op1:GPR (rol Op2:GPR imm:Op3:tgtimm));
) cost 1;
define instruction slw semantic as (
(transfer Op1:GPR (shl Op2:GPR Op3:GPR));
) cost 1;
define instruction srw semantic as (
(transfer Op1:GPR (shr Op2:GPR Op3:GPR));
) cost 1;
define instruction srawi semantic as (
(transfer Op1:GPR (asr Op2:GPR imm:Op3:tgtimm));
) cost 1;
define instruction sraw semantic as (
(transfer Op1:GPR (asr Op2:GPR Op3:GPR));
) cost 1;
// Special move instructions
define instruction mtspr semantic as () cost 10;
define instruction mtspr semantic as (
(transfer LR:SPECIAL Op1:GPR);
) cost 10;
define instruction mfspr semantic as () cost 10;
define instruction mfspr semantic as (
(transfer Op1:GPR LR:SPECIAL);
) cost 10;
// Arithmetic
define instruction add semantic as (
(transfer Op1:GPR (+ Op2:GPR Op3:GPR));
) cost 1;
define instruction addi semantic as (
(transfer Op1:GPR imm:Op2:tgtimm);
) cost 1;
define instruction addi semantic as () cost 1;
define instruction addi semantic as () cost 1;
define instruction addi semantic as (
(transfer Op1:GPR (+ Op2:GPR imm:Op3:tgtimm));
) cost 1;
define instruction subf semantic as (
(transfer Op1:GPR (- Op3:GPR Op2:GPR));
) cost 1;
define instruction subfic semantic as (
(transfer Op1:GPR (- imm:Op3:tgtimm Op2:GPR));
) cost 1;
define instruction neg semantic as (
(transfer Op1:GPR (~ Op2:GPR));
) cost 1;
define instruction mulli semantic as (
(transfer Op1:GPR (* Op2:GPR imm:Op3:tgtimm));
) cost 10;
define instruction mullw semantic as (
(transfer Op1:GPR (* Op2:GPR Op3:GPR));
) cost 10;
define instruction mulhw semantic as (
(transfer Op1:GPR (mulhs Op2:GPR Op3:GPR));
) cost 10;
define instruction mulhwu semantic as (
(transfer Op1:GPR (mulhu Op2:GPR Op3:GPR));
) cost 10;
// * LOAD/STORE INSTRUCTIONS *
define instruction lbz semantic as (
(transfer Op1:GPR (zext (memref (+ Op3:GPR imm:Op2:tgtimm)) const:num:8));
) cost 1;
define instruction lbzx semantic as (
(transfer Op1:GPR (zext (memref (+ Op2:GPR Op3:GPR)) const:num:8));
) cost 1;
define instruction lhz semantic as (
(transfer Op1:GPR (zext (memref (+ Op3:GPR imm:Op2:tgtimm)) const:num:16));
) cost 1;
define instruction lhzx semantic as (
(transfer Op1:GPR (zext (memref (+ Op2:GPR Op3:GPR)) const:num:16));
) cost 1;
define instruction lha semantic as (
(transfer Op1:GPR (sext (memref (+ Op3:GPR imm:Op2:tgtimm)) const:num:16));
) cost 1;
define instruction lhax semantic as (
(transfer Op1:GPR (sext (memref (+ Op2:GPR Op3:GPR)) const:num:16));
) cost 1;
define instruction lwz semantic as (
(transfer Op1:GPR (memref (+ Op3:GPR imm:Op2:tgtimm)));
) cost 1;
define instruction lwzx semantic as (
(transfer Op1:GPR (memref (+ Op2:GPR Op3:GPR)));
) cost 1;
define instruction stb semantic as (
(transfer (memref (+ Op3:GPR imm:Op2:tgtimm)) (trunc Op1:GPR const:num:8));
) cost 1;
define instruction stbx semantic as (
(transfer (memref (+ Op2:GPR Op3:GPR)) (trunc Op1:GPR const:num:8));
) cost 1;
define instruction sth semantic as (
(transfer (memref (+ Op3:GPR imm:Op2:tgtimm)) (trunc Op1:GPR const:num:16));
) cost 1;
define instruction sthx semantic as (
(transfer (memref (+ Op2:GPR Op3:GPR)) (trunc Op1:GPR const:num:16));
) cost 1;
define instruction stw semantic as (
(transfer (memref (+ Op3:GPR imm:Op2:tgtimm)) Op1:GPR);
) cost 1;
define instruction stwx semantic as (
(transfer (memref (+ Op2:GPR Op3:GPR)) Op1:GPR);
) cost 1;
define instruction extsb semantic as (
(transfer Op1:GPR (sext Op2:GPR const:num:8));
) cost 1;
define instruction extsh semantic as (
(transfer Op1:GPR (sext Op2:GPR const:num:16));
) cost 1;
// * BRANCH INSTRUCTIONS AND COMPARISON *
define instruction cmp semantic as (
let Op1 = "0" in
(transfer CR:SPECIAL (comp Op2:GPR Op3:GPR));
) cost 1;
define instruction cmpi semantic as (
let Op1 = "0" in
(transfer CR:SPECIAL (comp Op2:GPR imm:Op3:tgtimm));
) cost 1;
define instruction cmpl semantic as (
let Op1 = "0" in
(transfer CR:SPECIAL (compu Op2:GPR Op3:GPR));
) cost 1;
define instruction cmpli semantic as (
let Op1 = "0" in
(transfer CR:SPECIAL (compu Op2:GPR imm:Op3:tgtimm));
) cost 1;
define instruction ba semantic as (
(jump imm:Op1:int);
) cost 1;
define instruction bla semantic as (
(call imm:Op1:int);
) cost 1;
define instruction bclr semantic as (
(ret);
) cost 1;
define instruction bc semantic as (
let Op1 = "12", Op2 = "0" in
(cjump const:cond:lt CR:SPECIAL imm:Op3:int);
let Op1 = "12", Op2 = "1" in
(cjump const:cond:gt CR:SPECIAL imm:Op3:int);
let Op1 = "4", Op2 = "1" in
(cjump const:cond:le CR:SPECIAL imm:Op3:int);
let Op1 = "4", Op2 = "0" in
(cjump const:cond:ge CR:SPECIAL imm:Op3:int);
let Op1 = "4", Op2 = "2" in
(cjump const:cond:ne CR:SPECIAL imm:Op3:int);
let Op1 = "12", Op2 = "2" in
(cjump const:cond:eq CR:SPECIAL imm:Op3:int);
) cost 1;