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" ],
291 ins => [ "left", "right", "flags_input" ],
297 irn_flags => [ "rematerializable" ],
299 emit => '. sub %S0, %R1I, %D0',
300 constructors => \%binop_operand_constructors,
304 irn_flags => [ "rematerializable" ],
305 emit => '. subcc %S0, %R1I, %D0',
306 outs => [ "res", "flags" ],
307 constructors => \%binopcc_operand_constructors,
311 # Not rematerializable (see AddX)
312 emit => '. subx %S0, %R1I, %D0',
313 constructors => \%binopx_operand_constructors,
318 ins => [ "left", "right" ],
319 outs => [ "res", "flags" ],
325 ins => [ "left", "right", "flags_input" ],
332 op_flags => [ "labeled" ],
333 state => "exc_pinned",
336 reg_req => { in => [ "gp", "none" ], out => [ "gp", "none" ] },
337 ins => [ "ptr", "mem" ],
338 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
339 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
342 reg_req => { in => [ "gp", "gp", "none" ], out => [ "gp", "none" ] },
343 ins => [ "ptr", "ptr2", "mem" ],
344 attr => "ir_mode *ls_mode",
345 custominit => "init_sparc_load_store_attributes(res, ls_mode, NULL, 0, false, true);",
348 ins => [ "ptr", "mem" ],
349 outs => [ "res", "M" ],
350 attr_type => "sparc_load_store_attr_t",
351 emit => '. ld%LM [%S0%O1], %D0'
355 irn_flags => [ "rematerializable" ],
358 reg_req => { in => [], out => [ "gp" ] },
359 attr => "ir_entity *entity, int32_t immediate_value",
360 custominit => "sparc_set_attr_imm(res, entity, immediate_value);",
361 emit => '. sethi %HIM, %D0'
365 op_flags => [ "labeled" ],
367 state => "exc_pinned",
370 reg_req => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
371 ins => [ "val", "ptr", "mem" ],
372 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
373 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
376 reg_req => { in => [ "gp", "gp", "gp", "none" ], out => [ "none" ] },
377 ins => [ "val", "ptr", "ptr2", "mem" ],
378 attr => "ir_mode *ls_mode",
379 custominit => "init_sparc_load_store_attributes(res, ls_mode, NULL, 0, false, true);",
382 ins => [ "val", "ptr", "mem" ],
384 attr_type => "sparc_load_store_attr_t",
385 emit => '. st%SM %S0, [%S1%O2]'
389 emit => '. save %S0, %R1I, %D0',
394 attr => "ir_entity *immediate_entity, int32_t immediate_value",
395 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
396 reg_req => { in => [ "sp" ], out => [ "sp:I|S" ] },
400 reg_req => { in => [ "sp", "gp" ], out => [ "sp:I|S" ] },
401 ins => [ "stack", "increment" ],
408 emit => '. restore %S0, %R1I, %D0',
413 attr => "ir_entity *immediate_entity, int32_t immediate_value",
414 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
415 reg_req => { in => [ "sp" ], out => [ "sp:I|S" ] },
419 reg_req => { in => [ "sp", "gp" ], out => [ "sp:I|S" ] },
420 ins => [ "stack", "increment" ],
427 reg_req => { in => [ "frame_pointer" ], out => [ "sp:I|S" ] },
428 ins => [ "frame_pointer" ],
435 reg_req => { in => [ "sp", "gp" ], out => [ "sp:I|S" ] },
436 ins => [ "stack", "size" ],
438 emit => ". sub %S0, %S1, %D0\n",
443 reg_req => { in => [ "sp", "gp" ], out => [ "sp:I|S" ] },
444 ins => [ "stack", "size" ],
446 emit => ". add %S0, %S1, %D0\n",
451 op_flags => [ "constlike" ],
452 irn_flags => [ "rematerializable" ],
453 attr => "ir_entity *entity, int32_t offset",
454 reg_req => { in => [ "gp" ], out => [ "gp" ] },
456 attr_type => "sparc_attr_t",
457 custominit => "sparc_set_attr_imm(res, entity, offset);",
462 op_flags => [ "labeled", "cfopcode", "forking" ],
465 attr_type => "sparc_jmp_cond_attr_t",
466 attr => "ir_relation relation, bool is_unsigned",
467 init_attr => "\tinit_sparc_jmp_cond_attr(res, relation, is_unsigned);",
468 reg_req => { in => [ "flags" ], out => [ "none", "none" ] },
470 outs => [ "false", "true" ],
474 op_flags => [ "labeled", "cfopcode", "forking" ],
477 attr_type => "sparc_jmp_cond_attr_t",
478 attr => "ir_relation relation",
479 init_attr => "\tinit_sparc_jmp_cond_attr(res, relation, false);",
480 reg_req => { in => [ "fpflags" ], out => [ "none", "none" ] },
482 outs => [ "false", "true" ],
487 op_flags => [ "cfopcode" ],
488 irn_flags => [ "simple_jump" ],
489 reg_req => { out => [ "none" ] },
495 out_arity => "variable",
499 # This is a JumpLink instruction, but with the addition that you can add custom
500 # register constraints to model your calling conventions
503 op_flags => [ "cfopcode" ],
508 attr => "ir_entity *entity, int32_t offset",
509 custominit => "\tsparc_set_attr_imm(res, entity, offset);",
511 reg_req => { out => [ "none" ] },
515 reg_req => { out => [ "none" ] },
521 irn_flags => [ "modifies_flags", "modifies_fp_flags" ],
522 state => "exc_pinned",
524 out_arity => "variable",
527 attr => "ir_entity *entity, int32_t offset, bool aggregate_return",
528 custominit => "\tsparc_set_attr_imm(res, entity, offset);".
529 "\tif (aggregate_return) arch_add_irn_flags(res, sparc_arch_irn_flag_aggregate_return);",
531 out_arity => "variable",
534 attr => "bool aggregate_return",
536 out_arity => "variable",
537 custominit => "\tif (aggregate_return) arch_add_irn_flags(res, sparc_arch_irn_flag_aggregate_return);",
542 Cmp => { # aka SubccZero
543 irn_flags => [ "rematerializable", "modifies_flags" ],
544 emit => '. cmp %S0, %R1I',
546 constructors => \%binopcczero_operand_constructors,
550 op_flags => [ "labeled", "cfopcode", "forking" ],
553 reg_req => { in => [ "gp" ], out => [ ] },
554 attr_type => "sparc_switch_jmp_attr_t",
555 attr => "long default_pn, ir_entity *jump_table",
556 init_attr => "info->out_infos = NULL;", # XXX ugly hack for out requirements
560 irn_flags => [ "rematerializable" ],
562 emit => '. sll %S0, %R1I, %D0',
563 constructors => \%binop_operand_constructors,
567 irn_flags => [ "rematerializable" ],
569 emit => '. srl %S0, %R1I, %D0',
570 constructors => \%binop_operand_constructors,
574 irn_flags => [ "rematerializable" ],
576 emit => '. sra %S0, %R1I, %D0',
577 constructors => \%binop_operand_constructors,
581 irn_flags => [ "rematerializable" ],
583 emit => '. and %S0, %R1I, %D0',
584 constructors => \%binop_operand_constructors,
588 irn_flags => [ "rematerializable", "modifies_flags" ],
589 emit => '. andcc %S0, %R1I, %%g0',
591 constructors => \%binopcczero_operand_constructors,
595 irn_flags => [ "rematerializable" ],
597 emit => '. andn %S0, %R1I, %D0',
598 constructors => \%binop_operand_constructors,
602 irn_flags => [ "rematerializable", "modifies_flags" ],
603 emit => '. andncc %S0, %R1I, %%g0',
605 constructors => \%binopcczero_operand_constructors,
609 irn_flags => [ "rematerializable" ],
611 emit => '. or %S0, %R1I, %D0',
612 constructors => \%binop_operand_constructors,
616 irn_flags => [ "rematerializable", "modifies_flags" ],
617 emit => '. orcc %S0, %R1I, %%g0',
619 constructors => \%binopcczero_operand_constructors,
623 irn_flags => [ "rematerializable" ],
625 emit => '. orn %S0, %R1I, %D0',
626 constructors => \%binop_operand_constructors,
630 irn_flags => [ "rematerializable", "modifies_flags" ],
631 emit => '. orncc %S0, %R1I, %%g0',
633 constructors => \%binopcczero_operand_constructors,
637 irn_flags => [ "rematerializable" ],
639 emit => '. xor %S0, %R1I, %D0',
640 constructors => \%binop_operand_constructors,
644 irn_flags => [ "rematerializable", "modifies_flags" ],
645 emit => '. xorcc %S0, %R1I, %%g0',
647 constructors => \%binopcczero_operand_constructors,
651 irn_flags => [ "rematerializable" ],
653 emit => '. xnor %S0, %R1I, %D0',
654 constructors => \%binop_operand_constructors,
658 irn_flags => [ "rematerializable", "modifies_flags" ],
659 emit => '. xnorcc %S0, %R1I, %%g0',
661 constructors => \%binopcczero_operand_constructors,
665 irn_flags => [ "rematerializable" ],
667 emit => '. smul %S0, %R1I, %D0',
668 constructors => \%binop_operand_constructors,
672 irn_flags => [ "rematerializable" ],
673 outs => [ "low", "high" ],
674 constructors => \%binop_operand_constructors,
678 irn_flags => [ "rematerializable" ],
679 outs => [ "low", "high" ],
680 constructors => \%binop_operand_constructors,
684 irn_flags => [ "rematerializable" ],
685 state => "exc_pinned",
686 ins => [ "dividend_high", "dividend_low", "divisor" ],
687 outs => [ "res", "M" ],
688 constructors => \%div_operand_constructors,
692 irn_flags => [ "rematerializable" ],
693 state => "exc_pinned",
694 ins => [ "dividend_high", "dividend_low", "divisor" ],
695 outs => [ "res", "M" ],
696 constructors => \%div_operand_constructors,
700 irn_flags => [ "rematerializable", "modifies_fp_flags" ],
701 emit => '. fcmp%FPM %S0, %S1',
702 attr_type => "sparc_fp_attr_t",
703 attr => "ir_mode *fp_mode",
704 mode => $mode_fpflags,
707 reg_req => { in => [ "fp", "fp" ], out => [ "fpflags" ] },
710 reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fpflags" ] },
713 reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fpflags" ] },
719 op_flags => [ "commutative" ],
720 irn_flags => [ "rematerializable" ],
721 emit => '. fadd%FPM %S0, %S1, %D0',
722 attr_type => "sparc_fp_attr_t",
723 attr => "ir_mode *fp_mode",
724 ins => [ "left", "right" ],
725 constructors => \%float_binop_constructors,
729 irn_flags => [ "rematerializable" ],
730 emit => '. fsub%FPM %S0, %S1, %D0',
731 attr_type => "sparc_fp_attr_t",
732 attr => "ir_mode *fp_mode",
733 ins => [ "left", "right" ],
734 constructors => \%float_binop_constructors,
738 irn_flags => [ "rematerializable" ],
739 op_flags => [ "commutative" ],
740 emit =>'. fmul%FPM %S0, %S1, %D0',
741 attr_type => "sparc_fp_attr_t",
742 attr => "ir_mode *fp_mode",
743 ins => [ "left", "right" ],
744 constructors => \%float_binop_constructors,
748 irn_flags => [ "rematerializable" ],
749 emit => '. fdiv%FPM %S0, %S1, %D0',
750 attr_type => "sparc_fp_attr_t",
751 attr => "ir_mode *fp_mode",
752 ins => [ "left", "right" ],
753 outs => [ "res", "M" ],
756 reg_req => { in => [ "fp", "fp" ], out => [ "fp", "none" ] },
759 reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fp:a|2", "none" ] },
762 reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fp:a|4", "none" ] },
768 irn_flags => [ "rematerializable" ],
769 reg_req => { in => [ "fp" ], out => [ "fp" ] },
770 # note that we only need the first register even for wide-values
771 emit => '. fnegs %S0, %D0',
772 attr_type => "sparc_fp_attr_t",
773 attr => "ir_mode *fp_mode",
775 constructors => \%float_unop_constructors,
779 irn_flags => [ "rematerializable" ],
780 # note that we only need the first register even for wide-values
781 emit => '. fabs %S0, %D0',
782 attr_type => "sparc_fp_attr_t",
783 attr => "ir_mode *fp_mode",
785 constructors => \%float_unop_constructors,
789 irn_flags => [ "rematerializable" ],
790 emit => '. f%FCONVS%.to%FCONVD %S0, %D0',
791 attr_type => "sparc_fp_conv_attr_t",
792 attr => "ir_mode *src_mode, ir_mode *dest_mode",
795 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
799 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
803 reg_req => { in => [ "fp:a|2" ], out => [ "fp" ] },
807 reg_req => { in => [ "fp:a|2" ], out => [ "fp:a|4" ] },
811 reg_req => { in => [ "fp:a|4" ], out => [ "fp" ] },
815 reg_req => { in => [ "fp:a|4" ], out => [ "fp:a|2" ] },
822 irn_flags => [ "rematerializable" ],
823 emit => '. fito%FPM %S0, %D0',
824 attr_type => "sparc_fp_attr_t",
825 attr => "ir_mode *fp_mode",
828 reg_req => { in => [ "fp" ], out => [ "fp" ] },
832 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
836 reg_req => { in => [ "fp" ], out => [ "fp:a|4" ] },
843 irn_flags => [ "rematerializable" ],
844 emit => '. f%FPM%.toi %S0, %D0',
845 attr_type => "sparc_fp_attr_t",
846 attr => "ir_mode *fp_mode",
850 reg_req => { in => [ "fp" ], out => [ "fp" ] },
853 reg_req => { in => [ "fp:a|2" ], out => [ "fp" ] },
856 reg_req => { in => [ "fp:a|4" ], out => [ "fp" ] },
862 op_flags => [ "labeled" ],
863 state => "exc_pinned",
866 reg_req => { in => [ "gp", "none" ], out => [ "fp", "none" ] },
869 reg_req => { in => [ "gp", "none" ], out => [ "fp:a|2", "none" ] },
872 reg_req => { in => [ "gp", "none" ], out => [ "fp:a|4", "none" ] },
875 ins => [ "ptr", "mem" ],
876 outs => [ "res", "M" ],
877 attr_type => "sparc_load_store_attr_t",
878 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
879 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
880 emit => '. ld%FLSM [%S0%O1], %D0'
884 op_flags => [ "labeled" ],
885 state => "exc_pinned",
888 reg_req => { in => [ "fp", "gp", "none" ], out => [ "none" ] },
891 reg_req => { in => [ "fp:a|2", "gp", "none" ], out => [ "none" ] },
894 reg_req => { in => [ "fp:a|4", "gp", "none" ], out => [ "none" ] },
897 ins => [ "val", "ptr", "mem" ],
899 attr_type => "sparc_load_store_attr_t",
900 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
901 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
902 emit => '. st%FLSM %S0, [%S1%O2]',