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" ],
423 reg_req => { in => [ "frame_pointer" ], out => [ "sp:I|S" ] },
424 ins => [ "frame_pointer" ],
431 reg_req => { in => [ "sp", "gp" ], out => [ "sp:I|S" ] },
432 ins => [ "stack", "size" ],
434 emit => ". sub %S0, %S1, %D0\n",
439 reg_req => { in => [ "sp", "gp" ], out => [ "sp:I|S" ] },
440 ins => [ "stack", "size" ],
442 emit => ". add %S0, %S1, %D0\n",
447 op_flags => [ "constlike" ],
448 irn_flags => [ "rematerializable" ],
449 attr => "ir_entity *entity, int32_t offset",
450 reg_req => { in => [ "gp" ], out => [ "gp" ] },
452 attr_type => "sparc_attr_t",
453 custominit => "sparc_set_attr_imm(res, entity, offset);",
458 op_flags => [ "labeled", "cfopcode", "forking" ],
461 attr_type => "sparc_jmp_cond_attr_t",
462 attr => "ir_relation relation, bool is_unsigned",
463 init_attr => "\tinit_sparc_jmp_cond_attr(res, relation, is_unsigned);",
464 reg_req => { in => [ "flags" ], out => [ "none", "none" ] },
466 outs => [ "false", "true" ],
470 op_flags => [ "labeled", "cfopcode", "forking" ],
473 attr_type => "sparc_jmp_cond_attr_t",
474 attr => "ir_relation relation",
475 init_attr => "\tinit_sparc_jmp_cond_attr(res, relation, false);",
476 reg_req => { in => [ "fpflags" ], out => [ "none", "none" ] },
478 outs => [ "false", "true" ],
483 op_flags => [ "cfopcode" ],
484 irn_flags => [ "simple_jump" ],
485 reg_req => { out => [ "none" ] },
491 out_arity => "variable",
495 # This is a JumpLink instruction, but with the addition that you can add custom
496 # register constraints to model your calling conventions
499 op_flags => [ "cfopcode" ],
504 attr => "ir_entity *entity, int32_t offset",
505 custominit => "\tsparc_set_attr_imm(res, entity, offset);",
507 reg_req => { out => [ "none" ] },
511 reg_req => { out => [ "none" ] },
517 irn_flags => [ "modifies_flags", "modifies_fp_flags" ],
518 state => "exc_pinned",
520 out_arity => "variable",
523 attr => "ir_entity *entity, int32_t offset, bool aggregate_return",
524 custominit => "\tsparc_set_attr_imm(res, entity, offset);".
525 "\tif (aggregate_return) arch_add_irn_flags(res, sparc_arch_irn_flag_aggregate_return);",
527 out_arity => "variable",
530 attr => "bool aggregate_return",
532 out_arity => "variable",
533 custominit => "\tif (aggregate_return) arch_add_irn_flags(res, sparc_arch_irn_flag_aggregate_return);",
538 Cmp => { # aka SubccZero
539 irn_flags => [ "rematerializable", "modifies_flags" ],
540 emit => '. cmp %S0, %R1I',
542 constructors => \%binopcczero_operand_constructors,
546 op_flags => [ "labeled", "cfopcode", "forking" ],
549 reg_req => { in => [ "gp" ], out => [ ] },
550 attr_type => "sparc_switch_jmp_attr_t",
551 attr => "long default_pn, ir_entity *jump_table",
552 init_attr => "info->out_infos = NULL;", # XXX ugly hack for out requirements
556 irn_flags => [ "rematerializable" ],
558 emit => '. sll %S0, %R1I, %D0',
559 constructors => \%binop_operand_constructors,
563 irn_flags => [ "rematerializable" ],
565 emit => '. srl %S0, %R1I, %D0',
566 constructors => \%binop_operand_constructors,
570 irn_flags => [ "rematerializable" ],
572 emit => '. sra %S0, %R1I, %D0',
573 constructors => \%binop_operand_constructors,
577 irn_flags => [ "rematerializable" ],
579 emit => '. and %S0, %R1I, %D0',
580 constructors => \%binop_operand_constructors,
584 irn_flags => [ "rematerializable", "modifies_flags" ],
585 emit => '. andcc %S0, %R1I, %%g0',
587 constructors => \%binopcczero_operand_constructors,
591 irn_flags => [ "rematerializable" ],
593 emit => '. andn %S0, %R1I, %D0',
594 constructors => \%binop_operand_constructors,
598 irn_flags => [ "rematerializable", "modifies_flags" ],
599 emit => '. andncc %S0, %R1I, %%g0',
601 constructors => \%binopcczero_operand_constructors,
605 irn_flags => [ "rematerializable" ],
607 emit => '. or %S0, %R1I, %D0',
608 constructors => \%binop_operand_constructors,
612 irn_flags => [ "rematerializable", "modifies_flags" ],
613 emit => '. orcc %S0, %R1I, %%g0',
615 constructors => \%binopcczero_operand_constructors,
619 irn_flags => [ "rematerializable" ],
621 emit => '. orn %S0, %R1I, %D0',
622 constructors => \%binop_operand_constructors,
626 irn_flags => [ "rematerializable", "modifies_flags" ],
627 emit => '. orncc %S0, %R1I, %%g0',
629 constructors => \%binopcczero_operand_constructors,
633 irn_flags => [ "rematerializable" ],
635 emit => '. xor %S0, %R1I, %D0',
636 constructors => \%binop_operand_constructors,
640 irn_flags => [ "rematerializable", "modifies_flags" ],
641 emit => '. xorcc %S0, %R1I, %%g0',
643 constructors => \%binopcczero_operand_constructors,
647 irn_flags => [ "rematerializable" ],
649 emit => '. xnor %S0, %R1I, %D0',
650 constructors => \%binop_operand_constructors,
654 irn_flags => [ "rematerializable", "modifies_flags" ],
655 emit => '. xnorcc %S0, %R1I, %%g0',
657 constructors => \%binopcczero_operand_constructors,
661 irn_flags => [ "rematerializable" ],
663 emit => '. smul %S0, %R1I, %D0',
664 constructors => \%binop_operand_constructors,
668 irn_flags => [ "rematerializable" ],
669 outs => [ "low", "high" ],
670 constructors => \%binop_operand_constructors,
674 irn_flags => [ "rematerializable" ],
675 outs => [ "low", "high" ],
676 constructors => \%binop_operand_constructors,
680 irn_flags => [ "rematerializable" ],
681 state => "exc_pinned",
682 ins => [ "dividend_high", "dividend_low", "divisor" ],
683 outs => [ "res", "M" ],
684 constructors => \%div_operand_constructors,
688 irn_flags => [ "rematerializable" ],
689 state => "exc_pinned",
690 ins => [ "dividend_high", "dividend_low", "divisor" ],
691 outs => [ "res", "M" ],
692 constructors => \%div_operand_constructors,
696 irn_flags => [ "rematerializable", "modifies_fp_flags" ],
697 emit => '. fcmp%FPM %S0, %S1',
698 attr_type => "sparc_fp_attr_t",
699 attr => "ir_mode *fp_mode",
700 mode => $mode_fpflags,
703 reg_req => { in => [ "fp", "fp" ], out => [ "fpflags" ] },
706 reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fpflags" ] },
709 reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fpflags" ] },
715 op_flags => [ "commutative" ],
716 irn_flags => [ "rematerializable" ],
717 emit => '. fadd%FPM %S0, %S1, %D0',
718 attr_type => "sparc_fp_attr_t",
719 attr => "ir_mode *fp_mode",
720 ins => [ "left", "right" ],
721 constructors => \%float_binop_constructors,
725 irn_flags => [ "rematerializable" ],
726 emit => '. fsub%FPM %S0, %S1, %D0',
727 attr_type => "sparc_fp_attr_t",
728 attr => "ir_mode *fp_mode",
729 ins => [ "left", "right" ],
730 constructors => \%float_binop_constructors,
734 irn_flags => [ "rematerializable" ],
735 op_flags => [ "commutative" ],
736 emit =>'. fmul%FPM %S0, %S1, %D0',
737 attr_type => "sparc_fp_attr_t",
738 attr => "ir_mode *fp_mode",
739 ins => [ "left", "right" ],
740 constructors => \%float_binop_constructors,
744 irn_flags => [ "rematerializable" ],
745 emit => '. fdiv%FPM %S0, %S1, %D0',
746 attr_type => "sparc_fp_attr_t",
747 attr => "ir_mode *fp_mode",
748 ins => [ "left", "right" ],
749 outs => [ "res", "M" ],
752 reg_req => { in => [ "fp", "fp" ], out => [ "fp", "none" ] },
755 reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fp:a|2", "none" ] },
758 reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fp:a|4", "none" ] },
764 irn_flags => [ "rematerializable" ],
765 reg_req => { in => [ "fp" ], out => [ "fp" ] },
766 # note that we only need the first register even for wide-values
767 emit => '. fnegs %S0, %D0',
768 attr_type => "sparc_fp_attr_t",
769 attr => "ir_mode *fp_mode",
771 constructors => \%float_unop_constructors,
775 irn_flags => [ "rematerializable" ],
776 # note that we only need the first register even for wide-values
777 emit => '. fabs %S0, %D0',
778 attr_type => "sparc_fp_attr_t",
779 attr => "ir_mode *fp_mode",
781 constructors => \%float_unop_constructors,
785 irn_flags => [ "rematerializable" ],
786 emit => '. f%FCONVS%.to%FCONVD %S0, %D0',
787 attr_type => "sparc_fp_conv_attr_t",
788 attr => "ir_mode *src_mode, ir_mode *dest_mode",
791 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
795 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
799 reg_req => { in => [ "fp:a|2" ], out => [ "fp" ] },
803 reg_req => { in => [ "fp:a|2" ], out => [ "fp:a|4" ] },
807 reg_req => { in => [ "fp:a|4" ], out => [ "fp" ] },
811 reg_req => { in => [ "fp:a|4" ], out => [ "fp:a|2" ] },
818 irn_flags => [ "rematerializable" ],
819 emit => '. fito%FPM %S0, %D0',
820 attr_type => "sparc_fp_attr_t",
821 attr => "ir_mode *fp_mode",
824 reg_req => { in => [ "fp" ], out => [ "fp" ] },
828 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
832 reg_req => { in => [ "fp" ], out => [ "fp:a|4" ] },
839 irn_flags => [ "rematerializable" ],
840 emit => '. f%FPM%.toi %S0, %D0',
841 attr_type => "sparc_fp_attr_t",
842 attr => "ir_mode *fp_mode",
846 reg_req => { in => [ "fp" ], out => [ "fp" ] },
849 reg_req => { in => [ "fp:a|2" ], out => [ "fp" ] },
852 reg_req => { in => [ "fp:a|4" ], out => [ "fp" ] },
858 op_flags => [ "labeled" ],
859 state => "exc_pinned",
862 reg_req => { in => [ "gp", "none" ], out => [ "fp", "none" ] },
865 reg_req => { in => [ "gp", "none" ], out => [ "fp:a|2", "none" ] },
868 reg_req => { in => [ "gp", "none" ], out => [ "fp:a|4", "none" ] },
871 ins => [ "ptr", "mem" ],
872 outs => [ "res", "M" ],
873 attr_type => "sparc_load_store_attr_t",
874 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
875 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
876 emit => '. ld%FLSM [%S0%O1], %D0'
880 op_flags => [ "labeled" ],
881 state => "exc_pinned",
884 reg_req => { in => [ "fp", "gp", "none" ], out => [ "none" ] },
887 reg_req => { in => [ "fp:a|2", "gp", "none" ], out => [ "none" ] },
890 reg_req => { in => [ "fp:a|4", "gp", "none" ], out => [ "none" ] },
893 ins => [ "val", "ptr", "mem" ],
895 attr_type => "sparc_load_store_attr_t",
896 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
897 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
898 emit => '. st%FLSM %S0, [%S1%O2]',