TEMPLATE_spec.pl 8.39 KB
Newer Older
1
2
3
4
5
6
7
# Creation: 2006/02/13
# $Id$

# the cpu architecture (ia32, ia64, mips, sparc, ppc, ...)

$arch = "TEMPLATE";

8
9
10
11
12
13
#
# Modes
#
$mode_gp  = "mode_Iu"; # mode used by general purpose registers
$mode_fp  = "mode_E";  # mode used by floatingpoint registers

14
15
16
17
18
19
# The node description is done as a perl hash initializer with the
# following structure:
#
# %nodes = (
#
# <op-name> => {
Matthias Braun's avatar
Matthias Braun committed
20
21
#   arity     => "0|1|2|3 ... |variable|dynamic|any",   # optional
#   state     => "floats|pinned|mem_pinned|exc_pinned", # optional
Matthias Braun's avatar
Matthias Braun committed
22
23
24
#   args      => [
#                    { type => "type 1", name => "name 1" },
#                    { type => "type 2", name => "name 2" },
Christian Würdig's avatar
Christian Würdig committed
25
26
#                    ...
#                  ],
Matthias Braun's avatar
Matthias Braun committed
27
#   comment   => "any comment for constructor",  # optional
Matthias Braun's avatar
Matthias Braun committed
28
#   reg_req   => { in => [ "reg_class|register" ], out => [ "reg_class|register|in_rX" ] },
Matthias Braun's avatar
Matthias Braun committed
29
#   cmp_attr  => "c source code for comparing node attributes", # optional
30
31
32
#   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
33
#   emit      => "emit code with templates",   # optional for virtual nodes
34
#   attr      => "additional attribute arguments for constructor", # optional
35
36
37
38
39
#   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
40
41
42
43
44
45
# },
#
# ... # (all nodes you need to describe)
#
# ); # close the %nodes initializer

Christian Würdig's avatar
Christian Würdig committed
46
# state: state of the operation, OPTIONAL (default is "floats")
47
48
49
50
51
52
53
54
55
56
#
# 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
#
57
58
59
# outs:  if a node defines more than one output, the names of the projections
#        nodes having outs having automatically the mode mode_T
#
60
61
62
63
# comment: OPTIONAL comment for the node constructor
#
# register types:
#   0 - no special type
64
65
66
67
#   1 - ignore (do not assign this register)
#   2 - emitter can choose an arbitrary register of this class
#   4 - the register is a virtual one
#   8 - register represents a state
Christian Würdig's avatar
Christian Würdig committed
68
# NOTE: Last entry of each class is the largest Firm-Mode a register can hold
69
%reg_classes = (
70
	gp => [
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
		{ name => "r0" },
		{ name => "r1" },
		{ name => "r2" },
		{ name => "r3" },
		{ name => "r4" },
		{ name => "r5" },
		{ name => "r6" },
		{ name => "r7" },
		{ name => "r8" },
		{ name => "r9" },
		{ name => "r10" },
		{ name => "r11" },
		{ name => "r12" },
		{ name => "r13" },
		{ name => "sp", realname => "r14", type => 1 },  # stackpointer
		{ name => "bp", realname => "r15", type => 1 },  # basepointer
87
		{ mode => $mode_gp }
Matthias Braun's avatar
Matthias Braun committed
88
	],
89
	fp => [
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
		{ name => "f0" },
		{ name => "f1" },
		{ name => "f2" },
		{ name => "f3" },
		{ name => "f4" },
		{ name => "f5" },
		{ name => "f6" },
		{ name => "f7" },
		{ name => "f8" },
		{ name => "f9" },
		{ name => "f10" },
		{ name => "f11" },
		{ name => "f12" },
		{ name => "f13" },
		{ name => "f14" },
		{ name => "f15" },
106
		{ mode => $mode_fp }
Matthias Braun's avatar
Matthias Braun committed
107
	]
108
);
109

Matthias Braun's avatar
Matthias Braun committed
110
%emit_templates = (
111
112
113
114
115
116
117
118
119
120
121
122
	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);",
123
	C  => "${arch}_emit_immediate(node);"
Matthias Braun's avatar
Matthias Braun committed
124
125
);

126
127
128
$default_attr_type = "TEMPLATE_attr_t";
$default_copy_attr = "TEMPLATE_copy_attr";

