7 $mode_flags = "mode_Bu";
8 $mode_fpflags = "mode_Bu";
11 $mode_fp4 = "mode_E"; # not correct, we need to register a new mode
13 $normal = 0; # no special type
14 $caller_save = 1; # caller save (register must be saved by the caller of a function)
15 $callee_save = 2; # callee save (register must be saved by the called function)
16 $ignore = 4; # ignore (do not assign this register)
17 $arbitrary = 8; # emitter can choose an arbitrary register of this class
18 $virtual = 16; # the register is a virtual one
19 $state = 32; # register represents a state
21 # available SPARC registers: 8 globals, 24 window regs (8 ins, 8 outs, 8 locals)
24 { name => "g0", type => $ignore }, # hardwired 0, behaves like /dev/null
25 { name => "g1", type => $caller_save }, # temp. value
26 { name => "g2", type => $caller_save },
27 { name => "g3", type => $caller_save },
28 { name => "g4", type => $caller_save },
29 { name => "g5", type => $ignore }, # reserved by SPARC ABI
30 { name => "g6", type => $ignore }, # reserved by SPARC ABI
31 { name => "g7", type => $ignore }, # reserved by SPARC ABI
33 # window's out registers
34 { name => "o0", type => $caller_save }, # param 1 / return value from callee
35 { name => "o1", type => $caller_save }, # param 2
36 { name => "o2", type => $caller_save }, # param 3
37 { name => "o3", type => $caller_save }, # param 4
38 { name => "o4", type => $caller_save }, # param 5
39 { name => "o5", type => $caller_save }, # param 6
40 { name => "sp", type => $ignore }, # our stackpointer
41 { name => "o7", type => $ignore }, # temp. value / address of CALL instr.
43 # window's local registers
44 { name => "l0", type => 0 },
45 { name => "l1", type => 0 },
46 { name => "l2", type => 0 },
47 { name => "l3", type => 0 },
48 { name => "l4", type => 0 },
49 { name => "l5", type => 0 },
50 { name => "l6", type => 0 },
51 { name => "l7", type => 0 },
53 # window's in registers
54 { name => "i0", type => 0 }, # incoming param1 / return value to caller
55 { name => "i1", type => 0 }, # param 2
56 { name => "i2", type => 0 }, # param 3
57 { name => "i3", type => 0 }, # param 4
58 { name => "i4", type => 0 }, # param 5
59 { name => "i5", type => 0 }, # param 6
60 { name => "frame_pointer", realname => "fp", type => $ignore }, # our framepointer
61 { name => "i7", type => $ignore }, # return address - 8
65 { name => "fpflags", type => $ignore },
66 { mode => $mode_fpflags, flags => "manual_ra" }
69 { name => "flags", type => $ignore },
70 { mode => $mode_flags, flags => "manual_ra" }
73 { name => "y", type => $ignore },
74 { mode => $mode_gp, flags => "manual_ra" }
76 # fp registers can be accessed any time
78 { name => "f0", type => $caller_save },
79 { name => "f1", type => $caller_save },
80 { name => "f2", type => $caller_save },
81 { name => "f3", type => $caller_save },
82 { name => "f4", type => $caller_save },
83 { name => "f5", type => $caller_save },
84 { name => "f6", type => $caller_save },
85 { name => "f7", type => $caller_save },
86 { name => "f8", type => $caller_save },
87 { name => "f9", type => $caller_save },
88 { name => "f10", type => $caller_save },
89 { name => "f11", type => $caller_save },
90 { name => "f12", type => $caller_save },
91 { name => "f13", type => $caller_save },
92 { name => "f14", type => $caller_save },
93 { name => "f15", type => $caller_save },
94 { name => "f16", type => $caller_save },
95 { name => "f17", type => $caller_save },
96 { name => "f18", type => $caller_save },
97 { name => "f19", type => $caller_save },
98 { name => "f20", type => $caller_save },
99 { name => "f21", type => $caller_save },
100 { name => "f22", type => $caller_save },
101 { name => "f23", type => $caller_save },
102 { name => "f24", type => $caller_save },
103 { name => "f25", type => $caller_save },
104 { name => "f26", type => $caller_save },
105 { name => "f27", type => $caller_save },
106 { name => "f28", type => $caller_save },
107 { name => "f29", type => $caller_save },
108 { name => "f30", type => $caller_save },
109 { name => "f31", type => $caller_save },
115 # emit source reg or imm dep. on node's arity
116 RI => "${arch}_emit_reg_or_imm(node, -1);",
117 R1I => "${arch}_emit_reg_or_imm(node, 0);",
118 R2I => "${arch}_emit_reg_or_imm(node, 1);",
119 R3I => "${arch}_emit_reg_or_imm(node, 2);",
120 S1 => "${arch}_emit_source_register(node, 0);",
121 S2 => "${arch}_emit_source_register(node, 1);",
122 S3 => "${arch}_emit_source_register(node, 2);",
123 S4 => "${arch}_emit_source_register(node, 3);",
124 S5 => "${arch}_emit_source_register(node, 4);",
125 S6 => "${arch}_emit_source_register(node, 5);",
126 D1 => "${arch}_emit_dest_register(node, 0);",
127 D2 => "${arch}_emit_dest_register(node, 1);",
128 D3 => "${arch}_emit_dest_register(node, 2);",
129 D4 => "${arch}_emit_dest_register(node, 3);",
130 D5 => "${arch}_emit_dest_register(node, 4);",
131 D6 => "${arch}_emit_dest_register(node, 5);",
132 IM => "${arch}_emit_immediate(node);",
133 HIM => "${arch}_emit_high_immediate(node);",
134 LM => "${arch}_emit_load_mode(node);",
135 SM => "${arch}_emit_store_mode(node);",
136 FLSM => "${arch}_emit_float_load_store_mode(node);",
137 FPM => "${arch}_emit_fp_mode_suffix(node);",
138 FCONVS => "${arch}_emit_fp_conv_source(node);",
139 FCONVD => "${arch}_emit_fp_conv_destination(node);",
140 O => "${arch}_emit_offset(node);",
143 $default_attr_type = "sparc_attr_t";
144 $default_copy_attr = "sparc_copy_attr";
148 sparc_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
149 sparc_load_store_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);\n".
150 "\tinit_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity);",
151 sparc_jmp_cond_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
152 sparc_jmp_switch_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
153 sparc_save_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
154 sparc_fp_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);\n".
155 "\tinit_sparc_fp_attributes(res, fp_mode);\n",
156 sparc_fp_conv_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);".
157 "\tinit_sparc_fp_conv_attributes(res, src_mode, dest_mode);\n",
161 sparc_attr_t => "cmp_attr_sparc",
162 sparc_load_store_attr_t => "cmp_attr_sparc_load_store",
163 sparc_jmp_cond_attr_t => "cmp_attr_sparc_jmp_cond",
164 sparc_jmp_switch_attr_t => "cmp_attr_sparc_jmp_switch",
165 sparc_save_attr_t => "cmp_attr_sparc_save",
166 sparc_fp_attr_t => "cmp_attr_sparc_fp",
167 sparc_fp_conv_attr_t => "cmp_attr_sparc_fp_conv",
170 %custom_irn_flags = (
171 modifies_flags => "sparc_arch_irn_flag_modifies_flags",
172 modifies_fp_flags => "sparc_arch_irn_flag_modifies_fp_flags",
175 # addressing modes: imm, reg, reg +/- imm, reg + reg
176 # max. imm = 13 bits signed (-4096 ... 4096)
178 my %cmp_operand_constructors = (
180 attr => "ir_entity *immediate_entity, int32_t immediate_value",
181 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
182 reg_req => { in => [ "gp" ], out => [ "flags" ] },
186 reg_req => { in => [ "gp", "gp" ], out => [ "flags" ] },
187 ins => [ "left", "right" ],
191 my %unop_operand_constructors = (
193 attr => "ir_entity *immediate_entity, int32_t immediate_value",
194 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
195 reg_req => { in => [], out => [ "gp" ] },
198 reg_req => { in => [ "gp" ], out => [ "gp" ] },
202 my %binop_operand_constructors = (
204 attr => "ir_entity *immediate_entity, int32_t immediate_value",
205 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
206 reg_req => { in => [ "gp" ], out => [ "gp" ] },
210 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
211 ins => [ "left", "right" ],
215 my %div_operand_constructors = (
217 attr => "ir_entity *immediate_entity, int32_t immediate_value",
218 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
219 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
222 reg_req => { in => [ "gp", "gp", "gp" ], out => [ "gp" ] },
226 my %float_binop_constructors = (
228 reg_req => { in => [ "fp", "fp" ], out => [ "fp" ] },
229 ins => [ "left", "right" ],
233 reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fp:a|2" ] },
234 ins => [ "left", "right" ],
238 reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fp:a|4" ] },
239 ins => [ "left", "right" ],
244 my %float_unop_constructors = (
246 reg_req => { in => [ "fp" ], out => [ "fp" ] },
247 ins => [ "left", "right" ],
251 reg_req => { in => [ "fp:a|2" ], out => [ "fp:a|2" ] },
252 ins => [ "left", "right" ],
256 reg_req => { in => [ "fp:a|4" ], out => [ "fp:a|4" ] },
257 ins => [ "left", "right" ],
265 irn_flags => [ "rematerializable" ],
267 emit => '. add %S1, %R2I, %D1',
268 constructors => \%binop_operand_constructors,
272 irn_flags => [ "rematerializable" ],
274 emit => '. sub %S1, %R2I, %D1',
275 constructors => \%binop_operand_constructors,
281 op_flags => [ "labeled", "fragile" ],
282 state => "exc_pinned",
285 reg_req => { in => [ "gp", "none" ], out => [ "gp", "none" ] },
288 reg_req => { in => [ "gp", "none" ], out => [ "gp:a|2", "none" ] },
291 outs => [ "res", "M" ],
292 ins => [ "ptr", "mem" ],
293 attr_type => "sparc_load_store_attr_t",
294 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
295 emit => '. ld%LM [%S1%O], %D1'
299 irn_flags => [ "rematerializable" ],
302 reg_req => { in => [], out => [ "gp" ] },
303 attr => "ir_entity *entity, int32_t immediate_value",
304 custominit => "sparc_set_attr_imm(res, entity, immediate_value);",
305 emit => '. sethi %HIM, %D1'
309 op_flags => [ "labeled", "fragile" ],
311 state => "exc_pinned",
314 reg_req => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
317 reg_req => { in => [ "gp", "gp:a|2", "none" ], out => [ "none" ] },
320 ins => [ "ptr", "val", "mem" ],
322 attr_type => "sparc_load_store_attr_t",
323 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
324 emit => '. st%SM %S2, [%S1%O]'
329 in => [ "sp", "none"],
330 out => [ "sp:I|S", "frame_pointer:I", "none" ]
332 ins => [ "stack", "mem" ],
333 outs => [ "stack", "frame", "mem" ],
334 attr => "int initial_stacksize",
335 attr_type => "sparc_save_attr_t",
336 init_attr => "\tinit_sparc_save_attributes(res, initial_stacksize);",
340 reg_req => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "gp", "none" ] },
341 ins => [ "stack", "size", "mem" ],
342 outs => [ "stack", "addr", "M" ],
343 emit => ". sub %S1, %S2, %D1\n",
347 reg_req => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "none" ] },
348 ins => [ "stack", "size", "mem" ],
349 outs => [ "stack", "M" ],
350 emit => ". add %S1, %S2, %D1\n",
354 op_flags => [ "constlike" ],
355 irn_flags => [ "rematerializable" ],
356 attr => "ir_entity *entity, int32_t offset",
357 reg_req => { in => [ "gp" ], out => [ "gp" ] },
359 attr_type => "sparc_attr_t",
360 custominit => "sparc_set_attr_imm(res, entity, offset);",
365 op_flags => [ "labeled", "cfopcode", "forking" ],
368 attr_type => "sparc_jmp_cond_attr_t",
369 attr => "pn_Cmp pnc, bool is_unsigned",
370 init_attr => "\tinit_sparc_jmp_cond_attr(res, pnc, is_unsigned);",
371 reg_req => { in => [ "flags" ], out => [ "none", "none" ] },
375 op_flags => [ "labeled", "cfopcode", "forking" ],
378 attr_type => "sparc_jmp_cond_attr_t",
379 attr => "pn_Cmp pnc",
380 init_attr => "\tinit_sparc_jmp_cond_attr(res, pnc, false);",
381 reg_req => { in => [ "fpflags" ], out => [ "none", "none" ] },
386 op_flags => [ "cfopcode" ],
387 irn_flags => [ "simple_jump" ],
388 reg_req => { out => [ "none" ] },
393 irn_flags => [ "modifies_flags", "modifies_fp_flags" ],
394 state => "exc_pinned",
396 out_arity => "variable",
399 attr => "ir_entity *entity, int32_t offset",
400 custominit => "\tsparc_set_attr_imm(res, entity, offset);",
402 out_arity => "variable",
406 out_arity => "variable",
412 irn_flags => [ "rematerializable", "modifies_flags" ],
413 emit => '. cmp %S1, %R2I',
414 ins => [ "left", "right" ],
416 constructors => \%cmp_operand_constructors,
420 irn_flags => [ "rematerializable", "modifies_flags" ],
423 reg_req => { in => [ "gp" ], out => [ "flags" ] },
428 op_flags => [ "labeled", "cfopcode", "forking" ],
429 irn_flags => [ "modifies_flags" ],
432 attr => "int n_projs, long def_proj_num",
433 init_attr => "\tset_sparc_jmp_switch_n_projs(res, n_projs);\n".
434 "\tset_sparc_jmp_switch_default_proj_num(res, def_proj_num);",
435 reg_req => { in => [ "gp" ], out => [ "none" ] },
436 attr_type => "sparc_jmp_switch_attr_t",
440 irn_flags => [ "rematerializable" ],
442 emit => '. sll %S1, %R2I, %D1',
443 constructors => \%binop_operand_constructors,
447 irn_flags => [ "rematerializable" ],
449 emit => '. srl %S1, %R2I, %D1',
450 constructors => \%binop_operand_constructors,
454 irn_flags => [ "rematerializable" ],
456 emit => '. sra %S1, %R2I, %D1',
457 constructors => \%binop_operand_constructors,
461 irn_flags => [ "rematerializable" ],
463 emit => '. and %S1, %R2I, %D1',
464 constructors => \%binop_operand_constructors,
468 irn_flags => [ "rematerializable" ],
470 emit => '. andn %S1, %R2I, %D1',
471 constructors => \%binop_operand_constructors,
475 irn_flags => [ "rematerializable" ],
477 emit => '. or %S1, %R2I, %D1',
478 constructors => \%binop_operand_constructors,
482 irn_flags => [ "rematerializable" ],
484 emit => '. orn %S1, %R2I, %D1',
485 constructors => \%binop_operand_constructors,
489 irn_flags => [ "rematerializable" ],
491 emit => '. xor %S1, %R2I, %D1',
492 constructors => \%binop_operand_constructors,
496 irn_flags => [ "rematerializable" ],
498 emit => '. xnor %S1, %R2I, %D1',
499 constructors => \%binop_operand_constructors,
503 irn_flags => [ "rematerializable" ],
505 emit => '. smul %S1, %R2I, %D1',
506 constructors => \%binop_operand_constructors,
510 irn_flags => [ "rematerializable" ],
511 outs => [ "low", "high" ],
512 constructors => \%binop_operand_constructors,
516 irn_flags => [ "rematerializable" ],
517 state => "exc_pinned",
518 ins => [ "dividend_high", "dividend_low", "divisor" ],
519 outs => [ "res", "M" ],
520 constructors => \%div_operand_constructors,
524 irn_flags => [ "rematerializable" ],
525 state => "exc_pinned",
526 ins => [ "dividend_high", "dividend_low", "divisor" ],
527 outs => [ "res", "M" ],
528 constructors => \%div_operand_constructors,
532 irn_flags => [ "rematerializable", "modifies_fp_flags" ],
533 emit => '. fcmp%FPM %S1, %S2',
534 attr_type => "sparc_fp_attr_t",
535 attr => "ir_mode *fp_mode",
536 mode => $mode_fpflags,
539 reg_req => { in => [ "fp", "fp" ], out => [ "fpflags" ] },
542 reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fpflags" ] },
545 reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fpflags" ] },
551 op_flags => [ "commutative" ],
552 irn_flags => [ "rematerializable" ],
553 emit => '. fadd%FPM %S1, %S2, %D1',
554 attr_type => "sparc_fp_attr_t",
555 attr => "ir_mode *fp_mode",
556 constructors => \%float_binop_constructors,
560 irn_flags => [ "rematerializable" ],
561 emit => '. fsub%FPM %S1, %S2, %D1',
562 attr_type => "sparc_fp_attr_t",
563 attr => "ir_mode *fp_mode",
564 constructors => \%float_binop_constructors,
568 irn_flags => [ "rematerializable" ],
569 op_flags => [ "commutative" ],
570 emit =>'. fmul%FPM %S1, %S2, %D1',
571 attr_type => "sparc_fp_attr_t",
572 attr => "ir_mode *fp_mode",
573 constructors => \%float_binop_constructors,
577 irn_flags => [ "rematerializable" ],
578 emit => '. fdiv%FPM %S1, %S2, %D1',
579 attr_type => "sparc_fp_attr_t",
580 attr => "ir_mode *fp_mode",
581 outs => [ "res", "M" ],
582 constructors => \%float_binop_constructors,
586 irn_flags => [ "rematerializable" ],
587 reg_req => { in => [ "fp" ], out => [ "fp" ] },
588 # note that we only need the first register even for wide-values
589 emit => '. fneg %S1, %D1',
590 attr_type => "sparc_fp_attr_t",
591 attr => "ir_mode *fp_mode",
592 constructors => \%float_unop_constructors,
596 irn_flags => [ "rematerializable" ],
597 # note that we only need the first register even for wide-values
598 emit => '. fabs %S1, %D1',
599 attr_type => "sparc_fp_attr_t",
600 attr => "ir_mode *fp_mode",
601 constructors => \%float_unop_constructors,
605 irn_flags => [ "rematerializable" ],
606 emit => '. f%FCONVS%.to%FCONVD %S1, %D1',
607 attr_type => "sparc_fp_conv_attr_t",
608 attr => "ir_mode *src_mode, ir_mode *dest_mode",
611 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
615 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
619 reg_req => { in => [ "fp:a|2" ], out => [ "fp" ] },
623 reg_req => { in => [ "fp:a|2" ], out => [ "fp:a|4" ] },
627 reg_req => { in => [ "fp:a|4" ], out => [ "fp" ] },
631 reg_req => { in => [ "fp:a|4" ], out => [ "fp:a|2" ] },
638 irn_flags => [ "rematerializable" ],
639 reg_req => { in => [ "gp" ], out => [ "fp" ] },
640 emit => '. fito%FPM %S1, %D1',
641 attr_type => "sparc_fp_attr_t",
642 attr => "ir_mode *fp_mode",
645 reg_req => { in => [ "gp" ], out => [ "fp" ] },
649 reg_req => { in => [ "gp" ], out => [ "fp:a|2" ] },
653 reg_req => { in => [ "gp" ], out => [ "fp:a|4" ] },
660 irn_flags => [ "rematerializable" ],
661 reg_req => { in => [ "fp" ], out => [ "gp" ] },
662 emit => '. f%FPM.toi %S1, %D1',
663 attr_type => "sparc_fp_attr_t",
664 attr => "ir_mode *fp_mode",
668 reg_req => { in => [ "gp" ], out => [ "gp" ] },
671 reg_req => { in => [ "fp:a|2" ], out => [ "gp" ] },
674 reg_req => { in => [ "fp:a|4" ], out => [ "gp" ] },
680 op_flags => [ "labeled", "fragile" ],
681 state => "exc_pinned",
684 reg_req => { in => [ "gp", "none" ], out => [ "fp", "none" ] },
687 reg_req => { in => [ "gp", "none" ], out => [ "fp:a|2", "none" ] },
690 reg_req => { in => [ "gp", "none" ], out => [ "fp:a|4", "none" ] },
693 ins => [ "ptr", "mem" ],
694 outs => [ "res", "M" ],
695 attr_type => "sparc_load_store_attr_t",
696 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
697 emit => '. ld%FLSM [%S1%O], %D1'
701 op_flags => [ "labeled", "fragile" ],
702 state => "exc_pinned",
705 reg_req => { in => [ "gp", "fp", "none" ], out => [ "none" ] },
708 reg_req => { in => [ "gp", "fp:a|2", "none" ], out => [ "none" ] },
711 reg_req => { in => [ "gp", "fp:a|4", "none" ], out => [ "none" ] },
714 ins => [ "ptr", "val", "mem" ],
716 attr_type => "sparc_load_store_attr_t",
717 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
718 emit => '. st%FLSM %S2, [%S1%O]',