2c1752efb4650261f60e9d2f01966abc990ad5f0
[libfirm] / ir / be / amd64 / amd64_spec.pl
1 # Creation: 2006/02/13
2 # $Id: amd64_spec.pl 26673 2009-10-01 16:43:13Z matze $
3
4 # the cpu architecture (ia32, ia64, mips, sparc, ppc, ...)
5
6 $arch = "amd64";
7
8 # The node description is done as a perl hash initializer with the
9 # following structure:
10 #
11 # %nodes = (
12 #
13 # <op-name> => {
14 #   op_flags  => "N|L|C|X|I|F|Y|H|c|K",                 # optional
15 #   irn_flags => "R|N|I"                                # optional
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 # op_flags: flags for the operation, OPTIONAL (default is "N")
43 # the op_flags correspond to the firm irop_flags:
44 #   N   irop_flag_none
45 #   L   irop_flag_labeled
46 #   C   irop_flag_commutative
47 #   X   irop_flag_cfopcode
48 #   I   irop_flag_ip_cfopcode
49 #   F   irop_flag_fragile
50 #   Y   irop_flag_forking
51 #   H   irop_flag_highlevel
52 #   c   irop_flag_constlike
53 #   K   irop_flag_keep
54 #
55 # irn_flags: special node flags, OPTIONAL (default is 0)
56 # following irn_flags are supported:
57 #   R   rematerializeable
58 #   N   not spillable
59 #   I   ignore for register allocation
60 #
61 # state: state of the operation, OPTIONAL (default is "floats")
62 #
63 # arity: arity of the operation, MUST NOT BE OMITTED
64 #
65 # args:  the OPTIONAL arguments of the node constructor (debug, irg and block
66 #        are always the first 3 arguments and are always autmatically
67 #        created)
68 #        If this key is missing the following arguments will be created:
69 #        for i = 1 .. arity: ir_node *op_i
70 #        ir_mode *mode
71 #
72 # outs:  if a node defines more than one output, the names of the projections
73 #        nodes having outs having automatically the mode mode_T
74 #
75 # comment: OPTIONAL comment for the node constructor
76 #
77 # rd_constructor: for every operation there will be a
78 #      new_rd_<arch>_<op-name> function with the arguments from above
79 #      which creates the ir_node corresponding to the defined operation
80 #      you can either put the complete source code of this function here
81 #
82 #      This key is OPTIONAL. If omitted, the following constructor will
83 #      be created:
84 #      if (!op_<arch>_<op-name>) assert(0);
85 #      for i = 1 to arity
86 #         set in[i] = op_i
87 #      done
88 #      res = new_ir_node(db, irg, block, op_<arch>_<op-name>, mode, arity, in)
89 #      return res
90 #
91 # NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3
92
93 # register types:
94 #   0 - no special type
95 #   1 - caller save (register must be saved by the caller of a function)
96 #   2 - callee save (register must be saved by the called function)
97 #   4 - ignore (do not assign this register)
98 # NOTE: Last entry of each class is the largest Firm-Mode a register can hold
99 %reg_classes = (
100         gp => [
101                 { name => "rax", type => 1 },
102                 { name => "rcx", type => 1 },
103                 { name => "rdx", type => 1 },
104                 { name => "rsi", type => 1 },
105                 { name => "rdi", type => 1 },
106                 { name => "rbx", type => 2 },
107                 { name => "rbp", type => 2 },
108                 { name => "rsp", type => 4 }, # stackpointer?
109                 { name => "r8",  type => 1 },
110                 { name => "r9",  type => 1 },
111                 { name => "r10", type => 1 },
112                 { name => "r11", type => 1 },
113                 { name => "r12", type => 2 },
114                 { name => "r13", type => 2 },
115                 { name => "r14", type => 2 },
116                 { name => "r15", type => 2 },
117 #               { name => "gp_NOREG", type => 4 }, # we need a dummy register for NoReg nodes
118                 { mode => "mode_Iu" }
119         ],
120 #       fp => [
121 #               { name => "xmm0", type => 1 },
122 #               { name => "xmm1", type => 1 },
123 #               { name => "xmm2", type => 1 },
124 #               { name => "xmm3", type => 1 },
125 #               { name => "xmm4", type => 1 },
126 #               { name => "xmm5", type => 1 },
127 #               { name => "xmm6", type => 1 },
128 #               { name => "xmm7", type => 1 },
129 #               { name => "xmm8", type => 1 },
130 #               { name => "xmm9", type => 1 },
131 #               { name => "xmm10", type => 1 },
132 #               { name => "xmm11", type => 1 },
133 #               { name => "xmm12", type => 1 },
134 #               { name => "xmm13", type => 1 },
135 #               { name => "xmm14", type => 1 },
136 #               { name => "xmm15", type => 1 },
137 #               { mode => "mode_D" }
138 #       ]
139 );
140
141 %emit_templates = (
142         S1 => "${arch}_emit_source_register(node, 0);",
143         S2 => "${arch}_emit_source_register(node, 1);",
144         S3 => "${arch}_emit_source_register(node, 2);",
145         S4 => "${arch}_emit_source_register(node, 3);",
146         S5 => "${arch}_emit_source_register(node, 4);",
147         S6 => "${arch}_emit_source_register(node, 5);",
148         D1 => "${arch}_emit_dest_register(node, 0);",
149         D2 => "${arch}_emit_dest_register(node, 1);",
150         D3 => "${arch}_emit_dest_register(node, 2);",
151         D4 => "${arch}_emit_dest_register(node, 3);",
152         D5 => "${arch}_emit_dest_register(node, 4);",
153         D6 => "${arch}_emit_dest_register(node, 5);",
154         C  => "${arch}_emit_immediate(node);"
155 );
156
157 %init_attr = (
158         amd64_attr_t           =>
159                  "\tinit_amd64_attributes(res, flags, in_reqs, exec_units, n_res);",
160         amd64_immediate_attr_t =>
161                 "\tinit_amd64_attributes(res, flags, in_reqs, exec_units, n_res);"
162                 . "\tinit_amd64_immediate_attributes(res, imm_value);",
163         amd64_SymConst_attr_t =>
164                 "\tinit_amd64_attributes(res, flags, in_reqs, exec_units, n_res);"
165                 . "\tinit_amd64_SymConst_attributes(res, entity);",
166 );
167
168 %compare_attr = (
169         amd64_attr_t           => "cmp_amd64_attr",
170         amd64_immediate_attr_t => "cmp_amd64_attr_immediate",
171         amd64_SymConst_attr_t  => "cmp_amd64_attr_SymConst",
172 );
173
174 %nodes = (
175 Push => {
176         state     => "exc_pinned",
177         reg_req   => { in => [ "gp", "gp", "none", "gp", "rsp" ], out => [ "rsp:I|S", "none" ] },
178         ins       => [ "base", "index", "mem", "val", "stack" ],
179         emit      => '. push %S1',
180         outs      => [ "stack", "M" ],
181         am        => "source,unary",
182         latency   => 2,
183 #       units     => [ "GP" ],
184 },
185 Add => {
186         irn_flags  => "R",
187         state      => "exc_pinned",
188         reg_req    => { in => [ "gp", "gp" ],
189                         out => [ "gp" ] },
190         in         => [ "left", "right" ],
191         emit       => ". mov %S2, %D1\n"
192                       . ". add %S1, %D1\n",
193         outs       => [ "res" ],
194         mode       => "mode_Iu",
195 },
196 Immediate => {
197         op_flags  => "c",
198         attr      => "unsigned imm_value",
199         attr_type => "amd64_immediate_attr_t",
200         reg_req   => { out => [ "gp" ] },
201         emit      => '. movq %C, %D1',
202         mode      => "mode_Iu",
203 },
204 SymConst => {
205         op_flags  => "c",
206         irn_flags => "R",
207         attr      => "ir_entity *entity",
208         attr_type => "amd64_SymConst_attr_t",
209         reg_req   => { out => [ "gp" ] },
210         mode      => 'mode_Iu',
211 },
212 Conv => {
213         state     => "exc_pinned",
214         attr      => "ir_mode *smaller_mode",
215         init_attr => "attr->ls_mode = smaller_mode;",
216         reg_req   => { in => [ "gp" ], out => [ "gp" ] },
217         ins       => [ "val" ],
218         outs      => [ "res" ],
219         mode      => 'mode_Iu',
220 },
221 Jmp => {
222         state     => "pinned",
223         op_flags  => "X",
224         reg_req   => { out => [ "none" ] },
225         mode      => "mode_X",
226 },
227 #NoReg_GP => {
228 #       state     => "pinned",
229 #       op_flags  => "c|NB|NI",
230 #       reg_req   => { out => [ "gp_NOREG:I" ] },
231 #       units     => [],
232 #       emit      => "",
233 #       latency   => 0,
234 #       mode      => "mode_Iu",
235 #},
236 );