ircons.h 29 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
2
/*
 * This file is part of libFirm.
3
 * Copyright (C) 2012 University of Karlsruhe.
Christian Würdig's avatar
Christian Würdig committed
4
5
 */

Matthias Braun's avatar
Matthias Braun committed
6
7
8
9
10
11
/**
 * @file
 * @brief   Various irnode constructors. Automatic construction of SSA
 *          representation.
 * @author  Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Boris Boesler,
 *          Michael Beck
Götz Lindenmaier's avatar
Götz Lindenmaier committed
12
 */
Christian Schäfer's avatar
Christian Schäfer committed
13

Sebastian Felis's avatar
Sebastian Felis committed
14
/**
Matthias Braun's avatar
Matthias Braun committed
15
 *  @file
Michael Beck's avatar
Michael Beck committed
16
 *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
17
18
 *  documentation no more supported since 2001
 *
19
 *  IR node construction.
Boris Boesler's avatar
Boris Boesler committed
20
 *
Boris Boesler's avatar
Boris Boesler committed
21
 *    This file documents all datatypes and constructors needed to
Götz Lindenmaier's avatar
Götz Lindenmaier committed
22
 *    build a FIRM representation of a procedure.  The constructors are
Boris Boesler's avatar
Boris Boesler committed
23
24
25
26
27
28
29
30
31
32
 *    also implemented in this file.
 *
 *    The documentation also gives a short manual how to use the library.
 *
 *    For extensive documentation of FIRM see UKA Techreport 1999-14.
 *
 *
 *    Three kinds of nodes
 *    --------------------
 *
33
 *      There are three kinds of nodes known to the IR:  entities,
Boris Boesler's avatar
Boris Boesler committed
34
35
36
37
38
39
40
41
42
43
44
45
46
 *      types, and ir_nodes
 *
 *      + ir_nodes are the actual nodes of the FIRM intermediate representation.
 *        They represent operations on the data of the program and control flow
 *        operations.
 *
 *      + entity ==> implemented in entity.h
 *        Refers to a single entity of the compiled program, e.g. a field of a
 *        class or a method.  If a method or variable can not be assigned to
 *        a method or class or the like, it is a global object.
 *
 *      + types ==> implemented in type.h
 *        With types type information is represented.  There are several type
Götz Lindenmaier's avatar
Götz Lindenmaier committed
47
 *       nodes.
Boris Boesler's avatar
Boris Boesler committed
48
49
50
51
 *
 *    Implementation of the FIRM operations: ir_node
 *    ----------------------------------------------
 *
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
 *      Ir_nodes represent operations on the data of the program and control
 *      flow operations.  Examples of ir_nodes:  Add, Jmp, Cmp
 *
 *      FIRM is a dataflow graph.  A dataflow graph is a directed graph, so that
 *      every node has incoming and outgoing edges.  A node is executable if
 *      every input at its incoming edges is available.  Execution of the
 *      dataflow graph is started at the Start node which has no incoming edges
 *      and ends when the End node executes, even if there are still executable
 *      or not executed nodes.  (Is this true, or must all executable nodes be
 *      executed?)  (There are exceptions to the dataflow paradigma that all
 *      inputs have to be available before a node can execute: Phi, Block.  See
 *      UKA Techreport 1999-14.)
 *
 *      The implementation of FIRM differs from the view as a dataflow graph.
 *      To allow fast traversion of the graph edges are implemented as
 *      C-pointers.  Inputs to nodes are not ambiguous, the results can be used
 *      by several other nodes.  Each input can be implemented as a single
 *      pointer to a predecessor node, outputs need to be lists of pointers to
 *      successors.  Therefore a node contains pointers to its predecessors so
 *      that the implementation is a dataflow graph with reversed edges.  It has
 *      to be traversed bottom up.
Boris Boesler's avatar
Boris Boesler committed
73
 *
74
 *      All nodes of the IR have the same basic structure.  They are
Boris Boesler's avatar
Boris Boesler committed
75
76
77
78
79
80
81
82
83
84
85
86
 *      distinguished by a field containing the opcode.
 *
 *      The fields of an ir_node:
 *
 *      kind             A firm_kind tag containing k_ir_node.  This is useful for
 *                       dynamically checking the type of a node.
 *
 *      *op              This ir_op gives the opcode as a tag and a string
 *                       and the number of attributes of an ir_node.  There is
 *                       one statically allocated struct ir_op for each opcode.
 *
 *      *mode            The ir_mode of the operation represented by this firm
87
88
89
 *                       node.  The mode of the operation is the mode of its
 *                       result.  A Firm mode is a datatype as known to the
 *                       target, not a type of the source language.
Boris Boesler's avatar
Boris Boesler committed
90
 *
91
 *      visit            A flag for traversing the IR.
Boris Boesler's avatar
Boris Boesler committed
92
93
94
95
 *
 *      **in             An array with pointers to the node's predecessors.
 *
 *      *link            A pointer to an ir_node.  With this pointer all Phi nodes
96
 *                       are attached to a Block, i.e. a Block points to its
Boris Boesler's avatar
Boris Boesler committed
97
 *                       first Phi node, this node points to the second Phi node
98
 *                       in the Block and so forth.  Used in mature_immBlock
Boris Boesler's avatar
Boris Boesler committed
99
 *                       to find all Phi nodes to be matured.  It's also used to
100
 *                       annotate a node with a better, optimized version of it.
Boris Boesler's avatar
Boris Boesler committed
101
102
103
 *
 *      attr             An attr struct containing the attributes of the nodes. The
 *                       attributes depend on the opcode of the node.  The number
104
 *                       of these attributes is given in op.
Boris Boesler's avatar
Boris Boesler committed
105
106
107
108
109
110
111
112
113
 *
 *    The struct ir_op
 *    ----------------
 *                       Not yet documented. See irop.h.
 *
 *    The struct ir_mode
 *    ------------------
 *                       Not yet documented. See irmode.h.
 *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
114
 *    GLOBAL VARIABLES -- now also fields of ir_graph.
Boris Boesler's avatar
Boris Boesler committed
115
116
117
 *    ================
 *
 *    current_ir_graph   Points to the current ir_graph.  All constructors for
118
 *                       nodes add nodes to this graph.
Boris Boesler's avatar
Boris Boesler committed
119
120
121
122
123
124
125
126
127
128
 *
 *    ir_visited         An int used as flag to traverse the ir_graph.
 *
 *    block_visited      An int used as a flag to traverse block nodes in the
 *                       graph.
 *
 *                       Others not yet documented.
 *
 *
 *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
129
 *    CONSTRUCTOR FOR IR_GRAPH --> see irgraph.h
Boris Boesler's avatar
Boris Boesler committed
130
131
132
 *    ========================
 *
 *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
133
 *    PROCEDURE TO CONSTRUCT AN IR GRAPH --> see also Firm tutorial
Boris Boesler's avatar
Boris Boesler committed
134
135
136
137
 *    ==================================
 *
 *    This library supplies several interfaces to construct a FIRM graph for
 *    a program:
Michael Beck's avatar
Michael Beck committed
138
 *    - A "comfortable" interface generating SSA automatically.  Automatically
Boris Boesler's avatar
Boris Boesler committed
139
140
 *      computed predecessors of nodes need not be specified in the constructors.
 *      (new_<Node> constructurs and a set of additional routines.)
Michael Beck's avatar
Michael Beck committed
141
 *    - A less comfortable interface where all predecessors except the block
Boris Boesler's avatar
Boris Boesler committed
142
 *      an operation belongs to need to be specified.  SSA must be constructed
143
 *      by hand.  (new_<Node> constructors and set_cur_block()).  This interface
Boris Boesler's avatar
Boris Boesler committed
144
145
 *      is called "block oriented".  It automatically calles the local optimizations
 *      for each new node.
Michael Beck's avatar
Michael Beck committed
146
 *    - An even less comfortable interface where the block needs to be specified
Boris Boesler's avatar
Boris Boesler committed
147
 *      explicitly.  This is called the "raw" interface. (new_r_<Node>
148
 *      constructors).
Boris Boesler's avatar
Boris Boesler committed
149
 *
150
151
152
153
154
 *    To use the functionality of the comfortable interface correctly the front
 *    end needs to follow certain protocols.  This is explained in the
 *    following.  To build a correct IR with the other interfaces study the
 *    semantics of the firm node (See tech-reprot UKA 1999-14).  For the
 *    construction of types and entities see the documentation in these modules.
Boris Boesler's avatar
Boris Boesler committed
155
 *
156
157
158
159
160
161
 *    First the front end needs to decide which variables and values used in a
 *    procedure can be represented by dataflow edges.  These are variables that
 *    need not be saved to memory as they cause no side effects visible out of
 *    the procedure.  Often these are all compiler generated variables and
 *    simple local variables of the procedure as integers, reals and pointers.
 *    The front end has to count and number these variables.
Boris Boesler's avatar
Boris Boesler committed
162
163
 *
 *    First an ir_graph needs to be constructed with new_ir_graph.  The
164
 *    constructor gets the number of local variables.  The graph is held in the
Boris Boesler's avatar
Boris Boesler committed
165
166
167
 *    global variable irg.
 *
 *    Now the construction of the procedure can start.  Several basic blocks can
168
169
 *    be constructed in parallel, but the code within each block needs to be
 *    constructed (almost) in program order.
Boris Boesler's avatar
Boris Boesler committed
170
171
172
 *
 *    A global variable holds the current basic block.  All (non block) nodes
 *    generated are added to this block.  The current block can be set with
173
 *    set_cur_block(block).  If several blocks are constructed in parallel block
Boris Boesler's avatar
Boris Boesler committed
174
175
 *    switches need to be performed constantly.
 *
Christoph Mallon's avatar
Christoph Mallon committed
176
 *    To generate a Block node (with the comfortable interface), its predecessor
177
178
179
180
181
182
183
184
185
186
187
188
189
 *    control flow nodes need not be known.  In case of cyclic control flow
 *    these can not be known when the block is constructed.  With
 *    add_immBlock_pred(block, cfnode) predecessors can be added to the block.
 *    If all predecessors are added to the block mature_immBlock(b) needs to be
 *    called.  Calling mature_immBlock early improves the efficiency of the Phi
 *    node construction algorithm.  But if several  blocks are constructed at
 *    once, mature_immBlock must only be called after performing all set_values
 *    and set_stores in the block!  (See documentation of new_immBlock
 *    constructor.)
 *
 *    The constructors of arithmetic nodes require that their predecessors are
 *    mentioned.  Sometimes these are available in the Frontend as the
 *    predecessors have just been generated by the front end.  If they are local
190
 *    values, the predecessors can be obtained from the library with a call to
191
192
193
 *    get_value(local_val_nr).  (local_val_nr needs to be administered by the
 *    Frontend.)  A call to get_value triggers the generation of Phi nodes.  If
 *    an arithmetic operation produces a local value, this value needs to be
Boris Boesler's avatar
Boris Boesler committed
194
195
 *    passed to the library by set_value(node, local_val_nr).
 *    In straight line code these two operations just remember and return the
196
197
 *    pointer to nodes producing the value.  If the value passes block
 *    boundaries Phi nodes can be inserted.
Boris Boesler's avatar
Boris Boesler committed
198
199
200
201
202
203
204
205
 *    Similar routines exist to manage the Memory operands: set_store and
 *    get_store.
 *
 *    Several nodes produce more than one result.  An example is the Div node.
 *    Such nodes return tuples of values.  From these individual values can be
 *    extracted by proj nodes.
 *
 *    The following example illustrates the construction of a simple basic block
206
207
 *    with two predecessors stored in variables cf_pred1 and cf_pred2,
 *    containing the code
Boris Boesler's avatar
Boris Boesler committed
208
209
 *      a = a div a;
 *    and finally jumping to an other block.  The variable a got the local_val_nr
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
 *    42 by the front end.
 *
 *    ir_node *example(ir_node *cf_pred1, ir_node *cf_pred2)
 *    {
 *      ir_node *this_block = new_immBlock();
 *      add_immBlock_pred(this_block, cf_pred1);
 *      add_immBlock_pred(this_block, cf_pred2);
 *      mature_immBlock(this_block);
 *      set_cur_block(this_block);
 *      ir_node *a_val = get_value(42, mode_Iu);
 *      ir_node *div   = new_Div(get_store(), a_val, a_val, mode_Iu);
 *      ir_node *mem   = new_Proj(div, mode_M, pn_Div_M);
 *      ir_node *res   = new_Proj(div, mode_Iu, pn_Div_res);
 *      set_store(mem);
 *      set_value(res, 42);
 *      ir_node *cf_op = new_Jmp();
 *      return cf_op;
 *    }
Boris Boesler's avatar
Boris Boesler committed
228
229
 *
 *    For further information look at the documentation of the nodes and
230
231
 *    constructors and at the paragraph COPING WITH DATA OBJECTS at the end of
 *    this documentation.
Boris Boesler's avatar
Boris Boesler committed
232
233
234
235
 *
 *    IR_NODES AND CONSTRUCTORS FOR IR_NODES
 *    =======================================
 *
236
237
238
 *    All ir_nodes are defined by a common data structure.  They are
 *    distinguished by their opcode and differ in the number of their
 *    attributes.
Boris Boesler's avatar
Boris Boesler committed
239
 *
240
241
242
 *    Const nodes are always added to the start block.  All other constructors
 *    add the created node to the current_block.  set_cur_block(block) allows to
 *    set the current block to block.
Boris Boesler's avatar
Boris Boesler committed
243
 *
244
245
 *    Watch for my inconsistent use of input and predecessor (dataflow view) and
 *    `the node points to' (implementation view).
Boris Boesler's avatar
Boris Boesler committed
246
247
248
249
250
251
252
253
254
255
256
257
258
 *
 *    The following description of the nodes lists four properties them if these
 *    are of interest:
 *     - the parameters to the constructor
 *     - the inputs of the Firm node
 *     - the outputs of the Firm node
 *     - attributes to the node
 *
 *    ------------
 *
 *    COPING WITH DATA OBJECTS
 *    ========================
 *
259
260
261
262
263
264
265
266
267
268
269
270
271
 *    Two kinds of data objects have to be distinguished for generating FIRM.
 *    First there are local variables other than arrays that are known to be
 *    alias free.  Second there are all other data objects.  For the first a
 *    common SSA representation is built, the second are modeled by saving them
 *    to memory.  The memory is treated as a single local variable, the alias
 *    problem is hidden in the content of this variable.
 *
 *    All values known in a Block are listed in the block's attribute
 *    block.graph_arr which is used to automatically insert Phi nodes.  The
 *    following two functions can be used to add a newly computed value to the
 *    array, or to get the producer of a value, i.e., the current live value.
 *
 *    void set_value(int pos, ir_node *value)
Boris Boesler's avatar
Boris Boesler committed
272
273
 *    -----------------------------------------------
 *
274
275
276
277
278
 *    Has to be called for every assignment to a local variable.  It adds the
 *    value to the array of used values at position pos.  Pos has to be a unique
 *    identifier for an entry in the procedure's definition table.  It can be
 *    used to access the value again.  Requires current_block to be set
 *    correctly.
Boris Boesler's avatar
Boris Boesler committed
279
 *
280
 *    ir_node *get_value(int pos, ir_mode *mode)
Boris Boesler's avatar
Boris Boesler committed
281
282
 *    -------------------------------------------
 *
283
284
285
286
287
288
289
290
 *    Returns the node defining the value referred to by pos. If the value is
 *    not defined in this block a Phi node is generated and all definitions
 *    reaching this Phi node are collected.  It can happen that the algorithm
 *    allocates an unnecessary Phi node, e.g. if there is only one definition of
 *    this value, but this definition reaches the currend block on several
 *    different paths.  This Phi node will be eliminated if optimizations are
 *    turned on right after its creation.  Requires current_block to be set
 *    correctly.
Boris Boesler's avatar
Boris Boesler committed
291
292
293
 *
 *    There are two special routines for the global store:
 */
