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 => "fp", 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 # simple reg emitters
110 S1 => "${arch}_emit_source_register(node, 0);",
111 S2 => "${arch}_emit_source_register(node, 1);",
112 S3 => "${arch}_emit_source_register(node, 2);",
113 S4 => "${arch}_emit_source_register(node, 3);",
114 S5 => "${arch}_emit_source_register(node, 4);",
115 S6 => "${arch}_emit_source_register(node, 5);",
116 D1 => "${arch}_emit_dest_register(node, 0);",
117 D2 => "${arch}_emit_dest_register(node, 1);",
118 D3 => "${arch}_emit_dest_register(node, 2);",
119 D4 => "${arch}_emit_dest_register(node, 3);",
120 D5 => "${arch}_emit_dest_register(node, 4);",
121 D6 => "${arch}_emit_dest_register(node, 5);",
122 # more custom emitters
123 C => "${arch}_emit_immediate(node);",
124 LM => "${arch}_emit_load_mode(node);",
125 SM => "${arch}_emit_store_mode(node);",
126 EXTPREF => "${arch}_emit_mode_sign_prefix(node);",
127 FPM => "${arch}_emit_fp_mode_suffix(node);",
128 FPLM => "${arch}_emit_fp_load_mode(node);",
129 FPSM => "${arch}_emit_fp_store_mode(node);",
130 O => "${arch}_emit_offset(node);",
133 $default_attr_type = "sparc_attr_t";
134 $default_copy_attr = "sparc_copy_attr";
138 sparc_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
139 sparc_load_store_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);\n".
140 "\tinit_sparc_load_store_attributes(res, ls_mode, entity, entity_sign, offset, is_frame_entity);",
141 sparc_symconst_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);\n".
142 "\tinit_sparc_symconst_attributes(res, entity);",
143 sparc_cmp_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);\n",
144 sparc_jmp_cond_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
145 sparc_jmp_switch_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
146 sparc_save_attr_t => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
151 sparc_attr_t => "cmp_attr_sparc",
152 sparc_load_store_attr_t => "cmp_attr_sparc_load_store",
153 sparc_symconst_attr_t => "cmp_attr_sparc_symconst",
154 sparc_jmp_cond_attr_t => "cmp_attr_sparc_jmp_cond",
155 sparc_jmp_switch_attr_t => "cmp_attr_sparc_jmp_switch",
156 sparc_cmp_attr_t => "cmp_attr_sparc_cmp",
157 sparc_save_attr_t => "cmp_attr_sparc_save",
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, bool ins_permuted, bool is_unsigned",
166 custominit => "sparc_set_attr_imm(res, immediate_value);" .
167 "\tinit_sparc_cmp_attr(res, ins_permuted, is_unsigned);",
168 reg_req => { in => [ "gp" ], out => [ "flags" ] },
172 attr => "bool ins_permuted, bool is_unsigned",
173 custominit => "init_sparc_cmp_attr(res, ins_permuted, is_unsigned);",
174 reg_req => { in => [ "gp", "gp" ], out => [ "flags" ] },
175 ins => [ "left", "right" ],
179 my %unop_operand_constructors = (
181 attr => "int immediate_value",
182 custominit => "sparc_set_attr_imm(res, immediate_value);",
183 reg_req => { in => [], out => [ "gp" ] },
186 reg_req => { in => [ "gp" ], out => [ "gp" ] },
190 my %binop_operand_constructors = (
192 attr => "int immediate_value",
193 custominit => "sparc_set_attr_imm(res, immediate_value);",
194 reg_req => { in => [ "gp" ], out => [ "gp" ] },
198 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
199 ins => [ "left", "right" ],
206 irn_flags => [ "rematerializable" ],
208 emit => '. add %S1, %R2I, %D1',
209 constructors => \%binop_operand_constructors,
213 irn_flags => [ "rematerializable" ],
215 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
216 emit => '. sub %S1, %R2I, %D1',
217 constructors => \%binop_operand_constructors,
223 op_flags => [ "labeled", "fragile" ],
224 state => "exc_pinned",
225 ins => [ "ptr", "mem" ],
226 outs => [ "res", "M" ],
227 reg_req => { in => [ "gp", "none" ], out => [ "gp", "none" ] },
228 attr_type => "sparc_load_store_attr_t",
229 attr => "ir_mode *ls_mode, ir_entity *entity, int entity_sign, long offset, bool is_frame_entity",
230 emit => '. ld%LM [%S1%O], %D1'
234 op_flags => [ "labeled", "fragile" ],
235 state => "exc_pinned",
236 ins => [ "ptr", "mem" ],
237 outs => [ "res", "M" ],
238 reg_req => { in => [ "gp", "none" ], out => [ "gp", "none" ] },
239 attr_type => "sparc_load_store_attr_t",
240 attr => "ir_mode *ls_mode, ir_entity *entity, int entity_sign, long offset, bool is_frame_entity",
241 emit => '. sethi %%hi(%S1), %D1',
245 irn_flags => [ "rematerializable" ],
246 state => "exc_pinned",
249 reg_req => { in => [], out => [ "gp" ] },
250 #attr_type => "sparc_load_store_attr_t",
251 attr => "int immediate_value",
252 custominit => "sparc_set_attr_imm(res, immediate_value);",
256 irn_flags => [ "rematerializable" ],
257 state => "exc_pinned",
261 reg_req => { in => [ "gp" ], out => [ "gp" ] },
262 #attr_type => "sparc_load_store_attr_t",
263 attr => "int immediate_value",
264 custominit => "sparc_set_attr_imm(res, immediate_value);",
268 op_flags => [ "labeled", "fragile" ],
269 state => "exc_pinned",
270 ins => [ "hireg", "ptr", "mem" ],
271 outs => [ "res", "M" ],
272 reg_req => { in => [ "gp", "gp", "none" ], out => [ "gp", "none" ] },
273 attr_type => "sparc_load_store_attr_t",
274 attr => "ir_mode *ls_mode, ir_entity *entity, int entity_sign, long offset, bool is_frame_entity",
275 emit => '. or %S1, %%lo(%S2), %D1'
279 op_flags => [ "labeled", "fragile" ],
281 state => "exc_pinned",
282 ins => [ "ptr", "val", "mem" ],
284 reg_req => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
285 attr_type => "sparc_load_store_attr_t",
286 attr => "ir_mode *ls_mode, ir_entity *entity, int entity_sign, long offset, bool is_frame_entity",
287 emit => '. st%SM %S2, [%S1%O]'
291 irn_flags => [ "rematerializable" ],
293 emit => '. mov %R1I, %D1',
295 constructors => \%unop_operand_constructors,
300 in => [ "sp", "none"],
301 out => [ "sp:I|S","none" ]
303 ins => [ "stack", "mem" ],
304 outs => [ "stack", "mem" ],
305 attr => "int initial_stacksize",
306 attr_type => "sparc_save_attr_t",
307 init_attr => "\tinit_sparc_save_attr(res, initial_stacksize);",
311 reg_req => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "gp", "none" ] },
312 ins => [ "stack", "size", "mem" ],
313 outs => [ "stack", "addr", "M" ],
314 emit => ". sub %S1, %S2, %D1\n",
318 reg_req => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "none" ] },
319 ins => [ "stack", "size", "mem" ],
320 outs => [ "stack", "M" ],
321 emit => ". add %S1, %S2, %D1\n",
325 op_flags => [ "constlike" ],
326 irn_flags => [ "rematerializable" ],
327 attr => "ir_entity *entity",
328 reg_req => { out => [ "gp" ] },
329 attr_type => "sparc_symconst_attr_t",
334 op_flags => [ "constlike" ],
335 irn_flags => [ "rematerializable" ],
336 attr => "ir_entity *entity",
337 reg_req => { in => [ "gp" ], out => [ "gp" ] },
339 attr_type => "sparc_symconst_attr_t",
344 op_flags => [ "labeled", "cfopcode", "forking" ],
347 reg_req => { in => [ "flags" ], out => [ "none", "none" ] },
348 attr => "int proj_num",
349 attr_type => "sparc_jmp_cond_attr_t",
350 init_attr => "\tset_sparc_jmp_cond_proj_num(res, proj_num);",
355 op_flags => [ "cfopcode" ],
356 irn_flags => [ "simple_jump" ],
357 reg_req => { out => [ "none" ] },
362 irn_flags => [ "rematerializable", "modify_flags" ],
363 emit => '. cmp %S1, %R2I',
365 attr_type => "sparc_cmp_attr_t",
366 constructors => \%cmp_operand_constructors,
370 irn_flags => [ "rematerializable", "modify_flags" ],
373 attr_type => "sparc_cmp_attr_t",
374 attr => "bool ins_permuted, bool is_unsigned",
375 custominit => "init_sparc_cmp_attr(res, ins_permuted, is_unsigned);",
376 reg_req => { in => [ "gp" ], out => [ "flags" ] },
381 op_flags => [ "labeled", "cfopcode", "forking" ],
384 attr => "int n_projs, long def_proj_num",
385 init_attr => "\tset_sparc_jmp_switch_n_projs(res, n_projs);\n".
386 "\tset_sparc_jmp_switch_default_proj_num(res, def_proj_num);",
387 reg_req => { in => [ "gp" ], out => [ "none" ] },
388 attr_type => "sparc_jmp_switch_attr_t",
392 irn_flags => [ "rematerializable" ],
394 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
395 emit => '. sll %S1, %R2I, %D1',
396 constructors => \%binop_operand_constructors,
400 irn_flags => [ "rematerializable" ],
402 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
403 emit => '. srl %S1, %R2I, %D1',
404 constructors => \%binop_operand_constructors,
408 irn_flags => [ "rematerializable" ],
410 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
411 emit => '. sra %S1, %R2I, %D1',
412 constructors => \%binop_operand_constructors,
416 irn_flags => [ "rematerializable" ],
418 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
419 emit => '. and %S1, %R2I, %D1',
420 constructors => \%binop_operand_constructors,
424 irn_flags => [ "rematerializable" ],
426 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
427 emit => '. or %S1, %R2I, %D1',
428 constructors => \%binop_operand_constructors,
432 irn_flags => [ "rematerializable" ],
434 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
435 emit => '. xor %S1, %R2I, %D1',
436 constructors => \%binop_operand_constructors,
440 state => "exc_pinned",
441 reg_req => { in => [ "gp", "gp" ], out => [ "gp", "flags" ] },
442 outs => [ "low", "high" ],
443 constructors => \%binop_operand_constructors,
444 #emit =>'. mul %S1, %R2I, %D1'
448 state => "exc_pinned",
449 reg_req => { in => [ "gp", "gp" ], out => [ "gp", "gp" ] },
450 outs => [ "low", "high" ],
451 constructors => \%binop_operand_constructors,
455 irn_flags => [ "rematerializable" ],
456 state => "exc_pinned",
457 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
459 constructors => \%binop_operand_constructors,
461 #emit =>'. div %S1, %R2I, %D1'
465 irn_flags => [ "rematerializable" ],
467 #reg_req => { in => [ "gp" ], out => [ "in_r1" ] },
468 reg_req => { in => [ "gp" ], out => [ "gp" ] },
469 emit => ". sub %%g0, %S1, %D1"
473 irn_flags => [ "rematerializable" ],
475 reg_req => { in => [ "gp" ], out => [ "gp" ] },
476 emit => '. xnor %S1, %%g0, %D1'
480 op_flags => [ "keep" ],
481 reg_req => { in => [], out => [ "none" ] },
486 op_flags => [ "commutative" ],
487 irn_flags => [ "rematerializable" ],
488 reg_req => { in => [ "fp", "fp" ], out => [ "fp" ] },
489 emit => '. fadd%FPM %S1, %S2, %D1'
493 op_flags => [ "commutative" ],
494 reg_req => { in => [ "fp", "fp" ], out => [ "fp" ] },
495 emit =>'. fmul%FPM %S1, %S2, %D1'
499 op_flags => [ "commutative" ],
500 reg_req => { in => [ "fp", "fp" ], out => [ "fp" ] },
501 emit =>'. fsmuld %S1, %S2, %D1'
505 irn_flags => [ "rematerializable" ],
506 reg_req => { in => [ "fp" ], out => [ "fp" ] },
507 emit =>'. FsTOd %S1, %D1'
511 irn_flags => [ "rematerializable" ],
512 reg_req => { in => [ "fp" ], out => [ "fp" ] },
513 emit =>'. FdTOs %S1, %D1'
517 irn_flags => [ "rematerializable" ],
518 reg_req => { in => [ "fp" ], out => [ "gp" ] },
519 emit =>'. FiTOs %S1, %D1'
523 irn_flags => [ "rematerializable" ],
524 reg_req => { in => [ "fp" ], out => [ "gp" ] },
525 emit =>'. FiTOd %S1, %D1'
529 irn_flags => [ "rematerializable" ],
530 reg_req => { in => [ "gp" ], out => [ "fp" ] },
531 emit =>'. FsTOi %S1, %D1'
535 irn_flags => [ "rematerializable" ],
536 reg_req => { in => [ "gp" ], out => [ "fp" ] },
537 emit =>'. FdTOi %S1, %D1'