3 # This is a template specification for the Firm-Backend
5 # the cpu architecture (ia32, ia64, mips, sparc, ppc, ...)
9 # this string marks the beginning of a comment in emit
10 $comment_string = "/*";
12 # The node description is done as a perl hash initializer with the
13 # following structure:
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",
23 # { "type" => "type 1", "name" => "name 1" },
24 # { "type" => "type 2", "name" => "name 2" },
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"
34 # ... # (all nodes you need to describe)
36 # ); # close the %nodes initializer
38 # op_flags: flags for the operation, OPTIONAL (default is "N")
39 # the op_flags correspond to the firm irop_flags:
42 # C irop_flag_commutative
43 # X irop_flag_cfopcode
44 # I irop_flag_ip_cfopcode
47 # H irop_flag_highlevel
48 # c irop_flag_constlike
51 # irn_flags: special node flags, OPTIONAL (default is 0)
52 # following irn_flags are supported:
55 # I ignore for register allocation
57 # state: state of the operation, OPTIONAL (default is "floats")
59 # arity: arity of the operation, MUST NOT BE OMITTED
61 # args: the OPTIONAL arguments of the node constructor (debug, irg and block
62 # are always the first 3 arguments and are always autmatically
64 # If this key is missing the following arguments will be created:
65 # for i = 1 .. arity: ir_node *op_i
68 # comment: OPTIONAL comment for the node constructor
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
75 # This key is OPTIONAL. If omitted, the following constructor will
77 # if (!op_<arch>_<op-name>) assert(0);
81 # res = new_ir_node(db, irg, block, op_<arch>_<op-name>, mode, arity, in)
84 # NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3
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
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" }
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" }
133 #--------------------------------------------------#
136 # _ __ _____ __ _ _ __ ___ _ __ ___ #
137 # | '_ \ / _ \ \ /\ / / | | '__| / _ \| '_ \/ __| #
138 # | | | | __/\ V V / | | | | (_) | |_) \__ \ #
139 # |_| |_|\___| \_/\_/ |_|_| \___/| .__/|___/ #
142 #--------------------------------------------------#
146 #-----------------------------------------------------------------#
149 # _ _ __ | |_ ___ __ _ ___ _ __ _ __ ___ __| | ___ ___ #
150 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
151 # | | | | | || __/ (_| | __/ | | | | | (_) | (_| | __/\__ \ #
152 # |_|_| |_|\__\___|\__, |\___|_| |_| |_|\___/ \__,_|\___||___/ #
155 #-----------------------------------------------------------------#
157 # commutative operations
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) */'
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) */'
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) */'
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) */'
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) */'
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) */'
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) */'
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) */'
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) */'
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) */'
235 # not commutative operations
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) */'
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) */'
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) */'
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) */'
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) */'
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) */'
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) */'
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) */'
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) */'
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) */'
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) */'
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) */'
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) */'
334 "comment" => "represents an integer constant",
335 "reg_req" => { "out" => [ "general_purpose" ] },
336 "emit" => '. mov %C, %D1\t\t\t/* Mov Const into register */',
339 /* TODO: compare Const attributes */
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) */'
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) */'
364 #--------------------------------------------------------#
367 # | |_| | ___ __ _| |_ _ __ ___ __| | ___ ___ #
368 # | _| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
369 # | | | | (_) | (_| | |_ | | | | (_) | (_| | __/\__ \ #
370 # |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
371 #--------------------------------------------------------#
373 # commutative operations
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 */'
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 */'
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 */'
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 */'
406 # not commutative operations
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 */'
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 */'
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 */'
433 "comment" => "represents a FP constant",
434 "reg_req" => { "out" => [ "floating_point" ] },
435 "emit" => '. fmov %C, %D1\t\t\t/* Mov fConst into register */',
438 /* TODO: compare fConst attributes */
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 */'
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) */'