35f66d1f37031c2fb1755e257802d81bcde8e752
[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 #   0 - no special type
60 #   1 - ignore (do not assign this register)
61 #   2 - emitter can choose an arbitrary register of this class
62 #   4 - the register is a virtual one
63 #   8 - register represents a state
64 # NOTE: Last entry of each class is the largest Firm-Mode a register can hold
65 %reg_classes = (
66         gp => [
67                 { name => "r0" },
68                 { name => "r1" },
69                 { name => "r2" },
70                 { name => "r3" },
71                 { name => "r4" },
72                 { name => "r5" },
73                 { name => "r6" },
74                 { name => "r7" },
75                 { name => "r8" },
76                 { name => "r9" },
77                 { name => "r10" },
78                 { name => "r11" },
79                 { name => "r12" },
80                 { name => "r13" },
81                 { name => "sp", realname => "r14", type => 1 },  # stackpointer
82                 { name => "bp", realname => "r15", type => 1 },  # basepointer
83                 { mode => $mode_gp }
84         ],
85         fp => [
86                 { name => "f0" },
87                 { name => "f1" },
88                 { name => "f2" },
89                 { name => "f3" },
90                 { name => "f4" },
91                 { name => "f5" },
92                 { name => "f6" },
93                 { name => "f7" },
94                 { name => "f8" },
95                 { name => "f9" },
96                 { name => "f10" },
97                 { name => "f11" },
98                 { name => "f12" },
99                 { name => "f13" },
100                 { name => "f14" },
101                 { name => "f15" },
102                 { mode => $mode_fp }
103         ]
104 );
105
106 %emit_templates = (
107         S1 => "${arch}_emit_source_register(node, 0);",
108         S2 => "${arch}_emit_source_register(node, 1);",
109         S3 => "${arch}_emit_source_register(node, 2);",
110         S4 => "${arch}_emit_source_register(node, 3);",
111         S5 => "${arch}_emit_source_register(node, 4);",
112         S6 => "${arch}_emit_source_register(node, 5);",
113         D1 => "${arch}_emit_dest_register(node, 0);",
114         D2 => "${arch}_emit_dest_register(node, 1);",
115         D3 => "${arch}_emit_dest_register(node, 2);",
116         D4 => "${arch}_emit_dest_register(node, 3);",
117         D5 => "${arch}_emit_dest_register(node, 4);",
118         D6 => "${arch}_emit_dest_register(node, 5);",
119         C  => "${arch}_emit_immediate(node);"
120 );
121
122 $default_attr_type = "TEMPLATE_attr_t";
123 $default_copy_attr = "TEMPLATE_copy_attr";
124
125 %nodes = (
126
127 # Integer nodes
128
129 Add => {
130         op_flags  => [ "commutative" ],
131         irn_flags => [ "rematerializable" ],
132         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
133         emit      => '. add %S1, %S2, %D1',
134         mode      => $mode_gp,
135 },
136
137 Mul => {
138         op_flags  => [ "commutative" ],
139         irn_flags => [ "rematerializable" ],
140         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
141         emit      =>'. mul %S1, %S2, %D1',
142         mode      => $mode_gp,
143 },
144
145 And => {
146         op_flags  => [ "commutative" ],
147         irn_flags => [ "rematerializable" ],
148         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
149         emit      => '. and %S1, %S2, %D1',
150         mode      => $mode_gp,
151 },
152
153 Or => {
154         op_flags  => [ "commutative" ],
155         irn_flags => [ "rematerializable" ],
156         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
157         emit      => '. or %S1, %S2, %D1',
158         mode      => $mode_gp,
159 },
160
161 Xor => {
162         op_flags  => [ "commutative" ],
163         irn_flags => [ "rematerializable" ],
164         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
165         emit      => '. xor %S1, %S2, %D1',
166         mode      => $mode_gp,
167 },
168
169 Sub => {
170         irn_flags => [ "rematerializable" ],
171         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
172         emit      => '. sub %S1, %S2, %D1',
173         mode      => $mode_gp,
174 },
175
176 Shl => {
177         irn_flags => [ "rematerializable" ],
178         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
179         emit      => '. shl %S1, %S2, %D1',
180         mode      => $mode_gp,
181 },
182
183 Shr => {
184         irn_flags => [ "rematerializable" ],
185         reg_req   => { in => [ "gp", "gp" ], out => [ "in_r1" ] },
186         emit      => '. shr %S2, %D1',
187         mode      => $mode_gp,
188 },
189
190 Minus => {
191         irn_flags => [ "rematerializable" ],
192         reg_req   => { in => [ "gp" ], out => [ "gp" ] },
193         emit      => '. neg %S1, %D1',
194         mode      => $mode_gp,
195 },
196
197 Not => {
198         arity   => 1,
199         remat   => 1,
200         reg_req => { in => [ "gp" ], out => [ "gp" ] },
201         emit    => '. not %S1, %D1',
202         mode    => $mode_gp,
203 },
204
205 Const => {
206         op_flags   => [ "constlike" ],
207         irn_flags  => [ "rematerializable" ],
208         attr       => "ir_tarval *value",
209         custominit => "set_TEMPLATE_value(res, value);",
210         reg_req    => { out => [ "gp" ] },
211         emit       => '. mov %C, %D1',
212         cmp_attr   =>
213 '
214         /* TODO: compare Const attributes */
215     return 1;
216 ',
217         mode    => $mode_gp,
218 },
219
220 # Control Flow
221
222 Jmp => {
223         state     => "pinned",
224         op_flags  => [ "cfopcode" ],
225         irn_flags => [ "simple_jump" ],
226         reg_req   => { out => [ "none" ] },
227         mode      => "mode_X",
228 },
229
230 # Load / Store
231
232 Load => {
233         op_flags  => [ "uses_memory" ],
234         irn_flags => [ "rematerializable" ],
235         state     => "exc_pinned",
236         reg_req   => { in => [ "gp", "none" ], out => [ "gp" ] },
237         emit      => '. mov (%S1), %D1',
238 },
239
240 Store => {
241         op_flags  => [ "uses_memory" ],
242         irn_flags => [ "rematerializable" ],
243         state     => "exc_pinned",
244         reg_req   => { in => [ "gp", "gp", "none" ] },
245         emit      => '. movl %S2, (%S1)',
246 },
247
248 # Floating Point operations
249
250 fAdd => {
251         op_flags  => [ "commutative" ],
252         irn_flags => [ "rematerializable" ],
253         reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
254         emit      => '. fadd %S1, %S2, %D1',
255         mode    => $mode_fp,
256 },
257
258 fMul => {
259         op_flags  => [ "commutative" ],
260         reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
261         emit      =>'. fmul %S1, %S2, %D1',
262         mode      => $mode_fp,
263 },
264
265 fSub => {
266         irn_flags => [ "rematerializable" ],
267         reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
268         emit      => '. fsub %S1, %S2, %D1',
269         mode      => $mode_fp,
270 },
271
272 fDiv => {
273         reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
274         emit      => '. fdiv %S1, %S2, %D1',
275         mode      => $mode_fp,
276 },
277
278 fMinus => {
279         irn_flags => [ "rematerializable" ],
280         reg_req   => { in => [ "fp" ], out => [ "fp" ] },
281         emit      => '. fneg %S1, %D1',
282         mode      => $mode_fp,
283 },
284
285 fConst => {
286         op_flags  => [ "constlike" ],
287         irn_flags => [ "rematerializable" ],
288         reg_req   => { out => [ "fp" ] },
289         emit      => '. fmov %C, %D1',
290         cmp_attr  =>
291 '
292         /* TODO: compare fConst attributes */
293         return 1;
294 ',
295         mode      => $mode_fp,
296 },
297
298 # Load / Store
299
300 fLoad => {
301         op_flags  => [ "uses_memory" ],
302         irn_flags => [ "rematerializable" ],
303         state     => "exc_pinned",
304         reg_req   => { in => [ "gp", "none" ], out => [ "fp" ] },
305         emit      => '. fmov (%S1), %D1',
306 },
307
308 fStore => {
309         op_flags  => [ "uses_memory" ],
310         irn_flags => [ "rematerializable" ],
311         state     => "exc_pinned",
312         reg_req   => { in => [ "gp", "fp", "none" ] },
313         emit      => '. fmov %S2, (%S1)',
314 },
315
316 );