TEMPLATE_spec.pl 10.7 KB
Newer Older
1
2
3
4
# Creation: 2006/02/13
# $Id$
# This is a template specification for the Firm-Backend

yb9976's avatar
yb9976 committed
5
6
$new_emit_syntax = 1;

7
8
9
10
11
12
13
14
15
16
# the cpu architecture (ia32, ia64, mips, sparc, ppc, ...)

$arch = "TEMPLATE";

# The node description is done as a perl hash initializer with the
# following structure:
#
# %nodes = (
#
# <op-name> => {
Matthias Braun's avatar
Matthias Braun committed
17
18
19
20
#   op_flags  => "N|L|C|X|I|F|Y|H|c|K",                 # optional
#   irn_flags => "R|N|I"                                # optional
#   arity     => "0|1|2|3 ... |variable|dynamic|any",   # optional
#   state     => "floats|pinned|mem_pinned|exc_pinned", # optional
Matthias Braun's avatar
Matthias Braun committed
21
22
23
#   args      => [
#                    { type => "type 1", name => "name 1" },
#                    { type => "type 2", name => "name 2" },
Christian Würdig's avatar
Christian Würdig committed
24
25
#                    ...
#                  ],
Matthias Braun's avatar
Matthias Braun committed
26
#   comment   => "any comment for constructor",  # optional
Matthias Braun's avatar
Matthias Braun committed
27
#   reg_req   => { in => [ "reg_class|register" ], out => [ "reg_class|register|in_rX" ] },
Matthias Braun's avatar
Matthias Braun committed
28
#   cmp_attr  => "c source code for comparing node attributes", # optional
29
30
31
#   outs      => { "out1", "out2" },# optional, creates pn_op_out1, ... consts
#   ins       => { "in1", "in2" },  # optional, creates n_op_in1, ... consts
#   mode      => "mode_Iu",         # optional, predefines the mode
Matthias Braun's avatar
Matthias Braun committed
32
#   emit      => "emit code with templates",   # optional for virtual nodes
33
#   attr      => "additional attribute arguments for constructor", # optional
34
35
36
37
38
#   init_attr => "emit attribute initialization template",         # optional
#   rd_constructor => "c source code which constructs an ir_node", # optional
#   hash_func => "name of the hash function for this operation",   # optional, get the default hash function else
#   latency   => "latency of this operation (can be float)"        # optional
#   attr_type => "name of the attribute struct",                   # optional
39
40
41
42
43
44
# },
#
# ... # (all nodes you need to describe)
#
# ); # close the %nodes initializer

Christian Würdig's avatar
Christian Würdig committed
45
# op_flags: flags for the operation, OPTIONAL (default is "N")
46
47
48
49
50
51
52
53
54
55
56
57
# the op_flags correspond to the firm irop_flags:
#   N   irop_flag_none
#   L   irop_flag_labeled
#   C   irop_flag_commutative
#   X   irop_flag_cfopcode
#   I   irop_flag_ip_cfopcode
#   F   irop_flag_fragile
#   Y   irop_flag_forking
#   H   irop_flag_highlevel
#   c   irop_flag_constlike
#   K   irop_flag_keep
#
Christian Würdig's avatar
Christian Würdig committed
58
59
60
61
62
# irn_flags: special node flags, OPTIONAL (default is 0)
# following irn_flags are supported:
#   R   rematerializeable
#   N   not spillable
#   I   ignore for register allocation
63
#
Christian Würdig's avatar
Christian Würdig committed
64
# state: state of the operation, OPTIONAL (default is "floats")
65
66
67
68
69
70
71
72
73
74
#
# arity: arity of the operation, MUST NOT BE OMITTED
#
# args:  the OPTIONAL arguments of the node constructor (debug, irg and block
#        are always the first 3 arguments and are always autmatically
#        created)
#        If this key is missing the following arguments will be created:
#        for i = 1 .. arity: ir_node *op_i
#        ir_mode *mode
#
75
76
77
# outs:  if a node defines more than one output, the names of the projections
#        nodes having outs having automatically the mode mode_T
#
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# comment: OPTIONAL comment for the node constructor
#
# rd_constructor: for every operation there will be a
#      new_rd_<arch>_<op-name> function with the arguments from above
#      which creates the ir_node corresponding to the defined operation
#      you can either put the complete source code of this function here
#
#      This key is OPTIONAL. If omitted, the following constructor will
#      be created:
#      if (!op_<arch>_<op-name>) assert(0);
#      for i = 1 to arity
#         set in[i] = op_i
#      done
#      res = new_ir_node(db, irg, block, op_<arch>_<op-name>, mode, arity, in)
#      return res
#
# NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3

