ircons.h 37.9 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
/*
Michael Beck's avatar
Michael Beck committed
2
 * Copyright (C) 1995-2010 University of Karlsruhe.  All right reserved.
Christian Würdig's avatar
Christian Würdig committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 *
 * This file is part of libFirm.
 *
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 *
 * Licensees holding valid libFirm Professional Edition licenses may use
 * this file in accordance with the libFirm Commercial License.
 * Agreement provided with the Software.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 */

Matthias Braun's avatar
Matthias Braun committed
20
21
22
23
24
25
/**
 * @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
26
 */
Christian Schäfer's avatar
Christian Schäfer committed
27

Sebastian Felis's avatar
Sebastian Felis committed
28
/**
Matthias Braun's avatar
Matthias Braun committed
29
 *  @file
Michael Beck's avatar
Michael Beck committed
30
 *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
31
32
 *  documentation no more supported since 2001
 *
33
 *  IR node construction.
Boris Boesler's avatar
Boris Boesler committed
34
 *
Boris Boesler's avatar
Boris Boesler committed
35
 *    This file documents all datatypes and constructors needed to
Götz Lindenmaier's avatar
Götz Lindenmaier committed
36
 *    build a FIRM representation of a procedure.  The constructors are
Boris Boesler's avatar
Boris Boesler committed
37
38
39
40
41
42
43
44
45
46
 *    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
 *    --------------------
 *
47
 *      There are three kinds of nodes known to the IR:  entities,
Boris Boesler's avatar
Boris Boesler committed
48
49
50
51
52
53
54
55
56
57
58
59
60
 *      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
61
 *       nodes.
Boris Boesler's avatar
Boris Boesler committed
62
63
64
65
66
67
68
69
70
 *
 *    Implementation of the FIRM operations: ir_node
 *    ----------------------------------------------
 *
 *      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
71
 *      executable if every input at its incoming edges is available.
Boris Boesler's avatar
Boris Boesler committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
 *      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
86
 *      contains pointers to its predecessors so that the implementation is a
Boris Boesler's avatar
Boris Boesler committed
87
88
89
 *      dataflow graph with reversed edges.  It has to be traversed bottom
 *      up.
 *
90
 *      All nodes of the IR have the same basic structure.  They are
Boris Boesler's avatar
Boris Boesler committed
91
92
93
94
95
96
97
98
99
100
101
102
 *      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
103
104
105
 *                       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
106
 *
107
 *      visit            A flag for traversing the IR.
Boris Boesler's avatar
Boris Boesler committed
108
109
110
111
 *
 *      **in             An array with pointers to the node's predecessors.
 *
 *      *link            A pointer to an ir_node.  With this pointer all Phi nodes
112
 *                       are attached to a Block, i.e. a Block points to its
Boris Boesler's avatar
Boris Boesler committed
113
 *                       first Phi node, this node points to the second Phi node
114
 *                       in the Block and so forth.  Used in mature_immBlock
Boris Boesler's avatar
Boris Boesler committed
115
 *                       to find all Phi nodes to be matured.  It's also used to
116
 *                       annotate a node with a better, optimized version of it.
Boris Boesler's avatar
Boris Boesler committed
117
118
119
 *
 *      attr             An attr struct containing the attributes of the nodes. The
 *                       attributes depend on the opcode of the node.  The number
120
 *                       of these attributes is given in op.
Boris Boesler's avatar
Boris Boesler committed
121
122
123
124
125
126
127
128
129
 *
 *    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
130
 *    GLOBAL VARIABLES -- now also fields of ir_graph.
Boris Boesler's avatar
Boris Boesler committed
131
132
133
 *    ================
 *
 *    current_ir_graph   Points to the current ir_graph.  All constructors for
134
 *                       nodes add nodes to this graph.
Boris Boesler's avatar
Boris Boesler committed
135
136
137
138
139
140
141
142
143
144
 *
 *    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
145
 *    CONSTRUCTOR FOR IR_GRAPH --> see irgraph.h
Boris Boesler's avatar
Boris Boesler committed
146
147
148
 *    ========================
 *
 *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
149
 *    PROCEDURE TO CONSTRUCT AN IR GRAPH --> see also Firm tutorial
Boris Boesler's avatar
Boris Boesler committed
150
151
152
153
 *    ==================================
 *
 *    This library supplies several interfaces to construct a FIRM graph for
 *    a program:
Michael Beck's avatar
Michael Beck committed
154
 *    - A "comfortable" interface generating SSA automatically.  Automatically
Boris Boesler's avatar
Boris Boesler committed
155
156
 *      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
157
 *    - A less comfortable interface where all predecessors except the block
Boris Boesler's avatar
Boris Boesler committed
158
 *      an operation belongs to need to be specified.  SSA must be constructed
159
 *      by hand.  (new_<Node> constructors and set_cur_block()).  This interface
Boris Boesler's avatar
Boris Boesler committed
160
161
 *      is called "block oriented".  It automatically calles the local optimizations
 *      for each new node.
Michael Beck's avatar
Michael Beck committed
162
 *    - An even less comfortable interface where the block needs to be specified
Boris Boesler's avatar
Boris Boesler committed
163
164
165
166
167
168
 *      explicitly.  This is called the "raw" interface. (new_r_<Node>
 *      constructors).  These nodes are not optimized.
 *
 *    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
Götz Lindenmaier's avatar
Götz Lindenmaier committed
169
 *    the firm node (See tech-reprot UKA 1999-14).  For the construction of
Boris Boesler's avatar
Boris Boesler committed
170
171
172
173
174
 *    types and entities see the documentation in those modules.
 *
 *    First the Frontend 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
Götz Lindenmaier's avatar
Götz Lindenmaier committed
175
 *    out of the procedure.  Often these are all compiler generated
Boris Boesler's avatar
Boris Boesler committed
176
177
178
179
 *    variables and simple local variables of the procedure as integers,
 *    reals and pointers.  The frontend has to count and number these variables.
 *
 *    First an ir_graph needs to be constructed with new_ir_graph.  The
180
 *    constructor gets the number of local variables.  The graph is held in the
Boris Boesler's avatar
Boris Boesler committed
181
182
183
184
185
186
187
188
 *    global variable irg.
 *
 *    Now the construction of the procedure can start.  Several basic blocks can
 *    be constructed in parallel, but the code within each block needs to
 *    be constructed (almost) in program order.
 *
 *    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
189
 *    set_cur_block(block).  If several blocks are constructed in parallel block
Boris Boesler's avatar
Boris Boesler committed
190
191
 *    switches need to be performed constantly.
 *
Christoph Mallon's avatar
Christoph Mallon committed
192
 *    To generate a Block node (with the comfortable interface), its predecessor
Boris Boesler's avatar
Boris Boesler committed
193
 *    control flow nodes need not be known.  In case of cyclic control flow these
194
 *    can not be known when the block is constructed.  With add_immBlock_pred(block,
Boris Boesler's avatar
Boris Boesler committed
195
 *    cfnode) predecessors can be added to the block.  If all predecessors are
196
 *    added to the block mature_immBlock(b) needs to be called.  Calling mature_immBlock
Boris Boesler's avatar
Boris Boesler committed
197
 *    early improves the efficiency of the Phi node construction algorithm.
198
 *    But if several  blocks are constructed at once, mature_immBlock must only
Boris Boesler's avatar
Boris Boesler committed
199
200
201
202
203
204
 *    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 frontend.  If they are local
205
 *    values, the predecessors can be obtained from the library with a call to
Boris Boesler's avatar
Boris Boesler committed
206
207
 *    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.
208
 *    If an arithmetic operation produces a local value, this value needs to be
Boris Boesler's avatar
Boris Boesler committed
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
 *    passed to the library by set_value(node, local_val_nr).
 *    In straight line code these two operations just remember and return the
 *    pointer to nodes producing the value.  If the value passes block boundaries
 *    Phi nodes can be inserted.
 *    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
 *    with two predecessors stored in variables cf_pred1 and cf_pred2, containing
 *    the code
 *      a = a div a;
 *    and finally jumping to an other block.  The variable a got the local_val_nr
 *    42 by the frontend.
 *
 *    ir_node *this_block, *cf_pred1, *cf_pred2, *a_val, *mem, *div, *res, *cf_op;
 *
 *    this_block = new_immBlock();
230
231
232
 *    add_immBlock_pred(this_block, cf_pred1);
 *    add_immBlock_pred(this_block, cf_pred2);
 *    mature_immBlock(this_block);
Matthias Heil's avatar
Matthias Heil committed
233
 *    a_val = get_value(42, mode_Iu);
Boris Boesler's avatar
Boris Boesler committed
234
 *    mem = get_store();
235
236
237
 *    div = new_Div(mem, a_val, a_val, mode_Iu);
 *    mem = new_Proj(div, mode_M, pn_Div_M);   * for the numbers for Proj see docu *
 *    res = new_Proj(div, mode_Iu, pn_Div_res);
Boris Boesler's avatar
Boris Boesler committed
238
 *    set_store(mem);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
239
 *    set_value(res, 42);
Boris Boesler's avatar
Boris Boesler committed
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
 *    cf_op = new_Jmp();
 *
 *    For further information look at the documentation of the nodes and
 *    constructors and at the paragraph COPING WITH DATA OBJECTS at the
 *    end of this documentation.
 *
 *    IR_NODES AND CONSTRUCTORS FOR IR_NODES
 *    =======================================
 *
 *    All ir_nodes are defined by a common data structure.  They are distinguished
 *    by their opcode and differ in the number of their attributes.
 *
 *    Const nodes are always added to the start block.
 *    All other constructors add the created node to the current_block.
 *    swich_block(block) allows to set the current block to block.
 *
 *    Watch for my inconsistent use of input and predecessor (dataflow view)
 *    and `the node points to' (implementation view).
 *
 *    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
 *    ========================
 *
 *    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.
Michael Beck's avatar
Michael Beck committed
281
 *    The following two functions can be used to add a newly computed value
Boris Boesler's avatar
Boris Boesler committed
282
283
284
285
286
287
288
289
290
291
 *    to the array, or to get the producer of a value, i.e., the current
 *    live value.
 *
 *    inline void set_value (int pos, ir_node *value)
 *    -----------------------------------------------
 *
 *    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.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
292
 *    Requires current_block to be set correctly.
Boris Boesler's avatar
Boris Boesler committed
293
294
295
296
297
298
299
300
301
302
303
 *
 *    ir_node *get_value (int pos, ir_mode *mode)
 *    -------------------------------------------
 *
 *    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
304
 *    turned on right after its creation.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
305
 *    Requires current_block to be set correctly.
Boris Boesler's avatar
Boris Boesler committed
306
307
308
 *
 *    There are two special routines for the global store:
 */
