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 # available SPARC registers: 8 globals, 24 window regs (8 ins, 8 outs, 8 locals)
49 { name => "frame_pointer", realname => "fp" },
54 { name => "fpflags" },
55 { mode => $mode_fpflags, flags => "manual_ra" }
59 { mode => $mode_flags, flags => "manual_ra" }
63 { mode => $mode_gp, flags => "manual_ra" }
65 # fp registers can be accessed any time
104 # emit source reg or imm dep. on node's arity
105 RI => "${arch}_emit_reg_or_imm(node, -1);",
106 R1I => "${arch}_emit_reg_or_imm(node, 1);",
107 S0 => "${arch}_emit_source_register(node, 0);",
108 S1 => "${arch}_emit_source_register(node, 1);",
109 D0 => "${arch}_emit_dest_register(node, 0);",
110 HIM => "${arch}_emit_high_immediate(node);",
111 LM => "${arch}_emit_load_mode(node);",
112 SM => "${arch}_emit_store_mode(node);",
113 FLSM => "${arch}_emit_float_load_store_mode(node);",
114 FPM => "${arch}_emit_fp_mode_suffix(node);",
115 FCONVS => "${arch}_emit_fp_conv_source(node);",
116 FCONVD => "${arch}_emit_fp_conv_destination(node);",
117 O1 => "${arch}_emit_offset(node, 1);",
118 O2 => "${arch}_emit_offset(node, 2);",
121 $default_attr_type = "sparc_attr_t";
122 $default_copy_attr = "sparc_copy_attr";
126 sparc_attr_t => "\tinit_sparc_attributes(res, irn_flags_, in_reqs, exec_units, n_res);",
127 sparc_load_store_attr_t => "\tinit_sparc_attributes(res, irn_flags_, in_reqs, exec_units, n_res);",
128 sparc_jmp_cond_attr_t => "\tinit_sparc_attributes(res, irn_flags_, in_reqs, exec_units, n_res);",
129 sparc_switch_jmp_attr_t => "\tinit_sparc_attributes(res, irn_flags_, in_reqs, exec_units, n_res);\n".
130 "\tinit_sparc_switch_jmp_attributes(res, default_pn, jump_table);\n",
131 sparc_fp_attr_t => "\tinit_sparc_attributes(res, irn_flags_, in_reqs, exec_units, n_res);\n".
132 "\tinit_sparc_fp_attributes(res, fp_mode);\n",
133 sparc_fp_conv_attr_t => "\tinit_sparc_attributes(res, irn_flags_, in_reqs, exec_units, n_res);".
134 "\tinit_sparc_fp_conv_attributes(res, src_mode, dest_mode);\n",
138 sparc_attr_t => "cmp_attr_sparc",
139 sparc_load_store_attr_t => "cmp_attr_sparc_load_store",
140 sparc_jmp_cond_attr_t => "cmp_attr_sparc_jmp_cond",
141 sparc_switch_jmp_attr_t => "cmp_attr_sparc_switch_jmp",
142 sparc_fp_attr_t => "cmp_attr_sparc_fp",
143 sparc_fp_conv_attr_t => "cmp_attr_sparc_fp_conv",
146 %custom_irn_flags = (
147 modifies_flags => "(arch_irn_flags_t)sparc_arch_irn_flag_modifies_flags",
148 modifies_fp_flags => "(arch_irn_flags_t)sparc_arch_irn_flag_modifies_fp_flags",
151 my %cmp_operand_constructors = (
153 attr => "ir_entity *immediate_entity, int32_t immediate_value",
154 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
155 reg_req => { in => [ "gp" ], out => [ "flags" ] },
159 reg_req => { in => [ "gp", "gp" ], out => [ "flags" ] },
160 ins => [ "left", "right" ],
164 my %binop_operand_constructors = (
166 attr => "ir_entity *immediate_entity, int32_t immediate_value",
167 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
168 reg_req => { in => [ "gp" ], out => [ "gp" ] },
172 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
173 ins => [ "left", "right" ],
177 my %binopcc_operand_constructors = (
179 attr => "ir_entity *immediate_entity, int32_t immediate_value",
180 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
181 reg_req => { in => [ "gp" ], out => [ "gp", "flags" ] },
185 reg_req => { in => [ "gp", "gp" ], out => [ "gp", "flags" ] },
186 ins => [ "left", "right" ],
190 my %binopx_operand_constructors = (
192 attr => "ir_entity *immediate_entity, int32_t immediate_value",
193 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
194 reg_req => { in => [ "gp", "flags" ], out => [ "gp" ] },
195 ins => [ "left", "carry" ],
198 reg_req => { in => [ "gp", "gp", "flags" ], out => [ "gp" ] },
199 ins => [ "left", "right", "carry" ],
204 my %binopcczero_operand_constructors = (
206 attr => "ir_entity *immediate_entity, int32_t immediate_value",
207 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
208 reg_req => { in => [ "gp" ], out => [ "flags" ] },
212 reg_req => { in => [ "gp", "gp" ], out => [ "flags" ] },
213 ins => [ "left", "right" ],
217 my %div_operand_constructors = (
219 attr => "ir_entity *immediate_entity, int32_t immediate_value",
220 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
221 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
224 reg_req => { in => [ "gp", "gp", "gp" ], out => [ "gp" ] },
228 my %float_binop_constructors = (
230 reg_req => { in => [ "fp", "fp" ], out => [ "fp" ] },
234 reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fp:a|2" ] },
238 reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fp:a|4" ] },
243 my %float_unop_constructors = (
245 reg_req => { in => [ "fp" ], out => [ "fp" ] },
249 reg_req => { in => [ "fp:a|2" ], out => [ "fp:a|2" ] },
253 reg_req => { in => [ "fp:a|4" ], out => [ "fp:a|4" ] },
261 irn_flags => [ "rematerializable" ],
263 emit => '. add %S0, %R1I, %D0',
264 constructors => \%binop_operand_constructors,
268 irn_flags => [ "rematerializable" ],
269 emit => '. addcc %S0, %R1I, %D0',
270 outs => [ "res", "flags" ],
271 constructors => \%binopcc_operand_constructors,
275 # At the moment not rematerializable because of assert in beflags.c/
276 # (it claims that spiller can't rematerialize flag stuff correctly)
277 #irn_flags => [ "rematerializable" ],
278 emit => '. addx %S0, %R1I, %D0',
279 constructors => \%binopx_operand_constructors,
284 ins => [ "left", "right" ],
285 outs => [ "res", "flags" ],
290 ins => [ "left", "right", "flags_input" ],
295 irn_flags => [ "rematerializable" ],
297 emit => '. sub %S0, %R1I, %D0',
298 constructors => \%binop_operand_constructors,
302 irn_flags => [ "rematerializable" ],
303 emit => '. subcc %S0, %R1I, %D0',
304 outs => [ "res", "flags" ],
305 constructors => \%binopcc_operand_constructors,
309 # Not rematerializable (see AddX)
310 emit => '. subx %S0, %R1I, %D0',
311 constructors => \%binopx_operand_constructors,
316 ins => [ "left", "right" ],
317 outs => [ "res", "flags" ],
322 ins => [ "left", "right", "flags_input" ],
328 op_flags => [ "labeled" ],
329 state => "exc_pinned",
332 reg_req => { in => [ "gp", "none" ], out => [ "gp", "none" ] },
333 ins => [ "ptr", "mem" ],
334 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
335 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
338 reg_req => { in => [ "gp", "gp", "none" ], out => [ "gp", "none" ] },
339 ins => [ "ptr", "ptr2", "mem" ],
340 attr => "ir_mode *ls_mode",
341 custominit => "init_sparc_load_store_attributes(res, ls_mode, NULL, 0, false, true);",
344 ins => [ "ptr", "mem" ],
345 outs => [ "res", "M" ],
346 attr_type => "sparc_load_store_attr_t",
347 emit => '. ld%LM [%S0%O1], %D0'
351 irn_flags => [ "rematerializable" ],
354 reg_req => { in => [], out => [ "gp" ] },
355 attr => "ir_entity *entity, int32_t immediate_value",
356 custominit => "sparc_set_attr_imm(res, entity, immediate_value);",
357 emit => '. sethi %HIM, %D0'
361 op_flags => [ "labeled" ],
363 state => "exc_pinned",
366 reg_req => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
367 ins => [ "val", "ptr", "mem" ],
368 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
369 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
372 reg_req => { in => [ "gp", "gp", "gp", "none" ], out => [ "none" ] },
373 ins => [ "val", "ptr", "ptr2", "mem" ],
374 attr => "ir_mode *ls_mode",
375 custominit => "init_sparc_load_store_attributes(res, ls_mode, NULL, 0, false, true);",
378 ins => [ "val", "ptr", "mem" ],
380 attr_type => "sparc_load_store_attr_t",
381 emit => '. st%SM %S0, [%S1%O2]'
385 emit => '. save %S0, %R1I, %D0',
390 attr => "ir_entity *immediate_entity, int32_t immediate_value",
391 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
392 reg_req => { in => [ "sp" ], out => [ "sp:I|S" ] },
396 reg_req => { in => [ "sp", "gp" ], out => [ "sp:I|S" ] },
397 ins => [ "stack", "increment" ],
404 emit => '. restore %S0, %R1I, %D0',
409 attr => "ir_entity *immediate_entity, int32_t immediate_value",
410 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
411 reg_req => { in => [ "sp" ], out => [ "sp:I|S" ] },
415 reg_req => { in => [ "sp", "gp" ], out => [ "sp:I|S" ] },
416 ins => [ "stack", "increment" ],
424 reg_req => { in => [ "frame_pointer" ], out => [ "sp:I|S" ] },
425 ins => [ "frame_pointer" ],
431 reg_req => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "gp", "none" ] },
432 ins => [ "stack", "size", "mem" ],
433 outs => [ "stack", "addr", "M" ],
434 emit => ". sub %S0, %S1, %D0\n",
438 reg_req => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "none" ] },
439 ins => [ "stack", "size", "mem" ],
440 outs => [ "stack", "M" ],
441 emit => ". add %S0, %S1, %D0\n",
445 op_flags => [ "constlike" ],
446 irn_flags => [ "rematerializable" ],
447 attr => "ir_entity *entity, int32_t offset",
448 reg_req => { in => [ "gp" ], out => [ "gp" ] },
450 attr_type => "sparc_attr_t",
451 custominit => "sparc_set_attr_imm(res, entity, offset);",
456 op_flags => [ "labeled", "cfopcode", "forking" ],
459 attr_type => "sparc_jmp_cond_attr_t",
460 attr => "ir_relation relation, bool is_unsigned",
461 init_attr => "\tinit_sparc_jmp_cond_attr(res, relation, is_unsigned);",
462 reg_req => { in => [ "flags" ], out => [ "none", "none" ] },
464 outs => [ "false", "true" ],
468 op_flags => [ "labeled", "cfopcode", "forking" ],
471 attr_type => "sparc_jmp_cond_attr_t",
472 attr => "ir_relation relation",
473 init_attr => "\tinit_sparc_jmp_cond_attr(res, relation, false);",
474 reg_req => { in => [ "fpflags" ], out => [ "none", "none" ] },
476 outs => [ "false", "true" ],
481 op_flags => [ "cfopcode" ],
482 irn_flags => [ "simple_jump" ],
483 reg_req => { out => [ "none" ] },
489 out_arity => "variable",
493 # This is a JumpLink instruction, but with the addition that you can add custom
494 # register constraints to model your calling conventions
497 op_flags => [ "cfopcode" ],
502 attr => "ir_entity *entity, int32_t offset",
503 custominit => "\tsparc_set_attr_imm(res, entity, offset);",
505 reg_req => { out => [ "none" ] },
509 reg_req => { out => [ "none" ] },
515 irn_flags => [ "modifies_flags", "modifies_fp_flags" ],
516 state => "exc_pinned",
518 out_arity => "variable",
521 attr => "ir_entity *entity, int32_t offset",
522 custominit => "\tsparc_set_attr_imm(res, entity, offset);",
524 out_arity => "variable",
528 out_arity => "variable",
533 Cmp => { # aka SubccZero
534 irn_flags => [ "rematerializable", "modifies_flags" ],
535 emit => '. cmp %S0, %R1I',
537 constructors => \%binopcczero_operand_constructors,
541 op_flags => [ "labeled", "cfopcode", "forking" ],
544 reg_req => { in => [ "gp" ], out => [ ] },
545 attr_type => "sparc_switch_jmp_attr_t",
546 attr => "long default_pn, ir_entity *jump_table",
547 init_attr => "info->out_infos = NULL;", # XXX ugly hack for out requirements
551 irn_flags => [ "rematerializable" ],
553 emit => '. sll %S0, %R1I, %D0',
554 constructors => \%binop_operand_constructors,
558 irn_flags => [ "rematerializable" ],
560 emit => '. srl %S0, %R1I, %D0',
561 constructors => \%binop_operand_constructors,
565 irn_flags => [ "rematerializable" ],
567 emit => '. sra %S0, %R1I, %D0',
568 constructors => \%binop_operand_constructors,
572 irn_flags => [ "rematerializable" ],
574 emit => '. and %S0, %R1I, %D0',
575 constructors => \%binop_operand_constructors,
579 irn_flags => [ "rematerializable", "modifies_flags" ],
580 emit => '. andcc %S0, %R1I, %%g0',
582 constructors => \%binopcczero_operand_constructors,
586 irn_flags => [ "rematerializable" ],
588 emit => '. andn %S0, %R1I, %D0',
589 constructors => \%binop_operand_constructors,
593 irn_flags => [ "rematerializable", "modifies_flags" ],
594 emit => '. andncc %S0, %R1I, %%g0',
596 constructors => \%binopcczero_operand_constructors,
600 irn_flags => [ "rematerializable" ],
602 emit => '. or %S0, %R1I, %D0',
603 constructors => \%binop_operand_constructors,
607 irn_flags => [ "rematerializable", "modifies_flags" ],
608 emit => '. orcc %S0, %R1I, %%g0',
610 constructors => \%binopcczero_operand_constructors,
614 irn_flags => [ "rematerializable" ],
616 emit => '. orn %S0, %R1I, %D0',
617 constructors => \%binop_operand_constructors,
621 irn_flags => [ "rematerializable", "modifies_flags" ],
622 emit => '. orncc %S0, %R1I, %%g0',
624 constructors => \%binopcczero_operand_constructors,
628 irn_flags => [ "rematerializable" ],
630 emit => '. xor %S0, %R1I, %D0',
631 constructors => \%binop_operand_constructors,
635 irn_flags => [ "rematerializable", "modifies_flags" ],
636 emit => '. xorcc %S0, %R1I, %%g0',
638 constructors => \%binopcczero_operand_constructors,
642 irn_flags => [ "rematerializable" ],
644 emit => '. xnor %S0, %R1I, %D0',
645 constructors => \%binop_operand_constructors,
649 irn_flags => [ "rematerializable", "modifies_flags" ],
650 emit => '. xnorcc %S0, %R1I, %%g0',
652 constructors => \%binopcczero_operand_constructors,
656 irn_flags => [ "rematerializable" ],
658 emit => '. smul %S0, %R1I, %D0',
659 constructors => \%binop_operand_constructors,
663 irn_flags => [ "rematerializable" ],
664 outs => [ "low", "high" ],
665 constructors => \%binop_operand_constructors,
669 irn_flags => [ "rematerializable" ],
670 state => "exc_pinned",
671 ins => [ "dividend_high", "dividend_low", "divisor" ],
672 outs => [ "res", "M" ],
673 constructors => \%div_operand_constructors,
677 irn_flags => [ "rematerializable" ],
678 state => "exc_pinned",
679 ins => [ "dividend_high", "dividend_low", "divisor" ],
680 outs => [ "res", "M" ],
681 constructors => \%div_operand_constructors,
685 irn_flags => [ "rematerializable", "modifies_fp_flags" ],
686 emit => '. fcmp%FPM %S0, %S1',
687 attr_type => "sparc_fp_attr_t",
688 attr => "ir_mode *fp_mode",
689 mode => $mode_fpflags,
692 reg_req => { in => [ "fp", "fp" ], out => [ "fpflags" ] },
695 reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fpflags" ] },
698 reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fpflags" ] },
704 op_flags => [ "commutative" ],
705 irn_flags => [ "rematerializable" ],
706 emit => '. fadd%FPM %S0, %S1, %D0',
707 attr_type => "sparc_fp_attr_t",
708 attr => "ir_mode *fp_mode",
709 ins => [ "left", "right" ],
710 constructors => \%float_binop_constructors,
714 irn_flags => [ "rematerializable" ],
715 emit => '. fsub%FPM %S0, %S1, %D0',
716 attr_type => "sparc_fp_attr_t",
717 attr => "ir_mode *fp_mode",
718 ins => [ "left", "right" ],
719 constructors => \%float_binop_constructors,
723 irn_flags => [ "rematerializable" ],
724 op_flags => [ "commutative" ],
725 emit =>'. fmul%FPM %S0, %S1, %D0',
726 attr_type => "sparc_fp_attr_t",
727 attr => "ir_mode *fp_mode",
728 ins => [ "left", "right" ],
729 constructors => \%float_binop_constructors,
733 irn_flags => [ "rematerializable" ],
734 emit => '. fdiv%FPM %S0, %S1, %D0',
735 attr_type => "sparc_fp_attr_t",
736 attr => "ir_mode *fp_mode",
737 ins => [ "left", "right" ],
738 outs => [ "res", "M" ],
741 reg_req => { in => [ "fp", "fp" ], out => [ "fp", "none" ] },
744 reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fp:a|2", "none" ] },
747 reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fp:a|4", "none" ] },
753 irn_flags => [ "rematerializable" ],
754 reg_req => { in => [ "fp" ], out => [ "fp" ] },
755 # note that we only need the first register even for wide-values
756 emit => '. fnegs %S0, %D0',
757 attr_type => "sparc_fp_attr_t",
758 attr => "ir_mode *fp_mode",
760 constructors => \%float_unop_constructors,
764 irn_flags => [ "rematerializable" ],
765 # note that we only need the first register even for wide-values
766 emit => '. fabs %S0, %D0',
767 attr_type => "sparc_fp_attr_t",
768 attr => "ir_mode *fp_mode",
770 constructors => \%float_unop_constructors,
774 irn_flags => [ "rematerializable" ],
775 emit => '. f%FCONVS%.to%FCONVD %S0, %D0',
776 attr_type => "sparc_fp_conv_attr_t",
777 attr => "ir_mode *src_mode, ir_mode *dest_mode",
780 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
784 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
788 reg_req => { in => [ "fp:a|2" ], out => [ "fp" ] },
792 reg_req => { in => [ "fp:a|2" ], out => [ "fp:a|4" ] },
796 reg_req => { in => [ "fp:a|4" ], out => [ "fp" ] },
800 reg_req => { in => [ "fp:a|4" ], out => [ "fp:a|2" ] },
807 irn_flags => [ "rematerializable" ],
808 emit => '. fito%FPM %S0, %D0',
809 attr_type => "sparc_fp_attr_t",
810 attr => "ir_mode *fp_mode",
813 reg_req => { in => [ "fp" ], out => [ "fp" ] },
817 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
821 reg_req => { in => [ "fp" ], out => [ "fp:a|4" ] },
828 irn_flags => [ "rematerializable" ],
829 emit => '. f%FPM%.toi %S0, %D0',
830 attr_type => "sparc_fp_attr_t",
831 attr => "ir_mode *fp_mode",
835 reg_req => { in => [ "fp" ], out => [ "fp" ] },
838 reg_req => { in => [ "fp:a|2" ], out => [ "fp" ] },
841 reg_req => { in => [ "fp:a|4" ], out => [ "fp" ] },
847 op_flags => [ "labeled" ],
848 state => "exc_pinned",
851 reg_req => { in => [ "gp", "none" ], out => [ "fp", "none" ] },
854 reg_req => { in => [ "gp", "none" ], out => [ "fp:a|2", "none" ] },
857 reg_req => { in => [ "gp", "none" ], out => [ "fp:a|4", "none" ] },
860 ins => [ "ptr", "mem" ],
861 outs => [ "res", "M" ],
862 attr_type => "sparc_load_store_attr_t",
863 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
864 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
865 emit => '. ld%FLSM [%S0%O1], %D0'
869 op_flags => [ "labeled" ],
870 state => "exc_pinned",
873 reg_req => { in => [ "fp", "gp", "none" ], out => [ "none" ] },
876 reg_req => { in => [ "fp:a|2", "gp", "none" ], out => [ "none" ] },
879 reg_req => { in => [ "fp:a|4", "gp", "none" ], out => [ "none" ] },
882 ins => [ "val", "ptr", "mem" ],
884 attr_type => "sparc_load_store_attr_t",
885 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
886 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
887 emit => '. st%FLSM %S0, [%S1%O2]',