- add ir_bk_outport and ir_bk_inport
[libfirm] / ir / ir / ir_spec.pl
1 # This is the specification for the IR nodes
2 # Code is generated by scripts/gen_ir.pl
3 #
4 # $Id$
5
6 $NONE            = "#_#_#_#_#_NONE_#_#_#_#_#";
7 $MANUALFROMPARAM = "#_#_#_#_#_MANUALFROMPARAM_#_#_#_#_#";
8
9 # The IR node description is done as a perl hash with the following structure:
10 #
11 # %nodes = (
12 #
13 # <opname> => {
14 #  op          => use given node type instead of opname
15 #                 or 0 is this is an abstract node type (default: none)
16 #                 when present, no ir_op will be created
17 #  is_a        => name of another IR node description from which all data
18 #                 except "op" is inherited (default: none),
19 #  mode        => the mode of the op (default: parameter),
20 #  op_flags    => "N|L|C|X|I|F|Y|H|c|K|S|M|NB|NI" (default: "N"),
21 #  state       => "floats|pinned|mem_pinned|exc_pinned" (default: "floats"),
22 #  arity       => "dynamic|variable"
23 #                 dynamic allows to add inputs later,
24 #                 variable means, that the ins are given at construction time
25 #                 (default: automatically from args)
26 #  block       => the block for the node (default: parameter)
27 #  ins         => [ "in1", "in2", ... ] list of node inputs (default: none)
28 #  attrs_name  => name of the attribute structure
29 #                 (default if attrs exists: lcfirst(opname)),
30 #  attrs_type  => type of the attribute structure (default: auto generated),
31 #  attrs       => ordered list of attributes which will default to parameters
32 #                 after the ins and the mode parameters
33 #                 [
34 #                    {
35 #                       type  => the C type of the attribute or "bit",
36 #                       name  => the name of the attribute,
37 #                       init  => an initializer instead of a parameter
38 #                                or $MANUALFROMPARAM to disable automatic
39 #                                initialization but still using a parameter
40 #                                or $NONE to disable initialization completely
41 #                                by also not using a parameter
42 #                                (default: parameter),
43 #                       initname => name to access attribute
44 #                                when present, attribute will not be added
45 #                                to the according attribute struct
46 #                                (default: ".".name)
47 #                       comment => documentation for the attribute
48 #                    }, ...
49 #                 ] (default: none),
50 #  init        => additional initialization code to be emitted after the
51 #                 attribute initialization (default: none)
52 #  optimize    => whether optimize_node should be called (0|1, default: 1),
53 #  d_pre       => code to be inserted at the begining of the new_d_* function
54 #                 (may include declarations and statements, default: none),
55 #  d_post      => code to be inserted into the new_d_* function after the call
56 #                 to the new_rd_* function whose result is stored in the
57 #                 local variable res (default: none)
58 # },
59 #
60 # <more nodes>
61 #
62 # ); # close the %nodes initializer
63 #
64
65 # op_flags: flags for the operation corresponding to the firm irop_flags:
66 #       N   irop_flag_none
67 #       L   irop_flag_labeled
68 #       C   irop_flag_commutative
69 #       X   irop_flag_cfopcode
70 #       I   irop_flag_ip_cfopcode
71 #       F   irop_flag_fragile
72 #       Y   irop_flag_forking
73 #       H   irop_flag_highlevel
74 #       c   irop_flag_constlike
75 #       K   irop_flag_keep
76 #       S   irop_flag_start_block
77 #       M   irop_flag_uses_memory
78 #       NB  irop_flag_dump_noblock
79 #       NI  irop_flag_dump_noinput
80 #
81
82 %nodes = (
83
84 Start => {
85         mode        => "mode_T",
86         op_flags    => "X",
87         state       => "pinned"
88 },
89
90 End => {
91         mode        => "mode_X",
92         op_flags    => "X",
93         state       => "pinned",
94         arity       => "dynamic"
95 },
96
97 Block => {
98         mode        => "mode_BB",
99         op_flags    => "L",
100         state       => "pinned",
101         arity       => "variable",
102         block       => "NULL",
103         attrs       => [
104                 {
105                         type => "ir_graph *",
106                         name => "irg",
107                         init => "irg",
108                         comment => "The graph this block belongs to."
109                 },
110                 {
111                         type => "ir_visited_t",
112                         name => "block_visited",
113                         init => $NONE,
114                         comment => "For the walker that walks over all blocks."
115                 },
116                 {
117                         type => "bit",
118                         name => "is_matured",
119                         init => $NONE,
120                         comment => "If set, all in-nodes of the block are fixed."
121                 },
122                 {
123                         type => "bit",
124                         name => "is_dead",
125                         init => "0",
126                         comment => "If set, the block is dead (and could be replace by a Bad."
127                 },
128                 {
129                         type => "bit",
130                         name => "is_mb_head",
131                         init => "1",
132                         comment => "Set if this block is a macroblock head."
133                 },
134                 {
135                         type => "bit",
136                         name => "has_label",
137                         init => "0",
138                         comment => "Set if this block has a label assigned."
139                 },
140                 {
141                         type => "bit",
142                         name => "marked",
143                         init => $NONE,         # TODO: This is uninitialized!!
144                         comment => "Can be set/unset to temporary mark a block."
145                 },
146                 {
147                         type => "ir_node **",
148                         name => "graph_arr",
149                         init => $NONE,         # TODO: This is uninitialized!!
150                         comment => "An array to store all parameters."
151                 },
152                 {
153                         type => "ir_dom_info",
154                         name => "dom",
155                         init => $NONE,        # TODO: This is uninitialized!!
156                         comment => "Datastructure that holds information about dominators.
157                                          @@@ \@todo
158                                          Eventually overlay with graph_arr as only valid
159                                          in different phases.  Eventually inline the whole
160                                          datastructure."
161                 },
162                 {
163                         type => "ir_dom_info",
164                         name => "pdom",
165                         init => $NONE,        # TODO: This is uninitialized!!
166                         comment => "Datastructure that holds information about post-dominators."
167                 },
168                 {
169                         type => "ir_node **",
170                         name => "in_cg",
171                         init => "NULL",
172                         comment => "array with predecessors in
173                                      * interprocedural_view, if they differ
174                                      * from intraprocedural predecessors"
175                 },
176                 {
177                         type => "unsigned *",
178                         name => "backedge",
179                         init => "new_backedge_arr(irg->obst, arity)",
180                         comment => "Raw Bitfield n set to true if pred n is backedge."
181                 },
182                 {
183                         type => "unsigned *",
184                         name => "cg_backedge",
185                         init => "NULL",
186                         comment => "Raw Bitfield n set to true if pred n is interprocedural backedge."
187                 },
188                 {
189                         type => "ir_extblk *",
190                         name => "extblk",
191                         init => "NULL",
192                         comment => "The extended basic block this block belongs to."
193                 },
194                 {
195                         type => "ir_region *",
196                         name => "region",
197                         init => $NONE,        # TODO: This is uninitialized!!
198                         comment => "The immediate structural region this block belongs to."
199                 },
200                 {
201                         type => "unsigned",
202                         name => "mb_depth",
203                         init => "0",
204                         comment => "The macroblock depth: A distance from the macroblock header."
205                 },
206                 {
207                         type => "ir_label_t",
208                         name => "label",
209                         init => "0",
210                         comment => "The block label if assigned."
211                 },
212                 {
213                         type => "ir_node *",
214                         name => "phis",
215                         init => $NONE,        # TODO: This is uninitialized!!
216                         comment => "The list of Phi nodes in this block."
217                 },
218                 {
219                         type => "struct list_head",
220                         name => "succ_head",
221                         init => $NONE,        # TODO: This is uninitialized!!
222                         comment => "A list head for all successor edges of a block."
223                 },
224         ],
225         init        => "\t/* macroblock header */\n".
226                                    "\tres->in[0] = res;\n\n".
227                                    "\tset_Block_matured(res, 1);\n".
228                                    "\tset_Block_block_visited(res, 0);\n",
229         optimize    => 0,
230         d_pre       => "\tint i;\n\tint has_unknown = 0;\n",
231         d_post      => "\t/* Create and initialize array for Phi-node construction. */\n".
232                        "\tif (get_irg_phase_state(current_ir_graph) == phase_building) {\n".
233                            "\t\tres->attr.block.graph_arr = NEW_ARR_D(ir_node *, current_ir_graph->obst,\n".
234                            "\t\t                                      current_ir_graph->n_loc);\n".
235                            "\t\tmemset(res->attr.block.graph_arr, 0, sizeof(ir_node *) * current_ir_graph->n_loc);\n".
236                            "\t}\n\n".
237                            "\tfor (i = arity-1; i >= 0; i--)\n".
238                            "\t\tif (is_Unknown(in[i])) {\n".
239                            "\t\thas_unknown = 1;\n".
240                            "\t\tbreak;\n".
241                            "\t}\n".
242                            "\tif (!has_unknown) res = optimize_node(res);\n".
243                            "\tcurrent_ir_graph->current_block = res;\n".
244                            "\tIRN_VRFY_IRG(res, current_ir_graph);\n"
245 },
246
247 Const_type => {
248         op          => "Const",
249         op_flags    => "c|S",
250         mode        => "get_tarval_mode(tv)",
251         block       => "get_irg_start_block(irg)",
252         attrs_name  => "con",
253         attrs       => [
254                 {
255                         type => "tarval *",
256                         name => "tv"
257                 },
258                 {
259                         type => "ir_type *",
260                         name => "tp",
261                         init => $MANUALFROMPARAM
262                 }
263         ],
264         init        => "set_Const_type(res, tp);\n"
265 },
266
267 Id => {
268         ins         => [ "val" ]
269 },
270
271 Proj => {
272         ins         => [ "arg" ],
273         attrs_type  => "long",
274         attrs       => [
275                 {
276                         type => "long",
277                         name => "proj",
278                         initname => "",
279                 }
280         ],
281         init        => "assert(get_Proj_pred(res));\n".
282                        "\tassert(get_nodes_block(get_Proj_pred(res)));\n"
283 },
284
285 # Conv => {
286 #       ins        => [ "op" ],
287 #       attrs      => [
288 #               {
289 #                       type => "char",
290 #                       name => "strict",
291 #                       #init => "0",
292 #                       comment => "If set, this is a strict Conv that cannot be removed."
293 #               }
294 #       ]
295 # },
296
297 Cast => {
298         op_flags   => "H",
299         mode       => "get_irn_mode(op)",
300         ins        => [ "op" ],
301         attrs      => [
302                 {
303                         type => "ir_type *",
304                         name => "totype",
305                         comment => "Type of the casted node."
306                 }
307         ],
308         init       => "assert(is_atomic_type(totype));\n"
309 },
310
311 Jmp => {
312         op_flags    => "X",
313         state       => "pinned",
314         mode        => "mode_X"
315 },
316
317 IJmp => {
318         op_flags    => "X",
319         state       => "pinned",
320         mode        => "mode_X",
321         ins         => [ "target" ]
322 },
323
324 Cond => {
325         op_flags    => "X|Y",
326         state       => "pinned",
327         mode        => "mode_T",
328         ins         => [ "selector" ],
329         attrs       => [
330                 {
331                         type => "cond_kind",
332                         name => "kind",
333                         init => "dense",
334                         comment => "Flavor of Cond."
335                 },
336                 {
337                         type => "long",
338                         name => "default_proj",
339                         init => "0",
340                         comment => "Only for non-binary Conds: biggest Proj number, i.e. the one used for default."
341                 },
342                 {
343                         type => "cond_jmp_predicate",
344                         name => "pred",
345                         init => "COND_JMP_PRED_NONE",
346                         comment => "Only for binary Conds: The jump predication."
347                 },
348
349         ]
350 },
351
352 Tuple => {
353         op_flags    => "L",
354         mode        => "mode_T",
355         arity       => "variable"
356 },
357
358 BinOp => {
359         op          => 0,
360         ins         => [ "left", "right" ]
361 },
362
363 Cmp => {
364         is_a        => "BinOp",
365         mode        => "mode_T"
366 },
367
368 Add => {
369         is_a        => "BinOp",
370         op_flags    => "C",
371 },
372
373 Div => {
374         mode        => "mode_T",
375         op_flags    => "F|M",
376         state       => "exc_pinned",
377         ins         => [ "mem", "left", "right" ],
378         attrs_name  => "divmod",
379         attrs       => [
380                 {
381                         type => "except_attr",
382                         name => "exc",
383                         init => $NONE
384                 },
385                 {
386                         type => "ir_mode *",
387                         name => "res_mode"
388                 },
389                 {
390                         type => "op_pin_state",
391                         name => "state",
392                         initname => ".exc.pin_state"
393                 },
394                 {
395                         type => "char",
396                         name => "no_remainder",
397                         init => "0"
398                 }
399         ],
400         d_post      => "\t#if PRECISE_EXC_CONTEXT\n".
401                        "\tfirm_alloc_frag_arr(res, op_Div, &res->attr.except.frag_arr);\n".
402                        "\t#endif\n"
403 }
404
405 );