129
130
%nodes = (

131
# Integer nodes
132

Matthias Braun's avatar
Matthias Braun committed
133
Add => {
134
135
	op_flags  => [ "commutative" ],
	irn_flags => [ "rematerializable" ],
136
	reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
137
138
	emit      => '. add %S1, %S2, %D1',
	mode      => $mode_gp,
139
140
},

Matthias Braun's avatar
Matthias Braun committed
141
Mul => {
142
143
	op_flags  => [ "commutative" ],
	irn_flags => [ "rematerializable" ],
144
	reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
145
146
	emit      =>'. mul %S1, %S2, %D1',
	mode      => $mode_gp,
147
148
},

Matthias Braun's avatar
Matthias Braun committed
149
And => {
150
151
	op_flags  => [ "commutative" ],
	irn_flags => [ "rematerializable" ],
152
	reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
153
154
	emit      => '. and %S1, %S2, %D1',
	mode      => $mode_gp,
155
156
},

Matthias Braun's avatar
Matthias Braun committed
157
Or => {
158
159
	op_flags  => [ "commutative" ],
	irn_flags => [ "rematerializable" ],
160
	reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
161
162
	emit      => '. or %S1, %S2, %D1',
	mode      => $mode_gp,
163
164
},

165
Xor => {
166
167
	op_flags  => [ "commutative" ],
	irn_flags => [ "rematerializable" ],
168
	reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
169
170
	emit      => '. xor %S1, %S2, %D1',
	mode      => $mode_gp,
171
172
},

Matthias Braun's avatar
Matthias Braun committed
173
Sub => {
174
	irn_flags => [ "rematerializable" ],
175
	reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
176
177
	emit      => '. sub %S1, %S2, %D1',
	mode      => $mode_gp,
178
179
},

Matthias Braun's avatar
Matthias Braun committed
180
Shl => {
181
	irn_flags => [ "rematerializable" ],
182
	reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
183
184
	emit      => '. shl %S1, %S2, %D1',
	mode      => $mode_gp,
185
186
},

Matthias Braun's avatar
Matthias Braun committed
187
Shr => {
188
	irn_flags => [ "rematerializable" ],
189
	reg_req   => { in => [ "gp", "gp" ], out => [ "in_r1" ] },
190
191
	emit      => '. shr %S2, %D1',
	mode      => $mode_gp,
192
193
},

Matthias Braun's avatar
Matthias Braun committed
194
Minus => {
195
	irn_flags => [ "rematerializable" ],
196
	reg_req   => { in => [ "gp" ], out => [ "gp" ] },
197
198
	emit      => '. neg %S1, %D1',
	mode      => $mode_gp,
199
200
},

Matthias Braun's avatar
Matthias Braun committed
201
Not => {
202
203
204
205
206
	arity   => 1,
	remat   => 1,
	reg_req => { in => [ "gp" ], out => [ "gp" ] },
	emit    => '. not %S1, %D1',
	mode    => $mode_gp,
207
208
},

Matthias Braun's avatar
Matthias Braun committed
209
Const => {
210
211
	op_flags   => [ "constlike" ],
	irn_flags  => [ "rematerializable" ],
Matthias Braun's avatar
Matthias Braun committed
212
	attr       => "ir_tarval *value",
213
214
215
216
	custominit => "set_TEMPLATE_value(res, value);",
	reg_req    => { out => [ "gp" ] },
	emit       => '. mov %C, %D1',
	cmp_attr   =>
217
'
Christian Würdig's avatar
Christian Würdig committed
218
	/* TODO: compare Const attributes */
219
    return 1;
220
221
',
	mode    => $mode_gp,
222
223
},

224
225
# Control Flow

226
Jmp => {
227
	state     => "pinned",
228
229
	op_flags  => [ "cfopcode" ],
	irn_flags => [ "simple_jump" ],
230
231
	reg_req   => { out => [ "none" ] },
	mode      => "mode_X",
232
233
},

234
235
# Load / Store

Matthias Braun's avatar
Matthias Braun committed
236
Load => {
Matthias Braun's avatar
Matthias Braun committed
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
},

Matthias Braun's avatar
Matthias Braun committed
244
Store => {
Matthias Braun's avatar
Matthias Braun committed
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

Matthias Braun's avatar
Matthias Braun committed
254
fAdd => {
255
256
	op_flags  => [ "commutative" ],
	irn_flags => [ "rematerializable" ],
257
	reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
258
259
	emit      => '. fadd %S1, %S2, %D1',
	mode    => $mode_fp,
260
261
},

Matthias Braun's avatar
Matthias Braun committed
262
fMul => {
263
	op_flags  => [ "commutative" ],
264
	reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
265
266
	emit      =>'. fmul %S1, %S2, %D1',
	mode      => $mode_fp,
267
268
},

Matthias Braun's avatar
Matthias Braun committed
269
fSub => {
270
	irn_flags => [ "rematerializable" ],
271
	reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
272
273
	emit      => '. fsub %S1, %S2, %D1',
	mode      => $mode_fp,
274
275
},

Matthias Braun's avatar
Matthias Braun committed
276
fDiv => {
277
	reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
278
279
	emit      => '. fdiv %S1, %S2, %D1',
	mode      => $mode_fp,
280
281
},

Matthias Braun's avatar
Matthias Braun committed
282
fMinus => {
283
	irn_flags => [ "rematerializable" ],
284
	reg_req   => { in => [ "fp" ], out => [ "fp" ] },
285
286
	emit      => '. fneg %S1, %D1',
	mode      => $mode_fp,
287
288
},

Matthias Braun's avatar
Matthias Braun committed
289
fConst => {
290
291
	op_flags  => [ "constlike" ],
	irn_flags => [ "rematerializable" ],
292
	reg_req   => { out => [ "fp" ] },
293
294
	emit      => '. fmov %C, %D1',
	cmp_attr  =>
295
'
Christian Würdig's avatar
Christian Würdig committed
296
297
	/* TODO: compare fConst attributes */
	return 1;
298
299
',
	mode      => $mode_fp,
300
301
302
303
},

# Load / Store

Matthias Braun's avatar
Matthias Braun committed
304
fLoad => {
Matthias Braun's avatar
Matthias Braun committed
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',
Matthias Braun's avatar
Matthias Braun committed
310
311
312
},

fStore => {
Matthias Braun's avatar
Matthias Braun committed
313
	op_flags  => [ "labeled" ],
314
	irn_flags => [ "rematerializable" ],
315
	state     => "exc_pinned",
316
	reg_req   => { in => [ "gp", "fp", "none" ] },
317
	emit      => '. fmov %S2, (%S1)',
Christian Würdig's avatar
Christian Würdig committed
318
},
319

320
);