# register types:
#   0 - no special type
Christian Würdig's avatar
Christian Würdig committed
98
99
#   1 - caller save (register must be saved by the caller of a function)
#   2 - callee save (register must be saved by the called function)
100
#   4 - ignore (do not assign this register)
Christian Würdig's avatar
Christian Würdig committed
101
# NOTE: Last entry of each class is the largest Firm-Mode a register can hold
102
%reg_classes = (
103
	gp => [
Matthias Braun's avatar
Matthias Braun committed
104
105
106
107
108
109
110
111
112
113
114
115
116
117
		{ name => "r0", type => 1 },
		{ name => "r1", type => 1 },
		{ name => "r2", type => 1 },
		{ name => "r3", type => 1 },
		{ name => "r4", type => 1 },
		{ name => "r5", type => 1 },
		{ name => "r6", type => 1 },
		{ name => "r7", type => 2 },
		{ name => "r8", type => 2 },
		{ name => "r9", type => 2 },
		{ name => "r10", type => 2 },
		{ name => "r11", type => 2 },
		{ name => "r12", type => 2 },
		{ name => "r13", type => 2 },
118
119
		{ name => "sp", realname => "r14", type => 4 },  # stackpointer
		{ name => "bp", realname => "r15", type => 4 },  # basepointer
Matthias Braun's avatar
Matthias Braun committed
120
121
		{ mode => "mode_Iu" }
	],
122
	fp => [
Matthias Braun's avatar
Matthias Braun committed
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
		{ name => "f0", type => 1 },
		{ name => "f1", type => 1 },
		{ name => "f2", type => 1 },
		{ name => "f3", type => 1 },
		{ name => "f4", type => 1 },
		{ name => "f5", type => 1 },
		{ name => "f6", type => 1 },
		{ name => "f7", type => 1 },
		{ name => "f8", type => 1 },
		{ name => "f9", type => 1 },
		{ name => "f10", type => 1 },
		{ name => "f11", type => 1 },
		{ name => "f12", type => 1 },
		{ name => "f13", type => 1 },
		{ name => "f14", type => 1 },
		{ name => "f15", type => 1 },
		{ mode => "mode_D" }
	]
141
);
142

Matthias Braun's avatar
Matthias Braun committed
143
%emit_templates = (
144
145
146
147
148
149
150
151
152
153
154
155
	S1 => "${arch}_emit_source_register(node, 0);",
	S2 => "${arch}_emit_source_register(node, 1);",
	S3 => "${arch}_emit_source_register(node, 2);",
	S4 => "${arch}_emit_source_register(node, 3);",
	S5 => "${arch}_emit_source_register(node, 4);",
	S6 => "${arch}_emit_source_register(node, 5);",
	D1 => "${arch}_emit_dest_register(node, 0);",
	D2 => "${arch}_emit_dest_register(node, 1);",
	D3 => "${arch}_emit_dest_register(node, 2);",
	D4 => "${arch}_emit_dest_register(node, 3);",
	D5 => "${arch}_emit_dest_register(node, 4);",
	D6 => "${arch}_emit_dest_register(node, 5);",
156
	C  => "${arch}_emit_immediate(node);"
Matthias Braun's avatar
Matthias Braun committed
157
158
);

