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',
310 attr => "ir_entity *immediate_entity, int32_t immediate_value",
311 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
312 reg_req => { in => [ "sp" ], out => [ "sp:I|S" ] },
316 reg_req => { in => [ "sp", "gp" ], out => [ "sp:I|S" ] },
317 ins => [ "stack", "increment" ],
323 emit => '. restore %S0, %R1I, %D0',
327 attr => "ir_entity *immediate_entity, int32_t immediate_value",
328 custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
329 reg_req => { in => [ "sp" ], out => [ "sp:I|S" ] },
333 reg_req => { in => [ "sp", "gp" ], out => [ "sp:I|S" ] },
334 ins => [ "stack", "increment" ],
347 reg_req => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "gp", "none" ] },
348 ins => [ "stack", "size", "mem" ],
349 outs => [ "stack", "addr", "M" ],
350 emit => ". sub %S0, %S1, %D0\n",
354 reg_req => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "none" ] },
355 ins => [ "stack", "size", "mem" ],
356 outs => [ "stack", "M" ],
357 emit => ". add %S0, %S1, %D0\n",
361 op_flags => [ "constlike" ],
362 irn_flags => [ "rematerializable" ],
363 attr => "ir_entity *entity, int32_t offset",
364 reg_req => { in => [ "gp" ], out => [ "gp" ] },
366 attr_type => "sparc_attr_t",
367 custominit => "sparc_set_attr_imm(res, entity, offset);",
372 op_flags => [ "labeled", "cfopcode", "forking" ],
375 attr_type => "sparc_jmp_cond_attr_t",
376 attr => "pn_Cmp pnc, bool is_unsigned",
377 init_attr => "\tinit_sparc_jmp_cond_attr(res, pnc, is_unsigned);",
378 reg_req => { in => [ "flags" ], out => [ "none", "none" ] },
382 op_flags => [ "labeled", "cfopcode", "forking" ],
385 attr_type => "sparc_jmp_cond_attr_t",
386 attr => "pn_Cmp pnc",
387 init_attr => "\tinit_sparc_jmp_cond_attr(res, pnc, false);",
388 reg_req => { in => [ "fpflags" ], out => [ "none", "none" ] },
393 op_flags => [ "cfopcode" ],
394 irn_flags => [ "simple_jump" ],
395 reg_req => { out => [ "none" ] },
399 # This is a JumpLink instruction, but with the addition that you can add custom
400 # register constraints to model your calling conventions
403 out_arity => "variable",
406 attr => "ir_entity *entity, int32_t offset",
407 custominit => "\tsparc_set_attr_imm(res, entity, offset);",
409 out_arity => "variable",
413 out_arity => "variable",
419 irn_flags => [ "modifies_flags", "modifies_fp_flags" ],
420 state => "exc_pinned",
422 out_arity => "variable",
425 attr => "ir_entity *entity, int32_t offset",
426 custominit => "\tsparc_set_attr_imm(res, entity, offset);",
428 out_arity => "variable",
432 out_arity => "variable",
437 Cmp => { # aka SubccZero
438 irn_flags => [ "rematerializable", "modifies_flags" ],
439 emit => '. cmp %S0, %R1I',
441 constructors => \%binopcczero_operand_constructors,
445 op_flags => [ "labeled", "cfopcode", "forking" ],
448 reg_req => { in => [ "gp" ], out => [ ] },
449 attr_type => "sparc_switch_jmp_attr_t",
450 attr => "long default_pn, ir_entity *jump_table",
451 init_attr => "info->out_infos = NULL;", # XXX ugly hack for out requirements
455 irn_flags => [ "rematerializable" ],
457 emit => '. sll %S0, %R1I, %D0',
458 constructors => \%binop_operand_constructors,
462 irn_flags => [ "rematerializable" ],
464 emit => '. srl %S0, %R1I, %D0',
465 constructors => \%binop_operand_constructors,
469 irn_flags => [ "rematerializable" ],
471 emit => '. sra %S0, %R1I, %D0',
472 constructors => \%binop_operand_constructors,
476 irn_flags => [ "rematerializable" ],
478 emit => '. and %S0, %R1I, %D0',
479 constructors => \%binop_operand_constructors,
483 irn_flags => [ "rematerializable", "modifies_flags" ],
484 emit => '. andcc %S0, %R1I, %%g0',
486 constructors => \%binopcczero_operand_constructors,
490 irn_flags => [ "rematerializable" ],
492 emit => '. andn %S0, %R1I, %D0',
493 constructors => \%binop_operand_constructors,
497 irn_flags => [ "rematerializable", "modifies_flags" ],
498 emit => '. andncc %S0, %R1I, %%g0',
500 constructors => \%binopcczero_operand_constructors,
504 irn_flags => [ "rematerializable" ],
506 emit => '. or %S0, %R1I, %D0',
507 constructors => \%binop_operand_constructors,
511 irn_flags => [ "rematerializable", "modifies_flags" ],
512 emit => '. orcc %S0, %R1I, %%g0',
514 constructors => \%binopcczero_operand_constructors,
518 irn_flags => [ "rematerializable" ],
520 emit => '. orn %S0, %R1I, %D0',
521 constructors => \%binop_operand_constructors,
525 irn_flags => [ "rematerializable", "modifies_flags" ],
526 emit => '. orncc %S0, %R1I, %%g0',
528 constructors => \%binopcczero_operand_constructors,
532 irn_flags => [ "rematerializable" ],
534 emit => '. xor %S0, %R1I, %D0',
535 constructors => \%binop_operand_constructors,
539 irn_flags => [ "rematerializable", "modifies_flags" ],
540 emit => '. xorcc %S0, %R1I, %%g0',
542 constructors => \%binopcczero_operand_constructors,
546 irn_flags => [ "rematerializable" ],
548 emit => '. xnor %S0, %R1I, %D0',
549 constructors => \%binop_operand_constructors,
553 irn_flags => [ "rematerializable", "modifies_flags" ],
554 emit => '. xnorcc %S0, %R1I, %%g0',
556 constructors => \%binopcczero_operand_constructors,
560 irn_flags => [ "rematerializable" ],
562 emit => '. smul %S0, %R1I, %D0',
563 constructors => \%binop_operand_constructors,
567 irn_flags => [ "rematerializable" ],
568 outs => [ "low", "high" ],
569 constructors => \%binop_operand_constructors,
573 irn_flags => [ "rematerializable" ],
574 state => "exc_pinned",
575 ins => [ "dividend_high", "dividend_low", "divisor" ],
576 outs => [ "res", "M" ],
577 constructors => \%div_operand_constructors,
581 irn_flags => [ "rematerializable" ],
582 state => "exc_pinned",
583 ins => [ "dividend_high", "dividend_low", "divisor" ],
584 outs => [ "res", "M" ],
585 constructors => \%div_operand_constructors,
589 irn_flags => [ "rematerializable", "modifies_fp_flags" ],
590 emit => '. fcmp%FPM %S0, %S1',
591 attr_type => "sparc_fp_attr_t",
592 attr => "ir_mode *fp_mode",
593 mode => $mode_fpflags,
596 reg_req => { in => [ "fp", "fp" ], out => [ "fpflags" ] },
599 reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fpflags" ] },
602 reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fpflags" ] },
608 op_flags => [ "commutative" ],
609 irn_flags => [ "rematerializable" ],
610 emit => '. fadd%FPM %S0, %S1, %D0',
611 attr_type => "sparc_fp_attr_t",
612 attr => "ir_mode *fp_mode",
613 ins => [ "left", "right" ],
614 constructors => \%float_binop_constructors,
618 irn_flags => [ "rematerializable" ],
619 emit => '. fsub%FPM %S0, %S1, %D0',
620 attr_type => "sparc_fp_attr_t",
621 attr => "ir_mode *fp_mode",
622 ins => [ "left", "right" ],
623 constructors => \%float_binop_constructors,
627 irn_flags => [ "rematerializable" ],
628 op_flags => [ "commutative" ],
629 emit =>'. fmul%FPM %S0, %S1, %D0',
630 attr_type => "sparc_fp_attr_t",
631 attr => "ir_mode *fp_mode",
632 ins => [ "left", "right" ],
633 constructors => \%float_binop_constructors,
637 irn_flags => [ "rematerializable" ],
638 emit => '. fdiv%FPM %S0, %S1, %D0',
639 attr_type => "sparc_fp_attr_t",
640 attr => "ir_mode *fp_mode",
641 ins => [ "left", "right" ],
642 outs => [ "res", "M" ],
645 reg_req => { in => [ "fp", "fp" ], out => [ "fp", "none" ] },
648 reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fp:a|2", "none" ] },
651 reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fp:a|4", "none" ] },
657 irn_flags => [ "rematerializable" ],
658 reg_req => { in => [ "fp" ], out => [ "fp" ] },
659 # note that we only need the first register even for wide-values
660 emit => '. fneg %S0, %D0',
661 attr_type => "sparc_fp_attr_t",
662 attr => "ir_mode *fp_mode",
664 constructors => \%float_unop_constructors,
668 irn_flags => [ "rematerializable" ],
669 # note that we only need the first register even for wide-values
670 emit => '. fabs %S0, %D0',
671 attr_type => "sparc_fp_attr_t",
672 attr => "ir_mode *fp_mode",
674 constructors => \%float_unop_constructors,
678 irn_flags => [ "rematerializable" ],
679 emit => '. f%FCONVS%.to%FCONVD %S0, %D0',
680 attr_type => "sparc_fp_conv_attr_t",
681 attr => "ir_mode *src_mode, ir_mode *dest_mode",
684 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
688 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
692 reg_req => { in => [ "fp:a|2" ], out => [ "fp" ] },
696 reg_req => { in => [ "fp:a|2" ], out => [ "fp:a|4" ] },
700 reg_req => { in => [ "fp:a|4" ], out => [ "fp" ] },
704 reg_req => { in => [ "fp:a|4" ], out => [ "fp:a|2" ] },
711 irn_flags => [ "rematerializable" ],
712 emit => '. fito%FPM %S0, %D0',
713 attr_type => "sparc_fp_attr_t",
714 attr => "ir_mode *fp_mode",
717 reg_req => { in => [ "fp" ], out => [ "fp" ] },
721 reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
725 reg_req => { in => [ "fp" ], out => [ "fp:a|4" ] },
732 irn_flags => [ "rematerializable" ],
733 emit => '. f%FPM%.toi %S0, %D0',
734 attr_type => "sparc_fp_attr_t",
735 attr => "ir_mode *fp_mode",
739 reg_req => { in => [ "fp" ], out => [ "fp" ] },
742 reg_req => { in => [ "fp:a|2" ], out => [ "fp" ] },
745 reg_req => { in => [ "fp:a|4" ], out => [ "fp" ] },
751 op_flags => [ "labeled", "fragile" ],
752 state => "exc_pinned",
755 reg_req => { in => [ "gp", "none" ], out => [ "fp", "none" ] },
758 reg_req => { in => [ "gp", "none" ], out => [ "fp:a|2", "none" ] },
761 reg_req => { in => [ "gp", "none" ], out => [ "fp:a|4", "none" ] },
764 ins => [ "ptr", "mem" ],
765 outs => [ "res", "M" ],
766 attr_type => "sparc_load_store_attr_t",
767 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
768 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
769 emit => '. ld%FLSM [%S0%O1], %D0'
773 op_flags => [ "labeled", "fragile" ],
774 state => "exc_pinned",
777 reg_req => { in => [ "fp", "gp", "none" ], out => [ "none" ] },
780 reg_req => { in => [ "fp:a|2", "gp", "none" ], out => [ "none" ] },
783 reg_req => { in => [ "fp:a|4", "gp", "none" ], out => [ "none" ] },
786 ins => [ "val", "ptr", "mem" ],
788 attr_type => "sparc_load_store_attr_t",
789 attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
790 custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
791 emit => '. st%FLSM %S0, [%S1%O2]',