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" ],
207 comment => "construct Add: Add(a, b) = Add(b, a) = a + b",
209 emit => '. add %S1, %R2I, %D1',
210 constructors => \%binop_operand_constructors,
214 irn_flags => [ "rematerializable" ],
215 comment => "construct Sub: Sub(a, b) = a - b",
217 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
218 emit => '. sub %S1, %R2I, %D1',
219 constructors => \%binop_operand_constructors,
225 op_flags => [ "labeled", "fragile" ],
226 comment => "construct Load: Load(ptr, mem) = LD ptr -> reg",
227 state => "exc_pinned",
228 ins => [ "ptr", "mem" ],
229 outs => [ "res", "M" ],
230 reg_req => { in => [ "gp", "none" ], out => [ "gp", "none" ] },
231 attr_type => "sparc_load_store_attr_t",
232 attr => "ir_mode *ls_mode, ir_entity *entity, int entity_sign, long offset, bool is_frame_entity",
233 emit => '. ld%LM [%S1%O], %D1'
237 op_flags => [ "labeled", "fragile" ],
238 comment => "construct LoadHi: Load(ptr, mem) = sethi hi(ptr) -> reg",
239 state => "exc_pinned",
240 ins => [ "ptr", "mem" ],
241 outs => [ "res", "M" ],
242 reg_req => { in => [ "gp", "none" ], out => [ "gp", "none" ] },
243 attr_type => "sparc_load_store_attr_t",
244 attr => "ir_mode *ls_mode, ir_entity *entity, int entity_sign, long offset, bool is_frame_entity",
245 emit => '. sethi %%hi(%S1), %D1',
249 irn_flags => [ "rematerializable" ],
250 comment => "construct LoadHi: Load(imm, mem) = sethi hi(imm) -> reg",
251 state => "exc_pinned",
254 reg_req => { in => [], out => [ "gp" ] },
255 #attr_type => "sparc_load_store_attr_t",
256 attr => "int immediate_value",
257 custominit => "sparc_set_attr_imm(res, immediate_value);",
261 irn_flags => [ "rematerializable" ],
262 comment => "construct LoadHi: Load(imm, mem) = sethi hi(imm) -> reg",
263 state => "exc_pinned",
267 reg_req => { in => [ "gp" ], out => [ "gp" ] },
268 #attr_type => "sparc_load_store_attr_t",
269 attr => "int immediate_value",
270 custominit => "sparc_set_attr_imm(res, immediate_value);",
274 op_flags => [ "labeled", "fragile" ],
275 comment => "construct LoadLo: Or(in, ptr, mem) = or in lo(ptr) -> reg",
276 state => "exc_pinned",
277 ins => [ "hireg", "ptr", "mem" ],
278 outs => [ "res", "M" ],
279 reg_req => { in => [ "gp", "gp", "none" ], out => [ "gp", "none" ] },
280 attr_type => "sparc_load_store_attr_t",
281 attr => "ir_mode *ls_mode, ir_entity *entity, int entity_sign, long offset, bool is_frame_entity",
282 emit => '. or %S1, %%lo(%S2), %D1'
286 op_flags => [ "labeled", "fragile" ],
287 comment => "construct Store: Store(ptr, val, mem) = ST ptr,val",
289 state => "exc_pinned",
290 ins => [ "ptr", "val", "mem" ],
292 reg_req => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
293 attr_type => "sparc_load_store_attr_t",
294 attr => "ir_mode *ls_mode, ir_entity *entity, int entity_sign, long offset, bool is_frame_entity",
295 emit => '. st%SM %S2, [%S1%O]'
299 irn_flags => [ "rematerializable" ],
300 comment => "construct Mov: Mov(src, dest) = MV src,dest",
302 emit => '. mov %R1I, %D1',
304 constructors => \%unop_operand_constructors,
308 comment => "function prolog instruction. autom. saves sp & shifts the register window. previous out regs become the new in regs",
310 in => [ "sp", "none"],
311 out => [ "sp:I|S","none" ]
313 ins => [ "stack", "mem" ],
314 outs => [ "stack", "mem" ],
315 attr => "int initial_stacksize",
316 attr_type => "sparc_save_attr_t",
317 init_attr => "\tinit_sparc_save_attr(res, initial_stacksize);",
321 comment => "alloc stack space",
322 reg_req => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "gp", "none" ] },
323 ins => [ "stack", "size", "mem" ],
324 outs => [ "stack", "addr", "M" ],
325 emit => ". sub %S1, %S2, %D1\n",
329 comment => "free stack space",
330 reg_req => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "none" ] },
331 ins => [ "stack", "size", "mem" ],
332 outs => [ "stack", "M" ],
333 emit => ". add %S1, %S2, %D1\n",
337 op_flags => [ "constlike" ],
338 irn_flags => [ "rematerializable" ],
339 attr => "ir_entity *entity",
340 reg_req => { out => [ "gp" ] },
341 attr_type => "sparc_symconst_attr_t",
346 op_flags => [ "constlike" ],
347 irn_flags => [ "rematerializable" ],
348 attr => "ir_entity *entity",
349 reg_req => { in => [ "gp" ], out => [ "gp" ] },
351 attr_type => "sparc_symconst_attr_t",
356 op_flags => [ "labeled", "cfopcode", "forking" ],
359 reg_req => { in => [ "flags" ], out => [ "none", "none" ] },
360 attr => "int proj_num",
361 attr_type => "sparc_jmp_cond_attr_t",
362 init_attr => "\tset_sparc_jmp_cond_proj_num(res, proj_num);",
367 op_flags => [ "cfopcode" ],
368 irn_flags => [ "simple_jump" ],
369 reg_req => { out => [ "none" ] },
374 irn_flags => [ "rematerializable", "modify_flags" ],
375 emit => '. cmp %S1, %R2I',
377 attr_type => "sparc_cmp_attr_t",
378 constructors => \%cmp_operand_constructors,
382 irn_flags => [ "rematerializable", "modify_flags" ],
385 attr_type => "sparc_cmp_attr_t",
386 attr => "bool ins_permuted, bool is_unsigned",
387 custominit => "init_sparc_cmp_attr(res, ins_permuted, is_unsigned);",
388 reg_req => { in => [ "gp" ], out => [ "flags" ] },
393 op_flags => [ "labeled", "cfopcode", "forking" ],
396 attr => "int n_projs, long def_proj_num",
397 init_attr => "\tset_sparc_jmp_switch_n_projs(res, n_projs);\n".
398 "\tset_sparc_jmp_switch_default_proj_num(res, def_proj_num);",
399 reg_req => { in => [ "gp" ], out => [ "none" ] },
400 attr_type => "sparc_jmp_switch_attr_t",
404 irn_flags => [ "rematerializable" ],
405 comment => "construct shift logical left",
407 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
408 emit => '. sll %S1, %R2I, %D1',
409 constructors => \%binop_operand_constructors,
413 irn_flags => [ "rematerializable" ],
414 comment => "construct shift logical right",
416 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
417 emit => '. srl %S1, %R2I, %D1',
418 constructors => \%binop_operand_constructors,
422 irn_flags => [ "rematerializable" ],
423 comment => "construct shift right arithmetical",
425 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
426 emit => '. sra %S1, %R2I, %D1',
427 constructors => \%binop_operand_constructors,
431 irn_flags => [ "rematerializable" ],
432 comment => "construct logical and",
434 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
435 emit => '. and %S1, %R2I, %D1',
436 constructors => \%binop_operand_constructors,
440 irn_flags => [ "rematerializable" ],
441 comment => "construct logical or",
443 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
444 emit => '. or %S1, %R2I, %D1',
445 constructors => \%binop_operand_constructors,
449 irn_flags => [ "rematerializable" ],
450 comment => "construct logical xor",
452 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
453 emit => '. xor %S1, %R2I, %D1',
454 constructors => \%binop_operand_constructors,
458 state => "exc_pinned",
459 comment => "construct Mul: Mul(a, b) = Mul(b, a) = a * b",
460 reg_req => { in => [ "gp", "gp" ], out => [ "gp", "flags" ] },
461 outs => [ "low", "high" ],
462 constructors => \%binop_operand_constructors,
463 #emit =>'. mul %S1, %R2I, %D1'
467 state => "exc_pinned",
468 comment => "construct Mul: Mul(a, b) = Mul(b, a) = a * b",
469 reg_req => { in => [ "gp", "gp" ], out => [ "gp", "gp" ] },
470 outs => [ "low", "high" ],
471 constructors => \%binop_operand_constructors,
475 irn_flags => [ "rematerializable" ],
476 state => "exc_pinned",
477 comment => "construct Div: Div(a, b) = a / b",
478 reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
480 constructors => \%binop_operand_constructors,
482 #emit =>'. div %S1, %R2I, %D1'
486 irn_flags => [ "rematerializable" ],
488 comment => "construct Minus: Minus(a) = -a",
489 #reg_req => { in => [ "gp" ], out => [ "in_r1" ] },
490 reg_req => { in => [ "gp" ], out => [ "gp" ] },
491 emit => ". sub %%g0, %S1, %D1"
495 irn_flags => [ "rematerializable" ],
497 comment => "construct Not: Not(a) = !a",
498 reg_req => { in => [ "gp" ], out => [ "gp" ] },
499 emit => '. xnor %S1, %%g0, %D1'
503 op_flags => [ "keep" ],
504 reg_req => { in => [], out => [ "none" ] },
509 op_flags => [ "commutative" ],
510 irn_flags => [ "rematerializable" ],
511 comment => "construct FP Add: Add(a, b) = Add(b, a) = a + b",
512 reg_req => { in => [ "fp", "fp" ], out => [ "fp" ] },
513 emit => '. fadd%FPM %S1, %S2, %D1'
517 op_flags => [ "commutative" ],
518 comment => "construct FP Mul: Mul(a, b) = Mul(b, a) = a * b",
519 reg_req => { in => [ "fp", "fp" ], out => [ "fp" ] },
520 emit =>'. fmul%FPM %S1, %S2, %D1'
524 op_flags => [ "commutative" ],
525 comment => "construct FP single to double precision Mul: Mul(a, b) = Mul(b, a) = a * b",
526 reg_req => { in => [ "fp", "fp" ], out => [ "fp" ] },
527 emit =>'. fsmuld %S1, %S2, %D1'
531 irn_flags => [ "rematerializable" ],
532 comment => "convert FP (single) to FP (double)",
533 reg_req => { in => [ "fp" ], out => [ "fp" ] },
534 emit =>'. FsTOd %S1, %D1'
538 irn_flags => [ "rematerializable" ],
539 comment => "convert FP (double) to FP (single)",
540 reg_req => { in => [ "fp" ], out => [ "fp" ] },
541 emit =>'. FdTOs %S1, %D1'
545 irn_flags => [ "rematerializable" ],
546 comment => "convert integer to FP",
547 reg_req => { in => [ "fp" ], out => [ "gp" ] },
548 emit =>'. FiTOs %S1, %D1'
552 irn_flags => [ "rematerializable" ],
553 comment => "convert integer to FP",
554 reg_req => { in => [ "fp" ], out => [ "gp" ] },
555 emit =>'. FiTOd %S1, %D1'
559 irn_flags => [ "rematerializable" ],
560 comment => "convert FP (single) to integer",
561 reg_req => { in => [ "gp" ], out => [ "fp" ] },
562 emit =>'. FsTOi %S1, %D1'
566 irn_flags => [ "rematerializable" ],
567 comment => "convert FP (double) to integer",
568 reg_req => { in => [ "gp" ], out => [ "fp" ] },
569 emit =>'. FdTOi %S1, %D1'