Matthias Braun's avatar
Matthias Braun committed
309
310
#ifndef FIRM_IR_IRCONS_H
#define FIRM_IR_IRCONS_H
Christian Schäfer's avatar
Christian Schäfer committed
311

Matthias Braun's avatar
Matthias Braun committed
312
#include "firm_types.h"
313
#include "begin.h"
314
#include "irnode.h"
Christian Schäfer's avatar
Christian Schäfer committed
315

Matthias Braun's avatar
Matthias Braun committed
316
317
318
/** @addtogroup Const
 * @{
 */
Christian Schäfer's avatar
Christian Schäfer committed
319

320
321
/**
 * Constructor for a Const node.
yb9976's avatar
yb9976 committed
322
323
324
325
326
327
328
329
330
331
332
333
 *
 * Adds the node to the start block.
 *
 * Constructor for a Const node. The constant represents a target
 * value.  Sets the type information to type_unknown.  (No more
 * supported: If tv is entity derives a somehow useful type.)
 *
 * @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
334
FIRM_API ir_node *new_rd_Const_long(dbg_info *db, ir_graph *irg,
335
                                    ir_mode *mode, long value);
yb9976's avatar
yb9976 committed
336

Matthias Braun's avatar
Matthias Braun committed
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
372
373
374
375
376
377
378
/** Constructor for a Const node.
 *
 * Adds the node to the start block.
 *
 * Constructor for a Const node. The constant represents a target
 * value.  Sets the type information to type_unknown.  (No more
 * supported: If tv is entity derives a somehow useful type.)
 *
 * @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 SymConst
 * @{
 */

