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