amd64_spec.pl 9.85 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# the cpu architecture (ia32, ia64, mips, sparc, ppc, ...)

$arch = "amd64";

# The node description is done as a perl hash initializer with the
# following structure:
#
# %nodes = (
#
# <op-name> => {
#   arity     => "0|1|2|3 ... |variable|dynamic|any",   # optional
#   state     => "floats|pinned|mem_pinned|exc_pinned", # optional
#   args      => [
#                    { type => "type 1", name => "name 1" },
#                    { type => "type 2", name => "name 2" },
#                    ...
#                  ],
#   comment   => "any comment for constructor",  # optional
#   reg_req   => { in => [ "reg_class|register" ], out => [ "reg_class|register|in_rX" ] },
#   cmp_attr  => "c source code for comparing node attributes", # optional
#   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
#   emit      => "emit code with templates",   # optional for virtual nodes
#   attr      => "additional attribute arguments for constructor", # optional
#   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
# },
#
# ... # (all nodes you need to describe)
#
# ); # close the %nodes initializer

# state: state of the operation, OPTIONAL (default is "floats")
#
# 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
#
# outs:  if a node defines more than one output, the names of the projections
#        nodes having outs having automatically the mode mode_T
#
# comment: OPTIONAL comment for the node constructor
#
# register types:
54
$normal      =  0; # no special type
55
56
57
58
$ignore      =  1; # ignore (do not assign this register)
$arbitrary   =  2; # emitter can choose an arbitrary register of this class
$virtual     =  4; # the register is a virtual one
$state       =  8; # register represents a state
59
60
61
# NOTE: Last entry of each class is the largest Firm-Mode a register can hold
%reg_classes = (
	gp => [
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
		{ name => "rax", dwarf => 0 },
		{ name => "rcx", dwarf => 2 },
		{ name => "rdx", dwarf => 1 },
		{ name => "rsi", dwarf => 4 },
		{ name => "rdi", dwarf => 5 },
		{ name => "rbx", dwarf => 3 },
		{ name => "rbp", dwarf => 6 },
		{ name => "rsp", dwarf => 7, type => $ignore }, # stackpointer?
		{ name => "r8",  dwarf => 8 },
		{ name => "r9",  dwarf => 9 },
		{ name => "r10", dwarf => 10 },
		{ name => "r11", dwarf => 11 },
		{ name => "r12", dwarf => 12 },
		{ name => "r13", dwarf => 13 },
		{ name => "r14", dwarf => 14 },
		{ name => "r15", dwarf => 15 },
78
#		{ name => "gp_NOREG", type => $ignore }, # we need a dummy register for NoReg nodes
79
		{ mode => "mode_Lu" }
80
	],
81
#	fp => [
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#		{ name => "xmm0",  dwarf => 17 },
#		{ name => "xmm1",  dwarf => 18 },
#		{ name => "xmm2",  dwarf => 19 },
#		{ name => "xmm3",  dwarf => 20 },
#		{ name => "xmm4",  dwarf => 21 },
#		{ name => "xmm5",  dwarf => 22 },
#		{ name => "xmm6",  dwarf => 23 },
#		{ name => "xmm7",  dwarf => 24 },
#		{ name => "xmm8",  dwarf => 25 },
#		{ name => "xmm9",  dwarf => 26 },
#		{ name => "xmm10", dwarf => 27 },
#		{ name => "xmm11", dwarf => 28 },
#		{ name => "xmm12", dwarf => 29 },
#		{ name => "xmm13", dwarf => 30 },
#		{ name => "xmm14", dwarf => 31 },
#		{ name => "xmm15", dwarf => 32 },
98
99
#		{ mode => "mode_D" }
#	]
100
	flags => [
101
		{ name => "eflags", dwarf => 49 },
102
103
		{ mode => "mode_Iu", flags => "manual_ra" }
	],
104
105
);

106
$mode_gp        = "mode_Lu";
107
108
109
110
111
112
113
114
115
$mode_flags     = "mode_Iu";

