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 O2 => "${arch}_emit_offset(node, 1);",
141 O3 => "${arch}_emit_offset(node, 2);",
144 $default_attr_type = "sparc_attr_t";
145 $default_copy_attr = "sparc_copy_attr";
149 sparc_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
150 sparc_load_store_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
151 sparc_jmp_cond_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
152 sparc_switch_jmp_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);\n".
153 "\tinit_sparc_switch_jmp_attributes(res, default_pn, jump_table);\n",
154 sparc_save_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
155 sparc_fp_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);\n".
156 "\tinit_sparc_fp_attributes(res, fp_mode);\n",
157 sparc_fp_conv_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);".
158 "\tinit_sparc_fp_conv_attributes(res, src_mode, dest_mode);\n",
162 sparc_attr_t => "cmp_attr_sparc",
163 sparc_load_store_attr_t => "cmp_attr_sparc_load_store",
164 sparc_jmp_cond_attr_t => "cmp_attr_sparc_jmp_cond",
165 sparc_switch_jmp_attr_t => "cmp_attr_sparc_switch_jmp",
166 sparc_save_attr_t => "cmp_attr_sparc_save",
167 sparc_fp_attr_t => "cmp_attr_sparc_fp",
168 sparc_fp_conv_attr_t => "cmp_attr_sparc_fp_conv",
171 %custom_irn_flags = (
172 modifies_flags => "sparc_arch_irn_flag_modifies_flags",
173 modifies_fp_flags => "sparc_arch_irn_flag_modifies_fp_flags",
176 # addressing modes: imm, reg, reg +/- imm, reg + reg
177 # max. imm = 13 bits signed (-4096 ... 4096)
179 my %cmp_operand_constructors = (
181 attr => "ir_entity *immediate_entity, int32_t immediate_value",
182 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
183 reg_req => { in => [ "gp" ], out => [ "flags" ] },
187 reg_req => { in => [ "gp", "gp" ], out => [ "flags" ] },
188 ins => [ "left", "right" ],
192 my %binop_operand_constructors = (
194 attr => "ir_entity *immediate_entity, int32_t immediate_value",
195 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
196 reg_req => { in => [ "gp" ], out => [ "gp" ] },
200 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
201 ins => [ "left", "right" ],
205 my %binopcczero_operand_constructors = (
207 attr => "ir_entity *immediate_entity, int32_t immediate_value",
208 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
209 reg_req => { in => [ "gp" ], out => [ "flags" ] },
213 reg_req => { in => [ "gp", "gp" ], out => [ "flags" ] },
214 ins => [ "left", "right" ],
218 my %div_operand_constructors = (
220 attr => "ir_entity *immediate_entity, int32_t immediate_value",
221 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
222 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
225 reg_req => { in => [ "gp", "gp", "gp" ], out => [ "gp" ] },
229 my %float_binop_constructors = (
231 reg_req => { in => [ "fp", "fp" ], out => [ "fp" ] },
235 reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fp:a|2" ] },
239 reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fp:a|4" ] },
244 my %float_unop_constructors = (
246 reg_req => { in => [ "fp" ], out => [ "fp" ] },
250 reg_req => { in => [ "fp:a|2" ], out => [ "fp:a|2" ] },
254 reg_req => { in => [ "fp:a|4" ], out => [ "fp:a|4" ] },
262 irn_flags => [ "rematerializable" ],
264 emit => '. add %S1, %R2I, %D1',
265 constructors => \%binop_operand_constructors,
269 irn_flags => [ "rematerializable" ],
271 emit => '. sub %S1, %R2I, %D1',
272 constructors => \%binop_operand_constructors,
278 op_flags => [ "labeled", "fragile" ],
279 state => "exc_pinned",
282 reg_req => { in => [ "gp", "none" ], out => [ "gp", "none" ] },
283 ins => [ "ptr", "mem" ],
284 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
285 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
288 reg_req => { in => [ "gp", "gp", "none" ], out => [ "gp", "none" ] },
289 ins => [ "ptr", "ptr2", "mem" ],
290 attr => "ir_mode *ls_mode",
291 custominit => "init_sparc_load_store_attributes(res, ls_mode, NULL, 0, false, true);",
294 ins => [ "ptr", "mem" ],
295 outs => [ "res", "M" ],
296 attr_type => "sparc_load_store_attr_t",
297 emit => '. ld%LM [%S1%O2], %D1'
301 irn_flags => [ "rematerializable" ],
304 reg_req => { in => [], out => [ "gp" ] },
305 attr => "ir_entity *entity, int32_t immediate_value",
306 custominit => "sparc_set_attr_imm(res, entity, immediate_value);",
307 emit => '. sethi %HIM, %D1'
311 op_flags => [ "labeled", "fragile" ],
313 state => "exc_pinned",
316 reg_req => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
317 ins => [ "val", "ptr", "mem" ],
318 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
319 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
322 reg_req => { in => [ "gp", "gp", "gp", "none" ], out => [ "none" ] },
323 ins => [ "val", "ptr", "ptr2", "mem" ],
324 attr => "ir_mode *ls_mode",
325 custominit => "init_sparc_load_store_attributes(res, ls_mode, NULL, 0, false, true);",
328 ins => [ "val", "ptr", "mem" ],
330 attr_type => "sparc_load_store_attr_t",
331 emit => '. st%SM %S1, [%S2%O3]'
336 in => [ "sp", "none"],
337 out => [ "sp:I|S", "frame_pointer:I", "none" ]
339 ins => [ "stack", "mem" ],
340 outs => [ "stack", "frame", "mem" ],
341 attr => "int initial_stacksize",
342 attr_type => "sparc_save_attr_t",
343 init_attr => "\tinit_sparc_save_attributes(res, initial_stacksize);",
347 reg_req => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "gp", "none" ] },
348 ins => [ "stack", "size", "mem" ],
349 outs => [ "stack", "addr", "M" ],
350 emit => ". sub %S1, %S2, %D1\n",
354 reg_req => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "none" ] },
355 ins => [ "stack", "size", "mem" ],
356 outs => [ "stack", "M" ],
357 emit => ". add %S1, %S2, %D1\n",
361 op_flags => [ "constlike" ],
362 irn_flags => [ "rematerializable" ],
363 attr => "ir_entity *entity, int32_t offset",
364 reg_req => { in => [ "gp" ], out => [ "gp" ] },
366 attr_type => "sparc_attr_t",
367 custominit => "sparc_set_attr_imm(res, entity, offset);",
372 op_flags => [ "labeled", "cfopcode", "forking" ],
375 attr_type => "sparc_jmp_cond_attr_t",
376 attr => "pn_Cmp pnc, bool is_unsigned",
377 init_attr => "\tinit_sparc_jmp_cond_attr(res, pnc, is_unsigned);",
378 reg_req => { in => [ "flags" ], out => [ "none", "none" ] },
382 op_flags => [ "labeled", "cfopcode", "forking" ],
385 attr_type => "sparc_jmp_cond_attr_t",
386 attr => "pn_Cmp pnc",
387 init_attr => "\tinit_sparc_jmp_cond_attr(res, pnc, false);",
388 reg_req => { in => [ "fpflags" ], out => [ "none", "none" ] },
393 op_flags => [ "cfopcode" ],
394 irn_flags => [ "simple_jump" ],
395 reg_req => { out => [ "none" ] },
400 irn_flags => [ "modifies_flags", "modifies_fp_flags" ],
401 state => "exc_pinned",
403 out_arity => "variable",
406 attr => "ir_entity *entity, int32_t offset",
407 custominit => "\tsparc_set_attr_imm(res, entity, offset);",
409 out_arity => "variable",
413 out_arity => "variable",
418 Cmp => { # aka SubccZero
419 irn_flags => [ "rematerializable", "modifies_flags" ],
420 emit => '. cmp %S1, %R2I',
422 constructors => \%binopcczero_operand_constructors,
426 op_flags => [ "labeled", "cfopcode", "forking" ],
429 reg_req => { in => [ "gp" ], out => [ ] },
430 attr_type => "sparc_switch_jmp_attr_t",
431 attr => "long default_pn, ir_entity *jump_table",
432 init_attr => "info->out_infos = NULL;", # XXX ugly hack for out requirements
436 irn_flags => [ "rematerializable" ],
438 emit => '. sll %S1, %R2I, %D1',
439 constructors => \%binop_operand_constructors,
443 irn_flags => [ "rematerializable" ],
445 emit => '. srl %S1, %R2I, %D1',
446 constructors => \%binop_operand_constructors,
450 irn_flags => [ "rematerializable" ],
452 emit => '. sra %S1, %R2I, %D1',
453 constructors => \%binop_operand_constructors,
457 irn_flags => [ "rematerializable" ],
459 emit => '. and %S1, %R2I, %D1',
460 constructors => \%binop_operand_constructors,
464 irn_flags => [ "rematerializable", "modifies_flags" ],
465 emit => '. and %S1, %R2I, %%g0',
467 constructors => \%binopcczero_operand_constructors,
471 irn_flags => [ "rematerializable" ],
473 emit => '. andn %S1, %R2I, %D1',
474 constructors => \%binop_operand_constructors,
478 irn_flags => [ "rematerializable", "modifies_flags" ],
479 emit => '. andn %S1, %R2I, %%g0',
481 constructors => \%binopcczero_operand_constructors,
485 irn_flags => [ "rematerializable" ],
487 emit => '. or %S1, %R2I, %D1',
488 constructors => \%binop_operand_constructors,
492 irn_flags => [ "rematerializable", "modifies_flags" ],
493 emit => '. or %S1, %R2I, %%g0',
495 constructors => \%binopcczero_operand_constructors,
499 irn_flags => [ "rematerializable" ],
501 emit => '. orn %S1, %R2I, %D1',
502 constructors => \%binop_operand_constructors,
506 irn_flags => [ "rematerializable", "modifies_flags" ],
507 emit => '. orn %S1, %R2I, %%g0',
509 constructors => \%binopcczero_operand_constructors,
513 irn_flags => [ "rematerializable" ],
515 emit => '. xor %S1, %R2I, %D1',
516 constructors => \%binop_operand_constructors,
520 irn_flags => [ "rematerializable", "modifies_flags" ],
521 emit => '. xor %S1, %R2I, %%g0',
523 constructors => \%binopcczero_operand_constructors,
527 irn_flags => [ "rematerializable" ],
529 emit => '. xnor %S1, %R2I, %D1',
530 constructors => \%binop_operand_constructors,
534 irn_flags => [ "rematerializable", "modifies_flags" ],
535 emit => '. xnor %S1, %R2I, %%g0',
537 constructors => \%binopcczero_operand_constructors,
541 irn_flags => [ "rematerializable" ],
543 emit => '. smul %S1, %R2I, %D1',
544 constructors => \%binop_operand_constructors,
548 irn_flags => [ "rematerializable" ],
549 outs => [ "low", "high" ],
550 constructors => \%binop_operand_constructors,
554 irn_flags => [ "rematerializable" ],
555 state => "exc_pinned",
556 ins => [ "dividend_high", "dividend_low", "divisor" ],
557 outs => [ "res", "M" ],
558 constructors => \%div_operand_constructors,
562 irn_flags => [ "rematerializable" ],
563 state => "exc_pinned",
564 ins => [ "dividend_high", "dividend_low", "divisor" ],
565 outs => [ "res", "M" ],
566 constructors => \%div_operand_constructors,
570 irn_flags => [ "rematerializable", "modifies_fp_flags" ],
571 emit => '. fcmp%FPM %S1, %S2',
572 attr_type => "sparc_fp_attr_t",
573 attr => "ir_mode *fp_mode",
574 mode => $mode_fpflags,
577 reg_req => { in => [ "fp", "fp" ], out => [ "fpflags" ] },
580 reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fpflags" ] },
583 reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fpflags" ] },
589 op_flags => [ "commutative" ],
590 irn_flags => [ "rematerializable" ],
591 emit => '. fadd%FPM %S1, %S2, %D1',
592 attr_type => "sparc_fp_attr_t",
593 attr => "ir_mode *fp_mode",
594 ins => [ "left", "right" ],
595 constructors => \%float_binop_constructors,
599 irn_flags => [ "rematerializable" ],
600 emit => '. fsub%FPM %S1, %S2, %D1',
601 attr_type => "sparc_fp_attr_t",
602 attr => "ir_mode *fp_mode",
603 ins => [ "left", "right" ],
604 constructors => \%float_binop_constructors,
608 irn_flags => [ "rematerializable" ],
609 op_flags => [ "commutative" ],
610 emit =>'. fmul%FPM %S1, %S2, %D1',
611 attr_type => "sparc_fp_attr_t",
612 attr => "ir_mode *fp_mode",
613 ins => [ "left", "right" ],
614 constructors => \%float_binop_constructors,
618 irn_flags => [ "rematerializable" ],
619 emit => '. fdiv%FPM %S1, %S2, %D1',
620 attr_type => "sparc_fp_attr_t",
621 attr => "ir_mode *fp_mode",
622 ins => [ "left", "right" ],
623 outs => [ "res", "M" ],
624 constructors => \%float_binop_constructors,
628 irn_flags => [ "rematerializable" ],
629 reg_req => { in => [ "fp" ], out => [ "fp" ] },
630 # note that we only need the first register even for wide-values
631 emit => '. fneg %S1, %D1',
632 attr_type => "sparc_fp_attr_t",
633 attr => "ir_mode *fp_mode",
635 constructors => \%float_unop_constructors,
639 irn_flags => [ "rematerializable" ],
640 # note that we only need the first register even for wide-values
641 emit => '. fabs %S1, %D1',
642 attr_type => "sparc_fp_attr_t",
643 attr => "ir_mode *fp_mode",
645 constructors => \%float_unop_constructors,
649 irn_flags => [ "rematerializable" ],
650 emit => '. f%FCONVS%.to%FCONVD %S1, %D1',
651 attr_type => "sparc_fp_conv_attr_t",
652 attr => "ir_mode *src_mode, ir_mode *dest_mode",
655 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
659 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
663 reg_req => { in => [ "fp:a|2" ], out => [ "fp" ] },
667 reg_req => { in => [ "fp:a|2" ], out => [ "fp:a|4" ] },
671 reg_req => { in => [ "fp:a|4" ], out => [ "fp" ] },
675 reg_req => { in => [ "fp:a|4" ], out => [ "fp:a|2" ] },
682 irn_flags => [ "rematerializable" ],
683 reg_req => { in => [ "gp" ], out => [ "fp" ] },
684 emit => '. fito%FPM %S1, %D1',
685 attr_type => "sparc_fp_attr_t",
686 attr => "ir_mode *fp_mode",
689 reg_req => { in => [ "gp" ], out => [ "fp" ] },
693 reg_req => { in => [ "gp" ], out => [ "fp:a|2" ] },
697 reg_req => { in => [ "gp" ], out => [ "fp:a|4" ] },
704 irn_flags => [ "rematerializable" ],
705 reg_req => { in => [ "fp" ], out => [ "gp" ] },
706 emit => '. f%FPM.toi %S1, %D1',
707 attr_type => "sparc_fp_attr_t",
708 attr => "ir_mode *fp_mode",
712 reg_req => { in => [ "gp" ], out => [ "gp" ] },
715 reg_req => { in => [ "fp:a|2" ], out => [ "gp" ] },
718 reg_req => { in => [ "fp:a|4" ], out => [ "gp" ] },
724 op_flags => [ "labeled", "fragile" ],
725 state => "exc_pinned",
728 reg_req => { in => [ "gp", "none" ], out => [ "fp", "none" ] },
731 reg_req => { in => [ "gp", "none" ], out => [ "fp:a|2", "none" ] },
734 reg_req => { in => [ "gp", "none" ], out => [ "fp:a|4", "none" ] },
737 ins => [ "ptr", "mem" ],
738 outs => [ "res", "M" ],
739 attr_type => "sparc_load_store_attr_t",
740 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
741 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
742 emit => '. ld%FLSM [%S1%O2], %D1'
746 op_flags => [ "labeled", "fragile" ],
747 state => "exc_pinned",
750 reg_req => { in => [ "fp", "gp", "none" ], out => [ "none" ] },
753 reg_req => { in => [ "fp:a|2", "gp", "none" ], out => [ "none" ] },
756 reg_req => { in => [ "fp:a|4", "gp", "none" ], out => [ "none" ] },
759 ins => [ "val", "ptr", "mem" ],
761 attr_type => "sparc_load_store_attr_t",
762 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
763 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
764 emit => '. st%FLSM %S2, [%S1%O2]',