TEMPLATE_spec.pl 10.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Creation: 2006/02/13
# $Id$
# This is a template specification for the Firm-Backend

# 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
15
16
17
18
#   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
19
20
21
#   args      => [
#                    { type => "type 1", name => "name 1" },
#                    { type => "type 2", name => "name 2" },
Christian Würdig's avatar
Christian Würdig committed
22
23
#                    ...
#                  ],
Matthias Braun's avatar
Matthias Braun committed
24
#   comment   => "any comment for constructor",  # optional
Matthias Braun's avatar
Matthias Braun committed
25
#   reg_req   => { in => [ "reg_class|register" ], out => [ "reg_class|register|in_rX" ] },
Matthias Braun's avatar
Matthias Braun committed
26
#   cmp_attr  => "c source code for comparing node attributes", # optional
27
28
29
#   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
30
#   emit      => "emit code with templates",   # optional for virtual nodes
31
#   attr      => "additional attribute arguments for constructor", # optional
32
33
34
35
36
#   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
37
38
39
40
41
42
# },
#
# ... # (all nodes you need to describe)
#
# ); # close the %nodes initializer

Christian Würdig's avatar
Christian Würdig committed
43
# op_flags: flags for the operation, OPTIONAL (default is "N")
44
45
46
47
48
49
50
51
52
53
54
55
# 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
56
57
58
59
60
# irn_flags: special node flags, OPTIONAL (default is 0)
# following irn_flags are supported:
#   R   rematerializeable
#   N   not spillable
#   I   ignore for register allocation
61
#
Christian Würdig's avatar
Christian Würdig committed
62
# state: state of the operation, OPTIONAL (default is "floats")
63
64
65
66
67
68
69
70
71
72
#
# 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
#
73
74
75
# outs:  if a node defines more than one output, the names of the projections
#        nodes having outs having automatically the mode mode_T
#
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# 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
96
97
#   1 - caller save (register must be saved by the caller of a function)
#   2 - callee save (register must be saved by the called function)
98
#   4 - ignore (do not assign this register)
Christian Würdig's avatar
Christian Würdig committed
99
# NOTE: Last entry of each class is the largest Firm-Mode a register can hold
100
%reg_classes = (
101
	gp => [
Matthias Braun's avatar
Matthias Braun committed
102
103
104
105
106
107
108
109
110
111
112
113
114
115
		{ 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 },
116
117
		{ name => "sp", realname => "r14", type => 4 },  # stackpointer
		{ name => "bp", realname => "r15", type => 4 },  # basepointer
Matthias Braun's avatar
Matthias Braun committed
118
119
		{ mode => "mode_Iu" }
	],
120
	fp => [
Matthias Braun's avatar
Matthias Braun committed
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
		{ 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" }
	]
139
);
140

Matthias Braun's avatar
Matthias Braun committed
141
%emit_templates = (
142
143
144
145
146
147
148
149
150
151
152
153
	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);",
154
	C  => "${arch}_emit_immediate(node);"
Matthias Braun's avatar
Matthias Braun committed
155
156
);

157
158
%nodes = (

159
# Integer nodes
160

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

318
319
# Control Flow

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

328
329
# Load / Store

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

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

346
# Floating Point operations
347

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

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

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

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

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

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

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

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

# Load / Store

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

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

422
);