379
/** Constructor for a SymConst node.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
380
381
 *
 *  This is the constructor for a symbolic constant.
382
383
384
385
386
387
388
389
390
391
392
393
394
395
 *    There are several kinds of symbolic constants:
 *    - symconst_type_size  The symbolic constant represents the size of a type.
 *                          The type of which the constant represents the size
 *                          is given explicitly.
 *    - symconst_type_align The symbolic constant represents the alignment of a
 *                          type.  The type of which the constant represents the
 *                          size is given explicitly.
 *    - symconst_addr_ent   The symbolic constant represents the address of an
 *                          entity (variable or method).  The variable is given
 *                          explicitly by a firm entity.
 *    - symconst_ofs_ent    The symbolic constant represents the offset of an
 *                          entity in its owner type.
 *    - symconst_enum_const The symbolic constant is a enumeration constant of
 *                          an enumeration type.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
396
397
 *
 *    Inputs to the node:
Götz Lindenmaier's avatar
Götz Lindenmaier committed
398
 *      No inputs except the block it belongs to.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
399
400
401
 *    Outputs of the node.
 *      An unsigned integer (I_u) or a pointer (P).
 *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
402
403
404
 *    Mention union in declaration so that the firmjni generator recognizes that
 *    it can not cast the argument to an int.
 *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
405
 * @param *db     A pointer for debug information.
406
407
 * @param *irg    The IR graph the node  belongs to.
 * @param mode    The mode for the SymConst.
Matthias Braun's avatar
Matthias Braun committed
408
 * @param value   A type, ident, entity or enum constant depending on the
409
410
 *                SymConst kind.
 * @param kind    The kind of the symbolic constant, see the list above
411
 */