Matthias Braun's avatar
Matthias Braun committed
294
295
#ifndef FIRM_IR_IRCONS_H
#define FIRM_IR_IRCONS_H
Christian Schäfer's avatar
Christian Schäfer committed
296

Matthias Braun's avatar
Matthias Braun committed
297
#include "firm_types.h"
298
#include "begin.h"
299
#include "irnode.h"
Christian Schäfer's avatar
Christian Schäfer committed
300

Matthias Braun's avatar
Matthias Braun committed
301
302
303
/** @addtogroup Const
 * @{
 */
Christian Schäfer's avatar
Christian Schäfer committed
304

305
306
/**
 * Constructor for a Const node.
yb9976's avatar
yb9976 committed
307
308
309
 *
 * Adds the node to the start block.
 *
310
 * The constant represents a target value.
yb9976's avatar
yb9976 committed
311
312
313
314
315
316
 *
 * @param *db    A pointer for debug information.
 * @param *irg   The IR graph the node  belongs to.
 * @param *mode  The mode of the operands and results.
 * @param value  A value from which the tarval is made.
 */
Michael Beck's avatar
Michael Beck committed
317
FIRM_API ir_node *new_rd_Const_long(dbg_info *db, ir_graph *irg,
318
                                    ir_mode *mode, long value);
