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);",
141 #--------------------------------------------------#
144 # _ __ _____ __ _ _ __ ___ _ __ ___ #
145 # | '_ \ / _ \ \ /\ / / | | '__| / _ \| '_ \/ __| #
146 # | | | | __/\ V V / | | | | (_) | |_) \__ \ #
147 # |_| |_|\___| \_/\_/ |_|_| \___/| .__/|___/ #
150 #--------------------------------------------------#
154 #-----------------------------------------------------------------#
157 # _ _ __ | |_ ___ __ _ ___ _ __ _ __ ___ __| | ___ ___ #
158 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
159 # | | | | | || __/ (_| | __/ | | | | | (_) | (_| | __/\__ \ #
160 # |_|_| |_|\__\___|\__, |\___|_| |_| |_|\___/ \__,_|\___||___/ #
163 #-----------------------------------------------------------------#
165 # commutative operations
169 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
170 emit => '. addu %D1, %S1, %S2',
175 reg_req => { in => [ "gp" ], out => [ "gp" ] },
176 emit => '. addiu %D1, %S1, %C',
177 cmp_attr => 'return attr_a->tv != attr_b->tv;',
183 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
184 emit => '. and %D1, %S1, %S2',
189 reg_req => { in => [ "gp" ], out => [ "gp" ] },
190 emit => '. andi %D1, %S1, %C',
191 cmp_attr => 'return attr_a->tv != attr_b->tv;',
196 reg_req => { in => [ "gp", "gp" ], out => [ "none" ] },
197 emit => '. div %S1, %S2',
202 reg_req => { in => [ "gp", "gp" ], out => [ "none" ] },
203 emit => '. divu %S1, %S2',
209 reg_req => { in => [ "gp", "gp" ], out => [ "none" ] },
210 emit => '. mult %S1, %S2',
216 reg_req => { in => [ "gp", "gp" ], out => [ "none" ] },
217 emit => '. multu %S1, %S2',
223 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
224 emit => '. nor %D1, %S1, %S2',
229 reg_req => { in => [ "gp" ], out => [ "gp" ] },
230 emit => '. nor %D1, %S1, $zero',
236 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
237 emit => '. or %D1, %S1, %S2',
242 reg_req => { in => [ "gp" ], out => [ "gp" ] },
243 emit => '. ori %D1, %S1, %C',
244 cmp_attr => 'return attr_a->tv != attr_b->tv;',
249 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
251 if (mode_is_signed(get_irn_mode(node))) {
261 reg_req => { in => [ "gp" ], out => [ "gp" ] },
263 if (mode_is_signed(get_irn_mode(node))) {
273 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
274 emit => '. sra %D1, %S1, %S2',
279 reg_req => { in => [ "gp" ], out => [ "gp" ] },
280 emit => '. sra %D1, %S1, %C',
281 cmp_attr => 'return attr_a->tv != attr_b->tv;',
286 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
288 if (mode_is_signed(get_irn_mode(node))) {
298 reg_req => { in => [ "gp" ], out => [ "gp" ] },
300 if (mode_is_signed(get_irn_mode(node))) {
310 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
311 emit => '. srlv %D1, %S1, %S2',
316 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
317 emit => '. sllv %D1, %S1, %S2',
322 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
323 emit => '. subu %D1, %S1, %S2',
328 reg_req => { in => [ "gp" ], out => [ "gp" ] },
329 emit => '. subu %D1, $zero, %S1',
334 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
335 emit => '. xor %D1, %S1, %S2',
340 reg_req => { in => [ "gp" ], out => [ "gp" ] },
341 emit => '. xori %D1, %S1, %C',
342 cmp_attr => 'return attr_a->tv != attr_b->tv;',
347 # / ___|___ _ __ ___| |_ __ _ _ __ | |_ ___
348 # | | / _ \| '_ \/ __| __/ _` | '_ \| __/ __|
349 # | |__| (_) | | | \__ \ || (_| | | | | |_\__ \
350 # \____\___/|_| |_|___/\__\__,_|_| |_|\__|___/
353 # load upper imediate
356 reg_req => { out => [ "gp" ] },
357 emit => '. lui %D1, %C',
358 cmp_attr => 'return attr_a->tv != attr_b->tv;',
362 # load lower immediate
365 reg_req => { in => [ "gp" ], out => [ "gp" ] },
366 emit => '. ori %D1, %S1, %C',
367 cmp_attr => 'return attr_a->tv != attr_b->tv;',
373 reg_req => { out => [ "gp" ] },
374 emit => '. la %D1, %C',
375 cmp_attr => 'return attr_a->symconst_id != attr_b->symconst_id;',
380 reg_req => { in => [ "none" ], out => [ "gp" ] },
381 emit => '. mflo %D1',
386 reg_req => { in => [ "none" ], out => [ "gp" ] },
387 emit => '. mfhi %D1',
392 reg_req => { out => [ "zero" ] },
399 # | __ ) _ __ __ _ _ __ ___| |__ / / | |_ _ _ __ ___ _ __
400 # | _ \| '__/ _` | '_ \ / __| '_ \ / / | | | | | '_ ` _ \| '_ \
401 # | |_) | | | (_| | | | | (__| | | |/ / |_| | |_| | | | | | | |_) |
402 # |____/|_| \__,_|_| |_|\___|_| |_/_/ \___/ \__,_|_| |_| |_| .__/
407 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
409 if (mode_is_signed(get_irn_mode(node))) {
420 reg_req => { in => [ "gp" ], out => [ "gp" ] },
422 if (mode_is_signed(get_irn_mode(node))) {
429 cmp_attr => 'return attr_a->tv != attr_b->tv;',
436 reg_req => { in => [ "gp", "gp" ], out => [ "in_r0", "none" ] },
437 emit => '. beq %S1, %S2, %JumpTarget1'
443 reg_req => { in => [ "gp", "gp" ], out => [ "in_r0", "none" ] },
444 emit => '. bne %S1, %S2, %JumpTarget1'
450 reg_req => { in => [ "gp" ], out => [ "in_r0", "none" ] },
451 emit => '. bgtz %S1, %JumpTarget1'
457 reg_req => { in => [ "gp" ], out => [ "in_r0", "none" ] },
458 emit => '. blez %S1, %JumpTarget1'
463 reg_req => { in => [ "gp" ] },
470 reg_req => { in => [ ], out => [ "none" ] },
471 emit => '. b %JumpTarget'
477 reg_req => { in => [ ], out => [ "none" ] },
478 emit => '. /* fallthrough to %JumpTarget */'
484 reg_req => { in => [ "gp" ], out => [ "none" ] },
490 # | | / _ \ / _` |/ _` |
491 # | |__| (_) | (_| | (_| |
492 # |_____\___/ \__,_|\__,_|
496 reg_req => { in => [ "none", "gp" ], out => [ "none", "none", "gp" ] },
498 mips_attr_t* attr = get_mips_attr(node);
501 mode = attr->modes.load_store_mode;
503 switch (get_mode_size_bits(mode)) {
505 if (mode_is_signed(mode)) {
512 if (mode_is_signed(mode)) {
522 assert(! "Only 8, 16 and 32 bit loads supported");
526 cmp_attr => 'return attr_a->tv != attr_b->tv || attr_a->stack_entity != attr_b->stack_entity;',
531 # | | ___ __ _ __| | / / ___|| |_ ___ _ __ ___
532 # | | / _ \ / _` |/ _` | / /\___ \| __/ _ \| '__/ _ \
533 # | |__| (_) | (_| | (_| |/ / ___) | || (_) | | | __/
534 # |_____\___/ \__,_|\__,_/_/ |____/ \__\___/|_| \___|
538 reg_req => { in => [ "none", "gp", "gp" ], out => [ "none", "none" ] },
540 mips_attr_t* attr = get_mips_attr(node);
543 mode = attr->modes.load_store_mode;
545 switch (get_mode_size_bits(mode)) {
547 if (mode_is_signed(mode))
551 if (mode_is_signed(mode))
558 assert(! "Only 8, 16 and 32 bit stores supported");
562 cmp_attr => 'return attr_a->tv != attr_b->tv;',
566 reg_req => { in => [ "none", "none", "gp" ], out => [ "none", "none" ] },
568 mips_attr_t* attr = get_mips_attr(node);
571 mode = attr->modes.load_store_mode;
573 switch (get_mode_size_bits(mode)) {
584 assert(! "Only 8, 16 and 32 bit stores supported");
588 cmp_attr => 'return attr_a->stack_entity != attr_b->stack_entity;',
592 reg_req => { in => [ "gp" ], out => [ "gp" ] },
593 emit => '. move %D1, %S1',
601 reinterpret_conv => {
602 reg_req => { in => [ "gp" ], out => [ "in_r1" ] },
603 emit => '. # reinterpret %S1 -> %D1',
613 reg_req => { in => [], out => [ "none" ] },