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