yb9976's avatar
yb9976 committed
319

Matthias Braun's avatar
Matthias Braun committed
320
321
322
323
/** Constructor for a Const node.
 *
 * Adds the node to the start block.
 *
324
 * The constant represents a target value.
Matthias Braun's avatar
Matthias Braun committed
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
 *
 * @param *irg   The IR graph the node  belongs to.
 * @param *mode  The mode of the operands and the results.
 * @param value  A value from which the tarval is made.
 */
FIRM_API ir_node *new_r_Const_long(ir_graph *irg, ir_mode *mode, long value);

/**
 * @see new_rd_Const_long()
 *
 * @param *db    A pointer for debug information.
 * @param *mode  The mode of the operands and results.
 * @param value  A value from which the tarval is made.
 */
FIRM_API ir_node *new_d_Const_long(dbg_info *db, ir_mode *mode, long value);

/**
 * Make a const from a long.
 * This is just convenience for the usual
 * <code>
 * new_Const(mode, tarval_from_long(mode, ...))
 * </code>
 * pain.
 * @param mode The mode for the const.
 * @param value The value of the constant.
 * @return A new const node.
 */
FIRM_API ir_node *new_Const_long(ir_mode *mode, long value);

/** @} */

/** @addtogroup Sel
 * @{
 */

