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 S1 => "${arch}_emit_source_register(env, node, 0);",
130 S2 => "${arch}_emit_source_register(env, node, 1);",
131 S3 => "${arch}_emit_source_register(env, node, 2);",
132 D1 => "${arch}_emit_dest_register(env, node, 0);",
133 D2 => "${arch}_emit_dest_register(env, node, 1);",
134 D3 => "${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 #--------------------------------------------------#
153 $default_cmp_attr = "return mips_compare_attr(attr_a, attr_b);";
157 #-----------------------------------------------------------------#
160 # _ _ __ | |_ ___ __ _ ___ _ __ _ __ ___ __| | ___ ___ #
161 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
162 # | | | | | || __/ (_| | __/ | | | | | (_) | (_| | __/\__ \ #
163 # |_|_| |_|\__\___|\__, |\___|_| |_| |_|\___/ \__,_|\___||___/ #
166 #-----------------------------------------------------------------#
168 # commutative operations
172 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
173 emit => '. addu %D1, %S1, %S2',
178 reg_req => { in => [ "gp" ], out => [ "gp" ] },
179 emit => '. addiu %D1, %S1, %C',
180 cmp_attr => 'return attr_a->tv != attr_b->tv;',
186 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
187 emit => '. and %D1, %S1, %S2',
192 reg_req => { in => [ "gp" ], out => [ "gp" ] },
193 emit => '. andi %D1, %S1, %C',
194 cmp_attr => 'return attr_a->tv != attr_b->tv;',
199 reg_req => { in => [ "gp", "gp" ], out => [ "none" ] },
200 emit => '. div %S1, %S2',
205 reg_req => { in => [ "gp", "gp" ], out => [ "none" ] },
206 emit => '. divu %S1, %S2',
212 reg_req => { in => [ "gp", "gp" ], out => [ "none" ] },
213 emit => '. mult %S1, %S2',
219 reg_req => { in => [ "gp", "gp" ], out => [ "none" ] },
220 emit => '. multu %S1, %S2',
226 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
227 emit => '. nor %D1, %S1, %S2',
232 reg_req => { in => [ "gp" ], out => [ "gp" ] },
233 emit => '. nor %D1, %S1, $zero',
239 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
240 emit => '. or %D1, %S1, %S2',
245 reg_req => { in => [ "gp" ], out => [ "gp" ] },
246 emit => '. ori %D1, %S1, %C',
247 cmp_attr => 'return attr_a->tv != attr_b->tv;',
252 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
254 if (mode_is_signed(get_irn_mode(node))) {
264 reg_req => { in => [ "gp" ], out => [ "gp" ] },
266 if (mode_is_signed(get_irn_mode(node))) {
276 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
277 emit => '. sra %D1, %S1, %S2',
282 reg_req => { in => [ "gp" ], out => [ "gp" ] },
283 emit => '. sra %D1, %S1, %C',
284 cmp_attr => 'return attr_a->tv != attr_b->tv;',
289 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
291 if (mode_is_signed(get_irn_mode(node))) {
301 reg_req => { in => [ "gp" ], out => [ "gp" ] },
303 if (mode_is_signed(get_irn_mode(node))) {
313 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
314 emit => '. srlv %D1, %S1, %S2',
319 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
320 emit => '. sllv %D1, %S1, %S2',
325 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
326 emit => '. subu %D1, %S1, %S2',
331 reg_req => { in => [ "gp" ], out => [ "gp" ] },
332 emit => '. subu %D1, $zero, %S1',
337 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
338 emit => '. xor %D1, %S1, %S2',
343 reg_req => { in => [ "gp" ], out => [ "gp" ] },
344 emit => '. xori %D1, %S1, %C',
345 cmp_attr => 'return attr_a->tv != attr_b->tv;',
350 # / ___|___ _ __ ___| |_ __ _ _ __ | |_ ___
351 # | | / _ \| '_ \/ __| __/ _` | '_ \| __/ __|
352 # | |__| (_) | | | \__ \ || (_| | | | | |_\__ \
353 # \____\___/|_| |_|___/\__\__,_|_| |_|\__|___/
356 # load upper imediate
359 reg_req => { out => [ "gp" ] },
360 emit => '. lui %D1, %C',
361 cmp_attr => 'return attr_a->tv != attr_b->tv;',
366 reg_req => { in => [ "none" ], out => [ "gp" ] },
367 emit => '. mflo %D1',
372 reg_req => { in => [ "none" ], out => [ "gp" ] },
373 emit => '. mfhi %D1',
381 reg_req => { out => [ "zero" ] },
388 # | __ ) _ __ __ _ _ __ ___| |__ / / | |_ _ _ __ ___ _ __
389 # | _ \| '__/ _` | '_ \ / __| '_ \ / / | | | | | '_ ` _ \| '_ \
390 # | |_) | | | (_| | | | | (__| | | |/ / |_| | |_| | | | | | | |_) |
391 # |____/|_| \__,_|_| |_|\___|_| |_/_/ \___/ \__,_|_| |_| |_| .__/
396 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
397 emit => '. slt %D1, %S1, %S2',
402 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
403 emit => '. sltu %D1, %S1, %S2',
408 reg_req => { in => [ "gp" ], out => [ "gp" ] },
409 emit => '. slti %D1, %S1, %C',
414 reg_req => { in => [ "gp" ], out => [ "gp" ] },
415 emit => '. slti %D1, %S1, %C',
421 reg_req => { in => [ "gp", "gp" ], out => [ "none", "none" ] },
422 outs => [ "false", "true" ],
423 emit => '. beq %S1, %S2, %JumpTarget1
424 . %JumpOrFallthrough'
429 reg_req => { in => [ "gp", "gp" ], out => [ "none", "none" ] },
430 outs => [ "false", "true" ],
431 emit => '. bne %S1, %S2, %JumpTarget1
432 . %JumpOrFallthrough'
437 reg_req => { in => [ "gp" ], out => [ "none", "none" ] },
438 outs => [ "false", "true" ],
439 emit => '. bgtz %S1, %JumpTarget1
440 . %JumpOrFallthrough'
445 reg_req => { in => [ "gp" ], out => [ "none", "none" ] },
446 outs => [ "false", "true" ],
447 emit => '. blez %S1, %JumpTarget1
448 . %JumpOrFallthrough'
453 reg_req => { in => [ ], out => [ "none" ] },
454 emit => '. b %JumpTarget',
460 reg_req => { in => [ "gp" ], out => [ "none" ] },
467 reg_req => { in => [ "gp" ], out => [ "none" ] },
472 # | | ___ __ _ __| | / / ___|| |_ ___ _ __ ___
473 # | | / _ \ / _` |/ _` | / /\___ \| __/ _ \| '__/ _ \
474 # | |__| (_) | (_| | (_| |/ / ___) | || (_) | | | __/
475 # |_____\___/ \__,_|\__,_/_/ |____/ \__\___/|_| \___|
480 state => "exc_pinned",
481 reg_req => { in => [ "none", "gp" ], out => [ "gp", "none" ] },
482 outs => [ "res", "M" ],
483 emit => '. lw %D1, %C(%S2)',
488 state => "exc_pinned",
489 reg_req => { in => [ "none", "gp" ], out => [ "gp", "none" ] },
490 outs => [ "res", "M" ],
491 emit => '. lh %D1, %C(%S2)',
496 state => "exc_pinned",
497 reg_req => { in => [ "none", "gp" ], out => [ "gp", "none" ] },
498 outs => [ "res", "M" ],
499 emit => '. lhu %D1, %C(%S2)',
504 state => "exc_pinned",
505 reg_req => { in => [ "none", "gp" ], out => [ "gp", "none" ] },
506 outs => [ "res", "M" ],
507 emit => '. lb %D1, %C(%S2)',
512 state => "exc_pinned",
513 reg_req => { in => [ "none", "gp" ], out => [ "gp", "none" ] },
514 outs => [ "res", "M" ],
515 emit => '. lbu %D1, %C(%S2)',
520 state => "exc_pinned",
521 reg_req => { in => [ "none", "gp", "gp" ], out => [ "none" ] },
522 emit => '. sw %S3, %C(%S2)',
528 state => "exc_pinned",
529 reg_req => { in => [ "none", "gp", "gp" ], out => [ "none" ] },
530 emit => '. sh %S3, %C(%S2)',
536 state => "exc_pinned",
537 reg_req => { in => [ "none", "gp", "gp" ], out => [ "none" ] },
538 emit => '. sb %S3, %C(%S2)',
543 reg_req => { in => [ "gp" ], out => [ "gp" ] },
544 emit => '. move %D1, %S1',
554 reg_req => { in => [], out => [ "none" ] },