3 # This is a template specification for the Firm-Backend
5 # the cpu architecture (ia32, ia64, mips, sparc, ppc, ...)
10 # The node description is done as a perl hash initializer with the
11 # following structure:
16 # op_flags => "N|L|C|X|I|F|Y|H|c|K",
17 # "arity" => "0|1|2|3 ... |variable|dynamic|any",
18 # "state" => "floats|pinned|mem_pinned|exc_pinned",
20 # { "type" => "type 1", "name" => "name 1" },
21 # { "type" => "type 2", "name" => "name 2" },
24 # "comment" => "any comment for constructor",
25 # reg_req => { in => [ "reg_class|register" ], out => [ "reg_class|register|in_rX" ] },
26 # "cmp_attr" => "c source code for comparing node attributes",
27 # emit => "emit code with templates",
28 # "rd_constructor" => "c source code which constructs an ir_node"
31 # ... # (all nodes you need to describe)
33 # ); # close the %nodes initializer
35 # op_flags: flags for the operation, OPTIONAL (default is "N")
36 # the op_flags correspond to the firm irop_flags:
39 # C irop_flag_commutative
40 # X irop_flag_cfopcode
41 # I irop_flag_ip_cfopcode
44 # H irop_flag_highlevel
45 # c irop_flag_constlike
50 # I ignore for register allocation
52 # state: state of the operation, OPTIONAL (default is "floats")
54 # arity: arity of the operation, MUST NOT BE OMITTED
56 # args: the OPTIONAL arguments of the node constructor (debug, irg and block
57 # are always the first 3 arguments and are always autmatically
59 # If this key is missing the following arguments will be created:
60 # for i = 1 .. arity: ir_node *op_i
63 # outs: if a node defines more than one output, the names of the projections
64 # nodes having outs having automatically the mode mode_T
66 # comment: OPTIONAL comment for the node constructor
68 # rd_constructor: for every operation there will be a
69 # new_rd_<arch>_<op-name> function with the arguments from above
70 # which creates the ir_node corresponding to the defined operation
71 # you can either put the complete source code of this function here
73 # This key is OPTIONAL. If omitted, the following constructor will
75 # if (!op_<arch>_<op-name>) assert(0);
79 # res = new_ir_node(db, irg, block, op_<arch>_<op-name>, mode, arity, in)
82 # NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3
86 # 1 - caller save (register must be saved by the caller of a function)
87 # 2 - callee save (register must be saved by the called function)
88 # 4 - ignore (do not assign this register)
89 # NOTE: Last entry of each class is the largest Firm-Mode a register can hold\
92 { name => "zero", type => 4+2 }, # always zero
93 { name => "at", type => 4 }, # reserved for assembler
94 { name => "v0", realname => "2", type => 1 }, # first return value
95 { name => "v1", realname => "3", type => 1 }, # second return value
96 { name => "a0", realname => "4", type => 1 }, # first argument
97 { name => "a1", realname => "5", type => 1 }, # second argument
98 { name => "a2", realname => "6", type => 1 }, # third argument
99 { name => "a3", realname => "7", type => 1 }, # fourth argument
100 { name => "t0", realname => "8", type => 1 },
101 { name => "t1", realname => "9", type => 1 },
102 { name => "t2", realname => "10", type => 1 },
103 { name => "t3", realname => "11", type => 1 },
104 { name => "t4", realname => "12", type => 1 },
105 { name => "t5", realname => "13", type => 1 },
106 { name => "t6", realname => "14", type => 1 },
107 { name => "t7", realname => "15", type => 1 },
108 { name => "s0", realname => "16", type => 2 },
109 { name => "s1", realname => "17", type => 2 },
110 { name => "s2", realname => "18", type => 2 },
111 { name => "s3", realname => "19", type => 2 },
112 { name => "s4", realname => "20", type => 2 },
113 { name => "s5", realname => "21", type => 2 },
114 { name => "s6", realname => "22", type => 2 },
115 { name => "s7", realname => "23", type => 2 },
116 { name => "t8", realname => "24", type => 1 },
117 { name => "t9", realname => "25", type => 1 },
118 { name => "kt0", type => 4 }, # reserved for OS
119 { name => "kt1", type => 4 }, # reserved for OS
120 { name => "gp", type => 4 }, # general purpose
121 { name => "sp", type => 4 }, # stack pointer
122 { name => "fp", type => 4 }, # frame pointer
123 { name => "ra", type => 2+1 }, # return address
124 { mode => "mode_Iu" }
129 S0 => "${arch}_emit_source_register(env, node, 0);",
130 S1 => "${arch}_emit_source_register(env, node, 1);",
131 S2 => "${arch}_emit_source_register(env, node, 2);",
132 D0 => "${arch}_emit_dest_register(env, node, 0);",
133 D1 => "${arch}_emit_dest_register(env, node, 1);",
134 D2 => "${arch}_emit_dest_register(env, node, 2);",
135 C => "${arch}_emit_immediate(env, node);",
136 JumpTarget => "${arch}_emit_jump_target(env, node);",
137 JumpTarget1 => "${arch}_emit_jump_target_proj(env, node, 1);",
138 JumpOrFallthrough => "${arch}_emit_jump_or_fallthrough(env, node, 0);",
142 #--------------------------------------------------#
145 # _ __ _____ __ _ _ __ ___ _ __ ___ #
146 # | '_ \ / _ \ \ /\ / / | | '__| / _ \| '_ \/ __| #
147 # | | | | __/\ V V / | | | | (_) | |_) \__ \ #
148 # |_| |_|\___| \_/\_/ |_|_| \___/| .__/|___/ #
151 #--------------------------------------------------#
155 #-----------------------------------------------------------------#
158 # _ _ __ | |_ ___ __ _ ___ _ __ _ __ ___ __| | ___ ___ #
159 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
160 # | | | | | || __/ (_| | __/ | | | | | (_) | (_| | __/\__ \ #
161 # |_|_| |_|\__\___|\__, |\___|_| |_| |_|\___/ \__,_|\___||___/ #
164 #-----------------------------------------------------------------#
166 # commutative operations
170 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
171 emit => '. addu %D0, %S0, %S1',
176 reg_req => { in => [ "gp" ], out => [ "gp" ] },
177 emit => '. addiu %D0, %S0, %C',
178 cmp_attr => 'return attr_a->tv != attr_b->tv;',
184 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
185 emit => '. and %D0, %S0, %S1',
190 reg_req => { in => [ "gp" ], out => [ "gp" ] },
191 emit => '. andi %D0, %S0, %C',
192 cmp_attr => 'return attr_a->tv != attr_b->tv;',
197 reg_req => { in => [ "gp", "gp" ], out => [ "none" ] },
198 emit => '. div %S0, %S1',
203 reg_req => { in => [ "gp", "gp" ], out => [ "none" ] },
204 emit => '. divu %S0, %S1',
210 reg_req => { in => [ "gp", "gp" ], out => [ "none" ] },
211 emit => '. mult %S0, %S1',
217 reg_req => { in => [ "gp", "gp" ], out => [ "none" ] },
218 emit => '. multu %S0, %S1',
224 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
225 emit => '. nor %D0, %S0, %S1',
230 reg_req => { in => [ "gp" ], out => [ "gp" ] },
231 emit => '. nor %D0, %S0, $zero',
237 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
238 emit => '. or %D0, %S0, %S1',
243 reg_req => { in => [ "gp" ], out => [ "gp" ] },
244 emit => '. ori %D0, %S0, %C',
245 cmp_attr => 'return attr_a->tv != attr_b->tv;',
250 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
252 if (mode_is_signed(get_irn_mode(node))) {
262 reg_req => { in => [ "gp" ], out => [ "gp" ] },
264 if (mode_is_signed(get_irn_mode(node))) {
274 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
275 emit => '. sra %D0, %S0, %S1',
280 reg_req => { in => [ "gp" ], out => [ "gp" ] },
281 emit => '. sra %D0, %S0, %C',
282 cmp_attr => 'return attr_a->tv != attr_b->tv;',
287 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
289 if (mode_is_signed(get_irn_mode(node))) {
299 reg_req => { in => [ "gp" ], out => [ "gp" ] },
301 if (mode_is_signed(get_irn_mode(node))) {
311 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
312 emit => '. srlv %D0, %S0, %S1',
317 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
318 emit => '. sllv %D0, %S0, %S1',
323 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
324 emit => '. subu %D0, %S0, %S1',
329 reg_req => { in => [ "gp" ], out => [ "gp" ] },
330 emit => '. subu %D0, $zero, %S0',
335 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
336 emit => '. xor %D0, %S0, %S1',
341 reg_req => { in => [ "gp" ], out => [ "gp" ] },
342 emit => '. xori %D0, %S0, %C',
343 cmp_attr => 'return attr_a->tv != attr_b->tv;',
348 # / ___|___ _ __ ___| |_ __ _ _ __ | |_ ___
349 # | | / _ \| '_ \/ __| __/ _` | '_ \| __/ __|
350 # | |__| (_) | | | \__ \ || (_| | | | | |_\__ \
351 # \____\___/|_| |_|___/\__\__,_|_| |_|\__|___/
354 # load upper imediate
357 reg_req => { out => [ "gp" ] },
358 emit => '. lui %D0, %C',
359 cmp_attr => 'return attr_a->tv != attr_b->tv;',
364 reg_req => { in => [ "none" ], out => [ "gp" ] },
365 emit => '. mflo %D0',
370 reg_req => { in => [ "none" ], out => [ "gp" ] },
371 emit => '. mfhi %D0',
379 reg_req => { out => [ "zero" ] },
386 # | __ ) _ __ __ _ _ __ ___| |__ / / | |_ _ _ __ ___ _ __
387 # | _ \| '__/ _` | '_ \ / __| '_ \ / / | | | | | '_ ` _ \| '_ \
388 # | |_) | | | (_| | | | | (__| | | |/ / |_| | |_| | | | | | | |_) |
389 # |____/|_| \__,_|_| |_|\___|_| |_/_/ \___/ \__,_|_| |_| |_| .__/
394 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
395 emit => '. slt %D0, %S0, %S1',
400 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
401 emit => '. sltu %D0, %S0, %S1',
406 reg_req => { in => [ "gp" ], out => [ "gp" ] },
407 emit => '. slti %D0, %S0, %C',
412 reg_req => { in => [ "gp" ], out => [ "gp" ] },
413 emit => '. slti %D0, %S0, %C',
419 reg_req => { in => [ "gp", "gp" ], out => [ "none", "none" ] },
420 outs => [ "false", "true" ],
421 emit => '. beq %S0, %S1, %JumpTarget1
422 . %JumpOrFallthrough'
427 reg_req => { in => [ "gp", "gp" ], out => [ "none", "none" ] },
428 outs => [ "false", "true" ],
429 emit => '. bne %S0, %S1, %JumpTarget1
430 . %JumpOrFallthrough'
435 reg_req => { in => [ "gp" ], out => [ "none", "none" ] },
436 outs => [ "false", "true" ],
437 emit => '. bgtz %S0, %JumpTarget1
438 . %JumpOrFallthrough'
443 reg_req => { in => [ "gp" ], out => [ "none", "none" ] },
444 outs => [ "false", "true" ],
445 emit => '. blez %S0, %JumpTarget1
446 . %JumpOrFallthrough'
451 reg_req => { in => [ ], out => [ "none" ] },
452 emit => '. b %JumpTarget',
458 reg_req => { in => [ "gp" ], out => [ "none" ] },
465 reg_req => { in => [ "gp" ], out => [ "none" ] },
470 # | | ___ __ _ __| | / / ___|| |_ ___ _ __ ___
471 # | | / _ \ / _` |/ _` | / /\___ \| __/ _ \| '__/ _ \
472 # | |__| (_) | (_| | (_| |/ / ___) | || (_) | | | __/
473 # |_____\___/ \__,_|\__,_/_/ |____/ \__\___/|_| \___|
478 state => "exc_pinned",
479 reg_req => { in => [ "none", "gp" ], out => [ "gp", "none" ] },
480 outs => [ "res", "M" ],
481 emit => '. lw %D0, %C(%S1)',
486 state => "exc_pinned",
487 reg_req => { in => [ "none", "gp" ], out => [ "gp", "none" ] },
488 outs => [ "res", "M" ],
489 emit => '. lh %D0, %C(%S1)',
494 state => "exc_pinned",
495 reg_req => { in => [ "none", "gp" ], out => [ "gp", "none" ] },
496 outs => [ "res", "M" ],
497 emit => '. lhu %D0, %C(%S1)',
502 state => "exc_pinned",
503 reg_req => { in => [ "none", "gp" ], out => [ "gp", "none" ] },
504 outs => [ "res", "M" ],
505 emit => '. lb %D0, %C(%S1)',
510 state => "exc_pinned",
511 reg_req => { in => [ "none", "gp" ], out => [ "gp", "none" ] },
512 outs => [ "res", "M" ],
513 emit => '. lbu %D0, %C(%S1)',
518 state => "exc_pinned",
519 reg_req => { in => [ "none", "gp", "gp" ], out => [ "none" ] },
520 emit => '. sw %S2, %C(%S1)',
526 state => "exc_pinned",
527 reg_req => { in => [ "none", "gp", "gp" ], out => [ "none" ] },
528 emit => '. sh %S2, %C(%S1)',
534 state => "exc_pinned",
535 reg_req => { in => [ "none", "gp", "gp" ], out => [ "none" ] },
536 emit => '. sb %S2, %C(%S1)',
541 reg_req => { in => [ "gp" ], out => [ "gp" ] },
542 emit => '. move %D0, %S0',
552 reg_req => { in => [], out => [ "none" ] },