/** Constructor for a simpleSel node.
 *
 *  This is a shortcut for the new_rd_Sel() constructor.  To be used for
 *  Sel nodes that do not select from an array, i.e., have no index
 *  inputs.  It adds the two parameters 0, NULL.
 *
 * @param   *db        A pointer for debug information.
 * @param   *block     The IR block the node belongs to.
 * @param   *objptr    The object from that the Sel operation selects a
 *                     single attribute out.
 * @param   *ent       The entity to select.
 */
372
FIRM_API ir_node *new_rd_simpleSel(dbg_info *db, ir_node *block,
Matthias Braun's avatar
Matthias Braun committed
373
374
375
376
377
378
379
380
381
382
383
384
385
386
                                   ir_node *objptr, ir_entity *ent);

/** Constructor for a simpleSel node.
 *
 *  This is a shortcut for the new_d_Sel() constructor.  To be used for
 *  Sel nodes that do not select from an array, i.e., have no index
 *  inputs.  It adds the two parameters 0, NULL.
 *
 * @param *block     The IR block the node belongs to.
 * @param *objptr    The object from that the Sel operation selects a
 *                   single attribute out.
 * @param *ent       The entity to select.
 * @ingroup Sel
 */
387
388
FIRM_API ir_node *new_r_simpleSel(ir_node *block, ir_node *objptr,
                                  ir_entity *ent);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
