546aeed2b58f8a211a99bab928bdd2dc49100189
[libfirm] / ir / be / TEMPLATE / TEMPLATE_spec.pl
1 # Creation: 2006/02/13
2 # $Id$
3 # This is a template specification for the Firm-Backend
4
5 # the cpu architecture (ia32, ia64, mips, sparc, ppc, ...)
6
7 $arch = "TEMPLATE";
8
9 # this string marks the beginning of a comment in emit
10 $comment_string = "/*";
11
12 # The node description is done as a perl hash initializer with the
13 # following structure:
14 #
15 # %nodes = (
16 #
17 # <op-name> => {
18 #   "op_flags"  => "N|L|C|X|I|F|Y|H|c|K",
19 #   "irn_flags" => "R|N|I"
20 #   "arity"     => "0|1|2|3 ... |variable|dynamic|any",
21 #   "state"     => "floats|pinned|mem_pinned|exc_pinned",
22 #   "args"      => [
23 #                    { "type" => "type 1", "name" => "name 1" },
24 #                    { "type" => "type 2", "name" => "name 2" },
25 #                    ...
26 #                  ],
27 #   "comment"   => "any comment for constructor",
28 #   "reg_req"   => { "in" => [ "reg_class|register" ], "out" => [ "reg_class|register|in_rX" ] },
29 #   "cmp_attr"  => "c source code for comparing node attributes",
30 #   "emit"      => "emit code with templates",
31 #   "rd_constructor" => "c source code which constructs an ir_node"
32 # },
33 #
34 # ... # (all nodes you need to describe)
35 #
36 # ); # close the %nodes initializer
37
38 # op_flags: flags for the operation, OPTIONAL (default is "N")
39 # the op_flags correspond to the firm irop_flags:
40 #   N   irop_flag_none
41 #   L   irop_flag_labeled
42 #   C   irop_flag_commutative
43 #   X   irop_flag_cfopcode
44 #   I   irop_flag_ip_cfopcode
45 #   F   irop_flag_fragile
46 #   Y   irop_flag_forking
47 #   H   irop_flag_highlevel
48 #   c   irop_flag_constlike
49 #   K   irop_flag_keep
50 #
51 # irn_flags: special node flags, OPTIONAL (default is 0)
52 # following irn_flags are supported:
53 #   R   rematerializeable
54 #   N   not spillable
55 #   I   ignore for register allocation
56 #
57 # state: state of the operation, OPTIONAL (default is "floats")
58 #
59 # arity: arity of the operation, MUST NOT BE OMITTED
60 #
61 # args:  the OPTIONAL arguments of the node constructor (debug, irg and block
62 #        are always the first 3 arguments and are always autmatically
63 #        created)
64 #        If this key is missing the following arguments will be created:
65 #        for i = 1 .. arity: ir_node *op_i
66 #        ir_mode *mode
67 #
68 # comment: OPTIONAL comment for the node constructor
69 #
70 # rd_constructor: for every operation there will be a
71 #      new_rd_<arch>_<op-name> function with the arguments from above
72 #      which creates the ir_node corresponding to the defined operation
73 #      you can either put the complete source code of this function here
74 #
75 #      This key is OPTIONAL. If omitted, the following constructor will
76 #      be created:
77 #      if (!op_<arch>_<op-name>) assert(0);
78 #      for i = 1 to arity
79 #         set in[i] = op_i
80 #      done
81 #      res = new_ir_node(db, irg, block, op_<arch>_<op-name>, mode, arity, in)
82 #      return res
83 #
84 # NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3
85
86 # register types:
87 #   0 - no special type
88 #   1 - caller save (register must be saved by the caller of a function)
89 #   2 - callee save (register must be saved by the called function)
90 #   4 - ignore (do not assign this register)
91 # NOTE: Last entry of each class is the largest Firm-Mode a register can hold
92 %reg_classes = (
93   "general_purpose" => [
94                          { "name" => "r0", "type" => 1 },
95                          { "name" => "r1", "type" => 1 },
96                          { "name" => "r2", "type" => 1 },
97                          { "name" => "r3", "type" => 1 },
98                          { "name" => "r4", "type" => 1 },
99                          { "name" => "r5", "type" => 1 },
100                          { "name" => "r6", "type" => 6 }, # this is our stackpointer
101                          { "name" => "r7", "type" => 6 }, # this is out basepointer
102                          { "name" => "r8", "type" => 2 },
103                          { "name" => "r9", "type" => 2 },
104                          { "name" => "r10", "type" => 2 },
105                          { "name" => "r11", "type" => 2 },
106                          { "name" => "r12", "type" => 2 },
107                          { "name" => "r13", "type" => 2 },
108                          { "name" => "r14", "type" => 2 },
109                          { "name" => "r15", "type" => 2 },
110                          { "mode" => "mode_P" }
111                        ],
112   "floating_point"  => [
113                          { "name" => "f0", "type" => 1 },
114                          { "name" => "f1", "type" => 1 },
115                          { "name" => "f2", "type" => 1 },
116                          { "name" => "f3", "type" => 1 },
117                          { "name" => "f4", "type" => 1 },
118                          { "name" => "f5", "type" => 1 },
119                          { "name" => "f6", "type" => 1 },
120                          { "name" => "f7", "type" => 1 },
121                          { "name" => "f8", "type" => 1 },
122                          { "name" => "f9", "type" => 1 },
123                          { "name" => "f10", "type" => 1 },
124                          { "name" => "f11", "type" => 1 },
125                          { "name" => "f12", "type" => 1 },
126                          { "name" => "f13", "type" => 1 },
127                          { "name" => "f14", "type" => 1 },
128                          { "name" => "f15", "type" => 1 },
129                          { "mode" => "mode_D" }
130                        ]
131 ); # %reg_classes
132
133 #--------------------------------------------------#
134 #                        _                         #
135 #                       (_)                        #
136 #  _ __   _____      __  _ _ __    ___  _ __  ___  #
137 # | '_ \ / _ \ \ /\ / / | | '__|  / _ \| '_ \/ __| #
138 # | | | |  __/\ V  V /  | | |    | (_) | |_) \__ \ #
139 # |_| |_|\___| \_/\_/   |_|_|     \___/| .__/|___/ #
140 #                                      | |         #
141 #                                      |_|         #
142 #--------------------------------------------------#
143
144 %nodes = (
145
146 #-----------------------------------------------------------------#
147 #  _       _                                         _            #
148 # (_)     | |                                       | |           #
149 #  _ _ __ | |_ ___  __ _  ___ _ __   _ __   ___   __| | ___  ___  #
150 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
151 # | | | | | ||  __/ (_| |  __/ |    | | | | (_) | (_| |  __/\__ \ #
152 # |_|_| |_|\__\___|\__, |\___|_|    |_| |_|\___/ \__,_|\___||___/ #
153 #                   __/ |                                         #
154 #                  |___/                                          #
155 #-----------------------------------------------------------------#
156
157 # commutative operations
158
159 "Add" => {
160   "op_flags"  => "C",
161   "irn_flags" => "R",
162   "comment"   => "construct Add: Add(a, b) = Add(b, a) = a + b",
163   "reg_req"   => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "general_purpose" ] },
164   "emit"      => '. add %S1, %S2, %D1\t\t\t/* Add(%S1, %S2) -> %D1, (%A1, %A2) */'
165 },
166
167 "Add_i" => {
168   "irn_flags" => "R",
169   "comment"   => "construct Add: Add(a, const) = Add(const, a) = a + const",
170   "reg_req"   => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
171   "emit"      => '. add %S1, %C, %D1\t\t\t/* Add(%C, %S1) -> %D1, (%A1, const) */'
172 },
173
174 "Mul" => {
175   "op_flags"  => "C",
176   "irn_flags" => "R",
177   "comment"   => "construct Mul: Mul(a, b) = Mul(b, a) = a * b",
178   "reg_req"   => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "general_purpose" ] },
179   "emit"      =>'. mul %S1, %S2, %D1\t\t\t/* Mul(%S1, %S2) -> %D1, (%A1, %A2) */'
180 },
181
182 "Mul_i" => {
183   "irn_flags" => "R",
184   "comment"   => "construct Mul: Mul(a, const) = Mul(const, a) = a * const",
185   "reg_req"   => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
186   "emit"      => '. mul %S1, %C, %D1\t\t\t/* signed Mul(%C, %S1) -> %D1, (%A1, const) */'
187 },
188
189 "And" => {
190   "op_flags"  => "C",
191   "irn_flags" => "R",
192   "comment"   => "construct And: And(a, b) = And(b, a) = a AND b",
193   "reg_req"   => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "general_purpose" ] },
194   "emit"      => '. and %S1, %S2, %D1\t\t\t/* And(%S1, %S2) -> %D1, (%A1, %A2) */'
195 },
196
197 "And_i" => {
198   "irn_flags" => "R",
199   "comment"   => "construct And: And(a, const) = And(const, a) = a AND const",
200   "reg_req"   => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
201   "emit"      => '. and %S1, %C, %D1\t\t\t/* And(%C, %S1) -> %D1, (%A1, const) */'
202 },
203
204 "Or" => {
205   "op_flags"  => "C",
206   "irn_flags" => "R",
207   "comment"   => "construct Or: Or(a, b) = Or(b, a) = a OR b",
208   "reg_req"   => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "general_purpose" ] },
209   "emit"      => '. or %S1, %S2, %D1\t\t\t/* Or(%S1, %S2) -> %D1, (%A1, %A2) */'
210 },
211
212 "Or_i" => {
213   "op_flags"  => "C",
214   "irn_flags" => "R",
215   "comment"   => "construct Or: Or(a, const) = Or(const, a) = a OR const",
216   "reg_req"   => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
217   "emit"      => '. or %S1, %C, %D1\t\t\t/* Or(%C, %S1) -> %D1, (%A1, const) */'
218 },
219
220 "Eor" => {
221   "op_flags"  => "C",
222   "irn_flags" => "R",
223   "comment"   => "construct Eor: Eor(a, b) = Eor(b, a) = a EOR b",
224   "reg_req"   => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "general_purpose" ] },
225   "emit"      => '. xor %S1, %S2, %D1\t\t\t/* Xor(%S1, %S2) -> %D1, (%A1, %A2) */'
226 },
227
228 "Eor_i" => {
229   "irn_flags" => "R",
230   "comment"   => "construct Eor: Eor(a, const) = Eor(const, a) = a EOR const",
231   "reg_req"   => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
232   "emit"      => '. xor %S1, %C, %D1\t\t\t/* Xor(%C, %S1) -> %D1, (%A1, const) */'
233 },
234
235 # not commutative operations
236
237 "Sub" => {
238   "irn_flags" => "R",
239   "comment"   => "construct Sub: Sub(a, b) = a - b",
240   "reg_req"   => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "general_purpose" ] },
241   "emit"      => '. sub %S1, %S2, %D1\t\t\t/* Sub(%S1, %S2) -> %D1, (%A1, %A2) */'
242 },
243
244 "Sub_i" => {
245   "irn_flags" => "R",
246   "comment"   => "construct Sub: Sub(a, const) = a - const",
247   "reg_req"   => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
248   "emit"      => '. subl %S1, %C, %D1\t\t\t/* Sub(%S1, %C) -> %D1, (%A1, const) */'
249 },
250
251 "Shl" => {
252   "irn_flags" => "R",
253   "comment"   => "construct Shl: Shl(a, b) = a << b",
254   "reg_req"   => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "general_purpose" ] },
255   "emit"      => '. shl %S1, %S2, %D1\t\t\t/* Shl(%S1, %S2) -> %D1, (%A1, %A2) */'
256 },
257
258 "Shl_i" => {
259   "irn_flags" => "R",
260   "comment"   => "construct Shl: Shl(a, const) = a << const",
261   "reg_req"   => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
262   "emit"      => '. shl %S1, %C, %D1\t\t\t/* Shl(%S1, %C) -> %D1, (%A1, const) */'
263 },
264
265 "Shr" => {
266   "irn_flags" => "R",
267   "comment"   => "construct Shr: Shr(a, b) = a >> b",
268   "reg_req"   => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "in_r1" ] },
269   "emit"      => '. shr %S2, %D1\t\t\t/* Shr(%S1, %S2) -> %D1, (%A1, %A2) */'
270 },
271
272 "Shr_i" => {
273   "irn_flags" => "R",
274   "comment"   => "construct Shr: Shr(a, const) = a >> const",
275   "reg_req"   => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
276   "emit"      => '. shr %S1, %C, %D1\t\t\t/* Shr(%S1, %C) -> %D1, (%A1, const) */'
277 },
278
279 "RotR" => {
280   "irn_flags" => "R",
281   "comment"   => "construct RotR: RotR(a, b) = a ROTR b",
282   "reg_req"   => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "general_purpose" ] },
283   "emit"      => '. ror %S1, %S2, %D1\t\t\t/* RotR(%S1, %S2) -> %D1, (%A1, %A2) */'
284 },
285
286 "RotL" => {
287   "irn_flags" => "R",
288   "comment"   => "construct RotL: RotL(a, b) = a ROTL b",
289   "reg_req"   => { "in" => [ "general_purpose", "general_purpose" ], "out" => [ "general_purpose" ] },
290   "emit"      => '. rol %S1, %S2, %D1\t\t\t/* RotL(%S1, %S2) -> %D1, (%A1, %A2) */'
291 },
292
293 "RotL_i" => {
294   "irn_flags" => "R",
295   "comment"   => "construct RotL: RotL(a, const) = a ROTL const",
296   "reg_req"   => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
297   "emit"      => '. rol %S1, %C, %D1\t\t\t/* RotL(%S1, %C) -> %D1, (%A1, const) */'
298 },
299
300 "Minus" => {
301   "irn_flags" => "R",
302   "comment"   => "construct Minus: Minus(a) = -a",
303   "reg_req"   => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
304   "emit"      => '. neg %S1, %D1\t\t\t/* Neg(%S1) -> %D1, (%A1) */'
305 },
306
307 "Inc" => {
308   "irn_flags" => "R",
309   "comment"   => "construct Increment: Inc(a) = a++",
310   "reg_req"   => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
311   "emit"      => '. inc %S1, %D1\t\t\t/* Inc(%S1) -> %D1, (%A1) */'
312 },
313
314 "Dec" => {
315   "irn_flags" => "R",
316   "comment"   => "construct Decrement: Dec(a) = a--",
317   "reg_req"   => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
318   "emit"      => '. dec %S1, %D1\t\t\t/* Dec(%S1) -> %D1, (%A1) */'
319 },
320
321 "Not" => {
322   "arity"       => 1,
323   "remat"       => 1,
324   "comment"     => "construct Not: Not(a) = !a",
325   "reg_req"     => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] },
326   "emit"        => '. not %S1, %D1\t\t\t/* Not(%S1) -> %D1, (%A1) */'
327 },
328
329 # other operations
330
331 "Const" => {
332   "op_flags"  => "c",
333   "irn_flags" => "R",
334   "comment"   => "represents an integer constant",
335   "reg_req"   => { "out" => [ "general_purpose" ] },
336   "emit"      => '. mov %C, %D1\t\t\t/* Mov Const into register */',
337   "cmp_attr"  =>
338 '
339         /* TODO: compare Const attributes */
340     return 1;
341 '
342 },
343
344 # Load / Store
345
346 "Load" => {
347   "op_flags"  => "L|F",
348   "irn_flags" => "R",
349   "state"     => "exc_pinned",
350   "comment"   => "construct Load: Load(ptr, mem) = LD ptr -> reg",
351   "reg_req"   => { "in" => [ "general_purpose", "none" ], "out" => [ "general_purpose" ] },
352   "emit"      => '. mov %O(%S1), %D1\t\t\t/* Load((%S1)) -> %D1, (%A1) */'
353 },
354
355 "Store" => {
356   "op_flags"  => "L|F",
357   "irn_flags" => "R",
358   "state"     => "exc_pinned",
359   "comment"   => "construct Store: Store(ptr, val, mem) = ST ptr,val",
360   "reg_req"   => { "in" => [ "general_purpose", "general_purpose", "none" ] },
361   "emit"      => '. movl %S2, %O(%S1)\t\t\t/* Store(%S2) -> (%S1), (%A1, %A2) */'
362 },
363
364 #--------------------------------------------------------#
365 #    __ _             _                     _            #
366 #   / _| |           | |                   | |           #
367 #  | |_| | ___   __ _| |_   _ __   ___   __| | ___  ___  #
368 #  |  _| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
369 #  | | | | (_) | (_| | |_  | | | | (_) | (_| |  __/\__ \ #
370 #  |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
371 #--------------------------------------------------------#
372
373 # commutative operations
374
375 "fAdd" => {
376   "op_flags"  => "C",
377   "irn_flags" => "R",
378   "comment"   => "construct FP Add: Add(a, b) = Add(b, a) = a + b",
379   "reg_req"   => { "in" => [ "floating_point", "floating_point" ], "out" => [ "floating_point" ] },
380   "emit"      => '. fadd %S1, %S2, %D1\t\t\t/* FP Add(%S1, %S2) -> %D1 */'
381 },
382
383 "fMul" => {
384   "op_flags"  => "C",
385   "comment"   => "construct FP Mul: Mul(a, b) = Mul(b, a) = a * b",
386   "reg_req"   => { "in" => [ "floating_point", "floating_point" ], "out" => [ "floating_point" ] },
387   "emit"      =>'. fmul %S1, %S2, %D1\t\t\t/* FP Mul(%S1, %S2) -> %D1 */'
388 },
389
390 "fMax" => {
391   "op_flags"  => "C",
392   "irn_flags" => "R",
393   "comment"   => "construct FP Max: Max(a, b) = Max(b, a) = a > b ? a : b",
394   "reg_req"   => { "in" => [ "floating_point", "floating_point" ], "out" => [ "floating_point" ] },
395   "emit"      =>'. fmax %S1, %S2, %D1\t\t\t/* FP Max(%S1, %S2) -> %D1 */'
396 },
397
398 "fMin" => {
399   "op_flags"  => "C",
400   "irn_flags" => "R",
401   "comment"   => "construct FP Min: Min(a, b) = Min(b, a) = a < b ? a : b",
402   "reg_req"   => { "in" => [ "floating_point", "floating_point" ], "out" => [ "floating_point" ] },
403   "emit"      =>'. fmin %S1, %S2, %D1\t\t\t/* FP Min(%S1, %S2) -> %D1 */'
404 },
405
406 # not commutative operations
407
408 "fSub" => {
409   "irn_flags" => "R",
410   "comment"   => "construct FP Sub: Sub(a, b) = a - b",
411   "reg_req"   => { "in" => [ "floating_point", "floating_point" ], "out" => [ "floating_point" ] },
412   "emit"      => '. fsub %S1, %S2, %D1\t\t\t/* FP Sub(%S1, %S2) -> %D1 */'
413 },
414
415 "fDiv" => {
416   "comment"   => "construct FP Div: Div(a, b) = a / b",
417   "reg_req"   => { "in" => [ "floating_point", "floating_point" ], "out" => [ "floating_point" ] },
418   "emit"      => '. fdiv %S1, %S2, %D1\t\t\t/* FP Div(%S1, %S2) -> %D1 */'
419 },
420
421 "fMinus" => {
422   "irn_flags" => "R",
423   "comment"   => "construct FP Minus: Minus(a) = -a",
424   "reg_req"   => { "in" => [ "floating_point" ], "out" => [ "floating_point" ] },
425   "emit"      => '. fneg %S1, %D1\t\t\t/* FP Minus(%S1) -> %D1 */'
426 },
427
428 # other operations
429
430 "fConst" => {
431   "op_flags"  => "c",
432   "irn_flags" => "R",
433   "comment"   => "represents a FP constant",
434   "reg_req"   => { "out" => [ "floating_point" ] },
435   "emit"      => '. fmov %C, %D1\t\t\t/* Mov fConst into register */',
436   "cmp_attr"  =>
437 '
438         /* TODO: compare fConst attributes */
439         return 1;
440 '
441 },
442
443 # Load / Store
444
445 "fLoad" => {
446   "op_flags"  => "L|F",
447   "irn_flags" => "R",
448   "state"     => "exc_pinned",
449   "comment"   => "construct FP Load: Load(ptr, mem) = LD ptr",
450   "reg_req"   => { "in" => [ "general_purpose", "none" ], "out" => [ "floating_point" ] },
451   "emit"      => '. fmov %O(%S1), %D1\t\t\t/* Load((%S1)) -> %D1 */'
452 },
453
454 "fStore" => {
455   "op_flags"  => "L|F",
456   "irn_flags" => "R",
457   "state"     => "exc_pinned",
458   "comment"   => "construct Store: Store(ptr, val, mem) = ST ptr,val",
459   "reg_req"   => { "in" => [ "general_purpose", "floating_point", "none" ] },
460   "emit"      => '. fmov %S2, %O(%S1)\t\t\t/* Store(%S2) -> (%S1), (%A1, %A2) */'
461 },
462
463 ); # end of %nodes