3 # This is a template specification for the Firm-Backend
5 # the cpu architecture (ia32, ia64, mips, sparc, ppc, ...)
9 # this strings mark the beginning and the end of a comment in emit
10 $comment_string = "#";
11 $comment_string_end = "";
13 # The node description is done as a perl hash initializer with the
14 # following structure:
19 # op_flags => "N|L|C|X|I|F|Y|H|c|K",
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
53 # I ignore for register allocation
55 # state: state of the operation, OPTIONAL (default is "floats")
57 # arity: arity of the operation, MUST NOT BE OMITTED
59 # args: the OPTIONAL arguments of the node constructor (debug, irg and block
60 # are always the first 3 arguments and are always autmatically
62 # If this key is missing the following arguments will be created:
63 # for i = 1 .. arity: ir_node *op_i
66 # outs: if a node defines more than one output, the names of the projections
67 # nodes having outs having automatically the mode mode_T
69 # comment: OPTIONAL comment for the node constructor
71 # rd_constructor: for every operation there will be a
72 # new_rd_<arch>_<op-name> function with the arguments from above
73 # which creates the ir_node corresponding to the defined operation
74 # you can either put the complete source code of this function here
76 # This key is OPTIONAL. If omitted, the following constructor will
78 # if (!op_<arch>_<op-name>) assert(0);
82 # res = new_ir_node(db, irg, block, op_<arch>_<op-name>, mode, arity, in)
85 # NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3
89 # 1 - caller save (register must be saved by the caller of a function)
90 # 2 - callee save (register must be saved by the called function)
91 # 4 - ignore (do not assign this register)
92 # NOTE: Last entry of each class is the largest Firm-Mode a register can hold\
95 { name => "zero", type => 4+2 }, # always zero
96 { name => "at", type => 4 }, # reserved for assembler
97 { name => "v0", type => 1 }, # first return value
98 { name => "v1", type => 1 }, # second return value
99 { name => "a0", type => 1 }, # first argument
100 { name => "a1", type => 1 }, # second argument
101 { name => "a2", type => 1 }, # third argument
102 { name => "a3", type => 1 }, # fourth argument
103 { name => "t0", type => 1 },
104 { name => "t1", type => 1 },
105 { name => "t2", type => 1 },
106 { name => "t3", type => 1 },
107 { name => "t4", type => 1 },
108 { name => "t5", type => 1 },
109 { name => "t6", type => 1 },
110 { name => "t7", type => 1 },
111 { name => "s0", type => 2 },
112 { name => "s1", type => 2 },
113 { name => "s2", type => 2 },
114 { name => "s3", type => 2 },
115 { name => "s4", type => 2 },
116 { name => "s5", type => 2 },
117 { name => "s6", type => 2 },
118 { name => "s7", type => 2 },
119 { name => "t8", type => 1 },
120 { name => "t9", type => 1 },
121 { name => "k0", type => 4 }, # reserved for OS
122 { name => "k1", type => 4 }, # reserved for OS
123 { name => "gp", type => 4 }, # general purpose
124 { name => "sp", type => 4+2 }, # stack pointer
125 { name => "fp", type => 4+2 }, # frame pointer
126 { name => "ra", type => 2+1 }, # return address. This is also caller
127 # save, because the jla instruction that
128 # is used for calls modifies the ra
129 # register. It is callee save too,
130 # because at the last command of a
131 # function (the ja $ra) it needs to have
137 #--------------------------------------------------#
140 # _ __ _____ __ _ _ __ ___ _ __ ___ #
141 # | '_ \ / _ \ \ /\ / / | | '__| / _ \| '_ \/ __| #
142 # | | | | __/\ V V / | | | | (_) | |_) \__ \ #
143 # |_| |_|\___| \_/\_/ |_|_| \___/| .__/|___/ #
146 #--------------------------------------------------#
150 #-----------------------------------------------------------------#
153 # _ _ __ | |_ ___ __ _ ___ _ __ _ __ ___ __| | ___ ___ #
154 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
155 # | | | | | || __/ (_| | __/ | | | | | (_) | (_| | __/\__ \ #
156 # |_|_| |_|\__\___|\__, |\___|_| |_| |_|\___/ \__,_|\___||___/ #
159 #-----------------------------------------------------------------#
161 # commutative operations
165 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
166 emit => '. addu %D1, %S1, %S2'
170 reg_req => { in => [ "gp" ], out => [ "gp" ] },
171 emit => '. addiu %D1, %S1, %C',
172 cmp_attr => 'return attr_a->tv != attr_b->tv;',
177 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
178 emit => '. and %D1, %S1, %S2',
182 reg_req => { in => [ "gp" ], out => [ "gp" ] },
183 emit => '. andi %D1, %S1, %C',
184 cmp_attr => 'return attr_a->tv != attr_b->tv;',
188 reg_req => { in => [ "gp", "gp" ], out => [ "none", "none", "none", "none" ] },
190 mips_attr_t *attr = get_mips_attr(n);
191 if (attr->modes.original_mode->sign) {
201 reg_req => { in => [ "gp", "gp" ], out => [ "none" ] },
203 if (mode_is_signed(get_irn_mode(n))) {
214 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
215 emit => '. nor %D1, %S1, %S2'
219 reg_req => { in => [ "gp" ], out => [ "gp" ] },
220 emit => '. nor %D1, %S1, $zero'
225 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
226 emit => '. or %D1, %S1, %S2'
230 reg_req => { in => [ "gp" ], out => [ "gp" ] },
231 emit => '. ori %D1, %S1, %C',
232 cmp_attr => 'return attr_a->tv != attr_b->tv;',
236 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
238 if (mode_is_signed(get_irn_mode(n))) {
248 reg_req => { in => [ "gp" ], out => [ "gp" ] },
250 if (mode_is_signed(get_irn_mode(n))) {
260 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
261 emit => '. sra %D1, %S1, %S2',
265 reg_req => { in => [ "gp" ], out => [ "gp" ] },
266 emit => '. sra %D1, %S1, %C',
267 cmp_attr => 'return attr_a->tv != attr_b->tv;',
271 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
273 if (mode_is_signed(get_irn_mode(n))) {
283 reg_req => { in => [ "gp" ], out => [ "gp" ] },
285 if (mode_is_signed(get_irn_mode(n))) {
295 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
296 emit => '. srlv %D1, %S1, %S2',
300 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
301 emit => '. sllv %D1, %S1, %S2',
305 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
306 emit => '. subu %D1, %S1, %S2',
310 reg_req => { in => [ "gp" ], out => [ "gp" ] },
311 emit => '. subu %D1, $zero, %S1',
315 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
316 emit => '. xor %D1, %S1, %S2'
320 reg_req => { in => [ "gp" ], out => [ "gp" ] },
321 emit => '. xori %D1, %S1, %C',
322 cmp_attr => 'return attr_a->tv != attr_b->tv;',
326 # / ___|___ _ __ ___| |_ __ _ _ __ | |_ ___
327 # | | / _ \| '_ \/ __| __/ _` | '_ \| __/ __|
328 # | |__| (_) | | | \__ \ || (_| | | | | |_\__ \
329 # \____\___/|_| |_|___/\__\__,_|_| |_|\__|___/
332 # load upper imediate
335 reg_req => { out => [ "gp" ] },
336 emit => '. lui %D1, %C',
337 cmp_attr => 'return attr_a->tv != attr_b->tv;',
340 # load lower immediate
343 reg_req => { in => [ "gp" ], out => [ "gp" ] },
344 emit => '. ori %D1, %S1, %C',
345 cmp_attr => 'return attr_a->tv != attr_b->tv;',
350 reg_req => { out => [ "gp" ] },
351 emit => '. la %D1, %C',
352 cmp_attr => 'return attr_a->symconst_id != attr_b->symconst_id;',
356 reg_req => { in => [ "none" ], out => [ "gp" ] },
361 reg_req => { in => [ "none" ], out => [ "gp" ] },
366 reg_req => { out => [ "zero" ] },
372 # | __ ) _ __ __ _ _ __ ___| |__ / / | |_ _ _ __ ___ _ __
373 # | _ \| '__/ _` | '_ \ / __| '_ \ / / | | | | | '_ ` _ \| '_ \
374 # | |_) | | | (_| | | | | (__| | | |/ / |_| | |_| | | | | | | |_) |
375 # |____/|_| \__,_|_| |_|\___|_| |_/_/ \___/ \__,_|_| |_| |_| .__/
380 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
382 if (mode_is_signed(get_irn_mode(n))) {
386 2. sltu %D1, %S1, %S2
392 reg_req => { in => [ "gp" ], out => [ "gp" ] },
394 if (mode_is_signed(get_irn_mode(n))) {
398 2. sltiu %D1, %S1, %C
401 cmp_attr => 'return attr_a->tv != attr_b->tv;',
407 reg_req => { in => [ "gp", "gp" ], out => [ "in_r0", "none" ] },
409 ir_node *jumpblock = mips_get_jump_block(n, 1);
410 assert(jumpblock != NULL);
414 lc_efprintf(arg_env, F, "\tbeq %1S, %2S, BLOCK_%d\n", n, n, get_irn_node_nr(jumpblock));
421 reg_req => { in => [ "gp", "gp" ], out => [ "in_r0", "none" ] },
423 ir_node *jumpblock = mips_get_jump_block(n, 1);
424 assert(jumpblock != NULL);
428 lc_efprintf(arg_env, F, "\tbne %1S, %2S, BLOCK_%d\n", n, n, get_irn_node_nr(jumpblock));
435 reg_req => { in => [ "gp" ], out => [ "in_r0", "none" ] },
437 ir_node *jumpblock = mips_get_jump_block(n, 1);
438 assert(jumpblock != NULL);
442 lc_efprintf(arg_env, F, "\tbgtz %1S, BLOCK_%d\n", n, get_irn_node_nr(jumpblock));
449 reg_req => { in => [ "gp" ], out => [ "in_r0", "none" ] },
451 ir_node *jumpblock = mips_get_jump_block(n, 1);
452 assert(jumpblock != NULL);
456 lc_efprintf(arg_env, F, "\tblez %1S, BLOCK_%d\n", n, get_irn_node_nr(jumpblock));
462 reg_req => { in => [ "gp" ] },
469 reg_req => { in => [ ], out => [ "none" ] },
471 ir_node *jumpblock = get_irn_link(n);
472 assert(jumpblock != NULL);
476 lc_efprintf(arg_env, F, "\tb BLOCK_%d\t\t\t# mips_b\n", get_irn_node_nr(jumpblock));
483 reg_req => { in => [ ], out => [ "none" ] },
484 emit => '. # fallthrough'
490 reg_req => { in => [ "gp" ], out => [ "none" ] },
496 # | | / _ \ / _` |/ _` |
497 # | |__| (_) | (_| | (_| |
498 # |_____\___/ \__,_|\__,_|
502 reg_req => { in => [ "none", "gp" ], out => [ "none", "none", "gp" ] },
504 mips_attr_t* attr = get_mips_attr(n);
507 mode = attr->modes.load_store_mode;
509 switch (get_mode_size_bits(mode)) {
511 if (mode_is_signed(mode)) {
519 if (mode_is_signed(mode)) {
530 assert(! "Only 8, 16 and 32 bit loads supported");
534 cmp_attr => 'return attr_a->tv != attr_b->tv || attr_a->stack_entity != attr_b->stack_entity;',
539 # | | ___ __ _ __| | / / ___|| |_ ___ _ __ ___
540 # | | / _ \ / _` |/ _` | / /\___ \| __/ _ \| '__/ _ \
541 # | |__| (_) | (_| | (_| |/ / ___) | || (_) | | | __/
542 # |_____\___/ \__,_|\__,_/_/ |____/ \__\___/|_| \___|
546 reg_req => { in => [ "none", "gp", "gp" ], out => [ "none", "none" ] },
548 mips_attr_t* attr = get_mips_attr(n);
551 mode = attr->modes.load_store_mode;
553 switch (get_mode_size_bits(mode)) {
555 if (mode_is_signed(mode))
559 if (mode_is_signed(mode))
566 assert(! "Only 8, 16 and 32 bit stores supported");
570 cmp_attr => 'return attr_a->tv != attr_b->tv;',
574 reg_req => { in => [ "none", "none", "gp" ], out => [ "none", "none" ] },
576 mips_attr_t* attr = get_mips_attr(n);
579 mode = attr->modes.load_store_mode;
581 switch (get_mode_size_bits(mode)) {
592 assert(! "Only 8, 16 and 32 bit stores supported");
597 return attr_a->stack_entity != attr_b->stack_entity;
602 reg_req => { in => [ "gp" ], out => [ "gp" ] },
603 emit => '. or %D1, $zero, %S1'
610 reinterpret_conv => {
611 reg_req => { in => [ "gp" ], out => [ "in_r1" ] },
612 emit => '. # reinterpret %S1 -> %D1',
621 reg_req => { in => [], out => [ "none" ] },
622 emit => '. nop # nop',