389

390
/** Constructor for a simpleSel node.
391
 *
392
393
394
 *  This is a shortcut for the new_d_Sel() constructor.  To be used for
 *  Sel nodes that do not select from an array, i.e., have no index
 *  inputs.  It adds the two parameters 0, NULL.
395
 *
396
397
398
399
 * @param   *db        A pointer for debug information.
 * @param   *objptr    The object from that the Sel operation selects a
 *                     single attribute out.
 * @param   *ent       The entity to select.
400
 */
401
FIRM_API ir_node *new_d_simpleSel(dbg_info *db, ir_node *objptr,
402
                                  ir_entity *ent);
Matthias Braun's avatar
Matthias Braun committed
403
404
405
406
407
408
409
410
411
412

/** Constructor for a simpelSel node.
 *
 *  This is a shortcut for the new_Sel() constructor.  To be used for
 *  Sel nodes that do not select from an array, i.e., have no index
 *  inputs.  It adds the two parameters 0, NULL.
 *
 * @param   *objptr    The object from that the Sel operation selects a single attribute out.
 * @param   *ent       The entity to select.
 */
413
FIRM_API ir_node *new_simpleSel(ir_node *objptr, ir_entity *ent);
Matthias Braun's avatar
Matthias Braun committed
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447

/** @} */

/** @addtogroup Div
 * @{
 */

/** Constructor for a remainderless Div node.
 *
 * @param   *db    A pointer for debug information.
 * @param   *block The IR block the node belongs to.
 * @param   *memop The store needed to model exceptions
 * @param   *op1   The first operand.
 * @param   *op2   The second operand.
 * @param   *mode  The mode of the result.
 * @param   state  The pinned state.
 */
FIRM_API ir_node *new_rd_DivRL(dbg_info *db, ir_node *block, ir_node *memop,
                               ir_node *op1, ir_node *op2, ir_mode *mode,
                               op_pin_state state);

/** Constructor for a remainderless Div node.
 *
 * @param *block The IR block the node belongs to.
 * @param *memop The store needed to model exceptions
 * @param *op1   The first operand.
 * @param *op2   The second operand.
 * @param *mode  The mode of the result.
 * @param state  The pinned state.
 */
FIRM_API ir_node *new_r_DivRL(ir_node *block, ir_node *memop,
                              ir_node *op1, ir_node *op2, ir_mode *mode,
                              op_pin_state state);

448
/** Constructor for a remainderless Div node.
449
450
451
 *
 * Adds the node to the block in current_ir_block.
 *
452
453
 * @param   *db    A pointer for debug information.
 * @param   *memop The store needed to model exceptions
454
455
 * @param   *op1   The first operand.
 * @param   *op2   The second operand.
456
457
 * @param   *mode  The mode of the result.
 * @param   state  The pinned state.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
458
 */
459
460
461
FIRM_API ir_node *new_d_DivRL(dbg_info *db, ir_node *memop,
                              ir_node *op1, ir_node *op2, ir_mode *mode,
                              op_pin_state state);
Matthias Braun's avatar
Matthias Braun committed
462
463

