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 # rd_constructor => "c source code which constructs an ir_node" # optional
36 # ... # (all nodes you need to describe)
38 # ); # close the %nodes initializer
40 # op_flags: flags for the operation, OPTIONAL (default is "N")
41 # the op_flags correspond to the firm irop_flags:
44 # C irop_flag_commutative
45 # X irop_flag_cfopcode
46 # I irop_flag_ip_cfopcode
49 # H irop_flag_highlevel
50 # c irop_flag_constlike
53 # irn_flags: special node flags, OPTIONAL (default is 0)
54 # following irn_flags are supported:
57 # I ignore for register allocation
59 # state: state of the operation, OPTIONAL (default is "floats")
61 # arity: arity of the operation, MUST NOT BE OMITTED
63 # args: the OPTIONAL arguments of the node constructor (debug, irg and block
64 # are always the first 3 arguments and are always autmatically
66 # If this key is missing the following arguments will be created:
67 # for i = 1 .. arity: ir_node *op_i
70 # outs: if a node defines more than one output, the names of the projections
71 # nodes having outs having automatically the mode mode_T
73 # comment: OPTIONAL comment for the node constructor
75 # rd_constructor: for every operation there will be a
76 # new_rd_<arch>_<op-name> function with the arguments from above
77 # which creates the ir_node corresponding to the defined operation
78 # you can either put the complete source code of this function here
80 # This key is OPTIONAL. If omitted, the following constructor will
82 # if (!op_<arch>_<op-name>) assert(0);
86 # res = new_ir_node(db, irg, block, op_<arch>_<op-name>, mode, arity, in)
89 # NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3
93 # 1 - caller save (register must be saved by the caller of a function)
94 # 2 - callee save (register must be saved by the called function)
95 # 4 - ignore (do not assign this register)
96 # NOTE: Last entry of each class is the largest Firm-Mode a register can hold
99 { name => "r0", type => 1 },
100 { name => "r1", type => 1 },
101 { name => "r2", type => 1 },
102 { name => "r3", type => 1 },
103 { name => "r4", type => 1 },
104 { name => "r5", type => 1 },
105 { name => "r6", type => 1 },
106 { name => "r7", type => 2 },
107 { name => "r8", type => 2 },
108 { name => "r9", type => 2 },
109 { name => "r10", type => 2 },
110 { name => "r11", type => 2 },
111 { name => "r12", type => 2 },
112 { name => "r13", type => 2 },
113 { name => "sp", realname => "r14", type => 4 }, # this is our stackpointer
114 { name => "bp", realname => "r15", type => 4 }, # this is out basepointer
115 { mode => "mode_Iu" }
118 { name => "f0", type => 1 },
119 { name => "f1", type => 1 },
120 { name => "f2", type => 1 },
121 { name => "f3", type => 1 },
122 { name => "f4", type => 1 },
123 { name => "f5", type => 1 },
124 { name => "f6", type => 1 },
125 { name => "f7", type => 1 },
126 { name => "f8", type => 1 },
127 { name => "f9", type => 1 },
128 { name => "f10", type => 1 },
129 { name => "f11", type => 1 },
130 { name => "f12", type => 1 },
131 { name => "f13", type => 1 },
132 { name => "f14", type => 1 },
133 { name => "f15", type => 1 },
139 S1 => "${arch}_emit_source_register(env, node, 0);",
140 S2 => "${arch}_emit_source_register(env, node, 1);",
141 S3 => "${arch}_emit_source_register(env, node, 2);",
142 S4 => "${arch}_emit_source_register(env, node, 3);",
143 S5 => "${arch}_emit_source_register(env, node, 4);",
144 S6 => "${arch}_emit_source_register(env, node, 5);",
145 D1 => "${arch}_emit_dest_register(env, node, 0);",
146 D2 => "${arch}_emit_dest_register(env, node, 1);",
147 D3 => "${arch}_emit_dest_register(env, node, 2);",
148 D4 => "${arch}_emit_dest_register(env, node, 3);",
149 D5 => "${arch}_emit_dest_register(env, node, 4);",
150 D6 => "${arch}_emit_dest_register(env, node, 5);",
151 C => "${arch}_emit_immediate(env, node);"
154 #--------------------------------------------------#
157 # _ __ _____ __ _ _ __ ___ _ __ ___ #
158 # | '_ \ / _ \ \ /\ / / | | '__| / _ \| '_ \/ __| #
159 # | | | | __/\ V V / | | | | (_) | |_) \__ \ #
160 # |_| |_|\___| \_/\_/ |_|_| \___/| .__/|___/ #
163 #--------------------------------------------------#
167 #-----------------------------------------------------------------#
170 # _ _ __ | |_ ___ __ _ ___ _ __ _ __ ___ __| | ___ ___ #
171 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
172 # | | | | | || __/ (_| | __/ | | | | | (_) | (_| | __/\__ \ #
173 # |_|_| |_|\__\___|\__, |\___|_| |_| |_|\___/ \__,_|\___||___/ #
176 #-----------------------------------------------------------------#
178 # commutative operations
183 comment => "construct Add: Add(a, b) = Add(b, a) = a + b",
184 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "general_purpose" ] },
185 emit => '. add %S1, %S2, %D1'
190 comment => "construct Add: Add(a, const) = Add(const, a) = a + const",
191 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
192 emit => '. add %S1, %C, %D1'
198 comment => "construct Mul: Mul(a, b) = Mul(b, a) = a * b",
199 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "general_purpose" ] },
200 emit =>'. mul %S1, %S2, %D1'
205 comment => "construct Mul: Mul(a, const) = Mul(const, a) = a * const",
206 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
207 emit => '. mul %S1, %C, %D1'
213 comment => "construct And: And(a, b) = And(b, a) = a AND b",
214 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "general_purpose" ] },
215 emit => '. and %S1, %S2, %D1'
220 comment => "construct And: And(a, const) = And(const, a) = a AND const",
221 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
222 emit => '. and %S1, %C, %D1'
228 comment => "construct Or: Or(a, b) = Or(b, a) = a OR b",
229 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "general_purpose" ] },
230 emit => '. or %S1, %S2, %D1'
236 comment => "construct Or: Or(a, const) = Or(const, a) = a OR const",
237 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
238 emit => '. or %S1, %C, %D1'
244 comment => "construct Eor: Eor(a, b) = Eor(b, a) = a EOR b",
245 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "general_purpose" ] },
246 emit => '. xor %S1, %S2, %D1'
251 comment => "construct Eor: Eor(a, const) = Eor(const, a) = a EOR const",
252 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
253 emit => '. xor %S1, %C, %D1'
256 # not commutative operations
260 comment => "construct Sub: Sub(a, b) = a - b",
261 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "general_purpose" ] },
262 emit => '. sub %S1, %S2, %D1'
267 comment => "construct Sub: Sub(a, const) = a - const",
268 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
269 emit => '. subl %S1, %C, %D1'
274 comment => "construct Shl: Shl(a, b) = a << b",
275 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "general_purpose" ] },
276 emit => '. shl %S1, %S2, %D1'
281 comment => "construct Shl: Shl(a, const) = a << const",
282 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
283 emit => '. shl %S1, %C, %D1'
288 comment => "construct Shr: Shr(a, b) = a >> b",
289 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "in_r1" ] },
290 emit => '. shr %S2, %D1'
295 comment => "construct Shr: Shr(a, const) = a >> const",
296 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
297 emit => '. shr %S1, %C, %D1'
302 comment => "construct RotR: RotR(a, b) = a ROTR b",
303 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "general_purpose" ] },
304 emit => '. ror %S1, %S2, %D1'
309 comment => "construct RotL: RotL(a, b) = a ROTL b",
310 reg_req => { in => [ "general_purpose", "general_purpose" ], out => [ "general_purpose" ] },
311 emit => '. rol %S1, %S2, %D1'
316 comment => "construct RotL: RotL(a, const) = a ROTL const",
317 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
318 emit => '. rol %S1, %C, %D1'
323 comment => "construct Minus: Minus(a) = -a",
324 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
325 emit => '. neg %S1, %D1'
330 comment => "construct Increment: Inc(a) = a++",
331 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
332 emit => '. inc %S1, %D1'
337 comment => "construct Decrement: Dec(a) = a--",
338 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
339 emit => '. dec %S1, %D1'
345 comment => "construct Not: Not(a) = !a",
346 reg_req => { in => [ "general_purpose" ], out => [ "general_purpose" ] },
347 emit => '. not %S1, %D1'
355 comment => "represents an integer constant",
356 reg_req => { out => [ "general_purpose" ] },
357 emit => '. mov %C, %D1',
360 /* TODO: compare Const attributes */
370 state => "exc_pinned",
371 comment => "construct Load: Load(ptr, mem) = LD ptr -> reg",
372 reg_req => { in => [ "general_purpose", "none" ], out => [ "general_purpose" ] },
373 emit => '. mov (%S1), %D1'
379 state => "exc_pinned",
380 comment => "construct Store: Store(ptr, val, mem) = ST ptr,val",
381 reg_req => { in => [ "general_purpose", "general_purpose", "none" ] },
382 emit => '. movl %S2, (%S1)'
385 #--------------------------------------------------------#
388 # | |_| | ___ __ _| |_ _ __ ___ __| | ___ ___ #
389 # | _| |/ _ \ / _` | __| | '_ \ / _ \ / _` |/ _ \/ __| #
390 # | | | | (_) | (_| | |_ | | | | (_) | (_| | __/\__ \ #
391 # |_| |_|\___/ \__,_|\__| |_| |_|\___/ \__,_|\___||___/ #
392 #--------------------------------------------------------#
394 # commutative operations
399 comment => "construct FP Add: Add(a, b) = Add(b, a) = a + b",
400 reg_req => { in => [ "floating_point", "floating_point" ], out => [ "floating_point" ] },
401 emit => '. fadd %S1, %S2, %D1'
406 comment => "construct FP Mul: Mul(a, b) = Mul(b, a) = a * b",
407 reg_req => { in => [ "floating_point", "floating_point" ], out => [ "floating_point" ] },
408 emit =>'. fmul %S1, %S2, %D1'
414 comment => "construct FP Max: Max(a, b) = Max(b, a) = a > b ? a : b",
415 reg_req => { in => [ "floating_point", "floating_point" ], out => [ "floating_point" ] },
416 emit =>'. fmax %S1, %S2, %D1'
422 comment => "construct FP Min: Min(a, b) = Min(b, a) = a < b ? a : b",
423 reg_req => { in => [ "floating_point", "floating_point" ], out => [ "floating_point" ] },
424 emit =>'. fmin %S1, %S2, %D1'
427 # not commutative operations
431 comment => "construct FP Sub: Sub(a, b) = a - b",
432 reg_req => { in => [ "floating_point", "floating_point" ], out => [ "floating_point" ] },
433 emit => '. fsub %S1, %S2, %D1'
437 comment => "construct FP Div: Div(a, b) = a / b",
438 reg_req => { in => [ "floating_point", "floating_point" ], out => [ "floating_point" ] },
439 emit => '. fdiv %S1, %S2, %D1'
444 comment => "construct FP Minus: Minus(a) = -a",
445 reg_req => { in => [ "floating_point" ], out => [ "floating_point" ] },
446 emit => '. fneg %S1, %D1'
454 comment => "represents a FP constant",
455 reg_req => { out => [ "floating_point" ] },
456 emit => '. fmov %C, %D1',
459 /* TODO: compare fConst attributes */
469 state => "exc_pinned",
470 comment => "construct FP Load: Load(ptr, mem) = LD ptr",
471 reg_req => { in => [ "general_purpose", "none" ], out => [ "floating_point" ] },
472 emit => '. fmov (%S1), %D1'
478 state => "exc_pinned",
479 comment => "construct Store: Store(ptr, val, mem) = ST ptr,val",
480 reg_req => { in => [ "general_purpose", "floating_point", "none" ] },
481 emit => '. fmov %S2, (%S1)'