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 save, because
127 # the jla instruction that is used for calls modifies
128 # the ra register. It is callee save too, because at the last
129 # command of a function (the ja $ra) it needs to have it's
135 #--------------------------------------------------#
138 # _ __ _____ __ _ _ __ ___ _ __ ___ #
139 # | '_ \ / _ \ \ /\ / / | | '__| / _ \| '_ \/ __| #
140 # | | | | __/\ V V / | | | | (_) | |_) \__ \ #
141 # |_| |_|\___| \_/\_/ |_|_| \___/| .__/|___/ #
144 #--------------------------------------------------#
148 #-----------------------------------------------------------------#
151 # _ _ __ | |_ ___ __ _ ___ _ __ _ __ ___ __| | ___ ___ #
152 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
153 # | | | | | || __/ (_| | __/ | | | | | (_) | (_| | __/\__ \ #
154 # |_|_| |_|\__\___|\__, |\___|_| |_| |_|\___/ \__,_|\___||___/ #
157 #-----------------------------------------------------------------#
159 # commutative operations
163 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
164 emit => '. addu %D1, %S1, %S2'
168 reg_req => { in => [ "gp" ], out => [ "gp" ] },
169 emit => '. addiu %D1, %S1, %C',
170 cmp_attr => 'return attr_a->tv != attr_b->tv;',
175 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
176 emit => '. and %D1, %S1, %S2',
180 reg_req => { in => [ "gp" ], out => [ "gp" ] },
181 emit => '. andi %D1, %S1, %C',
182 cmp_attr => 'return attr_a->tv != attr_b->tv;',
186 reg_req => { in => [ "gp", "gp" ], out => [ "none", "none", "none", "none" ] },
188 mips_attr_t *attr = get_mips_attr(n);
189 if (attr->modes.original_mode->sign) {
199 reg_req => { in => [ "gp", "gp" ], out => [ "none" ] },
201 if (mode_is_signed(get_irn_mode(n))) {
212 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
213 emit => '. nor %D1, %S1, %S2'
217 reg_req => { in => [ "gp" ], out => [ "gp" ] },
218 emit => '. nor %D1, %S1, $zero'
223 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
224 emit => '. or %D1, %S1, %S2'
228 reg_req => { in => [ "gp" ], out => [ "gp" ] },
229 emit => '. ori %D1, %S1, %C',
230 cmp_attr => 'return attr_a->tv != attr_b->tv;',
234 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
236 if (mode_is_signed(get_irn_mode(n))) {
246 reg_req => { in => [ "gp" ], out => [ "gp" ] },
248 if (mode_is_signed(get_irn_mode(n))) {
258 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
259 emit => '. sra %D1, %S1, %S2',
263 reg_req => { in => [ "gp" ], out => [ "gp" ] },
264 emit => '. sra %D1, %S1, %C',
265 cmp_attr => 'return attr_a->tv != attr_b->tv;',
269 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
271 if (mode_is_signed(get_irn_mode(n))) {
281 reg_req => { in => [ "gp" ], out => [ "gp" ] },
283 if (mode_is_signed(get_irn_mode(n))) {
293 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
294 emit => '. srlv %D1, %S1, %S2',
298 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
299 emit => '. sllv %D1, %S1, %S2',
303 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
304 emit => '. subu %D1, %S1, %S2',
308 reg_req => { in => [ "gp" ], out => [ "gp" ] },
309 emit => '. subu %D1, $zero, %S1',
313 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
314 emit => '. xor %D1, %S1, %S2'
318 reg_req => { in => [ "gp" ], out => [ "gp" ] },
319 emit => '. xori %D1, %S1, %C',
320 cmp_attr => 'return attr_a->tv != attr_b->tv;',
324 # / ___|___ _ __ ___| |_ __ _ _ __ | |_ ___
325 # | | / _ \| '_ \/ __| __/ _` | '_ \| __/ __|
326 # | |__| (_) | | | \__ \ || (_| | | | | |_\__ \
327 # \____\___/|_| |_|___/\__\__,_|_| |_|\__|___/
330 # load upper imediate
333 reg_req => { out => [ "gp" ] },
334 emit => '. lui %D1, %C',
335 cmp_attr => 'return attr_a->tv != attr_b->tv;',
338 # load lower immediate
341 reg_req => { in => [ "gp" ], out => [ "gp" ] },
342 emit => '. ori %D1, %S1, %C',
343 cmp_attr => 'return attr_a->tv != attr_b->tv;',
348 reg_req => { out => [ "gp" ] },
349 emit => '. la %D1, %C',
350 cmp_attr => 'return attr_a->symconst_id != attr_b->symconst_id;',
354 reg_req => { in => [ "none" ], out => [ "gp" ] },
359 reg_req => { in => [ "none" ], out => [ "gp" ] },
364 reg_req => { out => [ "zero" ] },
370 # | __ ) _ __ __ _ _ __ ___| |__ / / | |_ _ _ __ ___ _ __
371 # | _ \| '__/ _` | '_ \ / __| '_ \ / / | | | | | '_ ` _ \| '_ \
372 # | |_) | | | (_| | | | | (__| | | |/ / |_| | |_| | | | | | | |_) |
373 # |____/|_| \__,_|_| |_|\___|_| |_/_/ \___/ \__,_|_| |_| |_| .__/
378 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
380 if (mode_is_signed(get_irn_mode(n))) {
384 2. sltu %D1, %S1, %S2
390 reg_req => { in => [ "gp" ], out => [ "gp" ] },
392 if (mode_is_signed(get_irn_mode(n))) {
396 2. sltiu %D1, %S1, %C
399 cmp_attr => 'return attr_a->tv != attr_b->tv;',
405 reg_req => { in => [ "gp", "gp" ], out => [ "in_r0", "none" ] },
407 ir_node *jumpblock = mips_get_jump_block(n, 1);
408 assert(jumpblock != NULL);
412 lc_efprintf(arg_env, F, "\tbeq %1S, %2S, BLOCK_%d\n", n, n, get_irn_node_nr(jumpblock));
419 reg_req => { in => [ "gp", "gp" ], out => [ "in_r0", "none" ] },
421 ir_node *jumpblock = mips_get_jump_block(n, 1);
422 assert(jumpblock != NULL);
426 lc_efprintf(arg_env, F, "\tbne %1S, %2S, BLOCK_%d\n", n, n, get_irn_node_nr(jumpblock));
433 reg_req => { in => [ "gp" ], out => [ "in_r0", "none" ] },
435 ir_node *jumpblock = mips_get_jump_block(n, 1);
436 assert(jumpblock != NULL);
440 lc_efprintf(arg_env, F, "\tbgtz %1S, BLOCK_%d\n", n, get_irn_node_nr(jumpblock));
447 reg_req => { in => [ "gp" ], out => [ "in_r0", "none" ] },
449 ir_node *jumpblock = mips_get_jump_block(n, 1);
450 assert(jumpblock != NULL);
454 lc_efprintf(arg_env, F, "\tblez %1S, BLOCK_%d\n", n, get_irn_node_nr(jumpblock));
460 reg_req => { in => [ "gp" ] },
467 reg_req => { in => [ ], out => [ "none" ] },
469 ir_node *jumpblock = get_irn_link(n);
470 assert(jumpblock != NULL);
474 lc_efprintf(arg_env, F, "\tb BLOCK_%d\t\t\t# mips_b\n", get_irn_node_nr(jumpblock));
481 reg_req => { in => [ ], out => [ "none" ] },
482 emit => '. # fallthrough'
488 reg_req => { in => [ "gp" ], out => [ "none" ] },
494 # | | / _ \ / _` |/ _` |
495 # | |__| (_) | (_| | (_| |
496 # |_____\___/ \__,_|\__,_|
500 reg_req => { in => [ "none", "gp" ], out => [ "none", "none", "gp" ] },
502 mips_attr_t* attr = get_mips_attr(n);
505 mode = attr->modes.load_store_mode;
507 switch (get_mode_size_bits(mode)) {
509 if (mode_is_signed(mode)) {
517 if (mode_is_signed(mode)) {
528 assert(! "Only 8, 16 and 32 bit loads supported");
532 cmp_attr => 'return attr_a->tv != attr_b->tv || attr_a->stack_entity != attr_b->stack_entity;',
537 # | | ___ __ _ __| | / / ___|| |_ ___ _ __ ___
538 # | | / _ \ / _` |/ _` | / /\___ \| __/ _ \| '__/ _ \
539 # | |__| (_) | (_| | (_| |/ / ___) | || (_) | | | __/
540 # |_____\___/ \__,_|\__,_/_/ |____/ \__\___/|_| \___|
544 reg_req => { in => [ "none", "gp", "gp" ], out => [ "none", "none" ] },
546 mips_attr_t* attr = get_mips_attr(n);
549 mode = attr->modes.load_store_mode;
551 switch (get_mode_size_bits(mode)) {
553 if (mode_is_signed(mode))
557 if (mode_is_signed(mode))
564 assert(! "Only 8, 16 and 32 bit stores supported");
568 cmp_attr => 'return attr_a->tv != attr_b->tv;',
572 reg_req => { in => [ "none", "none", "gp" ], out => [ "none", "none" ] },
574 mips_attr_t* attr = get_mips_attr(n);
577 mode = attr->modes.load_store_mode;
579 switch (get_mode_size_bits(mode)) {
590 assert(! "Only 8, 16 and 32 bit stores supported");
595 return attr_a->stack_entity != attr_b->stack_entity;
600 reg_req => { in => [ "gp" ], out => [ "gp" ] },
601 emit => '. or %D1, $zero, %S1'
608 reinterpret_conv => {
609 reg_req => { in => [ "gp" ], out => [ "in_r1" ] },
610 emit => '. # reinterpret %S1 -> %D1',
619 reg_req => { in => [], out => [ "none" ] },
620 emit => '. nop # nop',