/** Constructor for a remainderless Div node.
Beyhan's avatar
Beyhan committed
464
465
 *
 * Adds the node to the block in current_ir_block.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
466
 *
Matthias Braun's avatar
Matthias Braun committed
467
468
469
470
471
472
473
474
475
476
477
478
479
 * @param   *memop The store needed to model exceptions
 * @param   *op1   The first operand.
 * @param   *op2   The second operand.
 * @param   *mode  The mode of the result.
 * @param   state  The pinned state.
 */
FIRM_API ir_node *new_DivRL(ir_node *memop, ir_node *op1, ir_node *op2,
                            ir_mode *mode, op_pin_state state);

/** @} */

/** @addtogroup ASM
 * @{
Götz Lindenmaier's avatar
Götz Lindenmaier committed
480
481
 */

482
/** Constructor for an ASM pseudo node.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
483
 *
484
 * @param *db         A pointer for debug information.
Matthias Braun's avatar
Matthias Braun committed
485
 * @param *block      The block the node belong to.
486
 * @param *mem        memory dependency
487
488
489
490
491
492
493
494
 * @param arity       The number of data inputs to the node.
 * @param *in         The array of length arity of data inputs.
 * @param *inputs     The array of length arity of input constraints.
 * @param n_outs      The number of data outputs to the node.
 * @param *outputs    The array of length n_outs of output constraints.
 * @param n_clobber   The number of clobbered registers.
 * @param *clobber    The array of length n_clobber of clobbered registers.
 * @param *asm_text   The assembler text.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
495
 */
496
FIRM_API ir_node *new_rd_ASM(dbg_info *db, ir_node *block, ir_node *mem,
Matthias Braun's avatar
Matthias Braun committed
497
                            int arity, ir_node *in[], ir_asm_constraint *inputs,
498
499
500
                            size_t n_outs, ir_asm_constraint *outputs,
                            size_t n_clobber, ident *clobber[],
                            ident *asm_text);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
501

Matthias Braun's avatar
Matthias Braun committed
502
/** Constructor for an ASM pseudo node.
Michael Beck's avatar
Michael Beck committed
503
 *
Matthias Braun's avatar
Matthias Braun committed
504
 * @param *block      The block the node belong to.
505
 * @param *mem        memory dependency
Matthias Braun's avatar
Matthias Braun committed
506
507
508
509
510
511
512
513
 * @param arity       The number of data inputs to the node.
 * @param *in         The array of length arity of data inputs.
 * @param *inputs     The array of length arity of input constraints.
 * @param n_outs      The number of data outputs to the node.
 * @param *outputs    The array of length n_outs of output constraints.
 * @param n_clobber   The number of clobbered registers.
 * @param *clobber    The array of length n_clobber of clobbered registers.
 * @param *asm_text   The assembler text.
514
 */
515
FIRM_API ir_node *new_r_ASM(ir_node *block, ir_node *mem,
Matthias Braun's avatar
Matthias Braun committed
516
517
518
519
                            int arity, ir_node *in[], ir_asm_constraint *inputs,
                            size_t n_outs, ir_asm_constraint *outputs,
                            size_t n_clobber, ident *clobber[],
                            ident *asm_text);
520

Matthias Braun's avatar
Matthias Braun committed
521
/** Constructor for an ASM pseudo node.
522
 *
Matthias Braun's avatar
Matthias Braun committed
523
 * @param *db         A pointer for debug information.
524
 * @param *mem        memory dependency
Matthias Braun's avatar
Matthias Braun committed
525
526
527
528
529
530
531
532
533
 * @param arity       The number of data inputs to the node.
 * @param *in         The array of length arity of data inputs.
 * @param *inputs     The array of length arity of input constraints.
 * @param n_outs      The number of data outputs to the node.
 * @param *outputs    The array of length n_outs of output constraints.
 * @param n_clobber   The number of clobbered registers.
 * @param *clobber    The array of length n_clobber of clobbered registers.
 * @param *asm_text   The assembler text.
 * @ingroup ASM
534
 */
535
536
FIRM_API ir_node *new_d_ASM(dbg_info *db, ir_node *mem, int arity,
                            ir_node *in[], ir_asm_constraint *inputs,
Matthias Braun's avatar
Matthias Braun committed
537
538
539
                            size_t n_outs, ir_asm_constraint *outputs,
                            size_t n_clobber, ident *clobber[],
                            ident *asm_text);
540

Michael Beck's avatar
Michael Beck committed
541
542
/** Constructor for an ASM pseudo node.
 *
543
 * @param *mem        memory dependency
Michael Beck's avatar
Michael Beck committed
544
 * @param arity       The number of data inputs to the node.
Michael Beck's avatar
Michael Beck committed
545
546
547
548
 * @param *in         The array of length arity of data inputs.
 * @param *inputs     The array of length arity of input constraints.
 * @param n_outs      The number of data outputs to the node.
 * @param *outputs    The array of length n_outs of output constraints.
Michael Beck's avatar
Michael Beck committed
549
550
 * @param n_clobber   The number of clobbered registers.
 * @param *clobber    The array of length n_clobber of clobbered registers.
Michael Beck's avatar
Michael Beck committed
551
 * @param *asm_text   The assembler text.
Matthias Braun's avatar
Matthias Braun committed
552
 * @ingroup ASM
Michael Beck's avatar
Michael Beck committed
553
 */