sub amd64_custom_init_attr {
	my $constr = shift;
	my $node   = shift;
	my $name   = shift;
	my $res    = "";

	if(defined($node->{modified_flags})) {
116
		$res .= "\tarch_add_irn_flags(res, arch_irn_flags_modify_flags);\n";
117
118
119
120
121
	}
	return $res;
}
$custom_init_attr_func = \&amd64_custom_init_attr;

122
123
$default_copy_attr = "amd64_copy_attr";

124
125
126
127
128
129
130
131
132
133
134
135
136
%emit_templates = (
	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);",
137
138
	C  => "${arch}_emit_immediate(node);",
	O  => "${arch}_emit_fp_offset(node);",
139
140
141
142
);

%init_attr = (
	amd64_attr_t           =>
143
		 "\tinit_amd64_attributes(res, irn_flags_, in_reqs, n_res);",
144
	amd64_SymConst_attr_t =>
145
		"\tinit_amd64_attributes(res, irn_flags_, in_reqs, n_res);"
146
		. "\tinit_amd64_SymConst_attributes(res, entity);",
147
	amd64_condcode_attr_t =>
148
		"\tinit_amd64_attributes(res, irn_flags_, in_reqs, n_res);"
149
		. "\tinit_amd64_condcode_attributes(res, pnc);",
150
151
152
153
);

%compare_attr = (
	amd64_attr_t           => "cmp_amd64_attr",
154
	amd64_SymConst_attr_t  => "cmp_amd64_attr_SymConst",
155
	amd64_condcode_attr_t  => "cmp_amd64_attr_condcode",
156
157
158
159
160
161
162
163
164
165
166
167
168
);

