3 # This is a template specification for the Firm-Backend
7 # the cpu architecture (ia32, ia64, mips, sparc, ppc, ...)
11 # The node description is done as a perl hash initializer with the
12 # following structure:
17 # op_flags => "N|L|C|X|I|F|Y|H|c|K", # optional
18 # irn_flags => "R|N|I" # optional
19 # arity => "0|1|2|3 ... |variable|dynamic|any", # optional
20 # state => "floats|pinned|mem_pinned|exc_pinned", # optional
22 # { type => "type 1", name => "name 1" },
23 # { type => "type 2", name => "name 2" },
26 # comment => "any comment for constructor", # optional
27 # reg_req => { in => [ "reg_class|register" ], out => [ "reg_class|register|in_rX" ] },
28 # cmp_attr => "c source code for comparing node attributes", # optional
29 # outs => { "out1", "out2" },# optional, creates pn_op_out1, ... consts
30 # ins => { "in1", "in2" }, # optional, creates n_op_in1, ... consts
31 # mode => "mode_Iu", # optional, predefines the mode
32 # emit => "emit code with templates", # optional for virtual nodes
33 # attr => "attitional attribute arguments for constructor", # optional
34 # init_attr => "emit attribute initialization template", # optional
35 # rd_constructor => "c source code which constructs an ir_node", # optional
36 # hash_func => "name of the hash function for this operation", # optional, get the default hash function else
37 # latency => "latency of this operation (can be float)" # optional
38 # attr_type => "name of the attribute struct", # optional
41 # ... # (all nodes you need to describe)
43 # ); # close the %nodes initializer
45 # op_flags: flags for the operation, OPTIONAL (default is "N")
46 # the op_flags correspond to the firm irop_flags:
49 # C irop_flag_commutative
50 # X irop_flag_cfopcode
51 # I irop_flag_ip_cfopcode
54 # H irop_flag_highlevel
55 # c irop_flag_constlike
58 # irn_flags: special node flags, OPTIONAL (default is 0)
59 # following irn_flags are supported:
62 # I ignore for register allocation
64 # state: state of the operation, OPTIONAL (default is "floats")
66 # arity: arity of the operation, MUST NOT BE OMITTED
68 # args: the OPTIONAL arguments of the node constructor (debug, irg and block
69 # are always the first 3 arguments and are always autmatically
71 # If this key is missing the following arguments will be created:
72 # for i = 1 .. arity: ir_node *op_i
75 # outs: if a node defines more than one output, the names of the projections
76 # nodes having outs having automatically the mode mode_T
78 # comment: OPTIONAL comment for the node constructor
80 # rd_constructor: for every operation there will be a
81 # new_rd_<arch>_<op-name> function with the arguments from above
82 # which creates the ir_node corresponding to the defined operation
83 # you can either put the complete source code of this function here
85 # This key is OPTIONAL. If omitted, the following constructor will
87 # if (!op_<arch>_<op-name>) assert(0);
91 # res = new_ir_node(db, irg, block, op_<arch>_<op-name>, mode, arity, in)
94 # NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3
98 # 1 - caller save (register must be saved by the caller of a function)
99 # 2 - callee save (register must be saved by the called function)
100 # 4 - ignore (do not assign this register)
101 # NOTE: Last entry of each class is the largest Firm-Mode a register can hold
104 { name => "r0", type => 1 },
105 { name => "r1", type => 1 },
106 { name => "r2", type => 1 },
107 { name => "r3", type => 1 },
108 { name => "r4", type => 1 },
109 { name => "r5", type => 1 },
110 { name => "r6", type => 1 },
111 { name => "r7", type => 2 },
112 { name => "r8", type => 2 },
113 { name => "r9", type => 2 },
114 { name => "r10", type => 2 },
115 { name => "r11", type => 2 },
116 { name => "r12", type => 2 },
117 { name => "r13", type => 2 },
118 { name => "sp", realname => "r14", type => 4 }, # this is our stackpointer
119 { name => "bp", realname => "r15", type => 4 }, # this is out basepointer
120 { mode => "mode_Iu" }
123 { name => "f0", type => 1 },
124 { name => "f1", type => 1 },
125 { name => "f2", type => 1 },
126 { name => "f3", type => 1 },
127 { name => "f4", type => 1 },
128 { name => "f5", type => 1 },
129 { name => "f6", type => 1 },
130 { name => "f7", type => 1 },
131 { name => "f8", type => 1 },
132 { name => "f9", type => 1 },
133 { name => "f10", type => 1 },
134 { name => "f11", type => 1 },
135 { name => "f12", type => 1 },
136 { name => "f13", type => 1 },
137 { name => "f14", type => 1 },
138 { name => "f15", type => 1 },
144 S1 => "${arch}_emit_source_register(node, 0);",
145 S2 => "${arch}_emit_source_register(node, 1);",
146 S3 => "${arch}_emit_source_register(node, 2);",
147 S4 => "${arch}_emit_source_register(node, 3);",
148 S5 => "${arch}_emit_source_register(node, 4);",
149 S6 => "${arch}_emit_source_register(node, 5);",
150 D1 => "${arch}_emit_dest_register(node, 0);",
151 D2 => "${arch}_emit_dest_register(node, 1);",
152 D3 => "${arch}_emit_dest_register(node, 2);",
153 D4 => "${arch}_emit_dest_register(node, 3);",
154 D5 => "${arch}_emit_dest_register(node, 4);",
155 D6 => "${arch}_emit_dest_register(node, 5);",
156 C => "${arch}_emit_immediate(node);"
159 #--------------------------------------------------#
162 # _ __ _____ __ _ _ __ ___ _ __ ___ #
163 # | '_ \ / _ \ \ /\ / / | | '__| / _ \| '_ \/ __| #
164 # | | | | __/\ V V / | | | | (_) | |_) \__ \ #
165 # |_| |_|\___| \_/\_/ |_|_| \___/| .__/|___/ #
168 #--------------------------------------------------#
172 #-----------------------------------------------------------------#
175 # _ _ __ | |_ ___ __ _ ___ _ __ _ __ ___ __| | ___ ___ #
176 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
177 # | | | | | || __/ (_| | __/ | | | | | (_) | (_| | __/\__ \ #
178 # |_|_| |_|\__\___|\__, |\___|_| |_| |_|\___/ \__,_|\___||___/ #
181 #-----------------------------------------------------------------#
183 # commutative operations
188 comment => "construct Add: Add(a, b) = Add(b, a) = a + b",
189 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "general_purpose" ] },
190 emit => '. add %S1, %S2, %D1'
195 comment => "construct Add: Add(a, const) = Add(const, a) = a + const",
196 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
197 emit => '. add %S1, %C, %D1'
203 comment => "construct Mul: Mul(a, b) = Mul(b, a) = a * b",
204 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "general_purpose" ] },
205 emit =>'. mul %S1, %S2, %D1'
210 comment => "construct Mul: Mul(a, const) = Mul(const, a) = a * const",
211 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
212 emit => '. mul %S1, %C, %D1'
218 comment => "construct And: And(a, b) = And(b, a) = a AND b",
219 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "general_purpose" ] },
220 emit => '. and %S1, %S2, %D1'
225 comment => "construct And: And(a, const) = And(const, a) = a AND const",
226 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
227 emit => '. and %S1, %C, %D1'
233 comment => "construct Or: Or(a, b) = Or(b, a) = a OR b",
234 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "general_purpose" ] },
235 emit => '. or %S1, %S2, %D1'
241 comment => "construct Or: Or(a, const) = Or(const, a) = a OR const",
242 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
243 emit => '. or %S1, %C, %D1'
249 comment => "construct Eor: Eor(a, b) = Eor(b, a) = a EOR b",
250 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "general_purpose" ] },
251 emit => '. xor %S1, %S2, %D1'
256 comment => "construct Eor: Eor(a, const) = Eor(const, a) = a EOR const",
257 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
258 emit => '. xor %S1, %C, %D1'
261 # not commutative operations
265 comment => "construct Sub: Sub(a, b) = a - b",
266 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "general_purpose" ] },
267 emit => '. sub %S1, %S2, %D1'
272 comment => "construct Sub: Sub(a, const) = a - const",
273 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
274 emit => '. subl %S1, %C, %D1'
279 comment => "construct Shl: Shl(a, b) = a << b",
280 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "general_purpose" ] },
281 emit => '. shl %S1, %S2, %D1'
286 comment => "construct Shl: Shl(a, const) = a << const",
287 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
288 emit => '. shl %S1, %C, %D1'
293 comment => "construct Shr: Shr(a, b) = a >> b",
294 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "in_r1" ] },
295 emit => '. shr %S2, %D1'
300 comment => "construct Shr: Shr(a, const) = a >> const",
301 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
302 emit => '. shr %S1, %C, %D1'
307 comment => "construct RotR: RotR(a, b) = a ROTR b",
308 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "general_purpose" ] },
309 emit => '. ror %S1, %S2, %D1'
314 comment => "construct RotL: RotL(a, b) = a ROTL b",
315 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "general_purpose" ] },
316 emit => '. rol %S1, %S2, %D1'
321 comment => "construct RotL: RotL(a, const) = a ROTL const",
322 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
323 emit => '. rol %S1, %C, %D1'
328 comment => "construct Minus: Minus(a) = -a",
329 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
330 emit => '. neg %S1, %D1'
335 comment => "construct Increment: Inc(a) = a++",
336 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
337 emit => '. inc %S1, %D1'
342 comment => "construct Decrement: Dec(a) = a--",
343 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
344 emit => '. dec %S1, %D1'
350 comment => "construct Not: Not(a) = !a",
351 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
352 emit => '. not %S1, %D1'
360 comment => "represents an integer constant",
361 reg_req => { out => [ "general_purpose" ] },
362 emit => '. mov %C, %D1',
365 /* TODO: compare Const attributes */
375 state => "exc_pinned",
376 comment => "construct Load: Load(ptr, mem) = LD ptr -> reg",
377 reg_req => { in => [ "general_purpose", "none" ], out => [ "general_purpose" ] },
378 emit => '. mov (%S1), %D1'
384 state => "exc_pinned",
385 comment => "construct Store: Store(ptr, val, mem) = ST ptr,val",
386 reg_req => { in => [ "general_purpose", "general_purpose", "none" ] },
387 emit => '. movl %S2, (%S1)'
390 #--------------------------------------------------------#
393 # | |_| | ___ __ _| |_ _ __ ___ __| | ___ ___ #
394 # | _| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
395 # | | | | (_) | (_| | |_ | | | | (_) | (_| | __/\__ \ #
396 # |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
397 #--------------------------------------------------------#
399 # commutative operations
404 comment => "construct FP Add: Add(a, b) = Add(b, a) = a + b",
405 reg_req => { in => [ "floating_point", "floating_point" ], out => [ "floating_point" ] },
406 emit => '. fadd %S1, %S2, %D1'
411 comment => "construct FP Mul: Mul(a, b) = Mul(b, a) = a * b",
412 reg_req => { in => [ "floating_point", "floating_point" ], out => [ "floating_point" ] },
413 emit =>'. fmul %S1, %S2, %D1'
419 comment => "construct FP Max: Max(a, b) = Max(b, a) = a > b ? a : b",
420 reg_req => { in => [ "floating_point", "floating_point" ], out => [ "floating_point" ] },
421 emit =>'. fmax %S1, %S2, %D1'
427 comment => "construct FP Min: Min(a, b) = Min(b, a) = a < b ? a : b",
428 reg_req => { in => [ "floating_point", "floating_point" ], out => [ "floating_point" ] },
429 emit =>'. fmin %S1, %S2, %D1'
432 # not commutative operations
436 comment => "construct FP Sub: Sub(a, b) = a - b",
437 reg_req => { in => [ "floating_point", "floating_point" ], out => [ "floating_point" ] },
438 emit => '. fsub %S1, %S2, %D1'
442 comment => "construct FP Div: Div(a, b) = a / b",
443 reg_req => { in => [ "floating_point", "floating_point" ], out => [ "floating_point" ] },
444 emit => '. fdiv %S1, %S2, %D1'
449 comment => "construct FP Minus: Minus(a) = -a",
450 reg_req => { in => [ "floating_point" ], out => [ "floating_point" ] },
451 emit => '. fneg %S1, %D1'
459 comment => "represents a FP constant",
460 reg_req => { out => [ "floating_point" ] },
461 emit => '. fmov %C, %D1',
464 /* TODO: compare fConst attributes */
474 state => "exc_pinned",
475 comment => "construct FP Load: Load(ptr, mem) = LD ptr",
476 reg_req => { in => [ "general_purpose", "none" ], out => [ "floating_point" ] },
477 emit => '. fmov (%S1), %D1'
483 state => "exc_pinned",
484 comment => "construct Store: Store(ptr, val, mem) = ST ptr,val",
485 reg_req => { in => [ "general_purpose", "floating_point", "none" ] },
486 emit => '. fmov %S2, (%S1)'