beverify: test register width in regalloc verification
[libfirm] / ir / be / TEMPLATE / TEMPLATE_spec.pl
1 # Creation: 2006/02/13
2 # $Id$
3
4 # the cpu architecture (ia32, ia64, mips, sparc, ppc, ...)
5
6 $arch = "TEMPLATE";
7
8 #
9 # Modes
10 #
11 $mode_gp  = "mode_Iu"; # mode used by general purpose registers
12 $mode_fp  = "mode_E";  # mode used by floatingpoint registers
13
14 # The node description is done as a perl hash initializer with the
15 # following structure:
16 #
17 # %nodes = (
18 #
19 # <op-name> => {
20 #   arity     => "0|1|2|3 ... |variable|dynamic|any",   # optional
21 #   state     => "floats|pinned|mem_pinned|exc_pinned", # optional
22 #   args      => [
23 #                    { type => "type 1", name => "name 1" },
24 #                    { type => "type 2", name => "name 2" },
25 #                    ...
26 #                  ],
27 #   comment   => "any comment for constructor",  # optional
28 #   reg_req   => { in => [ "reg_class|register" ], out => [ "reg_class|register|in_rX" ] },
29 #   cmp_attr  => "c source code for comparing node attributes", # optional
30 #   outs      => { "out1", "out2" },# optional, creates pn_op_out1, ... consts
31 #   ins       => { "in1", "in2" },  # optional, creates n_op_in1, ... consts
32 #   mode      => "mode_Iu",         # optional, predefines the mode
33 #   emit      => "emit code with templates",   # optional for virtual nodes
34 #   attr      => "additional attribute arguments for constructor", # optional
35 #   init_attr => "emit attribute initialization template",         # optional
36 #   rd_constructor => "c source code which constructs an ir_node", # optional
37 #   hash_func => "name of the hash function for this operation",   # optional, get the default hash function else
38 #   latency   => "latency of this operation (can be float)"        # optional
39 #   attr_type => "name of the attribute struct",                   # optional
40 # },
41 #
42 # ... # (all nodes you need to describe)
43 #
44 # ); # close the %nodes initializer
45
46 # state: state of the operation, OPTIONAL (default is "floats")
47 #
48 # arity: arity of the operation, MUST NOT BE OMITTED
49 #
50 # args:  the OPTIONAL arguments of the node constructor (debug, irg and block
51 #        are always the first 3 arguments and are always autmatically
52 #        created)
53 #        If this key is missing the following arguments will be created:
54 #        for i = 1 .. arity: ir_node *op_i
55 #        ir_mode *mode
56 #
57 # outs:  if a node defines more than one output, the names of the projections
58 #        nodes having outs having automatically the mode mode_T
59 #
60 # comment: OPTIONAL comment for the node constructor
61 #
62 # register types:
63 #   0 - no special type
64 #   1 - ignore (do not assign this register)
65 #   2 - emitter can choose an arbitrary register of this class
66 #   4 - the register is a virtual one
67 #   8 - register represents a state
68 # NOTE: Last entry of each class is the largest Firm-Mode a register can hold
69 %reg_classes = (
70         gp => [
71                 { name => "r0" },
72                 { name => "r1" },
73                 { name => "r2" },
74                 { name => "r3" },
75                 { name => "r4" },
76                 { name => "r5" },
77                 { name => "r6" },
78                 { name => "r7" },
79                 { name => "r8" },
80                 { name => "r9" },
81                 { name => "r10" },
82                 { name => "r11" },
83                 { name => "r12" },
84                 { name => "r13" },
85                 { name => "sp", realname => "r14", type => 1 },  # stackpointer
86                 { name => "bp", realname => "r15", type => 1 },  # basepointer
87                 { mode => $mode_gp }
88         ],
89         fp => [
90                 { name => "f0" },
91                 { name => "f1" },
92                 { name => "f2" },
93                 { name => "f3" },
94                 { name => "f4" },
95                 { name => "f5" },
96                 { name => "f6" },
97                 { name => "f7" },
98                 { name => "f8" },
99                 { name => "f9" },
100                 { name => "f10" },
101                 { name => "f11" },
102                 { name => "f12" },
103                 { name => "f13" },
104                 { name => "f14" },
105                 { name => "f15" },
106                 { mode => $mode_fp }
107         ]
108 );
109
110 %emit_templates = (
111         S1 => "${arch}_emit_source_register(node, 0);",
112         S2 => "${arch}_emit_source_register(node, 1);",
113         S3 => "${arch}_emit_source_register(node, 2);",
114         S4 => "${arch}_emit_source_register(node, 3);",
115         S5 => "${arch}_emit_source_register(node, 4);",
116         S6 => "${arch}_emit_source_register(node, 5);",
117         D1 => "${arch}_emit_dest_register(node, 0);",
118         D2 => "${arch}_emit_dest_register(node, 1);",
119         D3 => "${arch}_emit_dest_register(node, 2);",
120         D4 => "${arch}_emit_dest_register(node, 3);",
121         D5 => "${arch}_emit_dest_register(node, 4);",
122         D6 => "${arch}_emit_dest_register(node, 5);",
123         C  => "${arch}_emit_immediate(node);"
124 );
125
126 $default_attr_type = "TEMPLATE_attr_t";
127 $default_copy_attr = "TEMPLATE_copy_attr";
128
129 %nodes = (
130
131 # Integer nodes
132
133 Add => {
134         op_flags  => [ "commutative" ],
135         irn_flags => [ "rematerializable" ],
136         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
137         emit      => '. add %S1, %S2, %D1',
138         mode      => $mode_gp,
139 },
140
141 Mul => {
142         op_flags  => [ "commutative" ],
143         irn_flags => [ "rematerializable" ],
144         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
145         emit      =>'. mul %S1, %S2, %D1',
146         mode      => $mode_gp,
147 },
148
149 And => {
150         op_flags  => [ "commutative" ],
151         irn_flags => [ "rematerializable" ],
152         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
153         emit      => '. and %S1, %S2, %D1',
154         mode      => $mode_gp,
155 },
156
157 Or => {
158         op_flags  => [ "commutative" ],
159         irn_flags => [ "rematerializable" ],
160         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
161         emit      => '. or %S1, %S2, %D1',
162         mode      => $mode_gp,
163 },
164
165 Xor => {
166         op_flags  => [ "commutative" ],
167         irn_flags => [ "rematerializable" ],
168         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
169         emit      => '. xor %S1, %S2, %D1',
170         mode      => $mode_gp,
171 },
172
173 Sub => {
174         irn_flags => [ "rematerializable" ],
175         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
176         emit      => '. sub %S1, %S2, %D1',
177         mode      => $mode_gp,
178 },
179
180 Shl => {
181         irn_flags => [ "rematerializable" ],
182         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
183         emit      => '. shl %S1, %S2, %D1',
184         mode      => $mode_gp,
185 },
186
187 Shr => {
188         irn_flags => [ "rematerializable" ],
189         reg_req   => { in => [ "gp", "gp" ], out => [ "in_r1" ] },
190         emit      => '. shr %S2, %D1',
191         mode      => $mode_gp,
192 },
193
194 Minus => {
195         irn_flags => [ "rematerializable" ],
196         reg_req   => { in => [ "gp" ], out => [ "gp" ] },
197         emit      => '. neg %S1, %D1',
198         mode      => $mode_gp,
199 },
200
201 Not => {
202         arity   => 1,
203         remat   => 1,
204         reg_req => { in => [ "gp" ], out => [ "gp" ] },
205         emit    => '. not %S1, %D1',
206         mode    => $mode_gp,
207 },
208
209 Const => {
210         op_flags   => [ "constlike" ],
211         irn_flags  => [ "rematerializable" ],
212         attr       => "ir_tarval *value",
213         custominit => "set_TEMPLATE_value(res, value);",
214         reg_req    => { out => [ "gp" ] },
215         emit       => '. mov %C, %D1',
216         cmp_attr   =>
217 '
218         /* TODO: compare Const attributes */
219     return 1;
220 ',
221         mode    => $mode_gp,
222 },
223
224 # Control Flow
225
226 Jmp => {
227         state     => "pinned",
228         op_flags  => [ "cfopcode" ],
229         irn_flags => [ "simple_jump" ],
230         reg_req   => { out => [ "none" ] },
231         mode      => "mode_X",
232 },
233
234 # Load / Store
235
236 Load => {
237         op_flags  => [ "labeled" ],
238         irn_flags => [ "rematerializable" ],
239         state     => "exc_pinned",
240         reg_req   => { in => [ "gp", "none" ], out => [ "gp" ] },
241         emit      => '. mov (%S1), %D1',
242 },
243
244 Store => {
245         op_flags  => [ "labeled" ],
246         irn_flags => [ "rematerializable" ],
247         state     => "exc_pinned",
248         reg_req   => { in => [ "gp", "gp", "none" ] },
249         emit      => '. movl %S2, (%S1)',
250 },
251
252 # Floating Point operations
253
254 fAdd => {
255         op_flags  => [ "commutative" ],
256         irn_flags => [ "rematerializable" ],
257         reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
258         emit      => '. fadd %S1, %S2, %D1',
259         mode    => $mode_fp,
260 },
261
262 fMul => {
263         op_flags  => [ "commutative" ],
264         reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
265         emit      =>'. fmul %S1, %S2, %D1',
266         mode      => $mode_fp,
267 },
268
269 fSub => {
270         irn_flags => [ "rematerializable" ],
271         reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
272         emit      => '. fsub %S1, %S2, %D1',
273         mode      => $mode_fp,
274 },
275
276 fDiv => {
277         reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
278         emit      => '. fdiv %S1, %S2, %D1',
279         mode      => $mode_fp,
280 },
281
282 fMinus => {
283         irn_flags => [ "rematerializable" ],
284         reg_req   => { in => [ "fp" ], out => [ "fp" ] },
285         emit      => '. fneg %S1, %D1',
286         mode      => $mode_fp,
287 },
288
289 fConst => {
290         op_flags  => [ "constlike" ],
291         irn_flags => [ "rematerializable" ],
292         reg_req   => { out => [ "fp" ] },
293         emit      => '. fmov %C, %D1',
294         cmp_attr  =>
295 '
296         /* TODO: compare fConst attributes */
297         return 1;
298 ',
299         mode      => $mode_fp,
300 },
301
302 # Load / Store
303
304 fLoad => {
305         op_flags  => [ "labeled" ],
306         irn_flags => [ "rematerializable" ],
307         state     => "exc_pinned",
308         reg_req   => { in => [ "gp", "none" ], out => [ "fp" ] },
309         emit      => '. fmov (%S1), %D1',
310 },
311
312 fStore => {
313         op_flags  => [ "labeled" ],
314         irn_flags => [ "rematerializable" ],
315         state     => "exc_pinned",
316         reg_req   => { in => [ "gp", "fp", "none" ] },
317         emit      => '. fmov %S2, (%S1)',
318 },
319
320 );