%nodes = (
Push => {
	state     => "exc_pinned",
	reg_req   => { in => [ "gp", "gp", "none", "gp", "rsp" ], out => [ "rsp:I|S", "none" ] },
	ins       => [ "base", "index", "mem", "val", "stack" ],
	emit      => '. push %S1',
	outs      => [ "stack", "M" ],
	am        => "source,unary",
	latency   => 2,
#	units     => [ "GP" ],
},
169

170
Add => {
171
172
	op_flags   => [ "commutative" ],
	irn_flags  => [ "rematerializable" ],
173
174
	state      => "exc_pinned",
	reg_req    => { in => [ "gp", "gp" ],
175
	                out => [ "gp" ] },
176
	ins        => [ "left", "right" ],
177
	outs       => [ "res" ],
178
	mode       => $mode_gp,
179
180
	modified_flags => 1,
},
181

182
Mul => {
Robin Redeker's avatar
Robin Redeker committed
183
184
185
186
187
188
189
190
191
192
193
	# we should not rematrialize this node. It produces 2 results and has
	# very strict constraints
	state     => "exc_pinned",
	reg_req   => { in  => [ "rax", "gp" ],
	               out => [ "rax rdx" ] },
	ins       => [ "left", "right" ],
	emit      => '. mul %S2',
	outs      => [ "res" ],
	mode      => $mode_gp,
	am        => "source,binary",
	modified_flags => $status_flags
194
},
195

196
Sub => {
197
	irn_flags  => [ "rematerializable" ],
198
199
200
	state      => "exc_pinned",
	reg_req    => { in => [ "gp", "gp" ],
	                out => [ "gp" ] },
201
	ins        => [ "left", "right" ],
202
203
204
	outs       => [ "res" ],
	mode       => $mode_gp,
	modified_flags => 1,
205
},
206

207
Neg => {
208
	irn_flags => [ "rematerializable" ],
209
210
211
212
213
214
215
216
	reg_req   => { in => [ "gp" ],
	               out => [ "in_r1", "flags" ] },
	emit      => '. neg %S1',
	ins       => [ "val" ],
	outs      => [ "res", "flags" ],
	mode      => $mode_gp,
	modified_flags => $status_flags
},
217

218
Immediate => {
219
	op_flags  => [ "constlike" ],
220
	attr      => "unsigned imm_value",
221
	init_attr => "attr->ext.imm_value = imm_value;",
222
	reg_req   => { out => [ "gp" ] },
223
	emit      => '. mov %C, %D1',
224
	mode      => $mode_gp,
225
},
226

227
SymConst => {
228
229
	op_flags  => [ "constlike" ],
	irn_flags => [ "rematerializable" ],
230
231
232
	attr      => "ir_entity *entity",
	attr_type => "amd64_SymConst_attr_t",
	reg_req   => { out => [ "gp" ] },
233
	outs      => [ "res" ],
234
	mode      => $mode_gp,
235
},
236

237
238
239
240
241
242
243
Conv => {
	state     => "exc_pinned",
	attr      => "ir_mode *smaller_mode",
	init_attr => "attr->ls_mode = smaller_mode;",
	reg_req   => { in => [ "gp" ], out => [ "gp" ] },
	ins       => [ "val" ],
	outs      => [ "res" ],
244
	mode      => $mode_gp,
245
},
246

247
248
Jmp => {
	state     => "pinned",
249
	op_flags  => [ "cfopcode" ],
250
251
252
	reg_req   => { out => [ "none" ] },
	mode      => "mode_X",
},
253

254
Cmp => {
255
	irn_flags => [ "rematerializable" ],
256
257
258
259
260
261
262
263
264
265
266
267
	state     => "exc_pinned",
	reg_req   => { in  => [ "gp", "gp" ],
	               out => [ "flags" ] },
	ins       => [ "left", "right" ],
	outs      => [ "eflags" ],
	emit      => '. cmp %S1, %S2',
	attr      => "int ins_permuted, int cmp_unsigned",
	init_attr => "attr->data.ins_permuted   = ins_permuted;\n".
	             "\tattr->data.cmp_unsigned = cmp_unsigned;\n",
	mode      => $mode_flags,
	modified_flags => 1,
},
268

269
270
Jcc => {
	state     => "pinned",
271
	op_flags  => [ "cfopcode", "forking" ],
272
273
274
	reg_req   => { in  => [ "eflags" ], out => [ "none", "none" ] },
	ins       => [ "eflags" ],
	outs      => [ "false", "true" ],
275
276
	attr      => "ir_relation relation",
	init_attr => "attr->ext.relation = relation;",
277
278
	mode      => "mode_T",
},
279

280
Load => {
281
	op_flags  => [ "uses_memory" ],
282
283
284
285
286
	state     => "exc_pinned",
	reg_req   => { in => [ "gp", "none" ],
	               out => [ "gp", "none" ] },
	ins       => [ "ptr", "mem" ],
	outs      => [ "res",  "M" ],
287
288
289
	attr      => "ir_entity *entity",
	attr_type => "amd64_SymConst_attr_t",
	emit      => ". mov %O(%S1), %D1"
290
},
291

292
FrameAddr => {
293
294
	op_flags  => [ "constlike" ],
	irn_flags => [ "rematerializable" ],
295
296
297
298
299
300
	reg_req   => { in => [ "gp" ], out => [ "gp" ] },
	ins       => [ "base" ],
	attr      => "ir_entity *entity",
	attr_type => "amd64_SymConst_attr_t",
	mode      => $mode_gp,
},
301

302
Store => {
303
	op_flags  => [ "uses_memory" ],
304
305
306
307
	state     => "exc_pinned",
	reg_req   => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
	ins       => [ "ptr", "val", "mem" ],
	outs      => [ "M" ],
308
309
	attr      => "ir_entity *entity",
	attr_type => "amd64_SymConst_attr_t",
310
	mode      => "mode_M",
311
	emit      => ". mov %S2, %O(%S1)"
312
},
313

314
315
#NoReg_GP => {
#	state     => "pinned",
316
#	op_flags  => [ "constlike", "dump_noblcok", "dump_noinput" ],
317
318
319
320
#	reg_req   => { out => [ "gp_NOREG:I" ] },
#	units     => [],
#	emit      => "",
#	latency   => 0,
321
#	mode      => $mode_gp,
322
#},
323
);