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