Michael Beck's avatar
Michael Beck committed
412
FIRM_API ir_node *new_rd_SymConst(dbg_info *db, ir_graph *irg, ir_mode *mode,
413
414
                                  union symconst_symbol value,
                                  symconst_kind kind);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
415
416
417

/** Constructor for a SymConst addr_ent node.
 *
418
 * Same as new_rd_SymConst, except that the constructor is tailored for
Götz Lindenmaier's avatar
Götz Lindenmaier committed
419
 * symconst_addr_ent.
Matthias Braun's avatar
Matthias Braun committed
420
421
 * Adds the SymConst to the start block of irg.
 */
Michael Beck's avatar
Michael Beck committed
422
FIRM_API ir_node *new_rd_SymConst_addr_ent(dbg_info *db, ir_graph *irg,
423
                                           ir_mode *mode, ir_entity *symbol);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
424

425
426
/** Constructor for a SymConst ofs_ent node.
 *
427
 * Same as new_rd_SymConst, except that the constructor is tailored for
428
 * symconst_ofs_ent.
429
430
 * Adds the SymConst to the start block of irg.
 */
Michael Beck's avatar
Michael Beck committed
431
FIRM_API ir_node *new_rd_SymConst_ofs_ent(dbg_info *db, ir_graph *irg,
432
                                          ir_mode *mode, ir_entity *symbol);
433

Götz Lindenmaier's avatar
Götz Lindenmaier committed
434
435
/** Constructor for a SymConst size node.
 *
436
 * Same as new_rd_SymConst, except that the constructor is tailored for
437
 * symconst_type_size.
Matthias Braun's avatar
Matthias Braun committed
438
439
 * Adds the SymConst to the start block of irg.
 */
Michael Beck's avatar
Michael Beck committed
440
FIRM_API ir_node *new_rd_SymConst_size(dbg_info *db, ir_graph *irg,
441
                                       ir_mode *mode, ir_type *symbol);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
442

443
444
/** Constructor for a SymConst size node.
 *
445
 * Same as new_rd_SymConst, except that the constructor is tailored for
446
 * symconst_type_align.
447
448
 * Adds the SymConst to the start block of irg.
 */
