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, flags, in_reqs, exec_units, n_res);",
127 sparc_load_store_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
128 sparc_jmp_cond_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
129 sparc_switch_jmp_attr_t => "\tinit_sparc_attributes(res, 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, 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, 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 %binopcczero_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 => [ "flags" ] },
185 reg_req => { in => [ "gp", "gp" ], out => [ "flags" ] },
186 ins => [ "left", "right" ],
190 my %div_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", "gp" ], out => [ "gp" ] },
197 reg_req => { in => [ "gp", "gp", "gp" ], out => [ "gp" ] },
201 my %float_binop_constructors = (
203 reg_req => { in => [ "fp", "fp" ], out => [ "fp" ] },
207 reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fp:a|2" ] },
211 reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fp:a|4" ] },
216 my %float_unop_constructors = (
218 reg_req => { in => [ "fp" ], out => [ "fp" ] },
222 reg_req => { in => [ "fp:a|2" ], out => [ "fp:a|2" ] },
226 reg_req => { in => [ "fp:a|4" ], out => [ "fp:a|4" ] },
234 irn_flags => [ "rematerializable" ],
236 emit => '. add %S0, %R1I, %D0',
237 constructors => \%binop_operand_constructors,
241 irn_flags => [ "rematerializable" ],
243 emit => '. sub %S0, %R1I, %D0',
244 constructors => \%binop_operand_constructors,
249 op_flags => [ "labeled", "fragile" ],
250 state => "exc_pinned",
253 reg_req => { in => [ "gp", "none" ], out => [ "gp", "none" ] },
254 ins => [ "ptr", "mem" ],
255 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
256 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
259 reg_req => { in => [ "gp", "gp", "none" ], out => [ "gp", "none" ] },
260 ins => [ "ptr", "ptr2", "mem" ],
261 attr => "ir_mode *ls_mode",
262 custominit => "init_sparc_load_store_attributes(res, ls_mode, NULL, 0, false, true);",
265 ins => [ "ptr", "mem" ],
266 outs => [ "res", "M" ],
267 attr_type => "sparc_load_store_attr_t",
268 emit => '. ld%LM [%S0%O1], %D0'
272 irn_flags => [ "rematerializable" ],
275 reg_req => { in => [], out => [ "gp" ] },
276 attr => "ir_entity *entity, int32_t immediate_value",
277 custominit => "sparc_set_attr_imm(res, entity, immediate_value);",
278 emit => '. sethi %HIM, %D0'
282 op_flags => [ "labeled", "fragile" ],
284 state => "exc_pinned",
287 reg_req => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
288 ins => [ "val", "ptr", "mem" ],
289 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
290 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
293 reg_req => { in => [ "gp", "gp", "gp", "none" ], out => [ "none" ] },
294 ins => [ "val", "ptr", "ptr2", "mem" ],
295 attr => "ir_mode *ls_mode",
296 custominit => "init_sparc_load_store_attributes(res, ls_mode, NULL, 0, false, true);",
299 ins => [ "val", "ptr", "mem" ],
301 attr_type => "sparc_load_store_attr_t",
302 emit => '. st%SM %S0, [%S1%O2]'
306 emit => '. save %S0, %R1I, %D0',
311 attr => "ir_entity *immediate_entity, int32_t immediate_value",
312 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
313 reg_req => { in => [ "sp" ], out => [ "sp:I|S" ] },
317 reg_req => { in => [ "sp", "gp" ], out => [ "sp:I|S" ] },
318 ins => [ "stack", "increment" ],
325 emit => '. restore %S0, %R1I, %D0',
330 attr => "ir_entity *immediate_entity, int32_t immediate_value",
331 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
332 reg_req => { in => [ "sp" ], out => [ "sp:I|S" ] },
336 reg_req => { in => [ "sp", "gp" ], out => [ "sp:I|S" ] },
337 ins => [ "stack", "increment" ],
345 reg_req => { out => [ "sp:I|S" ] },
352 reg_req => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "gp", "none" ] },
353 ins => [ "stack", "size", "mem" ],
354 outs => [ "stack", "addr", "M" ],
355 emit => ". sub %S0, %S1, %D0\n",
359 reg_req => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "none" ] },
360 ins => [ "stack", "size", "mem" ],
361 outs => [ "stack", "M" ],
362 emit => ". add %S0, %S1, %D0\n",
366 op_flags => [ "constlike" ],
367 irn_flags => [ "rematerializable" ],
368 attr => "ir_entity *entity, int32_t offset",
369 reg_req => { in => [ "gp" ], out => [ "gp" ] },
371 attr_type => "sparc_attr_t",
372 custominit => "sparc_set_attr_imm(res, entity, offset);",
377 op_flags => [ "labeled", "cfopcode", "forking" ],
380 attr_type => "sparc_jmp_cond_attr_t",
381 attr => "ir_relation relation, bool is_unsigned",
382 init_attr => "\tinit_sparc_jmp_cond_attr(res, relation, is_unsigned);",
383 reg_req => { in => [ "flags" ], out => [ "none", "none" ] },
387 op_flags => [ "labeled", "cfopcode", "forking" ],
390 attr_type => "sparc_jmp_cond_attr_t",
391 attr => "ir_relation relation",
392 init_attr => "\tinit_sparc_jmp_cond_attr(res, relation, false);",
393 reg_req => { in => [ "fpflags" ], out => [ "none", "none" ] },
398 op_flags => [ "cfopcode" ],
399 irn_flags => [ "simple_jump" ],
400 reg_req => { out => [ "none" ] },
404 # This is a JumpLink instruction, but with the addition that you can add custom
405 # register constraints to model your calling conventions
408 out_arity => "variable",
411 attr => "ir_entity *entity, int32_t offset",
412 custominit => "\tsparc_set_attr_imm(res, entity, offset);",
414 out_arity => "variable",
418 out_arity => "variable",
424 irn_flags => [ "modifies_flags", "modifies_fp_flags" ],
425 state => "exc_pinned",
427 out_arity => "variable",
430 attr => "ir_entity *entity, int32_t offset",
431 custominit => "\tsparc_set_attr_imm(res, entity, offset);",
433 out_arity => "variable",
437 out_arity => "variable",
442 Cmp => { # aka SubccZero
443 irn_flags => [ "rematerializable", "modifies_flags" ],
444 emit => '. cmp %S0, %R1I',
446 constructors => \%binopcczero_operand_constructors,
450 op_flags => [ "labeled", "cfopcode", "forking" ],
453 reg_req => { in => [ "gp" ], out => [ ] },
454 attr_type => "sparc_switch_jmp_attr_t",
455 attr => "long default_pn, ir_entity *jump_table",
456 init_attr => "info->out_infos = NULL;", # XXX ugly hack for out requirements
460 irn_flags => [ "rematerializable" ],
462 emit => '. sll %S0, %R1I, %D0',
463 constructors => \%binop_operand_constructors,
467 irn_flags => [ "rematerializable" ],
469 emit => '. srl %S0, %R1I, %D0',
470 constructors => \%binop_operand_constructors,
474 irn_flags => [ "rematerializable" ],
476 emit => '. sra %S0, %R1I, %D0',
477 constructors => \%binop_operand_constructors,
481 irn_flags => [ "rematerializable" ],
483 emit => '. and %S0, %R1I, %D0',
484 constructors => \%binop_operand_constructors,
488 irn_flags => [ "rematerializable", "modifies_flags" ],
489 emit => '. andcc %S0, %R1I, %%g0',
491 constructors => \%binopcczero_operand_constructors,
495 irn_flags => [ "rematerializable" ],
497 emit => '. andn %S0, %R1I, %D0',
498 constructors => \%binop_operand_constructors,
502 irn_flags => [ "rematerializable", "modifies_flags" ],
503 emit => '. andncc %S0, %R1I, %%g0',
505 constructors => \%binopcczero_operand_constructors,
509 irn_flags => [ "rematerializable" ],
511 emit => '. or %S0, %R1I, %D0',
512 constructors => \%binop_operand_constructors,
516 irn_flags => [ "rematerializable", "modifies_flags" ],
517 emit => '. orcc %S0, %R1I, %%g0',
519 constructors => \%binopcczero_operand_constructors,
523 irn_flags => [ "rematerializable" ],
525 emit => '. orn %S0, %R1I, %D0',
526 constructors => \%binop_operand_constructors,
530 irn_flags => [ "rematerializable", "modifies_flags" ],
531 emit => '. orncc %S0, %R1I, %%g0',
533 constructors => \%binopcczero_operand_constructors,
537 irn_flags => [ "rematerializable" ],
539 emit => '. xor %S0, %R1I, %D0',
540 constructors => \%binop_operand_constructors,
544 irn_flags => [ "rematerializable", "modifies_flags" ],
545 emit => '. xorcc %S0, %R1I, %%g0',
547 constructors => \%binopcczero_operand_constructors,
551 irn_flags => [ "rematerializable" ],
553 emit => '. xnor %S0, %R1I, %D0',
554 constructors => \%binop_operand_constructors,
558 irn_flags => [ "rematerializable", "modifies_flags" ],
559 emit => '. xnorcc %S0, %R1I, %%g0',
561 constructors => \%binopcczero_operand_constructors,
565 irn_flags => [ "rematerializable" ],
567 emit => '. smul %S0, %R1I, %D0',
568 constructors => \%binop_operand_constructors,
572 irn_flags => [ "rematerializable" ],
573 outs => [ "low", "high" ],
574 constructors => \%binop_operand_constructors,
578 irn_flags => [ "rematerializable" ],
579 state => "exc_pinned",
580 ins => [ "dividend_high", "dividend_low", "divisor" ],
581 outs => [ "res", "M" ],
582 constructors => \%div_operand_constructors,
586 irn_flags => [ "rematerializable" ],
587 state => "exc_pinned",
588 ins => [ "dividend_high", "dividend_low", "divisor" ],
589 outs => [ "res", "M" ],
590 constructors => \%div_operand_constructors,
594 irn_flags => [ "rematerializable", "modifies_fp_flags" ],
595 emit => '. fcmp%FPM %S0, %S1',
596 attr_type => "sparc_fp_attr_t",
597 attr => "ir_mode *fp_mode",
598 mode => $mode_fpflags,
601 reg_req => { in => [ "fp", "fp" ], out => [ "fpflags" ] },
604 reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fpflags" ] },
607 reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fpflags" ] },
613 op_flags => [ "commutative" ],
614 irn_flags => [ "rematerializable" ],
615 emit => '. fadd%FPM %S0, %S1, %D0',
616 attr_type => "sparc_fp_attr_t",
617 attr => "ir_mode *fp_mode",
618 ins => [ "left", "right" ],
619 constructors => \%float_binop_constructors,
623 irn_flags => [ "rematerializable" ],
624 emit => '. fsub%FPM %S0, %S1, %D0',
625 attr_type => "sparc_fp_attr_t",
626 attr => "ir_mode *fp_mode",
627 ins => [ "left", "right" ],
628 constructors => \%float_binop_constructors,
632 irn_flags => [ "rematerializable" ],
633 op_flags => [ "commutative" ],
634 emit =>'. fmul%FPM %S0, %S1, %D0',
635 attr_type => "sparc_fp_attr_t",
636 attr => "ir_mode *fp_mode",
637 ins => [ "left", "right" ],
638 constructors => \%float_binop_constructors,
642 irn_flags => [ "rematerializable" ],
643 emit => '. fdiv%FPM %S0, %S1, %D0',
644 attr_type => "sparc_fp_attr_t",
645 attr => "ir_mode *fp_mode",
646 ins => [ "left", "right" ],
647 outs => [ "res", "M" ],
650 reg_req => { in => [ "fp", "fp" ], out => [ "fp", "none" ] },
653 reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fp:a|2", "none" ] },
656 reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fp:a|4", "none" ] },
662 irn_flags => [ "rematerializable" ],
663 reg_req => { in => [ "fp" ], out => [ "fp" ] },
664 # note that we only need the first register even for wide-values
665 emit => '. fneg %S0, %D0',
666 attr_type => "sparc_fp_attr_t",
667 attr => "ir_mode *fp_mode",
669 constructors => \%float_unop_constructors,
673 irn_flags => [ "rematerializable" ],
674 # note that we only need the first register even for wide-values
675 emit => '. fabs %S0, %D0',
676 attr_type => "sparc_fp_attr_t",
677 attr => "ir_mode *fp_mode",
679 constructors => \%float_unop_constructors,
683 irn_flags => [ "rematerializable" ],
684 emit => '. f%FCONVS%.to%FCONVD %S0, %D0',
685 attr_type => "sparc_fp_conv_attr_t",
686 attr => "ir_mode *src_mode, ir_mode *dest_mode",
689 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
693 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
697 reg_req => { in => [ "fp:a|2" ], out => [ "fp" ] },
701 reg_req => { in => [ "fp:a|2" ], out => [ "fp:a|4" ] },
705 reg_req => { in => [ "fp:a|4" ], out => [ "fp" ] },
709 reg_req => { in => [ "fp:a|4" ], out => [ "fp:a|2" ] },
716 irn_flags => [ "rematerializable" ],
717 emit => '. fito%FPM %S0, %D0',
718 attr_type => "sparc_fp_attr_t",
719 attr => "ir_mode *fp_mode",
722 reg_req => { in => [ "fp" ], out => [ "fp" ] },
726 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
730 reg_req => { in => [ "fp" ], out => [ "fp:a|4" ] },
737 irn_flags => [ "rematerializable" ],
738 emit => '. f%FPM%.toi %S0, %D0',
739 attr_type => "sparc_fp_attr_t",
740 attr => "ir_mode *fp_mode",
744 reg_req => { in => [ "fp" ], out => [ "fp" ] },
747 reg_req => { in => [ "fp:a|2" ], out => [ "fp" ] },
750 reg_req => { in => [ "fp:a|4" ], out => [ "fp" ] },
756 op_flags => [ "labeled", "fragile" ],
757 state => "exc_pinned",
760 reg_req => { in => [ "gp", "none" ], out => [ "fp", "none" ] },
763 reg_req => { in => [ "gp", "none" ], out => [ "fp:a|2", "none" ] },
766 reg_req => { in => [ "gp", "none" ], out => [ "fp:a|4", "none" ] },
769 ins => [ "ptr", "mem" ],
770 outs => [ "res", "M" ],
771 attr_type => "sparc_load_store_attr_t",
772 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
773 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
774 emit => '. ld%FLSM [%S0%O1], %D0'
778 op_flags => [ "labeled", "fragile" ],
779 state => "exc_pinned",
782 reg_req => { in => [ "fp", "gp", "none" ], out => [ "none" ] },
785 reg_req => { in => [ "fp:a|2", "gp", "none" ], out => [ "none" ] },
788 reg_req => { in => [ "fp:a|4", "gp", "none" ], out => [ "none" ] },
791 ins => [ "val", "ptr", "mem" ],
793 attr_type => "sparc_load_store_attr_t",
794 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
795 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
796 emit => '. st%FLSM %S0, [%S1%O2]',