554
555
556
FIRM_API ir_node *new_ASM(ir_node *mem, int arity, ir_node *in[],
                          ir_asm_constraint *inputs, size_t n_outs,
                          ir_asm_constraint *outputs,
557
                          size_t n_clobber, ident *clobber[], ident *asm_text);
Michael Beck's avatar
Michael Beck committed
558

Matthias Braun's avatar
Matthias Braun committed
559
560
/** @} */

Matthias Braun's avatar
Matthias Braun committed
561
562
563
/**
 * @ingroup ir_graph
 * @defgroup ir_cons Construction Support
Matthias Braun's avatar
Matthias Braun committed
564
565
 * @{
 */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
566

567
568
/**
 * Global variable holding the graph which is currently constructed.
569
570
571
 */
FIRM_API ir_graph *current_ir_graph;

572
573
574
/**
 * Returns graph which is currently constructed
 */
575
FIRM_API ir_graph *get_current_ir_graph(void);
576
577
578
579

/**
 * Sets graph which is currently constructed
 */
580
581
FIRM_API void set_current_ir_graph(ir_graph *graph);

Michael Beck's avatar
Michael Beck committed
582
/** Create an immature Block.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
583
 *
Michael Beck's avatar
Michael Beck committed
584
 * An immature Block has an unknown number of predecessors.  Predecessors
Götz Lindenmaier's avatar
Götz Lindenmaier committed
585
586
587
 * can be added with add_immBlock_pred().  Once all predecessors are
 * added the block must be matured.
 *
588
 * Adds the block to the graph in current_ir_graph.
589
 * This constructor can only be used if the graph is in state_building.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
590
 */
Michael Beck's avatar
Michael Beck committed
591
FIRM_API ir_node *new_d_immBlock(dbg_info *db);
592
593
594
595
596
597
598
599
600
/** Create an immature Block.
 *
 * An immature Block has an unknown number of predecessors.  Predecessors
 * can be added with add_immBlock_pred().  Once all predecessors are
 * added the block must be matured.
 *
 * Adds the block to the graph in current_ir_graph.
 * This constructor can only be used if the graph is in state_building.
 */
Michael Beck's avatar
Michael Beck committed
601
FIRM_API ir_node *new_immBlock(void);
602
603
604
605
606
607
608
609
/** Create an immature Block.
 *
 * An immature Block has an unknown number of predecessors.  Predecessors
 * can be added with add_immBlock_pred().  Once all predecessors are
 * added the block must be matured.
 *
 * This constructor can only be used if the graph is in state_building.
 */
610
FIRM_API ir_node *new_r_immBlock(ir_graph *irg);
611
612
613
614
615
616
617
618
/** Create an immature Block.
 *
 * An immature Block has an unknown number of predecessors.  Predecessors
 * can be added with add_immBlock_pred().  Once all predecessors are
 * added the block must be matured.
 *
 * This constructor can only be used if the graph is in state_building.
 */
619
FIRM_API ir_node *new_rd_immBlock(dbg_info *db, ir_graph *irg);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
620

Michael Beck's avatar
Michael Beck committed
621
/** Add a control flow edge to an immature block. */
Michael Beck's avatar
Michael Beck committed
622
FIRM_API void add_immBlock_pred(ir_node *immblock, ir_node *jmp);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
623

Michael Beck's avatar
Michael Beck committed
624
/** Finalize a Block node, when all control flows are known. */
Michael Beck's avatar
Michael Beck committed
625
FIRM_API void mature_immBlock(ir_node *block);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
626

627
628
629
/**
 * Sets the current block in which the following constructors place the
 * nodes they construct.
Matthias Braun's avatar
Matthias Braun committed
630
 *
631
 * @param target  The new current block.
Matthias Braun's avatar
Matthias Braun committed
632
633
 */
FIRM_API void set_cur_block(ir_node *target);
634
635
636
637
/**
 * Sets current block of a given graph.
 * @see set_cur_block()
 */
Matthias Braun's avatar
Matthias Braun committed
638
639
640
641
FIRM_API void set_r_cur_block(ir_graph *irg, ir_node *target);