Michael Beck's avatar
Michael Beck committed
449
FIRM_API ir_node *new_rd_SymConst_align(dbg_info *db, ir_graph *irg,
450
                                        ir_mode *mode, ir_type *symbol);
451

452
/** Constructor for a SymConst node.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
453
 *
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
 *  This is the constructor for a symbolic constant.
 *    There are several kinds of symbolic constants:
 *    - symconst_type_size  The symbolic constant represents the size of a type.
 *                          The type of which the constant represents the size
 *                          is given explicitly.
 *    - symconst_type_align The symbolic constant represents the alignment of a
 *                          type.  The type of which the constant represents the
 *                          size is given explicitly.
 *    - symconst_addr_ent   The symbolic constant represents the address of an
 *                          entity (variable or method).  The variable is given
 *                          explicitly by a firm entity.
 *    - symconst_ofs_ent    The symbolic constant represents the offset of an
 *                          entity in its owner type.
 *    - symconst_enum_const The symbolic constant is a enumeration constant of
 *                          an enumeration type.
 *
 *    Inputs to the node:
 *      No inputs except the block it belongs to.
 *    Outputs of the node.
 *      An unsigned integer (I_u) or a pointer (P).
 *
 *    Mention union in declaration so that the firmjni generator recognizes that
 *    it can not cast the argument to an int.
 *
 * @param *irg    The IR graph the node  belongs to.
 * @param mode    The mode for the SymConst.
 * @param value   A type, ident, entity or enum constant depending on the
 *                SymConst kind.
 * @param kind    The kind of the symbolic constant, see the list above
Götz Lindenmaier's avatar
Götz Lindenmaier committed
483
 */
484
485
486
FIRM_API ir_node *new_r_SymConst(ir_graph *irg, ir_mode *mode,
                                 union symconst_symbol value,
                                 symconst_kind kind);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
487

Matthias Braun's avatar
Matthias Braun committed
488
/** Constructor for an SymConst node
Götz Lindenmaier's avatar
Götz Lindenmaier committed
489
 *
Matthias Braun's avatar
Matthias Braun committed
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
 *  This is the constructor for a symbolic constant.
 *    There are several kinds of symbolic constants:
 *    - symconst_type_size  The symbolic constant represents the size of a type.
 *                          The type of which the constant represents the size
 *                          is given explicitly.
 *    - symconst_type_align The symbolic constant represents the alignment of a
 *                          type.  The type of which the constant represents the
 *                          size is given explicitly.
 *    - symconst_addr_ent   The symbolic constant represents the address of an
 *                          entity (variable or method).  The variable is given
 *                          explicitly by a firm entity.
 *    - symconst_ofs_ent    The symbolic constant represents the offset of an
 *                          entity in its owner type.
 *    - symconst_enum_const The symbolic constant is a enumeration constant of
 *                          an enumeration type.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
505
 *
Matthias Braun's avatar
Matthias Braun committed
506
507
508
509
 *    Inputs to the node:
 *      No inputs except the block it belongs to.
 *    Outputs of the node.
 *      An unsigned integer (I_u) or a pointer (P).
Götz Lindenmaier's avatar
Götz Lindenmaier committed
510
 *
Matthias Braun's avatar
Matthias Braun committed
511
512
 *    Mention union in declaration so that the firmjni generator recognizes that
 *    it can not cast the argument to an int.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
513
 *
Matthias Braun's avatar
Matthias Braun committed
514
515
516
517
518
 * @param *db     A pointer for debug information.
 * @param mode    The mode for the SymConst.
 * @param value   A type, ident, entity or enum constant depending on the
 *                SymConst kind.
 * @param kind    The kind of the symbolic constant, see the list above
Götz Lindenmaier's avatar
Götz Lindenmaier committed
519
 */
Matthias Braun's avatar
Matthias Braun committed
520
521
522
FIRM_API ir_node *new_d_SymConst(dbg_info *db, ir_mode *mode,
                                 union symconst_symbol value,
                                 symconst_kind kind);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
523

