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