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);",
119 S0O1 => "${arch}_emit_source_reg_and_offset(node, 0, 1);",
120 S1O2 => "${arch}_emit_source_reg_and_offset(node, 1, 2);",
123 $default_attr_type = "sparc_attr_t";
124 $default_copy_attr = "sparc_copy_attr";
127 sparc_attr_t => "\tinit_sparc_attributes(res, irn_flags_, in_reqs, exec_units, n_res);",
128 sparc_load_store_attr_t => "\tinit_sparc_attributes(res, irn_flags_, in_reqs, exec_units, n_res);",
129 sparc_jmp_cond_attr_t => "\tinit_sparc_attributes(res, irn_flags_, in_reqs, exec_units, n_res);",
130 sparc_switch_jmp_attr_t => "\tinit_sparc_attributes(res, irn_flags_, in_reqs, exec_units, n_res);\n".
131 "\tinit_sparc_switch_jmp_attributes(res, default_pn, jump_table);\n",
132 sparc_fp_attr_t => "\tinit_sparc_attributes(res, irn_flags_, in_reqs, exec_units, n_res);\n".
133 "\tinit_sparc_fp_attributes(res, fp_mode);\n",
134 sparc_fp_conv_attr_t => "\tinit_sparc_attributes(res, irn_flags_, in_reqs, exec_units, n_res);".
135 "\tinit_sparc_fp_conv_attributes(res, src_mode, dest_mode);\n",
139 sparc_attr_t => "cmp_attr_sparc",
140 sparc_load_store_attr_t => "cmp_attr_sparc_load_store",
141 sparc_jmp_cond_attr_t => "cmp_attr_sparc_jmp_cond",
142 sparc_switch_jmp_attr_t => "cmp_attr_sparc_switch_jmp",
143 sparc_fp_attr_t => "cmp_attr_sparc_fp",
144 sparc_fp_conv_attr_t => "cmp_attr_sparc_fp_conv",
147 %custom_irn_flags = (
148 modifies_flags => "(arch_irn_flags_t)sparc_arch_irn_flag_modifies_flags",
149 modifies_fp_flags => "(arch_irn_flags_t)sparc_arch_irn_flag_modifies_fp_flags",
150 has_delay_slot => "(arch_irn_flags_t)sparc_arch_irn_flag_has_delay_slot",
153 my %cmp_operand_constructors = (
155 attr => "ir_entity *immediate_entity, int32_t immediate_value",
156 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
157 reg_req => { in => [ "gp" ], out => [ "flags" ] },
161 reg_req => { in => [ "gp", "gp" ], out => [ "flags" ] },
162 ins => [ "left", "right" ],
166 my %binop_operand_constructors = (
168 attr => "ir_entity *immediate_entity, int32_t immediate_value",
169 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
170 reg_req => { in => [ "gp" ], out => [ "gp" ] },
174 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
175 ins => [ "left", "right" ],
179 my %binopcc_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 => [ "gp", "flags" ] },
187 reg_req => { in => [ "gp", "gp" ], out => [ "gp", "flags" ] },
188 ins => [ "left", "right" ],
192 my %binopx_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", "flags" ], out => [ "gp" ] },
197 ins => [ "left", "carry" ],
200 reg_req => { in => [ "gp", "gp", "flags" ], out => [ "gp" ] },
201 ins => [ "left", "right", "carry" ],
206 my %binopcczero_operand_constructors = (
208 attr => "ir_entity *immediate_entity, int32_t immediate_value",
209 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
210 reg_req => { in => [ "gp" ], out => [ "flags" ] },
214 reg_req => { in => [ "gp", "gp" ], out => [ "flags" ] },
215 ins => [ "left", "right" ],
219 my %div_operand_constructors = (
221 attr => "ir_entity *immediate_entity, int32_t immediate_value",
222 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
223 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
226 reg_req => { in => [ "gp", "gp", "gp" ], out => [ "gp" ] },
230 my %float_binop_constructors = (
232 reg_req => { in => [ "fp", "fp" ], out => [ "fp" ] },
236 reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fp:a|2" ] },
240 reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fp:a|4" ] },
245 my %float_unop_constructors = (
247 reg_req => { in => [ "fp" ], out => [ "fp" ] },
251 reg_req => { in => [ "fp:a|2" ], out => [ "fp:a|2" ] },
255 reg_req => { in => [ "fp:a|4" ], out => [ "fp:a|4" ] },
263 irn_flags => [ "rematerializable" ],
265 emit => '. add %S0, %R1I, %D0',
266 constructors => \%binop_operand_constructors,
270 irn_flags => [ "rematerializable" ],
271 emit => '. addcc %S0, %R1I, %D0',
272 outs => [ "res", "flags" ],
273 constructors => \%binopcc_operand_constructors,
277 # At the moment not rematerializable because of assert in beflags.c/
278 # (it claims that spiller can't rematerialize flag stuff correctly)
279 #irn_flags => [ "rematerializable" ],
280 emit => '. addx %S0, %R1I, %D0',
281 constructors => \%binopx_operand_constructors,
286 ins => [ "left", "right" ],
287 outs => [ "res", "flags" ],
293 ins => [ "left", "right", "flags_input" ],
299 irn_flags => [ "rematerializable" ],
301 emit => '. sub %S0, %R1I, %D0',
302 constructors => \%binop_operand_constructors,
306 irn_flags => [ "rematerializable" ],
307 emit => '. subcc %S0, %R1I, %D0',
308 outs => [ "res", "flags" ],
309 constructors => \%binopcc_operand_constructors,
313 # Not rematerializable (see AddX)
314 emit => '. subx %S0, %R1I, %D0',
315 constructors => \%binopx_operand_constructors,
320 ins => [ "left", "right" ],
321 outs => [ "res", "flags" ],
327 ins => [ "left", "right", "flags_input" ],
334 op_flags => [ "labeled" ],
335 state => "exc_pinned",
338 reg_req => { in => [ "gp", "none" ], out => [ "gp", "none" ] },
339 ins => [ "ptr", "mem" ],
340 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
341 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
344 reg_req => { in => [ "gp", "gp", "none" ], out => [ "gp", "none" ] },
345 ins => [ "ptr", "ptr2", "mem" ],
346 attr => "ir_mode *ls_mode",
347 custominit => "init_sparc_load_store_attributes(res, ls_mode, NULL, 0, false, true);",
350 ins => [ "ptr", "mem" ],
351 outs => [ "res", "M" ],
352 attr_type => "sparc_load_store_attr_t",
353 emit => '. ld%LM [%S0O1], %D0'
357 irn_flags => [ "rematerializable" ],
360 reg_req => { in => [], out => [ "gp" ] },
361 attr => "ir_entity *entity, int32_t immediate_value",
362 custominit => "sparc_set_attr_imm(res, entity, immediate_value);",
363 emit => '. sethi %HIM, %D0'
367 op_flags => [ "labeled" ],
369 state => "exc_pinned",
372 reg_req => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
373 ins => [ "val", "ptr", "mem" ],
374 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
375 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
378 reg_req => { in => [ "gp", "gp", "gp", "none" ], out => [ "none" ] },
379 ins => [ "val", "ptr", "ptr2", "mem" ],
380 attr => "ir_mode *ls_mode",
381 custominit => "init_sparc_load_store_attributes(res, ls_mode, NULL, 0, false, true);",
384 ins => [ "val", "ptr", "mem" ],
386 attr_type => "sparc_load_store_attr_t",
387 emit => '. st%SM %S0, [%S1O2]'
391 emit => '. save %S0, %R1I, %D0',
396 attr => "ir_entity *immediate_entity, int32_t immediate_value",
397 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
398 reg_req => { in => [ "sp" ], out => [ "sp:I|S" ] },
402 reg_req => { in => [ "sp", "gp" ], out => [ "sp:I|S" ] },
403 ins => [ "stack", "increment" ],
410 emit => '. restore %S0, %R1I, %D0',
415 attr => "ir_entity *immediate_entity, int32_t immediate_value",
416 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
417 reg_req => { in => [ "sp" ], out => [ "sp:I|S" ] },
421 reg_req => { in => [ "sp", "gp" ], out => [ "sp:I|S" ] },
422 ins => [ "stack", "increment" ],
429 reg_req => { in => [ "frame_pointer" ], out => [ "sp:I|S" ] },
430 ins => [ "frame_pointer" ],
437 reg_req => { in => [ "sp", "gp" ], out => [ "sp:I|S" ] },
438 ins => [ "stack", "size" ],
440 emit => ". sub %S0, %S1, %D0\n",
445 reg_req => { in => [ "sp", "gp" ], out => [ "sp:I|S" ] },
446 ins => [ "stack", "size" ],
448 emit => ". add %S0, %S1, %D0\n",
453 op_flags => [ "constlike" ],
454 irn_flags => [ "rematerializable" ],
455 attr => "ir_entity *entity, int32_t offset",
456 reg_req => { in => [ "gp" ], out => [ "gp" ] },
458 attr_type => "sparc_attr_t",
459 custominit => "sparc_set_attr_imm(res, entity, offset);",
464 op_flags => [ "labeled", "cfopcode", "forking" ],
465 irn_flags => [ "has_delay_slot" ],
468 attr_type => "sparc_jmp_cond_attr_t",
469 attr => "ir_relation relation, bool is_unsigned",
470 init_attr => "\tinit_sparc_jmp_cond_attr(res, relation, is_unsigned);",
471 reg_req => { in => [ "flags" ], out => [ "none", "none" ] },
473 outs => [ "false", "true" ],
477 op_flags => [ "labeled", "cfopcode", "forking" ],
478 irn_flags => [ "has_delay_slot" ],
481 attr_type => "sparc_jmp_cond_attr_t",
482 attr => "ir_relation relation",
483 init_attr => "\tinit_sparc_jmp_cond_attr(res, relation, false);",
484 reg_req => { in => [ "fpflags" ], out => [ "none", "none" ] },
486 outs => [ "false", "true" ],
490 # Note: has_delay_slot depends on wether it is a fallthrough or not, so we
491 # have special code for this in sparc_emitter
493 op_flags => [ "cfopcode" ],
494 irn_flags => [ "simple_jump" ],
495 reg_req => { out => [ "none" ] },
501 out_arity => "variable",
505 # This is a JumpLink instruction, but with the addition that you can add custom
506 # register constraints to model your calling conventions
509 op_flags => [ "cfopcode" ],
510 irn_flags => [ "has_delay_slot" ],
515 attr => "ir_entity *entity, int32_t offset",
516 custominit => "\tsparc_set_attr_imm(res, entity, offset);",
518 reg_req => { out => [ "none" ] },
522 reg_req => { out => [ "none" ] },
528 irn_flags => [ "modifies_flags", "modifies_fp_flags", "has_delay_slot" ],
529 state => "exc_pinned",
531 out_arity => "variable",
534 attr => "ir_entity *entity, int32_t offset, bool aggregate_return",
535 custominit => "\tsparc_set_attr_imm(res, entity, offset);".
536 "\tif (aggregate_return) arch_add_irn_flags(res, sparc_arch_irn_flag_aggregate_return);",
538 out_arity => "variable",
541 attr => "bool aggregate_return",
543 out_arity => "variable",
544 custominit => "\tif (aggregate_return) arch_add_irn_flags(res, sparc_arch_irn_flag_aggregate_return);",
549 Cmp => { # aka SubccZero
550 irn_flags => [ "rematerializable", "modifies_flags" ],
551 emit => '. cmp %S0, %R1I',
553 constructors => \%binopcczero_operand_constructors,
557 op_flags => [ "labeled", "cfopcode", "forking" ],
558 irn_flags => [ "has_delay_slot" ],
561 reg_req => { in => [ "gp" ], out => [ ] },
562 attr_type => "sparc_switch_jmp_attr_t",
563 attr => "long default_pn, ir_entity *jump_table",
564 init_attr => "info->out_infos = NULL;", # XXX ugly hack for out requirements
568 irn_flags => [ "rematerializable" ],
570 emit => '. sll %S0, %R1I, %D0',
571 constructors => \%binop_operand_constructors,
575 irn_flags => [ "rematerializable" ],
577 emit => '. srl %S0, %R1I, %D0',
578 constructors => \%binop_operand_constructors,
582 irn_flags => [ "rematerializable" ],
584 emit => '. sra %S0, %R1I, %D0',
585 constructors => \%binop_operand_constructors,
589 irn_flags => [ "rematerializable" ],
591 emit => '. and %S0, %R1I, %D0',
592 constructors => \%binop_operand_constructors,
596 irn_flags => [ "rematerializable", "modifies_flags" ],
597 emit => '. andcc %S0, %R1I, %%g0',
599 constructors => \%binopcczero_operand_constructors,
603 irn_flags => [ "rematerializable" ],
605 emit => '. andn %S0, %R1I, %D0',
606 constructors => \%binop_operand_constructors,
610 irn_flags => [ "rematerializable", "modifies_flags" ],
611 emit => '. andncc %S0, %R1I, %%g0',
613 constructors => \%binopcczero_operand_constructors,
617 irn_flags => [ "rematerializable" ],
619 emit => '. or %S0, %R1I, %D0',
620 constructors => \%binop_operand_constructors,
624 irn_flags => [ "rematerializable", "modifies_flags" ],
625 emit => '. orcc %S0, %R1I, %%g0',
627 constructors => \%binopcczero_operand_constructors,
631 irn_flags => [ "rematerializable" ],
633 emit => '. orn %S0, %R1I, %D0',
634 constructors => \%binop_operand_constructors,
638 irn_flags => [ "rematerializable", "modifies_flags" ],
639 emit => '. orncc %S0, %R1I, %%g0',
641 constructors => \%binopcczero_operand_constructors,
645 irn_flags => [ "rematerializable" ],
647 emit => '. xor %S0, %R1I, %D0',
648 constructors => \%binop_operand_constructors,
652 irn_flags => [ "rematerializable", "modifies_flags" ],
653 emit => '. xorcc %S0, %R1I, %%g0',
655 constructors => \%binopcczero_operand_constructors,
659 irn_flags => [ "rematerializable" ],
661 emit => '. xnor %S0, %R1I, %D0',
662 constructors => \%binop_operand_constructors,
666 irn_flags => [ "rematerializable", "modifies_flags" ],
667 emit => '. xnorcc %S0, %R1I, %%g0',
669 constructors => \%binopcczero_operand_constructors,
673 irn_flags => [ "rematerializable" ],
675 emit => '. smul %S0, %R1I, %D0',
676 constructors => \%binop_operand_constructors,
680 irn_flags => [ "rematerializable" ],
681 outs => [ "low", "high" ],
682 constructors => \%binop_operand_constructors,
686 irn_flags => [ "rematerializable" ],
687 outs => [ "low", "high" ],
688 constructors => \%binop_operand_constructors,
692 irn_flags => [ "rematerializable", "has_delay_slot" ],
693 state => "exc_pinned",
694 ins => [ "dividend_high", "dividend_low", "divisor" ],
695 outs => [ "res", "M" ],
696 constructors => \%div_operand_constructors,
700 irn_flags => [ "rematerializable", "has_delay_slot" ],
701 state => "exc_pinned",
702 ins => [ "dividend_high", "dividend_low", "divisor" ],
703 outs => [ "res", "M" ],
704 constructors => \%div_operand_constructors,
708 irn_flags => [ "rematerializable", "modifies_fp_flags" ],
709 emit => '. fcmp%FPM %S0, %S1',
710 attr_type => "sparc_fp_attr_t",
711 attr => "ir_mode *fp_mode",
712 mode => $mode_fpflags,
715 reg_req => { in => [ "fp", "fp" ], out => [ "fpflags" ] },
718 reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fpflags" ] },
721 reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fpflags" ] },
727 op_flags => [ "commutative" ],
728 irn_flags => [ "rematerializable" ],
729 emit => '. fadd%FPM %S0, %S1, %D0',
730 attr_type => "sparc_fp_attr_t",
731 attr => "ir_mode *fp_mode",
732 ins => [ "left", "right" ],
733 constructors => \%float_binop_constructors,
737 irn_flags => [ "rematerializable" ],
738 emit => '. fsub%FPM %S0, %S1, %D0',
739 attr_type => "sparc_fp_attr_t",
740 attr => "ir_mode *fp_mode",
741 ins => [ "left", "right" ],
742 constructors => \%float_binop_constructors,
746 irn_flags => [ "rematerializable" ],
747 op_flags => [ "commutative" ],
748 emit =>'. fmul%FPM %S0, %S1, %D0',
749 attr_type => "sparc_fp_attr_t",
750 attr => "ir_mode *fp_mode",
751 ins => [ "left", "right" ],
752 constructors => \%float_binop_constructors,
756 irn_flags => [ "rematerializable" ],
757 emit => '. fdiv%FPM %S0, %S1, %D0',
758 attr_type => "sparc_fp_attr_t",
759 attr => "ir_mode *fp_mode",
760 ins => [ "left", "right" ],
761 outs => [ "res", "M" ],
764 reg_req => { in => [ "fp", "fp" ], out => [ "fp", "none" ] },
767 reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fp:a|2", "none" ] },
770 reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fp:a|4", "none" ] },
776 irn_flags => [ "rematerializable" ],
777 reg_req => { in => [ "fp" ], out => [ "fp" ] },
778 # note that we only need the first register even for wide-values
779 emit => '. fnegs %S0, %D0',
780 attr_type => "sparc_fp_attr_t",
781 attr => "ir_mode *fp_mode",
783 constructors => \%float_unop_constructors,
787 irn_flags => [ "rematerializable" ],
788 # note that we only need the first register even for wide-values
789 emit => '. fabs %S0, %D0',
790 attr_type => "sparc_fp_attr_t",
791 attr => "ir_mode *fp_mode",
793 constructors => \%float_unop_constructors,
797 irn_flags => [ "rematerializable" ],
798 emit => '. f%FCONVS%.to%FCONVD %S0, %D0',
799 attr_type => "sparc_fp_conv_attr_t",
800 attr => "ir_mode *src_mode, ir_mode *dest_mode",
803 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
807 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
811 reg_req => { in => [ "fp:a|2" ], out => [ "fp" ] },
815 reg_req => { in => [ "fp:a|2" ], out => [ "fp:a|4" ] },
819 reg_req => { in => [ "fp:a|4" ], out => [ "fp" ] },
823 reg_req => { in => [ "fp:a|4" ], out => [ "fp:a|2" ] },
830 irn_flags => [ "rematerializable" ],
831 emit => '. fito%FPM %S0, %D0',
832 attr_type => "sparc_fp_attr_t",
833 attr => "ir_mode *fp_mode",
836 reg_req => { in => [ "fp" ], out => [ "fp" ] },
840 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
844 reg_req => { in => [ "fp" ], out => [ "fp:a|4" ] },
851 irn_flags => [ "rematerializable" ],
852 emit => '. f%FPM%.toi %S0, %D0',
853 attr_type => "sparc_fp_attr_t",
854 attr => "ir_mode *fp_mode",
858 reg_req => { in => [ "fp" ], out => [ "fp" ] },
861 reg_req => { in => [ "fp:a|2" ], out => [ "fp" ] },
864 reg_req => { in => [ "fp:a|4" ], out => [ "fp" ] },
870 op_flags => [ "labeled" ],
871 state => "exc_pinned",
874 reg_req => { in => [ "gp", "none" ], out => [ "fp", "none" ] },
877 reg_req => { in => [ "gp", "none" ], out => [ "fp:a|2", "none" ] },
880 reg_req => { in => [ "gp", "none" ], out => [ "fp:a|4", "none" ] },
883 ins => [ "ptr", "mem" ],
884 outs => [ "res", "M" ],
885 attr_type => "sparc_load_store_attr_t",
886 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
887 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
888 emit => '. ld%FLSM [%S0%O1], %D0'
892 op_flags => [ "labeled" ],
893 state => "exc_pinned",
896 reg_req => { in => [ "fp", "gp", "none" ], out => [ "none" ] },
899 reg_req => { in => [ "fp:a|2", "gp", "none" ], out => [ "none" ] },
902 reg_req => { in => [ "fp:a|4", "gp", "none" ], out => [ "none" ] },
905 ins => [ "val", "ptr", "mem" ],
907 attr_type => "sparc_load_store_attr_t",
908 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
909 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
910 emit => '. st%FLSM %S0, [%S1%O2]',