524
/** Constructor for a SymConst node.
525
 *
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
 *  This is the constructor for a symbolic constant.
 *    There are several kinds of symbolic constants:
 *    - symconst_type_size  The symbolic constant represents the size of a type.
 *                          The type of which the constant represents the size
 *                          is given explicitly.
 *    - symconst_type_align The symbolic constant represents the alignment of a
 *                          type.  The type of which the constant represents the
 *                          size is given explicitly.
 *    - symconst_addr_ent   The symbolic constant represents the address of an
 *                          entity (variable or method).  The variable is given
 *                          explicitly by a firm entity.
 *    - symconst_ofs_ent    The symbolic constant represents the offset of an
 *                          entity in its owner type.
 *    - symconst_enum_const The symbolic constant is a enumeration constant of
 *                          an enumeration type.
541
 *
542
543
544
545
 *    Inputs to the node:
 *      No inputs except the block it belongs to.
 *    Outputs of the node.
 *      An unsigned integer (I_u) or a pointer (P).
Beyhan's avatar
Beyhan committed
546
 *
547
548
 *    Mention union in declaration so that the firmjni generator recognizes that
 *    it can not cast the argument to an int.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
549
 *
550
551
552
553
 * @param mode    The mode for the SymConst.
 * @param value   A type, ident, entity or enum constant depending on the
 *                SymConst kind.
 * @param kind    The kind of the symbolic constant, see the list above
Götz Lindenmaier's avatar
Götz Lindenmaier committed
554
 */
Matthias Braun's avatar
Matthias Braun committed
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
FIRM_API ir_node *new_SymConst(ir_mode *mode, union symconst_symbol value,
                               symconst_kind kind);

/** @} */

/** @addtogroup Conv
 * @{
 */

/** Constructor for a strictConv node.
 *
 * @param db    A pointer for debug information.
 * @param block The IR block the node belongs to.
 * @param op    The operand.
 * @param mode  The mode of this the operand muss be converted .
 */
FIRM_API ir_node *new_rd_strictConv(dbg_info *db, ir_node *block,
                                    ir_node *op, ir_mode *mode);

/** Constructor for a strictConv node.
 *
 * @param block The IR block the node belongs to.
 * @param op    The operand.
 * @param mode  The mode of this the operand muss be converted .
 */
FIRM_API ir_node *new_r_strictConv(ir_node *block, ir_node *op, ir_mode *mode);

/** Constructor for a strict Conv node.
 *
 * @param db    A pointer for debug information.
 * @param op    The operand.
 * @param mode  The mode of this the operand muss be converted .
 */
FIRM_API ir_node *new_d_strictConv(dbg_info *db, ir_node *op, ir_mode *mode);

/** Constructor for a strict Conv node.
 *
 * @param op    The operand.
 * @param mode  The mode of this the operand muss be converted .
 */
FIRM_API ir_node *new_strictConv(ir_node *op, ir_mode *mode);

/** @} */

/** @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   *store     The memory in which the object the entity should be
 *                     selected from is allocated.
 * @param   *objptr    The object from that the Sel operation selects a
 *                     single attribute out.
 * @param   *ent       The entity to select.
 */