159
160
%nodes = (

161
# Integer nodes
162

Matthias Braun's avatar
Matthias Braun committed
163
Add => {
164
165
	op_flags  => "C",
	irn_flags => "R",
166
	reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
167
	emit      => '. add %S1, %S2, %D1'
168
169
},

Matthias Braun's avatar
Matthias Braun committed
170
Add_i => {
171
	irn_flags => "R",
172
	reg_req   => { in => [ "gp" ], out => [ "gp" ] },
173
	emit      => '. add %S1, %C, %D1'
174
175
},

Matthias Braun's avatar
Matthias Braun committed
176
Mul => {
177
178
	op_flags  => "C",
	irn_flags => "R",
179
	reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
180
	emit      =>'. mul %S1, %S2, %D1'
181
182
},

Matthias Braun's avatar
Matthias Braun committed
183
Mul_i => {
184
	irn_flags => "R",
185
	reg_req   => { in => [ "gp" ], out => [ "gp" ] },
186
	emit      => '. mul %S1, %C, %D1'
187
188
},

Matthias Braun's avatar
Matthias Braun committed
189
And => {
190
191
	op_flags  => "C",
	irn_flags => "R",
192
	reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
193
	emit      => '. and %S1, %S2, %D1'
194
195
},

Matthias Braun's avatar
Matthias Braun committed
196
And_i => {
197
	irn_flags => "R",
198
	reg_req   => { in => [ "gp" ], out => [ "gp" ] },
199
	emit      => '. and %S1, %C, %D1'
200
201
},

Matthias Braun's avatar
Matthias Braun committed
202
Or => {
203
204
	op_flags  => "C",
	irn_flags => "R",
205
	reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
206
	emit      => '. or %S1, %S2, %D1'
207
208
},

Matthias Braun's avatar
Matthias Braun committed
209
Or_i => {
210
211
	op_flags  => "C",
	irn_flags => "R",
212
	reg_req   => { in => [ "gp" ], out => [ "gp" ] },
213
	emit      => '. or %S1, %C, %D1'
214
215
},

Matthias Braun's avatar
Matthias Braun committed
216
Eor => {
217
218
	op_flags  => "C",
	irn_flags => "R",
219
	reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
220
	emit      => '. xor %S1, %S2, %D1'
221
222
},

Matthias Braun's avatar
Matthias Braun committed
223
Eor_i => {
224
	irn_flags => "R",
225
	reg_req   => { in => [ "gp" ], out => [ "gp" ] },
226
	emit      => '. xor %S1, %C, %D1'
227
228
},

Matthias Braun's avatar
Matthias Braun committed
229
Sub => {
230
	irn_flags => "R",
231
	reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
232
	emit      => '. sub %S1, %S2, %D1'
233
234
},

Matthias Braun's avatar
Matthias Braun committed
235
Sub_i => {
236
	irn_flags => "R",
237
	reg_req   => { in => [ "gp" ], out => [ "gp" ] },
238
	emit      => '. subl %S1, %C, %D1'
239
240
},

Matthias Braun's avatar
Matthias Braun committed
241
Shl => {
242
	irn_flags => "R",
243
	reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
244
	emit      => '. shl %S1, %S2, %D1'
245
246
},

Matthias Braun's avatar
Matthias Braun committed
247
Shl_i => {
248
	irn_flags => "R",
249
	reg_req   => { in => [ "gp" ], out => [ "gp" ] },
250
	emit      => '. shl %S1, %C, %D1'
251
252
},

Matthias Braun's avatar
Matthias Braun committed
253
Shr => {
254
	irn_flags => "R",
255
	reg_req   => { in => [ "gp", "gp" ], out => [ "in_r1" ] },
256
	emit      => '. shr %S2, %D1'
257
258
},

Matthias Braun's avatar
Matthias Braun committed
259
Shr_i => {
260
	irn_flags => "R",
261
	reg_req   => { in => [ "gp" ], out => [ "gp" ] },
262
	emit      => '. shr %S1, %C, %D1'
263
264
},

Matthias Braun's avatar
Matthias Braun committed
265
RotR => {
266
	irn_flags => "R",
267
	reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
268
	emit      => '. ror %S1, %S2, %D1'
269
270
},

Matthias Braun's avatar
Matthias Braun committed
271
RotL => {
272
	irn_flags => "R",
273
	reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
274
	emit      => '. rol %S1, %S2, %D1'
275
276
},

Matthias Braun's avatar
Matthias Braun committed
277
RotL_i => {
278
	irn_flags => "R",
279
	reg_req   => { in => [ "gp" ], out => [ "gp" ] },
280
	emit      => '. rol %S1, %C, %D1'
281
282
},

Matthias Braun's avatar
Matthias Braun committed
283
Minus => {
284
	irn_flags => "R",
285
	reg_req   => { in => [ "gp" ], out => [ "gp" ] },
286
	emit      => '. neg %S1, %D1'
287
288
},

Matthias Braun's avatar
Matthias Braun committed
289
Inc => {
290
	irn_flags => "R",
291
	reg_req   => { in => [ "gp" ], out => [ "gp" ] },
292
	emit      => '. inc %S1, %D1'
293
294
},

Matthias Braun's avatar
Matthias Braun committed
295
Dec => {
296
	irn_flags => "R",
297
	reg_req   => { in => [ "gp" ], out => [ "gp" ] },
298
	emit      => '. dec %S1, %D1'
299
300
},

Matthias Braun's avatar
Matthias Braun committed
301
Not => {
302
303
	arity       => 1,
	remat       => 1,
304
	reg_req     => { in => [ "gp" ], out => [ "gp" ] },
305
	emit        => '. not %S1, %D1'
306
307
},

Matthias Braun's avatar
Matthias Braun committed
308
Const => {
309
310
	op_flags  => "c",
	irn_flags => "R",
311
	reg_req   => { out => [ "gp" ] },
312
313
	emit      => '. mov %C, %D1',
	cmp_attr  =>
314
'
Christian Würdig's avatar
Christian Würdig committed
315
	/* TODO: compare Const attributes */
316
317
318
319
    return 1;
'
},

320
321
# Control Flow

322
323
324
325
326
327
328
Jmp => {
	state    => "pinned",
	op_flags => "X",
	reg_req  => { out => [ "none" ] },
	mode     => "mode_X",
},

329
330
# Load / Store

Matthias Braun's avatar
Matthias Braun committed
331
Load => {
332
333
334
	op_flags  => "L|F",
	irn_flags => "R",
	state     => "exc_pinned",
335
	reg_req   => { in => [ "gp", "none" ], out => [ "gp" ] },
336
	emit      => '. mov (%S1), %D1'
337
338
},

Matthias Braun's avatar
Matthias Braun committed
339
Store => {
340
341
342
	op_flags  => "L|F",
	irn_flags => "R",
	state     => "exc_pinned",
343
	reg_req   => { in => [ "gp", "gp", "none" ] },
344
	emit      => '. movl %S2, (%S1)'
345
346
},

347
# Floating Point operations
348

Matthias Braun's avatar
Matthias Braun committed
349
fAdd => {
350
351
	op_flags  => "C",
	irn_flags => "R",
352
	reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
353
	emit      => '. fadd %S1, %S2, %D1'
354
355
},

Matthias Braun's avatar
Matthias Braun committed
356
fMul => {
357
	op_flags  => "C",
358
	reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
359
	emit      =>'. fmul %S1, %S2, %D1'
360
361
},

Matthias Braun's avatar
Matthias Braun committed
362
fMax => {
363
364
	op_flags  => "C",
	irn_flags => "R",
365
	reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
366
	emit      =>'. fmax %S1, %S2, %D1'
367
368
},

Matthias Braun's avatar
Matthias Braun committed
369
fMin => {
370
371
	op_flags  => "C",
	irn_flags => "R",
372
	reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
373
	emit      =>'. fmin %S1, %S2, %D1'
374
375
},

Matthias Braun's avatar
Matthias Braun committed
376
fSub => {
377
	irn_flags => "R",
378
	reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
379
	emit      => '. fsub %S1, %S2, %D1'
380
381
},

Matthias Braun's avatar
Matthias Braun committed
382
fDiv => {
383
	reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
384
	emit      => '. fdiv %S1, %S2, %D1'
385
386
},

Matthias Braun's avatar
Matthias Braun committed
387
fMinus => {
388
	irn_flags => "R",
389
	reg_req   => { in => [ "fp" ], out => [ "fp" ] },
390
	emit      => '. fneg %S1, %D1'
391
392
},

Matthias Braun's avatar
Matthias Braun committed
393
fConst => {
394
395
	op_flags  => "c",
	irn_flags => "R",
396
	reg_req   => { out => [ "fp" ] },
397
398
	emit      => '. fmov %C, %D1',
	cmp_attr  =>
399
'
Christian Würdig's avatar
Christian Würdig committed
400
401
	/* TODO: compare fConst attributes */
	return 1;
402
403
404
405
406
'
},

# Load / Store

Matthias Braun's avatar
Matthias Braun committed
407
fLoad => {
408
409
410
	op_flags  => "L|F",
	irn_flags => "R",
	state     => "exc_pinned",
411
	reg_req   => { in => [ "gp", "none" ], out => [ "fp" ] },
412
	emit      => '. fmov (%S1), %D1'
Matthias Braun's avatar
Matthias Braun committed
413
414
415
},

fStore => {
416
417
418
	op_flags  => "L|F",
	irn_flags => "R",
	state     => "exc_pinned",
419
	reg_req   => { in => [ "gp", "fp", "none" ] },
420
	emit      => '. fmov %S2, (%S1)'
Christian Würdig's avatar
Christian Würdig committed
421
},
422

423
);