/** Returns the current block of the current graph. */
FIRM_API ir_node *get_cur_block(void);
642
/** Returns current block of a given graph */
Matthias Braun's avatar
Matthias Braun committed
643
644
FIRM_API ir_node *get_r_cur_block(ir_graph *irg);

645
/** Returns the current value of a local variable.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
646
647
 *
 * Use this function to obtain the last definition of the local variable
648
 * associated with pos.  pos must be less than the value passed as n_loc
Götz Lindenmaier's avatar
Götz Lindenmaier committed
649
650
651
652
653
 * to new_ir_graph.  This call automatically inserts Phi nodes.
 *
 * @param  pos   The position/id of the local variable.
 * @param *mode  The mode of the value to get.
 */
Michael Beck's avatar
Michael Beck committed
654
FIRM_API ir_node *get_value(int pos, ir_mode *mode);
655
656
/** Returns the current value of a local variable in given graph
 * @see get_value() */
657
FIRM_API ir_node *get_r_value(ir_graph *irg, int pos, ir_mode *mode);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
658

659
660
661
662
663
664
665
666
667
/**
 * Try to guess the mode of a local variable.
 * This is done by recursively going up the control flow graph until
 * we find a definition for the variable. The mode of the first found
 * definition is returned. NULL in case no definition is found.
 *
 * @param  pos   The position/id of the local variable.
 */
FIRM_API ir_mode *ir_guess_mode(int pos);
668
669
670
/**
 * Try to guess the mode of a local variable in a given graph.
 */
671
FIRM_API ir_mode *ir_r_guess_mode(ir_graph *irg, int pos);
672

673
/** Memorize a new definition of a variable.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
674
675
 *
 * Use this function to remember a new definition of the value
676
 * associated with pos.  pos must be less than the value passed as n_loc
Götz Lindenmaier's avatar
Götz Lindenmaier committed
677
678
679
680
681
 * to new_ir_graph.  This call is needed to automatically inserts Phi
 * nodes.
 *
 * @param  pos   The position/id of the local variable.
 * @param *value The new value written to the local variable.
682
 */
Michael Beck's avatar
Michael Beck committed
683
FIRM_API void set_value(int pos, ir_node *value);
684
/** Sets current value of a variable in a given graph */
685
FIRM_API void set_r_value(ir_graph *irg, int pos, ir_node *value);
686

687
/** Returns the current memory state.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
688
689
690
691
692
 *
 * Use this function to obtain the last definition of the memory
 * state.  This call automatically inserts Phi nodes for the memory
 * state value.
 */
Michael Beck's avatar
Michael Beck committed
693
FIRM_API ir_node *get_store(void);
694
695
/** Returns current memory state for a given graph
 * @see get_store() */
696
FIRM_API ir_node *get_r_store(ir_graph *irg);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
697

698
/** Memorize a new definition of the memory state.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
699
700
701
702
703
 *
 * Use this function to remember a new definition of the memory state.
 * This call is needed to automatically inserts Phi nodes.
 *
 * @param *store The new memory state.
704
 */
Michael Beck's avatar
Michael Beck committed
705
FIRM_API void set_store(ir_node *store);
706
707
/** Sets current memory state for a given graph
 * @see set_store() */
708
FIRM_API void set_r_store(ir_graph *irg, ir_node *store);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
709

Götz Lindenmaier's avatar
Götz Lindenmaier committed
710
711
712
713
/** keep this node alive even if End is not control-reachable from it
 *
 * @param ka The node to keep alive.
 */
Michael Beck's avatar
Michael Beck committed
714
FIRM_API void keep_alive(ir_node *ka);
715

Michael Beck's avatar
Michael Beck committed
716
/** Puts the graph into state "phase_high" */
717
FIRM_API void irg_finalize_cons(ir_graph *irg);
718
719
720
721
722

/** Puts the program and all graphs into state phase_high.
 *
 * This also remarks, the construction of types is finished,
 * e.g., that no more subtypes will be added.  */
Michael Beck's avatar
Michael Beck committed
723
FIRM_API void irp_finalize_cons(void);
Christian Schäfer's avatar
Christian Schäfer committed
724

725
726
727
728
729
730
731
/**
 * If firm is built in debug mode, verify that a newly created node is fine.
 * The normal node constructors already call this function, you only need to
 * call this yourself if you create new node constructors on your own.
 */
FIRM_API void verify_new_node(ir_graph *irg, ir_node *node);

732
733
734
735
/**
 * Register a new callback for the case that the value of an uninitialized
 * variable is requested.
 */
736
737
738
FIRM_API void ir_set_uninitialized_local_variable_func(
		uninitialized_local_variable_func_t *func);

Matthias Braun's avatar
Matthias Braun committed
739
740
/** @} */

741
#include "end.h"
742

Matthias Braun's avatar
Matthias Braun committed
743
#endif