FIRM_API ir_node *new_rd_simpleSel(dbg_info *db, ir_node *block, ir_node *store,
                                   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 *store     The memory in which the object the entity should be selected
 *                   from is allocated.
 * @param *objptr    The object from that the Sel operation selects a
 *                   single attribute out.
 * @param *ent       The entity to select.
 * @ingroup Sel
 */
FIRM_API ir_node *new_r_simpleSel(ir_node *block, ir_node *store,
                                  ir_node *objptr, ir_entity *ent);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
636

637
/** Constructor for a simpleSel node.
638
 *
639
640
641
 *  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.
642
 *
643
644
645
646
647
648
 * @param   *db        A pointer for debug information.
 * @param   *store     The memory in which the object the entity should be
 *                     selected from is allocated.
 * @param   *objptr    The object from that the Sel operation selects a
 *                     single attribute out.
 * @param   *ent       The entity to select.
649
 */
650
651
FIRM_API ir_node *new_d_simpleSel(dbg_info *db, ir_node *store, ir_node *objptr,
                                  ir_entity *ent);
Matthias Braun's avatar
Matthias Braun committed
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698

/** 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   *store     The memory in which the object the entity should be selected from is allocated.
 * @param   *objptr    The object from that the Sel operation selects a single attribute out.
 * @param   *ent       The entity to select.
 */
FIRM_API ir_node *new_simpleSel(ir_node *store, ir_node *objptr,
                                ir_entity *ent);

/** @} */

/** @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);

699
/** Constructor for a remainderless Div node.
700
701
702
 *
 * Adds the node to the block in current_ir_block.
 *
703
704
 * @param   *db    A pointer for debug information.
 * @param   *memop The store needed to model exceptions
705
706
 * @param   *op1   The first operand.
 * @param   *op2   The second operand.
707
708
 * @param   *mode  The mode of the result.
 * @param   state  The pinned state.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
709
 */
710
711
712
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
713
714

/** Constructor for a remainderless Div node.
Beyhan's avatar
Beyhan committed
715
716
 *
 * Adds the node to the block in current_ir_block.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
717
 *
Matthias Braun's avatar
Matthias Braun committed
718
719
720
721
722
723
724
725
726
727
728
729
730
 * @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
731
732
 */

733
/** Constructor for an ASM pseudo node.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
734
 *
735
 * @param *db         A pointer for debug information.
Matthias Braun's avatar
Matthias Braun committed
736
 * @param *block      The block the node belong to.
737
738
739
740
741
742
743
744
 * @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
745
 */
Matthias Braun's avatar
Matthias Braun committed
746
747
FIRM_API ir_node *new_rd_ASM(dbg_info *db, ir_node *block,
                            int arity, ir_node *in[], ir_asm_constraint *inputs,
748
749
750
                            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
751

Matthias Braun's avatar
Matthias Braun committed
752
/** Constructor for an ASM pseudo node.
Michael Beck's avatar
Michael Beck committed
753
 *
Matthias Braun's avatar
Matthias Braun committed
754
755
756
757
758
759
760
761
762
 * @param *block      The block the node belong to.
 * @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.
763
 */
Matthias Braun's avatar
Matthias Braun committed
764
765
766
767
768
FIRM_API ir_node *new_r_ASM(ir_node *block,
                            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);
769

Matthias Braun's avatar
Matthias Braun committed
770
/** Constructor for an ASM pseudo node.
771
 *
Matthias Braun's avatar
Matthias Braun committed
772
773
774
775
776
777
778
779
780
781
 * @param *db         A pointer for debug information.
 * @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
782
 */
Matthias Braun's avatar
Matthias Braun committed
783
784
785
786
787
FIRM_API ir_node *new_d_ASM(dbg_info *db, 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);
788

Michael Beck's avatar
Michael Beck committed
789
790
791
/** Constructor for an ASM pseudo node.
 *
 * @param arity       The number of data inputs to the node.
Michael Beck's avatar
Michael Beck committed
792
793
794
795
 * @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
796
797
 * @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
798
 * @param *asm_text   The assembler text.
Matthias Braun's avatar
Matthias Braun committed
799
 * @ingroup ASM
Michael Beck's avatar
Michael Beck committed
800
 */
Michael Beck's avatar
Michael Beck committed
801
FIRM_API ir_node *new_ASM(int arity, ir_node *in[], ir_asm_constraint *inputs,
802
803
                          size_t n_outs, ir_asm_constraint *outputs,
                          size_t n_clobber, ident *clobber[], ident *asm_text);
Michael Beck's avatar
Michael Beck committed
804

Matthias Braun's avatar
Matthias Braun committed
805
806
807
808
809
/** @} */

/** @defgroup ir_cons Graph Construction Support
 * @{
 */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
810

Michael Beck's avatar
Michael Beck committed
811
/** Create an immature Block.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
812
 *
Michael Beck's avatar
Michael Beck committed
813
 * An immature Block has an unknown number of predecessors.  Predecessors
Götz Lindenmaier's avatar
Götz Lindenmaier committed
814
815
816
 * can be added with add_immBlock_pred().  Once all predecessors are
 * added the block must be matured.
 *
817
818
819
 * Adds the block to the graph in current_ir_graph. Can be used with automatic
 * Phi node construction.
 * This constructor can only be used if the graph is in state_building.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
820
 */
Michael Beck's avatar
Michael Beck committed
821
822
FIRM_API ir_node *new_d_immBlock(dbg_info *db);
FIRM_API ir_node *new_immBlock(void);
823
824
FIRM_API ir_node *new_r_immBlock(ir_graph *irg);
FIRM_API ir_node *new_rd_immBlock(dbg_info *db, ir_graph *irg);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
825

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

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

Matthias Braun's avatar
Matthias Braun committed
832
833
834
835
836
837
838
839
840
841
842
843
/** Sets the current block in which the following constructors place the
 *  nodes they construct.
 *
 *  @param target  The new current block.
 */
FIRM_API void set_cur_block(ir_node *target);
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);
FIRM_API ir_node *get_r_cur_block(ir_graph *irg);

Götz Lindenmaier's avatar
Götz Lindenmaier committed
844
845
846
847
848
849
850
851
852
/** Get the current value of a local variable.
 *
 * Use this function to obtain the last definition of the local variable
 * associated with pos.  Pos may not exceed the value passed as n_loc
 * 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
853
FIRM_API ir_node *get_value(int pos, ir_mode *mode);
854
FIRM_API ir_node *get_r_value(ir_graph *irg, int pos, ir_mode *mode);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
855

856
857
858
859
860
861
862
863
864
/**
 * 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);
865
FIRM_API ir_mode *ir_r_guess_mode(ir_graph *irg, int pos);
866

Götz Lindenmaier's avatar
Götz Lindenmaier committed
867
868
869
870
871
872
873
874
875
/** Remark a new definition of a variable.
 *
 * Use this function to remember a new definition of the value
 * associated with pos. Pos may not exceed the value passed as n_loc
 * 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.
876
 */
Michael Beck's avatar
Michael Beck committed
877
FIRM_API void set_value(int pos, ir_node *value);
878
FIRM_API void set_r_value(ir_graph *irg, int pos, ir_node *value);
879

880
881
882
883
884
885
886
887
/**
 * Find the value number for a node in the current block.
 *
 * @param value  the searched value
 *
 * @return the value number of the value or -1 if this value has
 * no value number in the current block.
 */
Michael Beck's avatar
Michael Beck committed
888
FIRM_API int find_value(ir_node *value);
889
FIRM_API int r_find_value(ir_graph *irg, ir_node *value);
890

Götz Lindenmaier's avatar
Götz Lindenmaier committed
891
892
893
894
895
896
/** Get the current memory state.
 *
 * 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
897
FIRM_API ir_node *get_store(void);
898
FIRM_API ir_node *get_r_store(ir_graph *irg);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
899

Götz Lindenmaier's avatar
Götz Lindenmaier committed
900
901
902
903
904
905
/** Remark a new definition of the memory state.
 *
 * 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.
906
 */
Michael Beck's avatar
Michael Beck committed
907
FIRM_API void set_store(ir_node *store);
908
FIRM_API void set_r_store(ir_graph *irg, ir_node *store);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
909

Götz Lindenmaier's avatar
Götz Lindenmaier committed
910
911
912
913
/** 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
914
FIRM_API void keep_alive(ir_node *ka);
915

916
/* --- initialize and finalize IR construction --- */
917

Michael Beck's avatar
Michael Beck committed
918
/** Puts the graph into state "phase_high" */
919
FIRM_API void irg_finalize_cons(ir_graph *irg);
920
921
922
923
924

/** 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
925
FIRM_API void irp_finalize_cons(void);
Christian Schäfer's avatar
Christian Schäfer committed
926

927
928
929
FIRM_API void ir_set_uninitialized_local_variable_func(
		uninitialized_local_variable_func_t *func);

Matthias Braun's avatar
Matthias Braun committed
930
931
/** @} */

932
#include "end.h"
933

Matthias Braun's avatar
Matthias Braun committed
934
#endif