7 $mode_flags = "mode_Bu";
10 $normal = 0; # no special type
11 $caller_save = 1; # caller save (register must be saved by the caller of a function)
12 $callee_save = 2; # callee save (register must be saved by the called function)
13 $ignore = 4; # ignore (do not assign this register)
14 $arbitrary = 8; # emitter can choose an arbitrary register of this class
15 $virtual = 16; # the register is a virtual one
16 $state = 32; # register represents a state
18 # available SPARC registers: 8 globals, 24 window regs (8 ins, 8 outs, 8 locals)
21 { name => "g0", realname => "g0", type => $ignore }, # hardwired 0, behaves like /dev/null
22 { name => "g1", realname => "g1", type => $caller_save }, # temp. value
23 { name => "g2", realname => "g2", type => $caller_save },
24 { name => "g3", realname => "g3", type => $caller_save },
25 { name => "g4", realname => "g4", type => $caller_save },
26 { name => "g5", realname => "g5", type => $ignore }, # reserved by SPARC ABI
27 { name => "g6", realname => "g6", type => $ignore }, # reserved by SPARC ABI
28 { name => "g7", realname => "g7", type => $ignore }, # reserved by SPARC ABI
30 # window's out registers
31 { name => "o0", realname => "o0", type => $caller_save }, # param 1 / return value from callee
32 { name => "o1", realname => "o1", type => $caller_save }, # param 2
33 { name => "o2", realname => "o2", type => $caller_save }, # param 3
34 { name => "o3", realname => "o3", type => $caller_save }, # param 4
35 { name => "o4", realname => "o4", type => $caller_save }, # param 5
36 { name => "o5", realname => "o5", type => $caller_save }, # param 6
37 { name => "sp", realname => "sp", type => $ignore }, # our stackpointer
38 { name => "o7", realname => "o6", type => $ignore }, # temp. value / address of CALL instr.
40 # window's local registers
41 { name => "l0", realname => "l0", type => 0 },
42 { name => "l1", realname => "l1", type => 0 },
43 { name => "l2", realname => "l2", type => 0 },
44 { name => "l3", realname => "l3", type => 0 },
45 { name => "l4", realname => "l4", type => 0 },
46 { name => "l5", realname => "l5", type => 0 },
47 { name => "l6", realname => "l6", type => 0 },
48 { name => "l7", realname => "l7", type => 0 },
50 # window's in registers
51 { name => "i0", realname => "i0", type => 0 }, # incoming param1 / return value to caller
52 { name => "i1", realname => "i1", type => 0 }, # param 2
53 { name => "i2", realname => "i2", type => 0 }, # param 3
54 { name => "i3", realname => "i3", type => 0 }, # param 4
55 { name => "i4", realname => "i4", type => 0 }, # param 5
56 { name => "i5", realname => "i5", type => 0 }, # param 6
57 { name => "frame_pointer", realname => "fp", type => $ignore }, # our framepointer
58 { name => "i7", realname => "i7", type => $ignore }, # return address - 8
62 { name => "y", realname => "y", type => $ignore }, # the multiply/divide state register
63 { mode => $mode_flags, flags => "manual_ra" }
65 # fp registers can be accessed any time
67 { name => "f0", type => $caller_save },
68 { name => "f1", type => $caller_save },
69 { name => "f2", type => $caller_save },
70 { name => "f3", type => $caller_save },
71 { name => "f4", type => $caller_save },
72 { name => "f5", type => $caller_save },
73 { name => "f6", type => $caller_save },
74 { name => "f7", type => $caller_save },
75 { name => "f8", type => $caller_save },
76 { name => "f9", type => $caller_save },
77 { name => "f10", type => $caller_save },
78 { name => "f11", type => $caller_save },
79 { name => "f12", type => $caller_save },
80 { name => "f13", type => $caller_save },
81 { name => "f14", type => $caller_save },
82 { name => "f15", type => $caller_save },
83 { name => "f16", type => $caller_save },
84 { name => "f17", type => $caller_save },
85 { name => "f18", type => $caller_save },
86 { name => "f19", type => $caller_save },
87 { name => "f20", type => $caller_save },
88 { name => "f21", type => $caller_save },
89 { name => "f22", type => $caller_save },
90 { name => "f23", type => $caller_save },
91 { name => "f24", type => $caller_save },
92 { name => "f25", type => $caller_save },
93 { name => "f26", type => $caller_save },
94 { name => "f27", type => $caller_save },
95 { name => "f28", type => $caller_save },
96 { name => "f29", type => $caller_save },
97 { name => "f30", type => $caller_save },
98 { name => "f31", type => $caller_save },
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, 0);",
107 R2I => "${arch}_emit_reg_or_imm(node, 1);",
108 R3I => "${arch}_emit_reg_or_imm(node, 2);",
109 S1 => "${arch}_emit_source_register(node, 0);",
110 S2 => "${arch}_emit_source_register(node, 1);",
111 S3 => "${arch}_emit_source_register(node, 2);",
112 S4 => "${arch}_emit_source_register(node, 3);",
113 S5 => "${arch}_emit_source_register(node, 4);",
114 S6 => "${arch}_emit_source_register(node, 5);",
115 D1 => "${arch}_emit_dest_register(node, 0);",
116 D2 => "${arch}_emit_dest_register(node, 1);",
117 D3 => "${arch}_emit_dest_register(node, 2);",
118 D4 => "${arch}_emit_dest_register(node, 3);",
119 D5 => "${arch}_emit_dest_register(node, 4);",
120 D6 => "${arch}_emit_dest_register(node, 5);",
121 IM => "${arch}_emit_immediate(node);",
122 LM => "${arch}_emit_load_mode(node);",
123 SM => "${arch}_emit_store_mode(node);",
124 FPM => "${arch}_emit_fp_mode_suffix(node);",
125 FCONVS => "${arch}_emit_fp_conv_source(node);",
126 FCONVD => "${arch}_emit_fp_conv_destination(node);",
127 O => "${arch}_emit_offset(node);",
130 $default_attr_type = "sparc_attr_t";
131 $default_copy_attr = "sparc_copy_attr";
135 sparc_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
136 sparc_load_store_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);\n".
137 "\tinit_sparc_load_store_attributes(res, ls_mode, entity, entity_sign, offset, is_frame_entity);",
138 sparc_symconst_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);\n".
139 "\tinit_sparc_symconst_attributes(res, entity);",
140 sparc_jmp_cond_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
141 sparc_jmp_switch_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
142 sparc_save_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
143 sparc_fp_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);\n".
144 "\tinit_sparc_fp_attributes(res, fp_mode);\n",
145 sparc_fp_conv_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);".
146 "\tinit_sparc_fp_conv_attributes(res, src_mode, dest_mode);\n",
150 sparc_attr_t => "cmp_attr_sparc",
151 sparc_load_store_attr_t => "cmp_attr_sparc_load_store",
152 sparc_symconst_attr_t => "cmp_attr_sparc_symconst",
153 sparc_jmp_cond_attr_t => "cmp_attr_sparc_jmp_cond",
154 sparc_jmp_switch_attr_t => "cmp_attr_sparc_jmp_switch",
155 sparc_save_attr_t => "cmp_attr_sparc_save",
156 sparc_fp_attr_t => "cmp_attr_sparc_fp",
157 sparc_fp_conv_attr_t => "cmp_attr_sparc_fp_conv",
160 # addressing modes: imm, reg, reg +/- imm, reg + reg
161 # max. imm = 13 bits signed (-4096 ... 4096)
163 my %cmp_operand_constructors = (
165 attr => "int immediate_value",
166 custominit => "sparc_set_attr_imm(res, immediate_value);",
167 reg_req => { in => [ "gp" ], out => [ "flags" ] },
171 reg_req => { in => [ "gp", "gp" ], out => [ "flags" ] },
172 ins => [ "left", "right" ],
176 my %unop_operand_constructors = (
178 attr => "int immediate_value",
179 custominit => "sparc_set_attr_imm(res, immediate_value);",
180 reg_req => { in => [], out => [ "gp" ] },
183 reg_req => { in => [ "gp" ], out => [ "gp" ] },
187 my %binop_operand_constructors = (
189 attr => "int immediate_value",
190 custominit => "sparc_set_attr_imm(res, immediate_value);",
191 reg_req => { in => [ "gp" ], out => [ "gp" ] },
195 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
196 ins => [ "left", "right" ],
203 irn_flags => [ "rematerializable" ],
205 emit => '. add %S1, %R2I, %D1',
206 constructors => \%binop_operand_constructors,
210 irn_flags => [ "rematerializable" ],
212 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
213 emit => '. sub %S1, %R2I, %D1',
214 constructors => \%binop_operand_constructors,
220 op_flags => [ "labeled", "fragile" ],
221 state => "exc_pinned",
222 ins => [ "ptr", "mem" ],
223 outs => [ "res", "M" ],
224 reg_req => { in => [ "gp", "none" ], out => [ "gp", "none" ] },
225 attr_type => "sparc_load_store_attr_t",
226 attr => "ir_mode *ls_mode, ir_entity *entity, int entity_sign, long offset, bool is_frame_entity",
227 emit => '. ld%LM [%S1%O], %D1'
231 irn_flags => [ "rematerializable" ],
232 state => "exc_pinned",
235 reg_req => { in => [], out => [ "gp" ] },
236 attr => "int immediate_value",
237 custominit => "sparc_set_attr_imm(res, immediate_value);",
241 irn_flags => [ "rematerializable" ],
242 state => "exc_pinned",
246 reg_req => { in => [ "gp" ], out => [ "gp" ] },
247 attr => "int immediate_value",
248 custominit => "sparc_set_attr_imm(res, immediate_value);",
252 op_flags => [ "labeled", "fragile" ],
254 state => "exc_pinned",
255 ins => [ "ptr", "val", "mem" ],
257 reg_req => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
258 attr_type => "sparc_load_store_attr_t",
259 attr => "ir_mode *ls_mode, ir_entity *entity, int entity_sign, long offset, bool is_frame_entity",
260 emit => '. st%SM %S2, [%S1%O]'
264 irn_flags => [ "rematerializable" ],
266 emit => '. mov %R1I, %D1',
268 constructors => \%unop_operand_constructors,
273 in => [ "sp", "none"],
274 out => [ "sp:I|S", "frame_pointer:I", "none" ]
276 ins => [ "stack", "mem" ],
277 outs => [ "stack", "frame", "mem" ],
278 attr => "int initial_stacksize",
279 attr_type => "sparc_save_attr_t",
280 init_attr => "\tinit_sparc_save_attributes(res, initial_stacksize);",
284 reg_req => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "gp", "none" ] },
285 ins => [ "stack", "size", "mem" ],
286 outs => [ "stack", "addr", "M" ],
287 emit => ". sub %S1, %S2, %D1\n",
291 reg_req => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "none" ] },
292 ins => [ "stack", "size", "mem" ],
293 outs => [ "stack", "M" ],
294 emit => ". add %S1, %S2, %D1\n",
298 op_flags => [ "constlike" ],
299 irn_flags => [ "rematerializable" ],
300 attr => "ir_entity *entity",
301 reg_req => { out => [ "gp" ] },
302 attr_type => "sparc_symconst_attr_t",
307 op_flags => [ "constlike" ],
308 irn_flags => [ "rematerializable" ],
309 attr => "ir_entity *entity",
310 reg_req => { in => [ "gp" ], out => [ "gp" ] },
312 attr_type => "sparc_symconst_attr_t",
317 op_flags => [ "labeled", "cfopcode", "forking" ],
320 reg_req => { in => [ "flags" ], out => [ "none", "none" ] },
321 attr => "int proj_num, bool is_unsigned",
322 attr_type => "sparc_jmp_cond_attr_t",
323 init_attr => "\tinit_sparc_jmp_cond_attr(res, proj_num, is_unsigned);",
328 op_flags => [ "cfopcode" ],
329 irn_flags => [ "simple_jump" ],
330 reg_req => { out => [ "none" ] },
335 irn_flags => [ "modify_flags" ],
336 state => "exc_pinned",
338 out_arity => "variable",
341 attr => "ir_entity *entity, long offset",
342 custominit => "get_sparc_attr(res)->immediate_value_entity = entity;",
344 out_arity => "variable",
348 out_arity => "variable",
354 irn_flags => [ "rematerializable", "modify_flags" ],
355 emit => '. cmp %S1, %R2I',
357 constructors => \%cmp_operand_constructors,
361 irn_flags => [ "rematerializable", "modify_flags" ],
364 reg_req => { in => [ "gp" ], out => [ "flags" ] },
369 op_flags => [ "labeled", "cfopcode", "forking" ],
372 attr => "int n_projs, long def_proj_num",
373 init_attr => "\tset_sparc_jmp_switch_n_projs(res, n_projs);\n".
374 "\tset_sparc_jmp_switch_default_proj_num(res, def_proj_num);",
375 reg_req => { in => [ "gp" ], out => [ "none" ] },
376 attr_type => "sparc_jmp_switch_attr_t",
380 irn_flags => [ "rematerializable" ],
382 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
383 emit => '. sll %S1, %R2I, %D1',
384 constructors => \%binop_operand_constructors,
388 irn_flags => [ "rematerializable" ],
390 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
391 emit => '. srl %S1, %R2I, %D1',
392 constructors => \%binop_operand_constructors,
396 irn_flags => [ "rematerializable" ],
398 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
399 emit => '. sra %S1, %R2I, %D1',
400 constructors => \%binop_operand_constructors,
404 irn_flags => [ "rematerializable" ],
406 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
407 emit => '. and %S1, %R2I, %D1',
408 constructors => \%binop_operand_constructors,
412 irn_flags => [ "rematerializable" ],
414 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
415 emit => '. or %S1, %R2I, %D1',
416 constructors => \%binop_operand_constructors,
420 irn_flags => [ "rematerializable" ],
422 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
423 emit => '. xor %S1, %R2I, %D1',
424 constructors => \%binop_operand_constructors,
428 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
429 constructors => \%binop_operand_constructors,
430 emit => '. mul %S1, %R2I, %D1',
435 reg_req => { in => [ "gp", "gp" ], out => [ "gp", "gp" ] },
436 outs => [ "low", "high" ],
437 constructors => \%binop_operand_constructors,
441 irn_flags => [ "rematerializable" ],
442 state => "exc_pinned",
443 reg_req => { in => [ "gp", "gp" ], out => [ "gp", "none" ] },
444 outs => [ "res", "M" ],
445 constructors => \%binop_operand_constructors,
446 emit => '. div %S1, %R2I, %D1',
450 irn_flags => [ "rematerializable" ],
452 reg_req => { in => [ "gp" ], out => [ "gp" ] },
453 emit => ". sub %%g0, %S1, %D1"
457 irn_flags => [ "rematerializable" ],
459 reg_req => { in => [ "gp" ], out => [ "gp" ] },
460 emit => '. xnor %S1, %%g0, %D1'
464 op_flags => [ "keep" ],
465 reg_req => { in => [], out => [ "none" ] },
470 op_flags => [ "commutative" ],
471 irn_flags => [ "rematerializable" ],
472 reg_req => { in => [ "fp", "fp" ], out => [ "fp" ] },
473 emit => '. fadd%FPM %S1, %S2, %D1',
474 attr_type => "sparc_fp_attr_t",
475 attr => "ir_mode *fp_mode",
480 irn_flags => [ "rematerializable" ],
481 reg_req => { in => [ "fp", "fp" ], out => [ "fp" ] },
482 emit => '. fsub%FPM %S1, %S2, %D1',
483 attr_type => "sparc_fp_attr_t",
484 attr => "ir_mode *fp_mode",
489 irn_flags => [ "rematerializable" ],
490 op_flags => [ "commutative" ],
491 reg_req => { in => [ "fp", "fp" ], out => [ "fp" ] },
492 emit =>'. fmul%FPM %S1, %S2, %D1',
493 attr_type => "sparc_fp_attr_t",
494 attr => "ir_mode *fp_mode",
499 irn_flags => [ "rematerializable" ],
500 reg_req => { in => [ "fp", "fp" ], out => [ "fp", "none" ] },
501 emit => '. fdiv%FPM %S1, %S2, %D1',
502 attr_type => "sparc_fp_attr_t",
503 attr => "ir_mode *fp_mode",
504 outs => [ "res", "M" ],
508 irn_flags => [ "rematerializable" ],
509 reg_req => { in => [ "fp" ], out => [ "fp" ] },
510 emit => '. fneg%FPM %S1, %D1',
511 attr_type => "sparc_fp_attr_t",
512 attr => "ir_mode *fp_mode",
517 irn_flags => [ "rematerializable" ],
518 reg_req => { in => [ "fp" ], out => [ "fp" ] },
519 emit => '. fabs%FPM %S1, %D1',
520 attr_type => "sparc_fp_attr_t",
521 attr => "ir_mode *fp_mode",
526 irn_flags => [ "rematerializable" ],
527 reg_req => { in => [ "fp" ], out => [ "fp" ] },
528 emit => '. f%FCONVS.to%FCONVD %S1, %D1',
529 attr_type => "sparc_fp_conv_attr_t",
530 attr => "ir_mode *src_mode, ir_mode *dest_mode",
535 irn_flags => [ "rematerializable" ],
536 reg_req => { in => [ "gp" ], out => [ "fp" ] },
537 emit => '. fito%FPM %S1, %D1',
538 attr_type => "sparc_fp_attr_t",
539 attr => "ir_mode *fp_mode",
544 irn_flags => [ "rematerializable" ],
545 reg_req => { in => [ "fp" ], out => [ "gp" ] },
546 emit => '. f%FPM.toi %S1, %D1',
547 attr_type => "sparc_fp_attr_t",
548 attr => "ir_mode *fp_mode",
553 op_flags => [ "labeled", "fragile" ],
554 state => "exc_pinned",
555 ins => [ "ptr", "mem" ],
556 outs => [ "res", "M" ],
557 reg_req => { in => [ "gp", "none" ], out => [ "fp", "none" ] },
558 attr_type => "sparc_load_store_attr_t",
559 attr => "ir_mode *ls_mode, ir_entity *entity, int entity_sign, long offset, bool is_frame_entity",
560 emit => '. ld [%S1%O], %D1'
564 op_flags => [ "labeled", "fragile" ],
565 state => "exc_pinned",
566 ins => [ "ptr", "val", "mem" ],
568 reg_req => { in => [ "gp", "fp", "none" ], out => [ "none" ] },
569 attr_type => "sparc_load_store_attr_t",
570 attr => "ir_mode *ls_mode, ir_entity *entity, int entity_sign, long offset, bool is_frame_entity",
571 emit => '. st %S2, [%S1%O]',