- BugFix: *__remove_iterator(): after _next(), the iterator already points to the...
[libfirm] / ir / ir / ircons.c
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   Various irnode constructors. Automatic construction of SSA
23  *          representation.
24  * @author  Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Boris Boesler
25             Michael Beck
26  * @version $Id$
27  */
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include "irprog_t.h"
33 #include "irgraph_t.h"
34 #include "irnode_t.h"
35 #include "irmode_t.h"
36 #include "ircons_t.h"
37 #include "firm_common_t.h"
38 #include "irvrfy.h"
39 #include "irop_t.h"
40 #include "iropt_t.h"
41 #include "irgmod.h"
42 #include "irhooks.h"
43 #include "array.h"
44 #include "irbackedge_t.h"
45 #include "irflag_t.h"
46 #include "iredges_t.h"
47 #include "irflag_t.h"
48 #include "xmalloc.h"
49
50 #if USE_EXPLICIT_PHI_IN_STACK
51 /* A stack needed for the automatic Phi node construction in constructor
52    Phi_in. Redefinition in irgraph.c!! */
53 struct Phi_in_stack {
54         ir_node **stack;
55         int       pos;
56 };
57 typedef struct Phi_in_stack Phi_in_stack;
58 #endif
59
60 /* when we need verifying */
61 #ifdef NDEBUG
62 # define IRN_VRFY_IRG(res, irg)
63 #else
64 # define IRN_VRFY_IRG(res, irg)  irn_vrfy_irg(res, irg)
65 #endif /* NDEBUG */
66
67 /**
68  * Language dependent variable initialization callback.
69  */
70 static uninitialized_local_variable_func_t *default_initialize_local_variable = NULL;
71
72 /* creates a bd constructor for a binop */
73 #define NEW_BD_BINOP(instr)                                     \
74 static ir_node *                                                \
75 new_bd_##instr(dbg_info *db, ir_node *block,                    \
76        ir_node *op1, ir_node *op2, ir_mode *mode)               \
77 {                                                               \
78   ir_node  *in[2];                                              \
79   ir_node  *res;                                                \
80   ir_graph *irg = current_ir_graph;                             \
81   in[0] = op1;                                                  \
82   in[1] = op2;                                                  \
83   res = new_ir_node(db, irg, block, op_##instr, mode, 2, in);   \
84   res = optimize_node(res);                                     \
85   IRN_VRFY_IRG(res, irg);                                       \
86   return res;                                                   \
87 }
88
89 /* creates a bd constructor for an unop */
90 #define NEW_BD_UNOP(instr)                                      \
91 static ir_node *                                                \
92 new_bd_##instr(dbg_info *db, ir_node *block,                    \
93               ir_node *op, ir_mode *mode)                       \
94 {                                                               \
95   ir_node  *res;                                                \
96   ir_graph *irg = current_ir_graph;                             \
97   res = new_ir_node(db, irg, block, op_##instr, mode, 1, &op);  \
98   res = optimize_node(res);                                     \
99   IRN_VRFY_IRG(res, irg);                                       \
100   return res;                                                   \
101 }
102
103 /* creates a bd constructor for an divop */
104 #define NEW_BD_DIVOP(instr)                                     \
105 static ir_node *                                                \
106 new_bd_##instr(dbg_info *db, ir_node *block,                    \
107             ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state) \
108 {                                                               \
109   ir_node  *in[3];                                              \
110   ir_node  *res;                                                \
111   ir_graph *irg = current_ir_graph;                             \
112   in[0] = memop;                                                \
113   in[1] = op1;                                                  \
114   in[2] = op2;                                                  \
115   res = new_ir_node(db, irg, block, op_##instr, mode_T, 3, in); \
116   res->attr.divmod.exc.pin_state = state;                       \
117   res->attr.divmod.res_mode = mode;                             \
118   res->attr.divmod.no_remainder = 0;                            \
119   res = optimize_node(res);                                     \
120   IRN_VRFY_IRG(res, irg);                                       \
121   return res;                                                   \
122 }
123
124 /* creates a rd constructor for a binop */
125 #define NEW_RD_BINOP(instr)                                     \
126 ir_node *                                                       \
127 new_rd_##instr(dbg_info *db, ir_graph *irg, ir_node *block,     \
128        ir_node *op1, ir_node *op2, ir_mode *mode)               \
129 {                                                               \
130   ir_node  *res;                                                \
131   ir_graph *rem = current_ir_graph;                             \
132   current_ir_graph = irg;                                       \
133   res = new_bd_##instr(db, block, op1, op2, mode);              \
134   current_ir_graph = rem;                                       \
135   return res;                                                   \
136 }
137
138 /* creates a rd constructor for an unop */
139 #define NEW_RD_UNOP(instr)                                      \
140 ir_node *                                                       \
141 new_rd_##instr(dbg_info *db, ir_graph *irg, ir_node *block,     \
142               ir_node *op, ir_mode *mode)                       \
143 {                                                               \
144   ir_node  *res;                                                \
145   ir_graph *rem = current_ir_graph;                             \
146   current_ir_graph = irg;                                       \
147   res = new_bd_##instr(db, block, op, mode);                    \
148   current_ir_graph = rem;                                       \
149   return res;                                                   \
150 }
151
152 /* creates a rd constructor for an divop */
153 #define NEW_RD_DIVOP(instr)                                     \
154 ir_node *                                                       \
155 new_rd_##instr(dbg_info *db, ir_graph *irg, ir_node *block,     \
156             ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state) \
157 {                                                               \
158   ir_node  *res;                                                \
159   ir_graph *rem = current_ir_graph;                             \
160   current_ir_graph = irg;                                       \
161   res = new_bd_##instr(db, block, memop, op1, op2, mode, state);\
162   current_ir_graph = rem;                                       \
163   return res;                                                   \
164 }
165
166 /* creates a d constructor for an binop */
167 #define NEW_D_BINOP(instr)                                                    \
168 ir_node *                                                                     \
169 new_d_##instr(dbg_info *db, ir_node *op1, ir_node *op2, ir_mode *mode) {      \
170   return new_bd_##instr(db, current_ir_graph->current_block, op1, op2, mode); \
171 }
172
173 /* creates a d constructor for an unop */
174 #define NEW_D_UNOP(instr)                                                     \
175 ir_node *                                                                     \
176 new_d_##instr(dbg_info *db, ir_node *op, ir_mode *mode) {                     \
177   return new_bd_##instr(db, current_ir_graph->current_block, op, mode);       \
178 }
179
180
181 /**
182  * Constructs a Block with a fixed number of predecessors.
183  * Does not set current_block.  Cannot be used with automatic
184  * Phi node construction.
185  */
186 static ir_node *
187 new_bd_Block(dbg_info *db, int arity, ir_node **in) {
188         ir_node  *res;
189         ir_graph *irg = current_ir_graph;
190
191         res = new_ir_node(db, irg, NULL, op_Block, mode_BB, arity, in);
192
193         /* macroblock header */
194         res->in[0] = res;
195
196         res->attr.block.is_dead     = 0;
197         res->attr.block.is_mb_head  = 1;
198         res->attr.block.has_label   = 0;
199         res->attr.block.irg         = irg;
200         res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
201         res->attr.block.in_cg       = NULL;
202         res->attr.block.cg_backedge = NULL;
203         res->attr.block.extblk      = NULL;
204         res->attr.block.mb_depth    = 0;
205         res->attr.block.label       = 0;
206
207         set_Block_matured(res, 1);
208         set_Block_block_visited(res, 0);
209
210         IRN_VRFY_IRG(res, irg);
211         return res;
212 }  /* new_bd_Block */
213
214 static ir_node *
215 new_bd_Start(dbg_info *db, ir_node *block) {
216         ir_node  *res;
217         ir_graph *irg = current_ir_graph;
218
219         res = new_ir_node(db, irg, block, op_Start, mode_T, 0, NULL);
220
221         IRN_VRFY_IRG(res, irg);
222         return res;
223 }  /* new_bd_Start */
224
225 static ir_node *
226 new_bd_End(dbg_info *db, ir_node *block) {
227         ir_node  *res;
228         ir_graph *irg = current_ir_graph;
229
230         res = new_ir_node(db, irg, block, op_End, mode_X, -1, NULL);
231
232         IRN_VRFY_IRG(res, irg);
233         return res;
234 }  /* new_bd_End */
235
236 /**
237  * Creates a Phi node with all predecessors.  Calling this constructor
238  * is only allowed if the corresponding block is mature.
239  */
240 static ir_node *
241 new_bd_Phi(dbg_info *db, ir_node *block, int arity, ir_node **in, ir_mode *mode) {
242         ir_node  *res;
243         ir_graph *irg = current_ir_graph;
244         int i;
245         int has_unknown = 0;
246
247         /* Don't assert that block matured: the use of this constructor is strongly
248            restricted ... */
249         if (get_Block_matured(block))
250                 assert(get_irn_arity(block) == arity);
251
252         res = new_ir_node(db, irg, block, op_Phi, mode, arity, in);
253
254         res->attr.phi.u.backedge = new_backedge_arr(irg->obst, arity);
255
256         for (i = arity - 1; i >= 0; --i)
257                 if (get_irn_op(in[i]) == op_Unknown) {
258                         has_unknown = 1;
259                         break;
260                 }
261
262         if (!has_unknown) res = optimize_node(res);
263         IRN_VRFY_IRG(res, irg);
264
265         /* Memory Phis in endless loops must be kept alive.
266            As we can't distinguish these easily we keep all of them alive. */
267         if (is_Phi(res) && mode == mode_M)
268                 add_End_keepalive(get_irg_end(irg), res);
269         return res;
270 }  /* new_bd_Phi */
271
272 static ir_node *
273 new_bd_Const_type(dbg_info *db, ir_node *block, ir_mode *mode, tarval *con, ir_type *tp) {
274         ir_node  *res;
275         ir_graph *irg = current_ir_graph;
276         (void) block;
277
278         res = new_ir_node(db, irg, get_irg_start_block(irg), op_Const, mode, 0, NULL);
279         res->attr.con.tv = con;
280         set_Const_type(res, tp);  /* Call method because of complex assertion. */
281         res = optimize_node (res);
282         assert(get_Const_type(res) == tp);
283         IRN_VRFY_IRG(res, irg);
284
285         return res;
286 }  /* new_bd_Const_type */
287
288 static ir_node *
289 new_bd_Const(dbg_info *db, ir_node *block, ir_mode *mode, tarval *con) {
290         ir_graph *irg = current_ir_graph;
291
292         return new_rd_Const_type (db, irg, block, mode, con, firm_unknown_type);
293 }  /* new_bd_Const */
294
295 static ir_node *
296 new_bd_Const_long(dbg_info *db, ir_node *block, ir_mode *mode, long value) {
297         ir_graph *irg = current_ir_graph;
298
299         return new_rd_Const(db, irg, block, mode, new_tarval_from_long(value, mode));
300 }  /* new_bd_Const_long */
301
302 static ir_node *
303 new_bd_Id(dbg_info *db, ir_node *block, ir_node *val, ir_mode *mode) {
304         ir_node  *res;
305         ir_graph *irg = current_ir_graph;
306
307         res = new_ir_node(db, irg, block, op_Id, mode, 1, &val);
308         res = optimize_node(res);
309         IRN_VRFY_IRG(res, irg);
310         return res;
311 }  /* new_bd_Id */
312
313 static ir_node *
314 new_bd_Proj(dbg_info *db, ir_node *block, ir_node *arg, ir_mode *mode,
315         long proj) {
316         ir_node  *res;
317         ir_graph *irg = current_ir_graph;
318
319         res = new_ir_node (db, irg, block, op_Proj, mode, 1, &arg);
320         res->attr.proj = proj;
321
322         assert(res);
323         assert(get_Proj_pred(res));
324         assert(get_nodes_block(get_Proj_pred(res)));
325
326         res = optimize_node(res);
327
328         IRN_VRFY_IRG(res, irg);
329         return res;
330 }  /* new_bd_Proj */
331
332 static ir_node *
333 new_bd_defaultProj(dbg_info *db, ir_node *block, ir_node *arg,
334            long max_proj) {
335         ir_node  *res;
336         ir_graph *irg = current_ir_graph;
337
338         assert(arg->op == op_Cond);
339         arg->attr.cond.kind = fragmentary;
340         arg->attr.cond.default_proj = max_proj;
341         res = new_rd_Proj (db, irg, block, arg, mode_X, max_proj);
342         return res;
343 }  /* new_bd_defaultProj */
344
345 static ir_node *
346 new_bd_Conv(dbg_info *db, ir_node *block, ir_node *op, ir_mode *mode, int strict_flag) {
347         ir_node  *res;
348         ir_graph *irg = current_ir_graph;
349
350         res = new_ir_node(db, irg, block, op_Conv, mode, 1, &op);
351         res->attr.conv.strict = strict_flag;
352         res = optimize_node(res);
353         IRN_VRFY_IRG(res, irg);
354         return res;
355 }  /* new_bd_Conv */
356
357 static ir_node *
358 new_bd_Cast(dbg_info *db, ir_node *block, ir_node *op, ir_type *to_tp) {
359         ir_node  *res;
360         ir_graph *irg = current_ir_graph;
361
362         assert(is_atomic_type(to_tp));
363
364         res = new_ir_node(db, irg, block, op_Cast, get_irn_mode(op), 1, &op);
365         res->attr.cast.totype = to_tp;
366         res = optimize_node(res);
367         IRN_VRFY_IRG(res, irg);
368         return res;
369 }  /* new_bd_Cast */
370
371 static ir_node *
372 new_bd_Tuple(dbg_info *db, ir_node *block, int arity, ir_node **in) {
373         ir_node  *res;
374         ir_graph *irg = current_ir_graph;
375
376         res = new_ir_node(db, irg, block, op_Tuple, mode_T, arity, in);
377         res = optimize_node (res);
378         IRN_VRFY_IRG(res, irg);
379         return res;
380 }  /* new_bd_Tuple */
381
382 NEW_BD_BINOP(Add)
383 NEW_BD_BINOP(Sub)
384 NEW_BD_UNOP(Minus)
385 NEW_BD_BINOP(Mul)
386 NEW_BD_BINOP(Mulh)
387 NEW_BD_DIVOP(Quot)
388 NEW_BD_DIVOP(DivMod)
389 NEW_BD_DIVOP(Div)
390 NEW_BD_DIVOP(Mod)
391 NEW_BD_BINOP(And)
392 NEW_BD_BINOP(Or)
393 NEW_BD_BINOP(Eor)
394 NEW_BD_UNOP(Not)
395 NEW_BD_BINOP(Shl)
396 NEW_BD_BINOP(Shr)
397 NEW_BD_BINOP(Shrs)
398 NEW_BD_BINOP(Rotl)
399 NEW_BD_UNOP(Abs)
400 NEW_BD_BINOP(Carry)
401 NEW_BD_BINOP(Borrow)
402
403 /** Creates a remainderless Div node. */
404 static ir_node *new_bd_DivRL(dbg_info *db, ir_node *block,
405             ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state)
406 {
407         ir_node  *in[3];
408         ir_node  *res;
409         ir_graph *irg = current_ir_graph;
410         in[0] = memop;
411         in[1] = op1;
412         in[2] = op2;
413         res = new_ir_node(db, irg, block, op_Div, mode_T, 3, in);
414         res->attr.divmod.exc.pin_state = state;
415         res->attr.divmod.res_mode = mode;
416         res->attr.divmod.no_remainder = 1;
417         res = optimize_node(res);
418         IRN_VRFY_IRG(res, irg);
419         return res;
420 }
421
422 static ir_node *
423 new_bd_Cmp(dbg_info *db, ir_node *block, ir_node *op1, ir_node *op2) {
424         ir_node  *in[2];
425         ir_node  *res;
426         ir_graph *irg = current_ir_graph;
427         in[0] = op1;
428         in[1] = op2;
429         res = new_ir_node(db, irg, block, op_Cmp, mode_T, 2, in);
430         res = optimize_node(res);
431         IRN_VRFY_IRG(res, irg);
432         return res;
433 }  /* new_bd_Cmp */
434
435 static ir_node *
436 new_bd_Jmp(dbg_info *db, ir_node *block) {
437         ir_node  *res;
438         ir_graph *irg = current_ir_graph;
439
440         res = new_ir_node(db, irg, block, op_Jmp, mode_X, 0, NULL);
441         res = optimize_node(res);
442         IRN_VRFY_IRG(res, irg);
443         return res;
444 }  /* new_bd_Jmp */
445
446 static ir_node *
447 new_bd_IJmp(dbg_info *db, ir_node *block, ir_node *tgt) {
448         ir_node  *res;
449         ir_graph *irg = current_ir_graph;
450
451         res = new_ir_node(db, irg, block, op_IJmp, mode_X, 1, &tgt);
452         res = optimize_node(res);
453         IRN_VRFY_IRG(res, irg);
454         return res;
455 }  /* new_bd_IJmp */
456
457 static ir_node *
458 new_bd_Cond(dbg_info *db, ir_node *block, ir_node *c) {
459         ir_node  *res;
460         ir_graph *irg = current_ir_graph;
461
462         res = new_ir_node(db, irg, block, op_Cond, mode_T, 1, &c);
463         res->attr.cond.kind         = dense;
464         res->attr.cond.default_proj = 0;
465         res->attr.cond.pred         = COND_JMP_PRED_NONE;
466         res = optimize_node(res);
467         IRN_VRFY_IRG(res, irg);
468         return res;
469 }  /* new_bd_Cond */
470
471 static ir_node *
472 new_bd_Call(dbg_info *db, ir_node *block, ir_node *store,
473         ir_node *callee, int arity, ir_node **in, ir_type *tp) {
474         ir_node  **r_in;
475         ir_node  *res;
476         int      r_arity;
477         ir_graph *irg = current_ir_graph;
478
479         r_arity = arity+2;
480         NEW_ARR_A(ir_node *, r_in, r_arity);
481         r_in[0] = store;
482         r_in[1] = callee;
483         memcpy(&r_in[2], in, sizeof(ir_node *) * arity);
484
485         res = new_ir_node(db, irg, block, op_Call, mode_T, r_arity, r_in);
486
487         assert((get_unknown_type() == tp) || is_Method_type(tp));
488         set_Call_type(res, tp);
489         res->attr.call.exc.pin_state = op_pin_state_pinned;
490         res->attr.call.callee_arr    = NULL;
491         res = optimize_node(res);
492         IRN_VRFY_IRG(res, irg);
493         return res;
494 }  /* new_bd_Call */
495
496 static ir_node *
497 new_bd_Return(dbg_info *db, ir_node *block,
498               ir_node *store, int arity, ir_node **in) {
499         ir_node  **r_in;
500         ir_node  *res;
501         int      r_arity;
502         ir_graph *irg = current_ir_graph;
503
504         r_arity = arity+1;
505         NEW_ARR_A (ir_node *, r_in, r_arity);
506         r_in[0] = store;
507         memcpy(&r_in[1], in, sizeof(ir_node *) * arity);
508         res = new_ir_node(db, irg, block, op_Return, mode_X, r_arity, r_in);
509         res = optimize_node(res);
510         IRN_VRFY_IRG(res, irg);
511         return res;
512 }  /* new_bd_Return */
513
514 static ir_node *
515 new_bd_Load(dbg_info *db, ir_node *block,
516         ir_node *store, ir_node *adr, ir_mode *mode) {
517         ir_node  *in[2];
518         ir_node  *res;
519         ir_graph *irg = current_ir_graph;
520
521         in[0] = store;
522         in[1] = adr;
523         res = new_ir_node(db, irg, block, op_Load, mode_T, 2, in);
524         res->attr.load.exc.pin_state = op_pin_state_pinned;
525         res->attr.load.load_mode     = mode;
526         res->attr.load.volatility    = volatility_non_volatile;
527         res->attr.load.aligned       = align_is_aligned;
528         res = optimize_node(res);
529         IRN_VRFY_IRG(res, irg);
530         return res;
531 }  /* new_bd_Load */
532
533 static ir_node *
534 new_bd_Store(dbg_info *db, ir_node *block,
535          ir_node *store, ir_node *adr, ir_node *val) {
536         ir_node  *in[3];
537         ir_node  *res;
538         ir_graph *irg = current_ir_graph;
539
540         in[0] = store;
541         in[1] = adr;
542         in[2] = val;
543         res = new_ir_node(db, irg, block, op_Store, mode_T, 3, in);
544         res->attr.store.exc.pin_state = op_pin_state_pinned;
545         res->attr.store.volatility    = volatility_non_volatile;
546         res->attr.store.aligned       = align_is_aligned;
547         res = optimize_node(res);
548         IRN_VRFY_IRG(res, irg);
549         return res;
550 }  /* new_bd_Store */
551
552 static ir_node *
553 new_bd_Alloc(dbg_info *db, ir_node *block, ir_node *store,
554         ir_node *size, ir_type *alloc_type, ir_where_alloc where) {
555         ir_node  *in[2];
556         ir_node  *res;
557         ir_graph *irg = current_ir_graph;
558
559         in[0] = store;
560         in[1] = size;
561         res = new_ir_node(db, irg, block, op_Alloc, mode_T, 2, in);
562         res->attr.alloc.exc.pin_state = op_pin_state_pinned;
563         res->attr.alloc.where         = where;
564         res->attr.alloc.type          = alloc_type;
565         res = optimize_node(res);
566         IRN_VRFY_IRG(res, irg);
567         return res;
568 }  /* new_bd_Alloc */
569
570 static ir_node *
571 new_bd_Free(dbg_info *db, ir_node *block, ir_node *store,
572         ir_node *ptr, ir_node *size, ir_type *free_type, ir_where_alloc where) {
573         ir_node  *in[3];
574         ir_node  *res;
575         ir_graph *irg = current_ir_graph;
576
577         in[0] = store;
578         in[1] = ptr;
579         in[2] = size;
580         res = new_ir_node (db, irg, block, op_Free, mode_M, 3, in);
581         res->attr.free.where = where;
582         res->attr.free.type  = free_type;
583         res = optimize_node(res);
584         IRN_VRFY_IRG(res, irg);
585         return res;
586 }  /* new_bd_Free */
587
588 static ir_node *
589 new_bd_Sel(dbg_info *db, ir_node *block, ir_node *store, ir_node *objptr,
590            int arity, ir_node **in, ir_entity *ent) {
591         ir_node  **r_in;
592         ir_node  *res;
593         int      r_arity;
594         ir_graph *irg = current_ir_graph;
595         ir_mode  *mode = is_Method_type(get_entity_type(ent)) ? mode_P_code : mode_P_data;
596
597         assert(ent != NULL && is_entity(ent) && "entity expected in Sel construction");
598
599         r_arity = arity + 2;
600         NEW_ARR_A(ir_node *, r_in, r_arity);  /* uses alloca */
601         r_in[0] = store;
602         r_in[1] = objptr;
603         memcpy(&r_in[2], in, sizeof(ir_node *) * arity);
604         /*
605          * Sel's can select functions which should be of mode mode_P_code.
606          */
607         res = new_ir_node(db, irg, block, op_Sel, mode, r_arity, r_in);
608         res->attr.sel.ent = ent;
609         res = optimize_node(res);
610         IRN_VRFY_IRG(res, irg);
611         return res;
612 }  /* new_bd_Sel */
613
614 static ir_node *
615 new_bd_SymConst_type(dbg_info *db, ir_node *block, ir_mode *mode,
616                      symconst_symbol value,symconst_kind symkind, ir_type *tp) {
617         ir_graph *irg = current_ir_graph;
618         ir_node  *res = new_ir_node(db, irg, block, op_SymConst, mode, 0, NULL);
619
620         res->attr.symc.kind = symkind;
621         res->attr.symc.sym  = value;
622         res->attr.symc.tp   = tp;
623
624         res = optimize_node(res);
625         IRN_VRFY_IRG(res, irg);
626         return res;
627 }  /* new_bd_SymConst_type */
628
629 static ir_node *
630 new_bd_Sync(dbg_info *db, ir_node *block) {
631         ir_node  *res;
632         ir_graph *irg = current_ir_graph;
633
634         res = new_ir_node(db, irg, block, op_Sync, mode_M, -1, NULL);
635         /* no need to call optimize node here, Sync are always created with no predecessors */
636         IRN_VRFY_IRG(res, irg);
637         return res;
638 }  /* new_bd_Sync */
639
640 static ir_node *
641 new_bd_Confirm(dbg_info *db, ir_node *block, ir_node *val, ir_node *bound, pn_Cmp cmp) {
642         ir_node  *in[2], *res;
643         ir_graph *irg = current_ir_graph;
644
645         in[0] = val;
646         in[1] = bound;
647         res = new_ir_node(db, irg, block, op_Confirm, get_irn_mode(val), 2, in);
648         res->attr.confirm.cmp = cmp;
649         res = optimize_node(res);
650         IRN_VRFY_IRG(res, irg);
651         return res;
652 }  /* new_bd_Confirm */
653
654 static ir_node *
655 new_bd_Unknown(ir_mode *m) {
656         ir_node  *res;
657         ir_graph *irg = current_ir_graph;
658
659         res = new_ir_node(NULL, irg, get_irg_start_block(irg), op_Unknown, m, 0, NULL);
660         res = optimize_node(res);
661         return res;
662 }  /* new_bd_Unknown */
663
664 static ir_node *
665 new_bd_CallBegin(dbg_info *db, ir_node *block, ir_node *call) {
666         ir_node  *in[1];
667         ir_node  *res;
668         ir_graph *irg = current_ir_graph;
669
670         in[0] = get_Call_ptr(call);
671         res = new_ir_node(db, irg, block, op_CallBegin, mode_T, 1, in);
672         /* res->attr.callbegin.irg = irg; */
673         res->attr.callbegin.call = call;
674         res = optimize_node(res);
675         IRN_VRFY_IRG(res, irg);
676         return res;
677 }  /* new_bd_CallBegin */
678
679 static ir_node *
680 new_bd_EndReg(dbg_info *db, ir_node *block) {
681         ir_node  *res;
682         ir_graph *irg = current_ir_graph;
683
684         res = new_ir_node(db, irg, block, op_EndReg, mode_T, -1, NULL);
685         set_irg_end_reg(irg, res);
686         IRN_VRFY_IRG(res, irg);
687         return res;
688 }  /* new_bd_EndReg */
689
690 static ir_node *
691 new_bd_EndExcept(dbg_info *db, ir_node *block) {
692         ir_node  *res;
693         ir_graph *irg = current_ir_graph;
694
695         res = new_ir_node(db, irg, block, op_EndExcept, mode_T, -1, NULL);
696         set_irg_end_except(irg, res);
697         IRN_VRFY_IRG (res, irg);
698         return res;
699 }  /* new_bd_EndExcept */
700
701 static ir_node *
702 new_bd_Break(dbg_info *db, ir_node *block) {
703         ir_node  *res;
704         ir_graph *irg = current_ir_graph;
705
706         res = new_ir_node(db, irg, block, op_Break, mode_X, 0, NULL);
707         res = optimize_node(res);
708         IRN_VRFY_IRG(res, irg);
709         return res;
710 }  /* new_bd_Break */
711
712 static ir_node *
713 new_bd_Filter(dbg_info *db, ir_node *block, ir_node *arg, ir_mode *mode,
714               long proj) {
715         ir_node  *res;
716         ir_graph *irg = current_ir_graph;
717
718         res = new_ir_node(db, irg, block, op_Filter, mode, 1, &arg);
719         res->attr.filter.proj = proj;
720         res->attr.filter.in_cg = NULL;
721         res->attr.filter.backedge = NULL;
722
723         assert(res);
724         assert(get_Proj_pred(res));
725         assert(get_nodes_block(get_Proj_pred(res)));
726
727         res = optimize_node(res);
728         IRN_VRFY_IRG(res, irg);
729         return res;
730 }  /* new_bd_Filter */
731
732 static ir_node *
733 new_bd_Mux(dbg_info *db, ir_node *block,
734            ir_node *sel, ir_node *ir_false, ir_node *ir_true, ir_mode *mode) {
735         ir_node  *in[3];
736         ir_node  *res;
737         ir_graph *irg = current_ir_graph;
738
739         in[0] = sel;
740         in[1] = ir_false;
741         in[2] = ir_true;
742
743         res = new_ir_node(db, irg, block, op_Mux, mode, 3, in);
744         assert(res);
745
746         res = optimize_node(res);
747         IRN_VRFY_IRG(res, irg);
748         return res;
749 }  /* new_bd_Mux */
750
751 static ir_node *
752 new_bd_Psi(dbg_info *db, ir_node *block,
753            int arity, ir_node *cond[], ir_node *vals[], ir_mode *mode) {
754         ir_node  **in;
755         ir_node  *res;
756         ir_graph *irg = current_ir_graph;
757         int i;
758
759         NEW_ARR_A(ir_node *, in, 2 * arity + 1);
760
761         for (i = 0; i < arity; ++i) {
762                 in[2 * i]     = cond[i];
763                 in[2 * i + 1] = vals[i];
764         }
765         in[2 * i] = vals[i];
766
767         res = new_ir_node(db, irg, block, op_Psi, mode, 2 * arity + 1, in);
768         assert(res);
769
770         res = optimize_node(res);
771         IRN_VRFY_IRG(res, irg);
772         return res;
773 }  /* new_bd_Psi */
774
775 static ir_node *
776 new_bd_CopyB(dbg_info *db, ir_node *block,
777     ir_node *store, ir_node *dst, ir_node *src, ir_type *data_type) {
778         ir_node  *in[3];
779         ir_node  *res;
780         ir_graph *irg = current_ir_graph;
781
782         in[0] = store;
783         in[1] = dst;
784         in[2] = src;
785
786         res = new_ir_node(db, irg, block, op_CopyB, mode_T, 3, in);
787
788         res->attr.copyb.exc.pin_state = op_pin_state_pinned;
789         res->attr.copyb.data_type     = data_type;
790         res = optimize_node(res);
791         IRN_VRFY_IRG(res, irg);
792         return res;
793 }  /* new_bd_CopyB */
794
795 static ir_node *
796 new_bd_InstOf(dbg_info *db, ir_node *block, ir_node *store,
797               ir_node *objptr, ir_type *type) {
798         ir_node  *in[2];
799         ir_node  *res;
800         ir_graph *irg = current_ir_graph;
801
802         in[0] = store;
803         in[1] = objptr;
804         res = new_ir_node(db, irg, block, op_Sel, mode_T, 2, in);
805         res->attr.instof.type = type;
806         res = optimize_node(res);
807         IRN_VRFY_IRG(res, irg);
808         return res;
809 }  /* new_bd_InstOf */
810
811 static ir_node *
812 new_bd_Raise(dbg_info *db, ir_node *block, ir_node *store, ir_node *obj) {
813         ir_node  *in[2];
814         ir_node  *res;
815         ir_graph *irg = current_ir_graph;
816
817         in[0] = store;
818         in[1] = obj;
819         res = new_ir_node(db, irg, block, op_Raise, mode_T, 2, in);
820         res = optimize_node(res);
821         IRN_VRFY_IRG(res, irg);
822         return res;
823 }  /* new_bd_Raise */
824
825 static ir_node *
826 new_bd_Bound(dbg_info *db, ir_node *block,
827              ir_node *store, ir_node *idx, ir_node *lower, ir_node *upper) {
828         ir_node  *in[4];
829         ir_node  *res;
830         ir_graph *irg = current_ir_graph;
831
832         in[0] = store;
833         in[1] = idx;
834         in[2] = lower;
835         in[3] = upper;
836         res = new_ir_node(db, irg, block, op_Bound, mode_T, 4, in);
837         res->attr.bound.exc.pin_state = op_pin_state_pinned;
838         res = optimize_node(res);
839         IRN_VRFY_IRG(res, irg);
840         return res;
841 }  /* new_bd_Bound */
842
843 static ir_node *
844 new_bd_Pin(dbg_info *db, ir_node *block, ir_node *node) {
845         ir_node  *res;
846         ir_graph *irg = current_ir_graph;
847
848         res = new_ir_node(db, irg, block, op_Pin, get_irn_mode(node), 1, &node);
849         res = optimize_node(res);
850         IRN_VRFY_IRG(res, irg);
851         return res;
852 }  /* new_bd_Pin */
853
854 static ir_node *
855 new_bd_ASM(dbg_info *db, ir_node *block, int arity, ir_node *in[], ir_asm_constraint *inputs,
856            int n_outs, ir_asm_constraint *outputs, int n_clobber, ident *clobber[], ident *asm_text) {
857         ir_node  *res;
858         ir_graph *irg = current_ir_graph;
859         (void) clobber;
860
861         res = new_ir_node(db, irg, block, op_ASM, mode_T, arity, in);
862         res->attr.assem.pin_state = op_pin_state_pinned;
863         res->attr.assem.inputs    = NEW_ARR_D(ir_asm_constraint, irg->obst, arity);
864         res->attr.assem.outputs   = NEW_ARR_D(ir_asm_constraint, irg->obst, n_outs);
865         res->attr.assem.clobber   = NEW_ARR_D(ident *, irg->obst, n_clobber);
866         res->attr.assem.asm_text  = asm_text;
867
868         memcpy(res->attr.assem.inputs,  inputs,  sizeof(inputs[0]) * arity);
869         memcpy(res->attr.assem.outputs, outputs, sizeof(outputs[0]) * n_outs);
870         memcpy(res->attr.assem.clobber, clobber, sizeof(clobber[0]) * n_clobber);
871
872         res = optimize_node(res);
873         IRN_VRFY_IRG(res, irg);
874         return res;
875 }  /* new_bd_ASM */
876
877 /* --------------------------------------------- */
878 /* private interfaces, for professional use only */
879 /* --------------------------------------------- */
880
881 /* Constructs a Block with a fixed number of predecessors.
882    Does not set current_block.  Can not be used with automatic
883    Phi node construction. */
884 ir_node *
885 new_rd_Block(dbg_info *db, ir_graph *irg, int arity, ir_node **in) {
886         ir_graph *rem = current_ir_graph;
887         ir_node  *res;
888
889         current_ir_graph = irg;
890         res = new_bd_Block(db, arity, in);
891         current_ir_graph = rem;
892
893         return res;
894 }  /* new_rd_Block */
895
896 ir_node *
897 new_rd_Start(dbg_info *db, ir_graph *irg, ir_node *block) {
898         ir_graph *rem = current_ir_graph;
899         ir_node  *res;
900
901         current_ir_graph = irg;
902         res = new_bd_Start(db, block);
903         current_ir_graph = rem;
904
905         return res;
906 }  /* new_rd_Start */
907
908 ir_node *
909 new_rd_End(dbg_info *db, ir_graph *irg, ir_node *block) {
910         ir_node  *res;
911         ir_graph *rem = current_ir_graph;
912
913         current_ir_graph = irg;
914         res = new_bd_End(db, block);
915         current_ir_graph = rem;
916
917         return res;
918 }  /* new_rd_End */
919
920 /* Creates a Phi node with all predecessors.  Calling this constructor
921    is only allowed if the corresponding block is mature.  */
922 ir_node *
923 new_rd_Phi(dbg_info *db, ir_graph *irg, ir_node *block, int arity, ir_node **in, ir_mode *mode) {
924         ir_node  *res;
925         ir_graph *rem = current_ir_graph;
926
927         current_ir_graph = irg;
928         res = new_bd_Phi(db, block,arity, in, mode);
929         current_ir_graph = rem;
930
931         return res;
932 }  /* new_rd_Phi */
933
934 ir_node *
935 new_rd_Const_type(dbg_info *db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con, ir_type *tp) {
936         ir_node  *res;
937         ir_graph *rem = current_ir_graph;
938
939         current_ir_graph = irg;
940         res = new_bd_Const_type(db, block, mode, con, tp);
941         current_ir_graph = rem;
942
943         return res;
944 }  /* new_rd_Const_type */
945
946 ir_node *
947 new_rd_Const(dbg_info *db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con) {
948         ir_node  *res;
949         ir_graph *rem = current_ir_graph;
950
951         current_ir_graph = irg;
952         res = new_bd_Const_type(db, block, mode, con, firm_unknown_type);
953         current_ir_graph = rem;
954
955         return res;
956 }  /* new_rd_Const */
957
958 ir_node *
959 new_rd_Const_long(dbg_info *db, ir_graph *irg, ir_node *block, ir_mode *mode, long value) {
960         return new_rd_Const(db, irg, block, mode, new_tarval_from_long(value, mode));
961 }  /* new_rd_Const_long */
962
963 ir_node *
964 new_rd_Id(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *val, ir_mode *mode) {
965         ir_node  *res;
966         ir_graph *rem = current_ir_graph;
967
968         current_ir_graph = irg;
969         res = new_bd_Id(db, block, val, mode);
970         current_ir_graph = rem;
971
972         return res;
973 }  /* new_rd_Id */
974
975 ir_node *
976 new_rd_Proj(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg, ir_mode *mode,
977             long proj) {
978         ir_node  *res;
979         ir_graph *rem = current_ir_graph;
980
981         current_ir_graph = irg;
982         res = new_bd_Proj(db, block, arg, mode, proj);
983         current_ir_graph = rem;
984
985         return res;
986 }  /* new_rd_Proj */
987
988 ir_node *
989 new_rd_defaultProj(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg,
990                    long max_proj) {
991         ir_node  *res;
992         ir_graph *rem = current_ir_graph;
993
994         current_ir_graph = irg;
995         res = new_bd_defaultProj(db, block, arg, max_proj);
996         current_ir_graph = rem;
997
998         return res;
999 }  /* new_rd_defaultProj */
1000
1001 ir_node *
1002 new_rd_Conv(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *op, ir_mode *mode) {
1003         ir_node  *res;
1004         ir_graph *rem = current_ir_graph;
1005
1006         current_ir_graph = irg;
1007         res = new_bd_Conv(db, block, op, mode, 0);
1008         current_ir_graph = rem;
1009
1010         return res;
1011 }  /* new_rd_Conv */
1012
1013 ir_node *
1014 new_rd_Cast(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *op, ir_type *to_tp) {
1015         ir_node  *res;
1016         ir_graph *rem = current_ir_graph;
1017
1018         current_ir_graph = irg;
1019         res = new_bd_Cast(db, block, op, to_tp);
1020         current_ir_graph = rem;
1021
1022         return res;
1023 }  /* new_rd_Cast */
1024
1025 ir_node *
1026 new_rd_Tuple(dbg_info *db, ir_graph *irg, ir_node *block, int arity, ir_node **in) {
1027         ir_node  *res;
1028         ir_graph *rem = current_ir_graph;
1029
1030         current_ir_graph = irg;
1031         res = new_bd_Tuple(db, block, arity, in);
1032         current_ir_graph = rem;
1033
1034         return res;
1035 }  /* new_rd_Tuple */
1036
1037 NEW_RD_BINOP(Add)
1038 NEW_RD_BINOP(Sub)
1039 NEW_RD_UNOP(Minus)
1040 NEW_RD_BINOP(Mul)
1041 NEW_RD_BINOP(Mulh)
1042 NEW_RD_DIVOP(Quot)
1043 NEW_RD_DIVOP(DivMod)
1044 NEW_RD_DIVOP(Div)
1045 NEW_RD_DIVOP(Mod)
1046 NEW_RD_BINOP(And)
1047 NEW_RD_BINOP(Or)
1048 NEW_RD_BINOP(Eor)
1049 NEW_RD_UNOP(Not)
1050 NEW_RD_BINOP(Shl)
1051 NEW_RD_BINOP(Shr)
1052 NEW_RD_BINOP(Shrs)
1053 NEW_RD_BINOP(Rotl)
1054 NEW_RD_UNOP(Abs)
1055 NEW_RD_BINOP(Carry)
1056 NEW_RD_BINOP(Borrow)
1057
1058 /* creates a rd constructor for an divRL */
1059 ir_node *new_rd_DivRL(dbg_info *db, ir_graph *irg, ir_node *block,
1060             ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state)
1061 {
1062         ir_node  *res;
1063         ir_graph *rem = current_ir_graph;
1064         current_ir_graph = irg;
1065         res = new_bd_DivRL(db, block, memop, op1, op2, mode, state);
1066         current_ir_graph = rem;
1067         return res;
1068 }
1069
1070 ir_node *
1071 new_rd_Cmp(dbg_info *db, ir_graph *irg, ir_node *block,
1072            ir_node *op1, ir_node *op2) {
1073         ir_node  *res;
1074         ir_graph *rem = current_ir_graph;
1075
1076         current_ir_graph = irg;
1077         res = new_bd_Cmp(db, block, op1, op2);
1078         current_ir_graph = rem;
1079
1080         return res;
1081 }  /* new_rd_Cmp */
1082
1083 ir_node *
1084 new_rd_Jmp(dbg_info *db, ir_graph *irg, ir_node *block) {
1085         ir_node  *res;
1086         ir_graph *rem = current_ir_graph;
1087
1088         current_ir_graph = irg;
1089         res = new_bd_Jmp(db, block);
1090         current_ir_graph = rem;
1091
1092         return res;
1093 }  /* new_rd_Jmp */
1094
1095 ir_node *
1096 new_rd_IJmp(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *tgt) {
1097         ir_node  *res;
1098         ir_graph *rem = current_ir_graph;
1099
1100         current_ir_graph = irg;
1101         res = new_bd_IJmp(db, block, tgt);
1102         current_ir_graph = rem;
1103
1104         return res;
1105 }  /* new_rd_IJmp */
1106
1107 ir_node *
1108 new_rd_Cond(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *c) {
1109         ir_node  *res;
1110         ir_graph *rem = current_ir_graph;
1111
1112         current_ir_graph = irg;
1113         res = new_bd_Cond(db, block, c);
1114         current_ir_graph = rem;
1115
1116         return res;
1117 }  /* new_rd_Cond */
1118
1119 ir_node *
1120 new_rd_Call(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
1121             ir_node *callee, int arity, ir_node **in, ir_type *tp) {
1122         ir_node  *res;
1123         ir_graph *rem = current_ir_graph;
1124
1125         current_ir_graph = irg;
1126         res = new_bd_Call(db, block, store, callee, arity, in, tp);
1127         current_ir_graph = rem;
1128
1129         return res;
1130 }  /* new_rd_Call */
1131
1132 ir_node *
1133 new_rd_Return(dbg_info *db, ir_graph *irg, ir_node *block,
1134               ir_node *store, int arity, ir_node **in) {
1135         ir_node  *res;
1136         ir_graph *rem = current_ir_graph;
1137
1138         current_ir_graph = irg;
1139         res = new_bd_Return(db, block, store, arity, in);
1140         current_ir_graph = rem;
1141
1142         return res;
1143 }  /* new_rd_Return */
1144
1145 ir_node *
1146 new_rd_Load(dbg_info *db, ir_graph *irg, ir_node *block,
1147             ir_node *store, ir_node *adr, ir_mode *mode) {
1148         ir_node  *res;
1149         ir_graph *rem = current_ir_graph;
1150
1151         current_ir_graph = irg;
1152         res = new_bd_Load(db, block, store, adr, mode);
1153         current_ir_graph = rem;
1154
1155         return res;
1156 }  /* new_rd_Load */
1157
1158 ir_node *
1159 new_rd_Store(dbg_info *db, ir_graph *irg, ir_node *block,
1160              ir_node *store, ir_node *adr, ir_node *val) {
1161         ir_node  *res;
1162         ir_graph *rem = current_ir_graph;
1163
1164         current_ir_graph = irg;
1165         res = new_bd_Store(db, block, store, adr, val);
1166         current_ir_graph = rem;
1167
1168         return res;
1169 }  /* new_rd_Store */
1170
1171 ir_node *
1172 new_rd_Alloc(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
1173              ir_node *size, ir_type *alloc_type, ir_where_alloc where) {
1174         ir_node  *res;
1175         ir_graph *rem = current_ir_graph;
1176
1177         current_ir_graph = irg;
1178         res = new_bd_Alloc(db, block, store, size, alloc_type, where);
1179         current_ir_graph = rem;
1180
1181         return res;
1182 }  /* new_rd_Alloc */
1183
1184 ir_node *
1185 new_rd_Free(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
1186             ir_node *ptr, ir_node *size, ir_type *free_type, ir_where_alloc where) {
1187         ir_node  *res;
1188         ir_graph *rem = current_ir_graph;
1189
1190         current_ir_graph = irg;
1191         res = new_bd_Free(db, block, store, ptr, size, free_type, where);
1192         current_ir_graph = rem;
1193
1194         return res;
1195 }  /* new_rd_Free */
1196
1197 ir_node *
1198 new_rd_simpleSel(dbg_info *db, ir_graph *irg, ir_node *block,
1199                  ir_node *store, ir_node *objptr, ir_entity *ent) {
1200         ir_node  *res;
1201         ir_graph *rem = current_ir_graph;
1202
1203         current_ir_graph = irg;
1204         res = new_bd_Sel(db, block, store, objptr, 0, NULL, ent);
1205         current_ir_graph = rem;
1206
1207         return res;
1208 }  /* new_rd_simpleSel */
1209
1210 ir_node *
1211 new_rd_Sel(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store, ir_node *objptr,
1212            int arity, ir_node **in, ir_entity *ent) {
1213         ir_node  *res;
1214         ir_graph *rem = current_ir_graph;
1215
1216         current_ir_graph = irg;
1217         res = new_bd_Sel(db, block, store, objptr, arity, in, ent);
1218         current_ir_graph = rem;
1219
1220         return res;
1221 }  /* new_rd_Sel */
1222
1223 ir_node *
1224 new_rd_SymConst_type(dbg_info *db, ir_graph *irg, ir_node *block, ir_mode *mode,
1225                      symconst_symbol value, symconst_kind symkind, ir_type *tp) {
1226         ir_node  *res;
1227         ir_graph *rem = current_ir_graph;
1228
1229         current_ir_graph = irg;
1230         res = new_bd_SymConst_type(db, block, mode, value, symkind, tp);
1231         current_ir_graph = rem;
1232
1233         return res;
1234 }  /* new_rd_SymConst_type */
1235
1236 ir_node *
1237 new_rd_SymConst(dbg_info *db, ir_graph *irg, ir_node *block, ir_mode *mode,
1238                 symconst_symbol value, symconst_kind symkind) {
1239         return new_rd_SymConst_type(db, irg, block, mode, value, symkind, firm_unknown_type);
1240 }  /* new_rd_SymConst */
1241
1242  ir_node *new_rd_SymConst_addr_ent(dbg_info *db, ir_graph *irg, ir_mode *mode, ir_entity *symbol, ir_type *tp) {
1243         symconst_symbol sym;
1244         sym.entity_p = symbol;
1245         return new_rd_SymConst_type(db, irg, get_irg_start_block(irg), mode, sym, symconst_addr_ent, tp);
1246 }  /* new_rd_SymConst_addr_ent */
1247
1248 ir_node *new_rd_SymConst_ofs_ent(dbg_info *db, ir_graph *irg, ir_mode *mode, ir_entity *symbol, ir_type *tp) {
1249         symconst_symbol sym;
1250         sym.entity_p = symbol;
1251         return new_rd_SymConst_type(db, irg, get_irg_start_block(irg), mode, sym, symconst_ofs_ent, tp);
1252 }  /* new_rd_SymConst_ofs_ent */
1253
1254 ir_node *new_rd_SymConst_addr_name(dbg_info *db, ir_graph *irg, ir_mode *mode, ident *symbol, ir_type *tp) {
1255         symconst_symbol sym;
1256         sym.ident_p = symbol;
1257         return new_rd_SymConst_type(db, irg, get_irg_start_block(irg), mode, sym, symconst_addr_name, tp);
1258 }  /* new_rd_SymConst_addr_name */
1259
1260 ir_node *new_rd_SymConst_type_tag(dbg_info *db, ir_graph *irg, ir_mode *mode, ir_type *symbol, ir_type *tp) {
1261         symconst_symbol sym;
1262         sym.type_p = symbol;
1263         return new_rd_SymConst_type(db, irg, get_irg_start_block(irg), mode, sym, symconst_type_tag, tp);
1264 }  /* new_rd_SymConst_type_tag */
1265
1266 ir_node *new_rd_SymConst_size(dbg_info *db, ir_graph *irg, ir_mode *mode, ir_type *symbol, ir_type *tp) {
1267         symconst_symbol sym;
1268         sym.type_p = symbol;
1269         return new_rd_SymConst_type(db, irg, get_irg_start_block(irg), mode, sym, symconst_type_size, tp);
1270 }  /* new_rd_SymConst_size */
1271
1272 ir_node *new_rd_SymConst_align(dbg_info *db, ir_graph *irg, ir_mode *mode, ir_type *symbol, ir_type *tp) {
1273         symconst_symbol sym;
1274         sym.type_p = symbol;
1275         return new_rd_SymConst_type(db, irg, get_irg_start_block(irg), mode, sym, symconst_type_align, tp);
1276 }  /* new_rd_SymConst_align */
1277
1278 ir_node *
1279 new_rd_Sync(dbg_info *db, ir_graph *irg, ir_node *block, int arity, ir_node *in[]) {
1280         ir_node  *res;
1281         ir_graph *rem = current_ir_graph;
1282         int      i;
1283
1284         current_ir_graph = irg;
1285         res = new_bd_Sync(db, block);
1286         current_ir_graph = rem;
1287
1288         for (i = 0; i < arity; ++i)
1289                 add_Sync_pred(res, in[i]);
1290
1291         return res;
1292 }  /* new_rd_Sync */
1293
1294 ir_node *
1295 new_rd_Bad(ir_graph *irg) {
1296         return get_irg_bad(irg);
1297 }  /* new_rd_Bad */
1298
1299 ir_node *
1300 new_rd_Confirm(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *val, ir_node *bound, pn_Cmp cmp) {
1301         ir_node  *res;
1302         ir_graph *rem = current_ir_graph;
1303
1304         current_ir_graph = irg;
1305         res = new_bd_Confirm(db, block, val, bound, cmp);
1306         current_ir_graph = rem;
1307
1308         return res;
1309 }  /* new_rd_Confirm */
1310
1311 ir_node *
1312 new_rd_Unknown(ir_graph *irg, ir_mode *m) {
1313         ir_node  *res;
1314         ir_graph *rem = current_ir_graph;
1315
1316         current_ir_graph = irg;
1317         res = new_bd_Unknown(m);
1318         current_ir_graph = rem;
1319
1320         return res;
1321 }  /* new_rd_Unknown */
1322
1323 ir_node *
1324 new_rd_CallBegin(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *call) {
1325         ir_node  *res;
1326         ir_graph *rem = current_ir_graph;
1327
1328         current_ir_graph = irg;
1329         res = new_bd_CallBegin(db, block, call);
1330         current_ir_graph = rem;
1331
1332         return res;
1333 }  /* new_rd_CallBegin */
1334
1335 ir_node *
1336 new_rd_EndReg(dbg_info *db, ir_graph *irg, ir_node *block) {
1337         ir_node *res;
1338
1339         res = new_ir_node(db, irg, block, op_EndReg, mode_T, -1, NULL);
1340         set_irg_end_reg(irg, res);
1341         IRN_VRFY_IRG(res, irg);
1342         return res;
1343 }  /* new_rd_EndReg */
1344
1345 ir_node *
1346 new_rd_EndExcept(dbg_info *db, ir_graph *irg, ir_node *block) {
1347         ir_node *res;
1348
1349         res = new_ir_node(db, irg, block, op_EndExcept, mode_T, -1, NULL);
1350         set_irg_end_except(irg, res);
1351         IRN_VRFY_IRG (res, irg);
1352         return res;
1353 }  /* new_rd_EndExcept */
1354
1355 ir_node *
1356 new_rd_Break(dbg_info *db, ir_graph *irg, ir_node *block) {
1357         ir_node  *res;
1358         ir_graph *rem = current_ir_graph;
1359
1360         current_ir_graph = irg;
1361         res = new_bd_Break(db, block);
1362         current_ir_graph = rem;
1363
1364         return res;
1365 }  /* new_rd_Break */
1366
1367 ir_node *
1368 new_rd_Filter(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg, ir_mode *mode,
1369               long proj) {
1370         ir_node  *res;
1371         ir_graph *rem = current_ir_graph;
1372
1373         current_ir_graph = irg;
1374         res = new_bd_Filter(db, block, arg, mode, proj);
1375         current_ir_graph = rem;
1376
1377         return res;
1378 }  /* new_rd_Filter */
1379
1380 ir_node *
1381 new_rd_NoMem(ir_graph *irg) {
1382         return get_irg_no_mem(irg);
1383 }  /* new_rd_NoMem */
1384
1385 ir_node *
1386 new_rd_Mux(dbg_info *db, ir_graph *irg, ir_node *block,
1387            ir_node *sel, ir_node *ir_false, ir_node *ir_true, ir_mode *mode) {
1388         ir_node  *res;
1389         ir_graph *rem = current_ir_graph;
1390
1391         current_ir_graph = irg;
1392         res = new_bd_Mux(db, block, sel, ir_false, ir_true, mode);
1393         current_ir_graph = rem;
1394
1395         return res;
1396 }  /* new_rd_Mux */
1397
1398 ir_node *
1399 new_rd_Psi(dbg_info *db, ir_graph *irg, ir_node *block,
1400            int arity, ir_node *cond[], ir_node *vals[], ir_mode *mode) {
1401         ir_node  *res;
1402         ir_graph *rem = current_ir_graph;
1403
1404         current_ir_graph = irg;
1405         res = new_bd_Psi(db, block, arity, cond, vals, mode);
1406         current_ir_graph = rem;
1407
1408         return res;
1409 }  /* new_rd_Psi */
1410
1411 ir_node *new_rd_CopyB(dbg_info *db, ir_graph *irg, ir_node *block,
1412                       ir_node *store, ir_node *dst, ir_node *src, ir_type *data_type) {
1413         ir_node  *res;
1414         ir_graph *rem = current_ir_graph;
1415
1416         current_ir_graph = irg;
1417         res = new_bd_CopyB(db, block, store, dst, src, data_type);
1418         current_ir_graph = rem;
1419
1420         return res;
1421 }  /* new_rd_CopyB */
1422
1423 ir_node *
1424 new_rd_InstOf(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
1425               ir_node *objptr, ir_type *type) {
1426         ir_node  *res;
1427         ir_graph *rem = current_ir_graph;
1428
1429         current_ir_graph = irg;
1430         res = new_bd_InstOf(db, block, store, objptr, type);
1431         current_ir_graph = rem;
1432
1433         return res;
1434 }  /* new_rd_InstOf */
1435
1436 ir_node *
1437 new_rd_Raise(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store, ir_node *obj) {
1438         ir_node  *res;
1439         ir_graph *rem = current_ir_graph;
1440
1441         current_ir_graph = irg;
1442         res = new_bd_Raise(db, block, store, obj);
1443         current_ir_graph = rem;
1444
1445         return res;
1446 }  /* new_rd_Raise */
1447
1448 ir_node *new_rd_Bound(dbg_info *db, ir_graph *irg, ir_node *block,
1449                       ir_node *store, ir_node *idx, ir_node *lower, ir_node *upper) {
1450         ir_node  *res;
1451         ir_graph *rem = current_ir_graph;
1452
1453         current_ir_graph = irg;
1454         res = new_bd_Bound(db, block, store, idx, lower, upper);
1455         current_ir_graph = rem;
1456
1457         return res;
1458 }  /* new_rd_Bound */
1459
1460 ir_node *new_rd_Pin(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *node) {
1461         ir_node  *res;
1462         ir_graph *rem = current_ir_graph;
1463
1464         current_ir_graph = irg;
1465         res = new_bd_Pin(db, block, node);
1466         current_ir_graph = rem;
1467
1468         return res;
1469 }  /* new_rd_Pin */
1470
1471 ir_node *new_rd_ASM(dbg_info *db, ir_graph *irg, ir_node *block,
1472                     int arity, ir_node *in[], ir_asm_constraint *inputs,
1473                     int n_outs, ir_asm_constraint *outputs,
1474                     int n_clobber, ident *clobber[], ident *asm_text) {
1475         ir_node  *res;
1476         ir_graph *rem = current_ir_graph;
1477
1478         current_ir_graph = irg;
1479         res = new_bd_ASM(db, block, arity, in, inputs, n_outs, outputs, n_clobber, clobber, asm_text);
1480         current_ir_graph = rem;
1481
1482         return res;
1483 }  /* new_rd_ASM */
1484
1485
1486 ir_node *new_r_Block(ir_graph *irg,  int arity, ir_node **in) {
1487         return new_rd_Block(NULL, irg, arity, in);
1488 }
1489 ir_node *new_r_Start(ir_graph *irg, ir_node *block) {
1490         return new_rd_Start(NULL, irg, block);
1491 }
1492 ir_node *new_r_End(ir_graph *irg, ir_node *block) {
1493         return new_rd_End(NULL, irg, block);
1494 }
1495 ir_node *new_r_Jmp(ir_graph *irg, ir_node *block) {
1496         return new_rd_Jmp(NULL, irg, block);
1497 }
1498 ir_node *new_r_IJmp(ir_graph *irg, ir_node *block, ir_node *tgt) {
1499         return new_rd_IJmp(NULL, irg, block, tgt);
1500 }
1501 ir_node *new_r_Cond(ir_graph *irg, ir_node *block, ir_node *c) {
1502         return new_rd_Cond(NULL, irg, block, c);
1503 }
1504 ir_node *new_r_Return(ir_graph *irg, ir_node *block,
1505                       ir_node *store, int arity, ir_node **in) {
1506         return new_rd_Return(NULL, irg, block, store, arity, in);
1507 }
1508 ir_node *new_r_Const(ir_graph *irg, ir_node *block,
1509                      ir_mode *mode, tarval *con) {
1510         return new_rd_Const(NULL, irg, block, mode, con);
1511 }
1512 ir_node *new_r_Const_long(ir_graph *irg, ir_node *block,
1513                           ir_mode *mode, long value) {
1514         return new_rd_Const_long(NULL, irg, block, mode, value);
1515 }
1516 ir_node *new_r_Const_type(ir_graph *irg, ir_node *block,
1517                           ir_mode *mode, tarval *con, ir_type *tp) {
1518         return new_rd_Const_type(NULL, irg, block, mode, con, tp);
1519 }
1520 ir_node *new_r_SymConst(ir_graph *irg, ir_node *block, ir_mode *mode,
1521                         symconst_symbol value, symconst_kind symkind) {
1522         return new_rd_SymConst(NULL, irg, block, mode, value, symkind);
1523 }
1524 ir_node *new_r_simpleSel(ir_graph *irg, ir_node *block, ir_node *store,
1525                          ir_node *objptr, ir_entity *ent) {
1526         return new_rd_Sel(NULL, irg, block, store, objptr, 0, NULL, ent);
1527 }
1528 ir_node *new_r_Sel(ir_graph *irg, ir_node *block, ir_node *store,
1529                    ir_node *objptr, int n_index, ir_node **index,
1530                    ir_entity *ent) {
1531         return new_rd_Sel(NULL, irg, block, store, objptr, n_index, index, ent);
1532 }
1533 ir_node *new_r_Call(ir_graph *irg, ir_node *block, ir_node *store,
1534                     ir_node *callee, int arity, ir_node **in,
1535                     ir_type *tp) {
1536         return new_rd_Call(NULL, irg, block, store, callee, arity, in, tp);
1537 }
1538 ir_node *new_r_Add(ir_graph *irg, ir_node *block,
1539                    ir_node *op1, ir_node *op2, ir_mode *mode) {
1540         return new_rd_Add(NULL, irg, block, op1, op2, mode);
1541 }
1542 ir_node *new_r_Sub(ir_graph *irg, ir_node *block,
1543                    ir_node *op1, ir_node *op2, ir_mode *mode) {
1544         return new_rd_Sub(NULL, irg, block, op1, op2, mode);
1545 }
1546 ir_node *new_r_Minus(ir_graph *irg, ir_node *block,
1547                      ir_node *op,  ir_mode *mode) {
1548         return new_rd_Minus(NULL, irg, block,  op, mode);
1549 }
1550 ir_node *new_r_Mul(ir_graph *irg, ir_node *block,
1551                    ir_node *op1, ir_node *op2, ir_mode *mode) {
1552         return new_rd_Mul(NULL, irg, block, op1, op2, mode);
1553 }
1554 ir_node *new_r_Mulh(ir_graph *irg, ir_node *block,
1555                    ir_node *op1, ir_node *op2, ir_mode *mode) {
1556         return new_rd_Mulh(NULL, irg, block, op1, op2, mode);
1557 }
1558 ir_node *new_r_Quot(ir_graph *irg, ir_node *block,
1559                     ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state) {
1560         return new_rd_Quot(NULL, irg, block, memop, op1, op2, mode, state);
1561 }
1562 ir_node *new_r_DivMod(ir_graph *irg, ir_node *block,
1563                       ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state) {
1564         return new_rd_DivMod(NULL, irg, block, memop, op1, op2, mode, state);
1565 }
1566 ir_node *new_r_Div(ir_graph *irg, ir_node *block,
1567                    ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state) {
1568         return new_rd_Div(NULL, irg, block, memop, op1, op2, mode, state);
1569 }
1570 ir_node *new_r_DivRL(ir_graph *irg, ir_node *block,
1571                    ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state) {
1572         return new_rd_DivRL(NULL, irg, block, memop, op1, op2, mode, state);
1573 }
1574 ir_node *new_r_Mod(ir_graph *irg, ir_node *block,
1575                    ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state) {
1576         return new_rd_Mod(NULL, irg, block, memop, op1, op2, mode, state);
1577 }
1578 ir_node *new_r_Abs(ir_graph *irg, ir_node *block,
1579                    ir_node *op, ir_mode *mode) {
1580         return new_rd_Abs(NULL, irg, block, op, mode);
1581 }
1582 ir_node *new_r_And(ir_graph *irg, ir_node *block,
1583                    ir_node *op1, ir_node *op2, ir_mode *mode) {
1584         return new_rd_And(NULL, irg, block,  op1, op2, mode);
1585 }
1586 ir_node *new_r_Or(ir_graph *irg, ir_node *block,
1587                   ir_node *op1, ir_node *op2, ir_mode *mode) {
1588         return new_rd_Or(NULL, irg, block,  op1, op2, mode);
1589 }
1590 ir_node *new_r_Eor(ir_graph *irg, ir_node *block,
1591                    ir_node *op1, ir_node *op2, ir_mode *mode) {
1592         return new_rd_Eor(NULL, irg, block,  op1, op2, mode);
1593 }
1594 ir_node *new_r_Not(ir_graph *irg, ir_node *block,
1595                    ir_node *op, ir_mode *mode) {
1596         return new_rd_Not(NULL, irg, block, op, mode);
1597 }
1598 ir_node *new_r_Shl(ir_graph *irg, ir_node *block,
1599                    ir_node *op, ir_node *k, ir_mode *mode) {
1600         return new_rd_Shl(NULL, irg, block, op, k, mode);
1601 }
1602 ir_node *new_r_Shr(ir_graph *irg, ir_node *block,
1603                    ir_node *op, ir_node *k, ir_mode *mode) {
1604         return new_rd_Shr(NULL, irg, block, op, k, mode);
1605 }
1606 ir_node *new_r_Shrs(ir_graph *irg, ir_node *block,
1607                     ir_node *op, ir_node *k, ir_mode *mode) {
1608         return new_rd_Shrs(NULL, irg, block, op, k, mode);
1609 }
1610 ir_node *new_r_Rotl(ir_graph *irg, ir_node *block,
1611                    ir_node *op, ir_node *k, ir_mode *mode) {
1612         return new_rd_Rotl(NULL, irg, block, op, k, mode);
1613 }
1614 ir_node *new_r_Carry(ir_graph *irg, ir_node *block,
1615                      ir_node *op, ir_node *k, ir_mode *mode) {
1616         return new_rd_Carry(NULL, irg, block, op, k, mode);
1617 }
1618 ir_node *new_r_Borrow(ir_graph *irg, ir_node *block,
1619                       ir_node *op, ir_node *k, ir_mode *mode) {
1620         return new_rd_Borrow(NULL, irg, block, op, k, mode);
1621 }
1622 ir_node *new_r_Cmp(ir_graph *irg, ir_node *block,
1623                    ir_node *op1, ir_node *op2) {
1624         return new_rd_Cmp(NULL, irg, block, op1, op2);
1625 }
1626 ir_node *new_r_Conv(ir_graph *irg, ir_node *block,
1627                     ir_node *op, ir_mode *mode) {
1628         return new_rd_Conv(NULL, irg, block, op, mode);
1629 }
1630 ir_node *new_r_Cast(ir_graph *irg, ir_node *block, ir_node *op, ir_type *to_tp) {
1631         return new_rd_Cast(NULL, irg, block, op, to_tp);
1632 }
1633 ir_node *new_r_Phi(ir_graph *irg, ir_node *block, int arity,
1634                    ir_node **in, ir_mode *mode) {
1635         return new_rd_Phi(NULL, irg, block, arity, in, mode);
1636 }
1637 ir_node *new_r_Load(ir_graph *irg, ir_node *block,
1638                     ir_node *store, ir_node *adr, ir_mode *mode) {
1639         return new_rd_Load(NULL, irg, block, store, adr, mode);
1640 }
1641 ir_node *new_r_Store(ir_graph *irg, ir_node *block,
1642                      ir_node *store, ir_node *adr, ir_node *val) {
1643         return new_rd_Store(NULL, irg, block, store, adr, val);
1644 }
1645 ir_node *new_r_Alloc(ir_graph *irg, ir_node *block, ir_node *store,
1646                      ir_node *size, ir_type *alloc_type, ir_where_alloc where) {
1647         return new_rd_Alloc(NULL, irg, block, store, size, alloc_type, where);
1648 }
1649 ir_node *new_r_Free(ir_graph *irg, ir_node *block, ir_node *store,
1650                     ir_node *ptr, ir_node *size, ir_type *free_type, ir_where_alloc where) {
1651         return new_rd_Free(NULL, irg, block, store, ptr, size, free_type, where);
1652 }
1653 ir_node *new_r_Sync(ir_graph *irg, ir_node *block, int arity, ir_node *in[]) {
1654         return new_rd_Sync(NULL, irg, block, arity, in);
1655 }
1656 ir_node *new_r_Proj(ir_graph *irg, ir_node *block, ir_node *arg,
1657                     ir_mode *mode, long proj) {
1658         return new_rd_Proj(NULL, irg, block, arg, mode, proj);
1659 }
1660 ir_node *new_r_defaultProj(ir_graph *irg, ir_node *block, ir_node *arg,
1661                            long max_proj) {
1662         return new_rd_defaultProj(NULL, irg, block, arg, max_proj);
1663 }
1664 ir_node *new_r_Tuple(ir_graph *irg, ir_node *block,
1665                      int arity, ir_node **in) {
1666         return new_rd_Tuple(NULL, irg, block, arity, in );
1667 }
1668 ir_node *new_r_Id(ir_graph *irg, ir_node *block,
1669                   ir_node *val, ir_mode *mode) {
1670         return new_rd_Id(NULL, irg, block, val, mode);
1671 }
1672 ir_node *new_r_Bad(ir_graph *irg) {
1673         return new_rd_Bad(irg);
1674 }
1675 ir_node *new_r_Confirm(ir_graph *irg, ir_node *block, ir_node *val, ir_node *bound, pn_Cmp cmp) {
1676         return new_rd_Confirm(NULL, irg, block, val, bound, cmp);
1677 }
1678 ir_node *new_r_Unknown(ir_graph *irg, ir_mode *m) {
1679         return new_rd_Unknown(irg, m);
1680 }
1681 ir_node *new_r_CallBegin(ir_graph *irg, ir_node *block, ir_node *callee) {
1682         return new_rd_CallBegin(NULL, irg, block, callee);
1683 }
1684 ir_node *new_r_EndReg(ir_graph *irg, ir_node *block) {
1685         return new_rd_EndReg(NULL, irg, block);
1686 }
1687 ir_node *new_r_EndExcept(ir_graph *irg, ir_node *block) {
1688         return new_rd_EndExcept(NULL, irg, block);
1689 }
1690 ir_node *new_r_Break(ir_graph *irg, ir_node *block) {
1691         return new_rd_Break(NULL, irg, block);
1692 }
1693 ir_node *new_r_Filter(ir_graph *irg, ir_node *block, ir_node *arg,
1694                       ir_mode *mode, long proj) {
1695         return new_rd_Filter(NULL, irg, block, arg, mode, proj);
1696 }
1697 ir_node *new_r_NoMem(ir_graph *irg) {
1698         return new_rd_NoMem(irg);
1699 }
1700 ir_node *new_r_Mux(ir_graph *irg, ir_node *block,
1701                    ir_node *sel, ir_node *ir_false, ir_node *ir_true, ir_mode *mode) {
1702         return new_rd_Mux(NULL, irg, block, sel, ir_false, ir_true, mode);
1703 }
1704 ir_node *new_r_Psi(ir_graph *irg, ir_node *block,
1705                    int arity, ir_node *conds[], ir_node *vals[], ir_mode *mode) {
1706         return new_rd_Psi(NULL, irg, block, arity, conds, vals, mode);
1707 }
1708 ir_node *new_r_CopyB(ir_graph *irg, ir_node *block,
1709                      ir_node *store, ir_node *dst, ir_node *src, ir_type *data_type) {
1710         return new_rd_CopyB(NULL, irg, block, store, dst, src, data_type);
1711 }
1712 ir_node *new_r_InstOf(ir_graph *irg, ir_node *block, ir_node *store, ir_node *objptr,
1713                       ir_type *type) {
1714         return new_rd_InstOf(NULL, irg, block, store, objptr, type);
1715 }
1716 ir_node *new_r_Raise(ir_graph *irg, ir_node *block,
1717                      ir_node *store, ir_node *obj) {
1718         return new_rd_Raise(NULL, irg, block, store, obj);
1719 }
1720 ir_node *new_r_Bound(ir_graph *irg, ir_node *block,
1721                      ir_node *store, ir_node *idx, ir_node *lower, ir_node *upper) {
1722         return new_rd_Bound(NULL, irg, block, store, idx, lower, upper);
1723 }
1724 ir_node *new_r_Pin(ir_graph *irg, ir_node *block, ir_node *node) {
1725         return new_rd_Pin(NULL, irg, block, node);
1726 }
1727 ir_node *new_r_ASM(ir_graph *irg, ir_node *block,
1728                    int arity, ir_node *in[], ir_asm_constraint *inputs,
1729                    int n_outs, ir_asm_constraint *outputs,
1730                    int n_clobber, ident *clobber[], ident *asm_text) {
1731         return new_rd_ASM(NULL, irg, block, arity, in, inputs, n_outs, outputs, n_clobber, clobber, asm_text);
1732 }
1733
1734 /** ********************/
1735 /** public interfaces  */
1736 /** construction tools */
1737
1738 /**
1739  *
1740  *   - create a new Start node in the current block
1741  *
1742  *   @return s - pointer to the created Start node
1743  *
1744  *
1745  */
1746 ir_node *
1747 new_d_Start(dbg_info *db) {
1748         ir_node *res;
1749
1750         res = new_ir_node(db, current_ir_graph, current_ir_graph->current_block,
1751                           op_Start, mode_T, 0, NULL);
1752
1753         res = optimize_node(res);
1754         IRN_VRFY_IRG(res, current_ir_graph);
1755         return res;
1756 }  /* new_d_Start */
1757
1758 ir_node *
1759 new_d_End(dbg_info *db) {
1760         ir_node *res;
1761         res = new_ir_node(db, current_ir_graph,  current_ir_graph->current_block,
1762                           op_End, mode_X, -1, NULL);
1763         res = optimize_node(res);
1764         IRN_VRFY_IRG(res, current_ir_graph);
1765
1766         return res;
1767 }  /* new_d_End */
1768
1769 /* Constructs a Block with a fixed number of predecessors.
1770    Does set current_block.  Can be used with automatic Phi
1771    node construction. */
1772 ir_node *
1773 new_d_Block(dbg_info *db, int arity, ir_node **in) {
1774         ir_node *res;
1775         int i;
1776         int has_unknown = 0;
1777
1778         res = new_bd_Block(db, arity, in);
1779
1780         /* Create and initialize array for Phi-node construction. */
1781         if (get_irg_phase_state(current_ir_graph) == phase_building) {
1782                 res->attr.block.graph_arr = NEW_ARR_D(ir_node *, current_ir_graph->obst,
1783                                                       current_ir_graph->n_loc);
1784                 memset(res->attr.block.graph_arr, 0, sizeof(ir_node *)*current_ir_graph->n_loc);
1785         }
1786
1787         for (i = arity-1; i >= 0; i--)
1788                 if (get_irn_op(in[i]) == op_Unknown) {
1789                         has_unknown = 1;
1790                         break;
1791                 }
1792
1793         if (!has_unknown) res = optimize_node(res);
1794         current_ir_graph->current_block = res;
1795
1796         IRN_VRFY_IRG(res, current_ir_graph);
1797
1798         return res;
1799 }  /* new_d_Block */
1800
1801 /* ***********************************************************************/
1802 /* Methods necessary for automatic Phi node creation                     */
1803 /*
1804   ir_node *phi_merge            (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
1805   ir_node *get_r_value_internal (ir_node *block, int pos, ir_mode *mode);
1806   ir_node *new_rd_Phi0          (ir_graph *irg, ir_node *block, ir_mode *mode)
1807   ir_node *new_rd_Phi_in        (ir_graph *irg, ir_node *block, ir_mode *mode, ir_node **in, int ins)
1808
1809   Call Graph:   ( A ---> B == A "calls" B)
1810
1811        get_value         mature_immBlock
1812           |                   |
1813           |                   |
1814           |                   |
1815           |          ---> phi_merge
1816           |         /       /   \
1817           |        /       /     \
1818          \|/      /      |/_      \
1819        get_r_value_internal        |
1820                 |                  |
1821                 |                  |
1822                \|/                \|/
1823            new_rd_Phi0          new_rd_Phi_in
1824
1825 * *************************************************************************** */
1826
1827 /** Creates a Phi node with 0 predecessors. */
1828 static INLINE ir_node *
1829 new_rd_Phi0(ir_graph *irg, ir_node *block, ir_mode *mode) {
1830         ir_node *res;
1831
1832         res = new_ir_node(NULL, irg, block, op_Phi, mode, 0, NULL);
1833         IRN_VRFY_IRG(res, irg);
1834         return res;
1835 }  /* new_rd_Phi0 */
1836
1837
1838 /**
1839  * Internal constructor of a Phi node by a phi_merge operation.
1840  *
1841  * @param irg    the graph on which the Phi will be constructed
1842  * @param block  the block in which the Phi will be constructed
1843  * @param mode   the mod eof the Phi node
1844  * @param in     the input array of the phi node
1845  * @param ins    number of elements in the input array
1846  * @param phi0   in non-NULL: the Phi0 node in the same block that represents
1847  *               the value for which the new Phi is constructed
1848  */
1849 static INLINE ir_node *
1850 new_rd_Phi_in(ir_graph *irg, ir_node *block, ir_mode *mode,
1851               ir_node **in, int ins, ir_node *phi0) {
1852         int i;
1853         ir_node *res, *known;
1854
1855         /* Allocate a new node on the obstack.  The allocation copies the in
1856            array. */
1857         res = new_ir_node(NULL, irg, block, op_Phi, mode, ins, in);
1858         res->attr.phi.u.backedge = new_backedge_arr(irg->obst, ins);
1859
1860         /* This loop checks whether the Phi has more than one predecessor.
1861            If so, it is a real Phi node and we break the loop.  Else the
1862            Phi node merges the same definition on several paths and therefore
1863            is not needed. Don't consider Bad nodes! */
1864         known = res;
1865         for (i = ins - 1; i >= 0; --i)  {
1866                 assert(in[i]);
1867
1868                 in[i] = skip_Id(in[i]);  /* increases the number of freed Phis. */
1869
1870                 /* Optimize self referencing Phis:  We can't detect them yet properly, as
1871                 they still refer to the Phi0 they will replace.  So replace right now. */
1872                 if (phi0 && in[i] == phi0)
1873                         in[i] = res;
1874
1875                 if (in[i] == res || in[i] == known || is_Bad(in[i]))
1876                         continue;
1877
1878                 if (known == res)
1879                         known = in[i];
1880                 else
1881                         break;
1882         }
1883
1884         /* i < 0: there is at most one predecessor, we don't need a phi node. */
1885         if (i < 0) {
1886                 if (res != known) {
1887                         edges_node_deleted(res, current_ir_graph);
1888                         obstack_free(current_ir_graph->obst, res);
1889                         if (is_Phi(known)) {
1890                                 /* If pred is a phi node we want to optimize it: If loops are matured in a bad
1891                                    order, an enclosing Phi know may get superfluous. */
1892                                 res = optimize_in_place_2(known);
1893                                 if (res != known)
1894                                         exchange(known, res);
1895                         }
1896                         else
1897                                 res = known;
1898                 } else {
1899                         /* A undefined value, e.g., in unreachable code. */
1900                         res = new_Bad();
1901                 }
1902         } else {
1903                 res = optimize_node(res);  /* This is necessary to add the node to the hash table for cse. */
1904                 IRN_VRFY_IRG(res, irg);
1905                 /* Memory Phis in endless loops must be kept alive.
1906                    As we can't distinguish these easily we keep all of them alive. */
1907                 if (is_Phi(res) && mode == mode_M)
1908                         add_End_keepalive(get_irg_end(irg), res);
1909         }
1910
1911         return res;
1912 }  /* new_rd_Phi_in */
1913
1914 static ir_node *
1915 get_r_value_internal(ir_node *block, int pos, ir_mode *mode);
1916
1917 #if PRECISE_EXC_CONTEXT
1918 static ir_node *
1919 phi_merge(ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins);
1920
1921 /**
1922  * Construct a new frag_array for node n.
1923  * Copy the content from the current graph_arr of the corresponding block:
1924  * this is the current state.
1925  * Set ProjM(n) as current memory state.
1926  * Further the last entry in frag_arr of current block points to n.  This
1927  * constructs a chain block->last_frag_op-> ... first_frag_op of all frag ops in the block.
1928  */
1929 static INLINE ir_node **new_frag_arr(ir_node *n) {
1930         ir_node **arr;
1931         int opt;
1932
1933         arr = NEW_ARR_D (ir_node *, current_ir_graph->obst, current_ir_graph->n_loc);
1934         memcpy(arr, current_ir_graph->current_block->attr.block.graph_arr,
1935                sizeof(ir_node *)*current_ir_graph->n_loc);
1936
1937         /* turn off optimization before allocating Proj nodes, as res isn't
1938            finished yet. */
1939         opt = get_opt_optimize(); set_optimize(0);
1940         /* Here we rely on the fact that all frag ops have Memory as first result! */
1941         if (get_irn_op(n) == op_Call)
1942                 arr[0] = new_Proj(n, mode_M, pn_Call_M_except);
1943         else if (get_irn_op(n) == op_CopyB)
1944                 arr[0] = new_Proj(n, mode_M, pn_CopyB_M_except);
1945         else {
1946                 assert((pn_Quot_M == pn_DivMod_M) &&
1947                        (pn_Quot_M == pn_Div_M)    &&
1948                        (pn_Quot_M == pn_Mod_M)    &&
1949                        (pn_Quot_M == pn_Load_M)   &&
1950                        (pn_Quot_M == pn_Store_M)  &&
1951                        (pn_Quot_M == pn_Alloc_M)  &&
1952                        (pn_Quot_M == pn_Bound_M));
1953                 arr[0] = new_Proj(n, mode_M, pn_Alloc_M);
1954         }
1955         set_optimize(opt);
1956
1957         current_ir_graph->current_block->attr.block.graph_arr[current_ir_graph->n_loc-1] = n;
1958         return arr;
1959 }  /* new_frag_arr */
1960
1961 /**
1962  * Returns the frag_arr from a node.
1963  */
1964 static INLINE ir_node **get_frag_arr(ir_node *n) {
1965         switch (get_irn_opcode(n)) {
1966         case iro_Call:
1967                 return n->attr.call.exc.frag_arr;
1968         case iro_Alloc:
1969                 return n->attr.alloc.exc.frag_arr;
1970         case iro_Load:
1971                 return n->attr.load.exc.frag_arr;
1972         case iro_Store:
1973                 return n->attr.store.exc.frag_arr;
1974         default:
1975                 return n->attr.except.frag_arr;
1976         }
1977 }  /* get_frag_arr */
1978
1979 static void
1980 set_frag_value(ir_node **frag_arr, int pos, ir_node *val) {
1981 #ifdef DEBUG_libfirm
1982         int i;
1983
1984         for (i = 1024; i >= 0; --i)
1985 #else
1986         for (;;)
1987 #endif
1988         {
1989                 if (frag_arr[pos] == NULL)
1990                         frag_arr[pos] = val;
1991                 if (frag_arr[current_ir_graph->n_loc - 1] != NULL) {
1992                         ir_node **arr = get_frag_arr(frag_arr[current_ir_graph->n_loc - 1]);
1993                         assert(arr != frag_arr && "Endless recursion detected");
1994                         frag_arr = arr;
1995                 } else
1996                         return;
1997         }
1998         assert(!"potential endless recursion in set_frag_value");
1999 }  /* set_frag_value */
2000
2001 static ir_node *
2002 get_r_frag_value_internal(ir_node *block, ir_node *cfOp, int pos, ir_mode *mode) {
2003         ir_node *res;
2004         ir_node **frag_arr;
2005
2006         assert(is_fragile_op(cfOp) && !is_Bad(cfOp));
2007
2008         frag_arr = get_frag_arr(cfOp);
2009         res = frag_arr[pos];
2010         if (res == NULL) {
2011                 if (block->attr.block.graph_arr[pos] != NULL) {
2012                         /* There was a set_value() after the cfOp and no get_value() before that
2013                            set_value().  We must build a Phi node now. */
2014                         if (block->attr.block.is_matured) {
2015                                 int ins = get_irn_arity(block);
2016                                 ir_node **nin;
2017                                 NEW_ARR_A(ir_node *, nin, ins);
2018                                 res = phi_merge(block, pos, mode, nin, ins);
2019                         } else {
2020                                 res = new_rd_Phi0(current_ir_graph, block, mode);
2021                                 res->attr.phi.u.pos    = pos;
2022                                 res->attr.phi.next     = block->attr.block.phis;
2023                                 block->attr.block.phis = res;
2024                         }
2025                         assert(res != NULL);
2026                         /* It's a Phi, we can write this into all graph_arrs with NULL */
2027                         set_frag_value(block->attr.block.graph_arr, pos, res);
2028                 } else {
2029                         res = get_r_value_internal(block, pos, mode);
2030                         set_frag_value(block->attr.block.graph_arr, pos, res);
2031                 }
2032         }
2033         return res;
2034 }  /* get_r_frag_value_internal */
2035 #endif /* PRECISE_EXC_CONTEXT */
2036
2037 /**
2038  * Check whether a control flownode  cf_pred represents an exception flow.
2039  *
2040  * @param cf_pred     the control flow node
2041  * @param prev_cf_op  if cf_pred is a Proj, the predecessor node, else equal to cf_pred
2042  */
2043 static int is_exception_flow(ir_node *cf_pred, ir_node *prev_cf_op) {
2044         /*
2045          * Note: all projections from a raise are "exceptional control flow" we we handle it
2046          * like a normal Jmp, because there is no "regular" one.
2047          * That's why Raise is no "fragile_op"!
2048          */
2049         if (is_fragile_op(prev_cf_op)) {
2050                 if (is_Proj(cf_pred)) {
2051                         if (get_Proj_proj(cf_pred) == pn_Generic_X_regular) {
2052                                 /* the regular control flow, NO exception */
2053                                 return 0;
2054                         }
2055                         assert(get_Proj_proj(cf_pred) == pn_Generic_X_except);
2056                         return 1;
2057                 }
2058                 /* Hmm, exception but not a Proj? */
2059                 assert(!"unexpected condition: fragile op without a proj");
2060                 return 1;
2061         }
2062         return 0;
2063 }  /* is_exception_flow */
2064
2065 /**
2066  * Computes the predecessors for the real phi node, and then
2067  * allocates and returns this node.  The routine called to allocate the
2068  * node might optimize it away and return a real value.
2069  * This function must be called with an in-array of proper size.
2070  */
2071 static ir_node *
2072 phi_merge(ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins) {
2073         ir_node *prevBlock, *res, *phi0, *phi0_all;
2074         int i;
2075
2076         /* If this block has no value at pos create a Phi0 and remember it
2077            in graph_arr to break recursions.
2078            Else we may not set graph_arr as there a later value is remembered. */
2079         phi0 = NULL;
2080         if (block->attr.block.graph_arr[pos] == NULL) {
2081                 ir_graph *irg = current_ir_graph;
2082
2083                 if (block == get_irg_start_block(irg)) {
2084                         /* Collapsing to Bad tarvals is no good idea.
2085                            So we call a user-supplied routine here that deals with this case as
2086                            appropriate for the given language. Sorrily the only help we can give
2087                            here is the position.
2088
2089                            Even if all variables are defined before use, it can happen that
2090                            we get to the start block, if a Cond has been replaced by a tuple
2091                            (bad, jmp).  In this case we call the function needlessly, eventually
2092                            generating an non existent error.
2093                            However, this SHOULD NOT HAPPEN, as bad control flow nodes are intercepted
2094                            before recurring.
2095                          */
2096                         if (default_initialize_local_variable != NULL) {
2097                                 ir_node *rem = get_cur_block();
2098
2099                                 set_cur_block(block);
2100                                 block->attr.block.graph_arr[pos] = default_initialize_local_variable(irg, mode, pos - 1);
2101                                 set_cur_block(rem);
2102                         }
2103                         else
2104                                 block->attr.block.graph_arr[pos] = new_Unknown(mode);
2105                         /* We don't need to care about exception ops in the start block.
2106                            There are none by definition. */
2107                         return block->attr.block.graph_arr[pos];
2108                 } else {
2109                         phi0 = new_rd_Phi0(irg, block, mode);
2110                         block->attr.block.graph_arr[pos] = phi0;
2111 #if PRECISE_EXC_CONTEXT
2112                         if (get_opt_precise_exc_context()) {
2113                                 /* Set graph_arr for fragile ops.  Also here we should break recursion.
2114                                    We could choose a cyclic path through an cfop.  But the recursion would
2115                                    break at some point. */
2116                                 set_frag_value(block->attr.block.graph_arr, pos, phi0);
2117                         }
2118 #endif
2119                 }
2120         }
2121
2122         /* This loop goes to all predecessor blocks of the block the Phi node
2123            is in and there finds the operands of the Phi node by calling
2124            get_r_value_internal.  */
2125         for (i = 1; i <= ins; ++i) {
2126                 ir_node *cf_pred = block->in[i];
2127                 ir_node *prevCfOp = skip_Proj(cf_pred);
2128                 assert(prevCfOp);
2129                 if (is_Bad(prevCfOp)) {
2130                         /* In case a Cond has been optimized we would get right to the start block
2131                         with an invalid definition. */
2132                         nin[i-1] = new_Bad();
2133                         continue;
2134                 }
2135                 prevBlock = prevCfOp->in[0]; /* go past control flow op to prev block */
2136                 assert(prevBlock);
2137                 if (!is_Bad(prevBlock)) {
2138 #if PRECISE_EXC_CONTEXT
2139                         if (get_opt_precise_exc_context() && is_exception_flow(cf_pred, prevCfOp)) {
2140                                 assert(get_r_frag_value_internal(prevBlock, prevCfOp, pos, mode));
2141                                 nin[i-1] = get_r_frag_value_internal(prevBlock, prevCfOp, pos, mode);
2142                         } else
2143 #endif
2144                                 nin[i-1] = get_r_value_internal(prevBlock, pos, mode);
2145                 } else {
2146                         nin[i-1] = new_Bad();
2147                 }
2148         }
2149
2150         /* We want to pass the Phi0 node to the constructor: this finds additional
2151            optimization possibilities.
2152            The Phi0 node either is allocated in this function, or it comes from
2153            a former call to get_r_value_internal(). In this case we may not yet
2154            exchange phi0, as this is done in mature_immBlock(). */
2155         if (phi0 == NULL) {
2156                 phi0_all = block->attr.block.graph_arr[pos];
2157                 if (!(is_Phi(phi0_all) &&
2158                         (get_irn_arity(phi0_all) == 0)   &&
2159                         (get_nodes_block(phi0_all) == block)))
2160                         phi0_all = NULL;
2161         } else {
2162                 phi0_all = phi0;
2163         }
2164
2165         /* After collecting all predecessors into the array nin a new Phi node
2166            with these predecessors is created.  This constructor contains an
2167            optimization: If all predecessors of the Phi node are identical it
2168            returns the only operand instead of a new Phi node.  */
2169         res = new_rd_Phi_in(current_ir_graph, block, mode, nin, ins, phi0_all);
2170
2171         /* In case we allocated a Phi0 node at the beginning of this procedure,
2172            we need to exchange this Phi0 with the real Phi. */
2173         if (phi0 != NULL) {
2174                 exchange(phi0, res);
2175                 block->attr.block.graph_arr[pos] = res;
2176                 /* Don't set_frag_value as it does not overwrite.  Doesn't matter, is
2177                    only an optimization. */
2178         }
2179
2180         return res;
2181 }  /* phi_merge */
2182
2183 /**
2184  * This function returns the last definition of a value.  In case
2185  * this value was last defined in a previous block, Phi nodes are
2186  * inserted.  If the part of the firm graph containing the definition
2187  * is not yet constructed, a dummy Phi node is returned.
2188  *
2189  * @param block   the current block
2190  * @param pos     the value number of the value searched
2191  * @param mode    the mode of this value (needed for Phi construction)
2192  */
2193 static ir_node *
2194 get_r_value_internal(ir_node *block, int pos, ir_mode *mode) {
2195         ir_node *res;
2196         /* There are 4 cases to treat.
2197
2198            1. The block is not mature and we visit it the first time.  We can not
2199               create a proper Phi node, therefore a Phi0, i.e., a Phi without
2200               predecessors is returned.  This node is added to the linked list (block
2201               attribute "phis") of the containing block to be completed when this block is
2202               matured. (Completion will add a new Phi and turn the Phi0 into an Id
2203               node.)
2204
2205            2. The value is already known in this block, graph_arr[pos] is set and we
2206               visit the block the first time.  We can return the value without
2207               creating any new nodes.
2208
2209            3. The block is mature and we visit it the first time.  A Phi node needs
2210               to be created (phi_merge).  If the Phi is not needed, as all it's
2211               operands are the same value reaching the block through different
2212               paths, it's optimized away and the value itself is returned.
2213
2214            4. The block is mature, and we visit it the second time.  Now two
2215               subcases are possible:
2216               * The value was computed completely the last time we were here. This
2217                 is the case if there is no loop.  We can return the proper value.
2218               * The recursion that visited this node and set the flag did not
2219                 return yet.  We are computing a value in a loop and need to
2220                 break the recursion.  This case only happens if we visited
2221             the same block with phi_merge before, which inserted a Phi0.
2222             So we return the Phi0.
2223         */
2224
2225         /* case 4 -- already visited. */
2226         if (get_irn_visited(block) == get_irg_visited(current_ir_graph)) {
2227                 /* As phi_merge allocates a Phi0 this value is always defined. Here
2228                 is the critical difference of the two algorithms. */
2229                 assert(block->attr.block.graph_arr[pos]);
2230                 return block->attr.block.graph_arr[pos];
2231         }
2232
2233         /* visited the first time */
2234         set_irn_visited(block, get_irg_visited(current_ir_graph));
2235
2236         /* Get the local valid value */
2237         res = block->attr.block.graph_arr[pos];
2238
2239         /* case 2 -- If the value is actually computed, return it. */
2240         if (res != NULL)
2241                 return res;
2242
2243         if (block->attr.block.is_matured) { /* case 3 */
2244
2245                 /* The Phi has the same amount of ins as the corresponding block. */
2246                 int ins = get_irn_arity(block);
2247                 ir_node **nin;
2248                 NEW_ARR_A(ir_node *, nin, ins);
2249
2250                 /* Phi merge collects the predecessors and then creates a node. */
2251                 res = phi_merge(block, pos, mode, nin, ins);
2252
2253         } else {  /* case 1 */
2254                 /* The block is not mature, we don't know how many in's are needed.  A Phi
2255                    with zero predecessors is created.  Such a Phi node is called Phi0
2256                    node.  The Phi0 is then added to the list of Phi0 nodes in this block
2257                    to be matured by mature_immBlock later.
2258                    The Phi0 has to remember the pos of it's internal value.  If the real
2259                    Phi is computed, pos is used to update the array with the local
2260                    values. */
2261                 res = new_rd_Phi0(current_ir_graph, block, mode);
2262                 res->attr.phi.u.pos    = pos;
2263                 res->attr.phi.next     = block->attr.block.phis;
2264                 block->attr.block.phis = res;
2265         }
2266
2267         assert(is_ir_node(res) && "phi_merge() failed to construct a definition");
2268
2269         /* The local valid value is available now. */
2270         block->attr.block.graph_arr[pos] = res;
2271
2272         return res;
2273 }  /* get_r_value_internal */
2274
2275 /* ************************************************************************** */
2276
2277 /*
2278  * Finalize a Block node, when all control flows are known.
2279  * Acceptable parameters are only Block nodes.
2280  */
2281 void
2282 mature_immBlock(ir_node *block) {
2283         int ins;
2284         ir_node *n, **nin;
2285         ir_node *next;
2286
2287         assert(is_Block(block));
2288         if (!get_Block_matured(block)) {
2289                 ir_graph *irg = current_ir_graph;
2290
2291                 ins = ARR_LEN(block->in) - 1;
2292                 /* Fix block parameters */
2293                 block->attr.block.backedge = new_backedge_arr(irg->obst, ins);
2294
2295                 /* An array for building the Phi nodes. */
2296                 NEW_ARR_A(ir_node *, nin, ins);
2297
2298                 /* Traverse a chain of Phi nodes attached to this block and mature
2299                 these, too. **/
2300                 for (n = block->attr.block.phis; n; n = next) {
2301                         inc_irg_visited(irg);
2302                         next = n->attr.phi.next;
2303                         exchange(n, phi_merge(block, n->attr.phi.u.pos, n->mode, nin, ins));
2304                 }
2305
2306                 block->attr.block.is_matured = 1;
2307
2308                 /* Now, as the block is a finished Firm node, we can optimize it.
2309                    Since other nodes have been allocated since the block was created
2310                    we can not free the node on the obstack.  Therefore we have to call
2311                    optimize_in_place().
2312                    Unfortunately the optimization does not change a lot, as all allocated
2313                    nodes refer to the unoptimized node.
2314                    We can call optimize_in_place_2(), as global cse has no effect on blocks. */
2315                 block = optimize_in_place_2(block);
2316                 IRN_VRFY_IRG(block, irg);
2317         }
2318 }  /* mature_immBlock */
2319
2320 ir_node *
2321 new_d_Phi(dbg_info *db, int arity, ir_node **in, ir_mode *mode) {
2322         return new_bd_Phi(db, current_ir_graph->current_block, arity, in, mode);
2323 }  /* new_d_Phi */
2324
2325 ir_node *
2326 new_d_Const(dbg_info *db, ir_mode *mode, tarval *con) {
2327         return new_bd_Const(db, get_irg_start_block(current_ir_graph), mode, con);
2328 }  /* new_d_Const */
2329
2330 ir_node *
2331 new_d_Const_long(dbg_info *db, ir_mode *mode, long value) {
2332         return new_bd_Const_long(db, get_irg_start_block(current_ir_graph), mode, value);
2333 }  /* new_d_Const_long */
2334
2335 ir_node *
2336 new_d_Const_type(dbg_info *db, ir_mode *mode, tarval *con, ir_type *tp) {
2337         return new_bd_Const_type(db, get_irg_start_block(current_ir_graph), mode, con, tp);
2338 }  /* new_d_Const_type */
2339
2340
2341 ir_node *
2342 new_d_Id(dbg_info *db, ir_node *val, ir_mode *mode) {
2343         return new_bd_Id(db, current_ir_graph->current_block, val, mode);
2344 }  /* new_d_Id */
2345
2346 ir_node *
2347 new_d_Proj(dbg_info *db, ir_node *arg, ir_mode *mode, long proj) {
2348         return new_bd_Proj(db, current_ir_graph->current_block, arg, mode, proj);
2349 }  /* new_d_Proj */
2350
2351 ir_node *
2352 new_d_defaultProj(dbg_info *db, ir_node *arg, long max_proj) {
2353         ir_node *res;
2354         (void) db;
2355         assert(arg->op == op_Cond);
2356         arg->attr.cond.kind = fragmentary;
2357         arg->attr.cond.default_proj = max_proj;
2358         res = new_Proj(arg, mode_X, max_proj);
2359         return res;
2360 }  /* new_d_defaultProj */
2361
2362 ir_node *
2363 new_d_Conv(dbg_info *db, ir_node *op, ir_mode *mode) {
2364         return new_bd_Conv(db, current_ir_graph->current_block, op, mode, 0);
2365 }  /* new_d_Conv */
2366
2367 ir_node *
2368 new_d_strictConv(dbg_info *db, ir_node *op, ir_mode *mode) {
2369         return new_bd_Conv(db, current_ir_graph->current_block, op, mode, 1);
2370 }  /* new_d_strictConv */
2371
2372 ir_node *
2373 new_d_Cast(dbg_info *db, ir_node *op, ir_type *to_tp) {
2374         return new_bd_Cast(db, current_ir_graph->current_block, op, to_tp);
2375 }  /* new_d_Cast */
2376
2377 ir_node *
2378 new_d_Tuple(dbg_info *db, int arity, ir_node **in) {
2379         return new_bd_Tuple(db, current_ir_graph->current_block, arity, in);
2380 }  /* new_d_Tuple */
2381
2382 NEW_D_BINOP(Add)
2383 NEW_D_BINOP(Sub)
2384 NEW_D_UNOP(Minus)
2385 NEW_D_BINOP(Mul)
2386 NEW_D_BINOP(Mulh)
2387
2388 /**
2389  * Allocate a frag array for a node if the current graph state is phase_building.
2390  *
2391  * @param irn         the node for which the frag array should be allocated
2392  * @param op          the opcode of the (original) node, if does not match opcode of irn,
2393  *                    nothing is done
2394  * @param frag_store  the address of the frag store in irn attributes, if this
2395  *                    address contains a value != NULL, does nothing
2396  */
2397 void firm_alloc_frag_arr(ir_node *irn, ir_op *op, ir_node ***frag_store) {
2398         if (get_opt_precise_exc_context()) {
2399                 if ((current_ir_graph->phase_state == phase_building) &&
2400                     (get_irn_op(irn) == op) && /* Could be optimized away. */
2401                     !*frag_store)    /* Could be a cse where the arr is already set. */ {
2402                         *frag_store = new_frag_arr(irn);
2403                 }
2404         }
2405 }  /* firm_alloc_frag_arr */
2406
2407 ir_node *
2408 new_d_Quot(dbg_info *db, ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state) {
2409         ir_node *res;
2410         res = new_bd_Quot(db, current_ir_graph->current_block, memop, op1, op2, mode, state);
2411 #if PRECISE_EXC_CONTEXT
2412         firm_alloc_frag_arr(res, op_Quot, &res->attr.except.frag_arr);
2413 #endif
2414
2415         return res;
2416 }  /* new_d_Quot */
2417
2418 ir_node *
2419 new_d_DivMod(dbg_info *db, ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state) {
2420         ir_node *res;
2421         res = new_bd_DivMod(db, current_ir_graph->current_block, memop, op1, op2, mode, state);
2422 #if PRECISE_EXC_CONTEXT
2423         firm_alloc_frag_arr(res, op_DivMod, &res->attr.except.frag_arr);
2424 #endif
2425
2426         return res;
2427 }  /* new_d_DivMod */
2428
2429 ir_node *
2430 new_d_Div(dbg_info *db, ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state) {
2431         ir_node *res;
2432         res = new_bd_Div(db, current_ir_graph->current_block, memop, op1, op2, mode, state);
2433 #if PRECISE_EXC_CONTEXT
2434         firm_alloc_frag_arr(res, op_Div, &res->attr.except.frag_arr);
2435 #endif
2436
2437         return res;
2438 }  /* new_d_Div */
2439
2440 ir_node *
2441 new_d_DivRL(dbg_info *db, ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state) {
2442         ir_node *res;
2443         res = new_bd_DivRL(db, current_ir_graph->current_block, memop, op1, op2, mode, state);
2444 #if PRECISE_EXC_CONTEXT
2445         firm_alloc_frag_arr(res, op_Div, &res->attr.except.frag_arr);
2446 #endif
2447
2448         return res;
2449 }  /* new_d_DivRL */
2450
2451 ir_node *
2452 new_d_Mod(dbg_info *db, ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state) {
2453         ir_node *res;
2454         res = new_bd_Mod(db, current_ir_graph->current_block, memop, op1, op2, mode, state);
2455 #if PRECISE_EXC_CONTEXT
2456         firm_alloc_frag_arr(res, op_Mod, &res->attr.except.frag_arr);
2457 #endif
2458
2459         return res;
2460 }  /* new_d_Mod */
2461
2462 NEW_D_BINOP(And)
2463 NEW_D_BINOP(Or)
2464 NEW_D_BINOP(Eor)
2465 NEW_D_UNOP(Not)
2466 NEW_D_BINOP(Shl)
2467 NEW_D_BINOP(Shr)
2468 NEW_D_BINOP(Shrs)
2469 NEW_D_BINOP(Rotl)
2470 NEW_D_UNOP(Abs)
2471 NEW_D_BINOP(Carry)
2472 NEW_D_BINOP(Borrow)
2473
2474 ir_node *
2475 new_d_Cmp(dbg_info *db, ir_node *op1, ir_node *op2) {
2476         return new_bd_Cmp(db, current_ir_graph->current_block, op1, op2);
2477 }  /* new_d_Cmp */
2478
2479 ir_node *
2480 new_d_Jmp(dbg_info *db) {
2481         return new_bd_Jmp(db, current_ir_graph->current_block);
2482 }  /* new_d_Jmp */
2483
2484 ir_node *
2485 new_d_IJmp(dbg_info *db, ir_node *tgt) {
2486         return new_bd_IJmp(db, current_ir_graph->current_block, tgt);
2487 }  /* new_d_IJmp */
2488
2489 ir_node *
2490 new_d_Cond(dbg_info *db, ir_node *c) {
2491         return new_bd_Cond(db, current_ir_graph->current_block, c);
2492 }  /* new_d_Cond */
2493
2494 ir_node *
2495 new_d_Call(dbg_info *db, ir_node *store, ir_node *callee, int arity, ir_node **in,
2496            ir_type *tp) {
2497         ir_node *res;
2498         res = new_bd_Call(db, current_ir_graph->current_block,
2499                           store, callee, arity, in, tp);
2500 #if PRECISE_EXC_CONTEXT
2501         firm_alloc_frag_arr(res, op_Call, &res->attr.call.exc.frag_arr);
2502 #endif
2503
2504         return res;
2505 }  /* new_d_Call */
2506
2507 ir_node *
2508 new_d_Return(dbg_info *db, ir_node* store, int arity, ir_node **in) {
2509         return new_bd_Return(db, current_ir_graph->current_block,
2510                              store, arity, in);
2511 }  /* new_d_Return */
2512
2513 ir_node *
2514 new_d_Load(dbg_info *db, ir_node *store, ir_node *addr, ir_mode *mode) {
2515         ir_node *res;
2516         res = new_bd_Load(db, current_ir_graph->current_block,
2517                           store, addr, mode);
2518 #if PRECISE_EXC_CONTEXT
2519         firm_alloc_frag_arr(res, op_Load, &res->attr.load.exc.frag_arr);
2520 #endif
2521
2522         return res;
2523 }  /* new_d_Load */
2524
2525 ir_node *
2526 new_d_Store(dbg_info *db, ir_node *store, ir_node *addr, ir_node *val) {
2527         ir_node *res;
2528         res = new_bd_Store(db, current_ir_graph->current_block,
2529                            store, addr, val);
2530 #if PRECISE_EXC_CONTEXT
2531         firm_alloc_frag_arr(res, op_Store, &res->attr.store.exc.frag_arr);
2532 #endif
2533
2534         return res;
2535 }  /* new_d_Store */
2536
2537 ir_node *
2538 new_d_Alloc(dbg_info *db, ir_node *store, ir_node *size, ir_type *alloc_type,
2539             ir_where_alloc where) {
2540         ir_node *res;
2541         res = new_bd_Alloc(db, current_ir_graph->current_block,
2542                            store, size, alloc_type, where);
2543 #if PRECISE_EXC_CONTEXT
2544         firm_alloc_frag_arr(res, op_Alloc, &res->attr.alloc.exc.frag_arr);
2545 #endif
2546
2547         return res;
2548 }  /* new_d_Alloc */
2549
2550 ir_node *
2551 new_d_Free(dbg_info *db, ir_node *store, ir_node *ptr,
2552            ir_node *size, ir_type *free_type, ir_where_alloc where) {
2553         return new_bd_Free(db, current_ir_graph->current_block,
2554                            store, ptr, size, free_type, where);
2555 }
2556
2557 ir_node *
2558 new_d_simpleSel(dbg_info *db, ir_node *store, ir_node *objptr, ir_entity *ent)
2559 /* GL: objptr was called frame before.  Frame was a bad choice for the name
2560    as the operand could as well be a pointer to a dynamic object. */
2561 {
2562         return new_bd_Sel(db, current_ir_graph->current_block,
2563                           store, objptr, 0, NULL, ent);
2564 }  /* new_d_simpleSel */
2565
2566 ir_node *
2567 new_d_Sel(dbg_info *db, ir_node *store, ir_node *objptr, int n_index, ir_node **index, ir_entity *sel) {
2568         return new_bd_Sel(db, current_ir_graph->current_block,
2569                           store, objptr, n_index, index, sel);
2570 }  /* new_d_Sel */
2571
2572 ir_node *
2573 new_d_SymConst_type(dbg_info *db, ir_mode *mode, symconst_symbol value, symconst_kind kind, ir_type *tp) {
2574         return new_bd_SymConst_type(db, get_irg_start_block(current_ir_graph), mode,
2575                                     value, kind, tp);
2576 }  /* new_d_SymConst_type */
2577
2578 ir_node *
2579 new_d_SymConst(dbg_info *db, ir_mode *mode, symconst_symbol value, symconst_kind kind) {
2580         return new_bd_SymConst_type(db, get_irg_start_block(current_ir_graph), mode,
2581                                     value, kind, firm_unknown_type);
2582 }  /* new_d_SymConst */
2583
2584 ir_node *
2585 new_d_Sync(dbg_info *db, int arity, ir_node *in[]) {
2586         return new_rd_Sync(db, current_ir_graph, current_ir_graph->current_block, arity, in);
2587 }  /* new_d_Sync */
2588
2589
2590 ir_node *
2591 (new_d_Bad)(void) {
2592         return _new_d_Bad();
2593 }  /* new_d_Bad */
2594
2595 ir_node *
2596 new_d_Confirm(dbg_info *db, ir_node *val, ir_node *bound, pn_Cmp cmp) {
2597         return new_bd_Confirm(db, current_ir_graph->current_block,
2598                               val, bound, cmp);
2599 }  /* new_d_Confirm */
2600
2601 ir_node *
2602 new_d_Unknown(ir_mode *m) {
2603         return new_bd_Unknown(m);
2604 }  /* new_d_Unknown */
2605
2606 ir_node *
2607 new_d_CallBegin(dbg_info *db, ir_node *call) {
2608         return new_bd_CallBegin(db, current_ir_graph->current_block, call);
2609 }  /* new_d_CallBegin */
2610
2611 ir_node *
2612 new_d_EndReg(dbg_info *db) {
2613         return new_bd_EndReg(db, current_ir_graph->current_block);
2614 }  /* new_d_EndReg */
2615
2616 ir_node *
2617 new_d_EndExcept(dbg_info *db) {
2618         return new_bd_EndExcept(db, current_ir_graph->current_block);
2619 }  /* new_d_EndExcept */
2620
2621 ir_node *
2622 new_d_Break(dbg_info *db) {
2623         return new_bd_Break(db, current_ir_graph->current_block);
2624 }  /* new_d_Break */
2625
2626 ir_node *
2627 new_d_Filter(dbg_info *db, ir_node *arg, ir_mode *mode, long proj) {
2628         return new_bd_Filter(db, current_ir_graph->current_block,
2629                              arg, mode, proj);
2630 }  /* new_d_Filter */
2631
2632 ir_node *
2633 (new_d_NoMem)(void) {
2634         return _new_d_NoMem();
2635 }  /* new_d_NoMem */
2636
2637 ir_node *
2638 new_d_Mux(dbg_info *db, ir_node *sel, ir_node *ir_false,
2639           ir_node *ir_true, ir_mode *mode) {
2640         return new_bd_Mux(db, current_ir_graph->current_block,
2641                           sel, ir_false, ir_true, mode);
2642 }  /* new_d_Mux */
2643
2644 ir_node *
2645 new_d_Psi(dbg_info *db,int arity, ir_node *conds[], ir_node *vals[], ir_mode *mode) {
2646   return new_bd_Psi(db, current_ir_graph->current_block,
2647                     arity, conds, vals, mode);
2648 }  /* new_d_Psi */
2649
2650 ir_node *new_d_CopyB(dbg_info *db,ir_node *store,
2651     ir_node *dst, ir_node *src, ir_type *data_type) {
2652         ir_node *res;
2653         res = new_bd_CopyB(db, current_ir_graph->current_block,
2654                            store, dst, src, data_type);
2655 #if PRECISE_EXC_CONTEXT
2656         firm_alloc_frag_arr(res, op_CopyB, &res->attr.copyb.exc.frag_arr);
2657 #endif
2658         return res;
2659 }  /* new_d_CopyB */
2660
2661 ir_node *
2662 new_d_InstOf(dbg_info *db, ir_node *store, ir_node *objptr, ir_type *type) {
2663         return new_bd_InstOf(db, current_ir_graph->current_block,
2664                              store, objptr, type);
2665 }  /* new_d_InstOf */
2666
2667 ir_node *
2668 new_d_Raise(dbg_info *db, ir_node *store, ir_node *obj) {
2669         return new_bd_Raise(db, current_ir_graph->current_block, store, obj);
2670 }  /* new_d_Raise */
2671
2672 ir_node *new_d_Bound(dbg_info *db,ir_node *store,
2673     ir_node *idx, ir_node *lower, ir_node *upper) {
2674         ir_node *res;
2675         res = new_bd_Bound(db, current_ir_graph->current_block,
2676                            store, idx, lower, upper);
2677 #if PRECISE_EXC_CONTEXT
2678         firm_alloc_frag_arr(res, op_Bound, &res->attr.bound.exc.frag_arr);
2679 #endif
2680         return res;
2681 }  /* new_d_Bound */
2682
2683 ir_node *
2684 new_d_Pin(dbg_info *db, ir_node *node) {
2685         return new_bd_Pin(db, current_ir_graph->current_block, node);
2686 }  /* new_d_Pin */
2687
2688 ir_node *
2689 new_d_ASM(dbg_info *db, int arity, ir_node *in[], ir_asm_constraint *inputs,
2690           int n_outs, ir_asm_constraint *outputs,
2691           int n_clobber, ident *clobber[], ident *asm_text) {
2692         return new_bd_ASM(db, current_ir_graph->current_block, arity, in, inputs, n_outs, outputs, n_clobber, clobber, asm_text);
2693 }  /* new_d_ASM */
2694
2695 /* ********************************************************************* */
2696 /* Comfortable interface with automatic Phi node construction.           */
2697 /* (Uses also constructors of ?? interface, except new_Block.            */
2698 /* ********************************************************************* */
2699
2700 /*  Block construction */
2701 /* immature Block without predecessors */
2702 ir_node *
2703 new_d_immBlock(dbg_info *db) {
2704         ir_node *res;
2705
2706         assert(get_irg_phase_state(current_ir_graph) == phase_building);
2707         /* creates a new dynamic in-array as length of in is -1 */
2708         res = new_ir_node(db, current_ir_graph, NULL, op_Block, mode_BB, -1, NULL);
2709         current_ir_graph->current_block = res;
2710
2711         /* macroblock head */
2712         res->in[0] = res;
2713
2714         res->attr.block.is_matured  = 0;
2715         res->attr.block.is_dead     = 0;
2716         res->attr.block.is_mb_head  = 1;
2717         res->attr.block.has_label   = 0;
2718         res->attr.block.irg         = current_ir_graph;
2719         res->attr.block.backedge    = NULL;
2720         res->attr.block.in_cg       = NULL;
2721         res->attr.block.cg_backedge = NULL;
2722         res->attr.block.extblk      = NULL;
2723         res->attr.block.region      = NULL;
2724         res->attr.block.mb_depth    = 0;
2725         res->attr.block.label       = 0;
2726
2727         set_Block_block_visited(res, 0);
2728
2729         /* Create and initialize array for Phi-node construction. */
2730         res->attr.block.graph_arr = NEW_ARR_D(ir_node *, current_ir_graph->obst,
2731                                               current_ir_graph->n_loc);
2732         memset(res->attr.block.graph_arr, 0, sizeof(ir_node *)*current_ir_graph->n_loc);
2733
2734         /* Immature block may not be optimized! */
2735         IRN_VRFY_IRG(res, current_ir_graph);
2736
2737         return res;
2738 }  /* new_d_immBlock */
2739
2740 ir_node *
2741 new_immBlock(void) {
2742         return new_d_immBlock(NULL);
2743 }  /* new_immBlock */
2744
2745 /* immature PartBlock with its predecessors */
2746 ir_node *
2747 new_d_immPartBlock(dbg_info *db, ir_node *pred_jmp) {
2748         ir_node *res = new_d_immBlock(db);
2749         ir_node *blk = get_nodes_block(pred_jmp);
2750
2751         res->in[0] = blk->in[0];
2752         assert(res->in[0] != NULL);
2753         add_immBlock_pred(res, pred_jmp);
2754
2755         res->attr.block.is_mb_head = 0;
2756         res->attr.block.mb_depth = blk->attr.block.mb_depth + 1;
2757
2758         return res;
2759 }  /* new_d_immPartBlock */
2760
2761 ir_node *
2762 new_immPartBlock(ir_node *pred_jmp) {
2763         return new_d_immPartBlock(NULL, pred_jmp);
2764 }  /* new_immPartBlock */
2765
2766 /* add an edge to a jmp/control flow node */
2767 void
2768 add_immBlock_pred(ir_node *block, ir_node *jmp) {
2769         int n = ARR_LEN(block->in) - 1;
2770
2771         assert(!block->attr.block.is_matured && "Error: Block already matured!\n");
2772         assert(block->attr.block.is_mb_head && "Error: Cannot add a predecessor to a PartBlock");
2773         assert(is_ir_node(jmp));
2774
2775         ARR_APP1(ir_node *, block->in, jmp);
2776         /* Call the hook */
2777         hook_set_irn_n(block, n, jmp, NULL);
2778 }  /* add_immBlock_pred */
2779
2780 /* changing the current block */
2781 void
2782 set_cur_block(ir_node *target) {
2783         current_ir_graph->current_block = target;
2784 }  /* set_cur_block */
2785
2786 /* ************************ */
2787 /* parameter administration */
2788
2789 /* get a value from the parameter array from the current block by its index */
2790 ir_node *
2791 get_d_value(dbg_info *db, int pos, ir_mode *mode) {
2792         ir_graph *irg = current_ir_graph;
2793         assert(get_irg_phase_state(irg) == phase_building);
2794         inc_irg_visited(irg);
2795         (void) db;
2796
2797         return get_r_value_internal(irg->current_block, pos + 1, mode);
2798 }  /* get_d_value */
2799
2800 /* get a value from the parameter array from the current block by its index */
2801 ir_node *
2802 get_value(int pos, ir_mode *mode) {
2803         return get_d_value(NULL, pos, mode);
2804 }  /* get_value */
2805
2806 /* set a value at position pos in the parameter array from the current block */
2807 void
2808 set_value(int pos, ir_node *value) {
2809         ir_graph *irg = current_ir_graph;
2810         assert(get_irg_phase_state(irg) == phase_building);
2811         assert(pos+1 < irg->n_loc);
2812         assert(is_ir_node(value));
2813         irg->current_block->attr.block.graph_arr[pos + 1] = value;
2814 }  /* set_value */
2815
2816 /* Find the value number for a node in the current block.*/
2817 int
2818 find_value(ir_node *value) {
2819         int i;
2820         ir_node *bl = current_ir_graph->current_block;
2821
2822         for (i = ARR_LEN(bl->attr.block.graph_arr) - 1; i >= 1; --i)
2823                 if (bl->attr.block.graph_arr[i] == value)
2824                         return i - 1;
2825         return -1;
2826 }  /* find_value */
2827
2828 /* get the current store */
2829 ir_node *
2830 get_store(void) {
2831         ir_graph *irg = current_ir_graph;
2832
2833         assert(get_irg_phase_state(irg) == phase_building);
2834         /* GL: one could call get_value instead */
2835         inc_irg_visited(irg);
2836         return get_r_value_internal(irg->current_block, 0, mode_M);
2837 }  /* get_store */
2838
2839 /* set the current store: handles automatic Sync construction for Load nodes */
2840 void
2841 set_store(ir_node *store) {
2842         ir_node *load, *pload, *pred, *in[2];
2843
2844         assert(get_irg_phase_state(current_ir_graph) == phase_building);
2845         /* Beware: due to dead code elimination, a store might become a Bad node even in
2846            the construction phase. */
2847         assert((get_irn_mode(store) == mode_M || is_Bad(store)) && "storing non-memory node");
2848
2849         if (get_opt_auto_create_sync()) {
2850                 /* handle non-volatile Load nodes by automatically creating Sync's */
2851                 load = skip_Proj(store);
2852                 if (is_Load(load) && get_Load_volatility(load) == volatility_non_volatile) {
2853                         pred = get_Load_mem(load);
2854
2855                         if (is_Sync(pred)) {
2856                                 /* a Load after a Sync: move it up */
2857                                 ir_node *mem = skip_Proj(get_Sync_pred(pred, 0));
2858
2859                                 set_Load_mem(load, get_memop_mem(mem));
2860                                 add_Sync_pred(pred, store);
2861                                 store = pred;
2862                         } else {
2863                                 pload = skip_Proj(pred);
2864                                 if (is_Load(pload) && get_Load_volatility(pload) == volatility_non_volatile) {
2865                                         /* a Load after a Load: create a new Sync */
2866                                         set_Load_mem(load, get_Load_mem(pload));
2867
2868                                         in[0] = pred;
2869                                         in[1] = store;
2870                                         store = new_Sync(2, in);
2871                                 }
2872                         }
2873                 }
2874         }
2875         current_ir_graph->current_block->attr.block.graph_arr[0] = store;
2876 }  /* set_store */
2877
2878 void
2879 keep_alive(ir_node *ka) {
2880         add_End_keepalive(get_irg_end(current_ir_graph), ka);
2881 }  /* keep_alive */
2882
2883 /* --- Useful access routines --- */
2884 /* Returns the current block of the current graph.  To set the current
2885    block use set_cur_block. */
2886 ir_node *get_cur_block(void) {
2887         return get_irg_current_block(current_ir_graph);
2888 }  /* get_cur_block */
2889
2890 /* Returns the frame type of the current graph */
2891 ir_type *get_cur_frame_type(void) {
2892         return get_irg_frame_type(current_ir_graph);
2893 }  /* get_cur_frame_type */
2894
2895
2896 /* ********************************************************************* */
2897 /* initialize */
2898
2899 /* call once for each run of the library */
2900 void
2901 firm_init_cons(uninitialized_local_variable_func_t *func) {
2902         default_initialize_local_variable = func;
2903 }  /* firm_init_cons */
2904
2905 void
2906 irp_finalize_cons(void) {
2907         int i;
2908         for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
2909                 irg_finalize_cons(get_irp_irg(i));
2910         }
2911         irp->phase_state = phase_high;
2912 }  /* irp_finalize_cons */
2913
2914
2915 ir_node *new_Block(int arity, ir_node **in) {
2916         return new_d_Block(NULL, arity, in);
2917 }
2918 ir_node *new_Start(void) {
2919         return new_d_Start(NULL);
2920 }
2921 ir_node *new_End(void) {
2922         return new_d_End(NULL);
2923 }
2924 ir_node *new_Jmp(void) {
2925         return new_d_Jmp(NULL);
2926 }
2927 ir_node *new_IJmp(ir_node *tgt) {
2928         return new_d_IJmp(NULL, tgt);
2929 }
2930 ir_node *new_Cond(ir_node *c) {
2931         return new_d_Cond(NULL, c);
2932 }
2933 ir_node *new_Return(ir_node *store, int arity, ir_node *in[]) {
2934         return new_d_Return(NULL, store, arity, in);
2935 }
2936 ir_node *new_Const(ir_mode *mode, tarval *con) {
2937         return new_d_Const(NULL, mode, con);
2938 }
2939
2940 ir_node *new_Const_long(ir_mode *mode, long value) {
2941         return new_d_Const_long(NULL, mode, value);
2942 }
2943
2944 ir_node *new_Const_type(tarval *con, ir_type *tp) {
2945         return new_d_Const_type(NULL, get_type_mode(tp), con, tp);
2946 }
2947
2948 ir_node *new_SymConst_type(ir_mode *mode, symconst_symbol value, symconst_kind kind, ir_type *type) {
2949         return new_d_SymConst_type(NULL, mode, value, kind, type);
2950 }
2951 ir_node *new_SymConst(ir_mode *mode, symconst_symbol value, symconst_kind kind) {
2952         return new_d_SymConst(NULL, mode, value, kind);
2953 }
2954 ir_node *new_simpleSel(ir_node *store, ir_node *objptr, ir_entity *ent) {
2955         return new_d_simpleSel(NULL, store, objptr, ent);
2956 }
2957 ir_node *new_Sel(ir_node *store, ir_node *objptr, int arity, ir_node **in,
2958                  ir_entity *ent) {
2959         return new_d_Sel(NULL, store, objptr, arity, in, ent);
2960 }
2961 ir_node *new_Call(ir_node *store, ir_node *callee, int arity, ir_node **in,
2962                   ir_type *tp) {
2963         return new_d_Call(NULL, store, callee, arity, in, tp);
2964 }
2965 ir_node *new_Add(ir_node *op1, ir_node *op2, ir_mode *mode) {
2966         return new_d_Add(NULL, op1, op2, mode);
2967 }
2968 ir_node *new_Sub(ir_node *op1, ir_node *op2, ir_mode *mode) {
2969         return new_d_Sub(NULL, op1, op2, mode);
2970 }
2971 ir_node *new_Minus(ir_node *op,  ir_mode *mode) {
2972         return new_d_Minus(NULL, op, mode);
2973 }
2974 ir_node *new_Mul(ir_node *op1, ir_node *op2, ir_mode *mode) {
2975         return new_d_Mul(NULL, op1, op2, mode);
2976 }
2977 ir_node *new_Mulh(ir_node *op1, ir_node *op2, ir_mode *mode) {
2978         return new_d_Mulh(NULL, op1, op2, mode);
2979 }
2980 ir_node *new_Quot(ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state) {
2981         return new_d_Quot(NULL, memop, op1, op2, mode, state);
2982 }
2983 ir_node *new_DivMod(ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state) {
2984         return new_d_DivMod(NULL, memop, op1, op2, mode, state);
2985 }
2986 ir_node *new_Div(ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state) {
2987         return new_d_Div(NULL, memop, op1, op2, mode, state);
2988 }
2989 ir_node *new_DivRL(ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state) {
2990         return new_d_DivRL(NULL, memop, op1, op2, mode, state);
2991 }
2992 ir_node *new_Mod(ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state) {
2993         return new_d_Mod(NULL, memop, op1, op2, mode, state);
2994 }
2995 ir_node *new_Abs(ir_node *op, ir_mode *mode) {
2996         return new_d_Abs(NULL, op, mode);
2997 }
2998 ir_node *new_And(ir_node *op1, ir_node *op2, ir_mode *mode) {
2999         return new_d_And(NULL, op1, op2, mode);
3000 }
3001 ir_node *new_Or(ir_node *op1, ir_node *op2, ir_mode *mode) {
3002         return new_d_Or(NULL, op1, op2, mode);
3003 }
3004 ir_node *new_Eor(ir_node *op1, ir_node *op2, ir_mode *mode) {
3005         return new_d_Eor(NULL, op1, op2, mode);
3006 }
3007 ir_node *new_Not(ir_node *op,                ir_mode *mode) {
3008         return new_d_Not(NULL, op, mode);
3009 }
3010 ir_node *new_Shl(ir_node *op,  ir_node *k,   ir_mode *mode) {
3011         return new_d_Shl(NULL, op, k, mode);
3012 }
3013 ir_node *new_Shr(ir_node *op,  ir_node *k,   ir_mode *mode) {
3014         return new_d_Shr(NULL, op, k, mode);
3015 }
3016 ir_node *new_Shrs(ir_node *op,  ir_node *k,   ir_mode *mode) {
3017         return new_d_Shrs(NULL, op, k, mode);
3018 }
3019 ir_node *new_Rotl(ir_node *op,  ir_node *k,   ir_mode *mode) {
3020         return new_d_Rotl(NULL, op, k, mode);
3021 }
3022 ir_node *new_Carry(ir_node *op1, ir_node *op2, ir_mode *mode) {
3023         return new_d_Carry(NULL, op1, op2, mode);
3024 }
3025 ir_node *new_Borrow(ir_node *op1, ir_node *op2, ir_mode *mode) {
3026         return new_d_Borrow(NULL, op1, op2, mode);
3027 }
3028 ir_node *new_Cmp(ir_node *op1, ir_node *op2) {
3029         return new_d_Cmp(NULL, op1, op2);
3030 }
3031 ir_node *new_Conv(ir_node *op, ir_mode *mode) {
3032         return new_d_Conv(NULL, op, mode);
3033 }
3034 ir_node *new_strictConv(ir_node *op, ir_mode *mode) {
3035         return new_d_strictConv(NULL, op, mode);
3036 }
3037 ir_node *new_Cast(ir_node *op, ir_type *to_tp) {
3038         return new_d_Cast(NULL, op, to_tp);
3039 }
3040 ir_node *new_Phi(int arity, ir_node **in, ir_mode *mode) {
3041         return new_d_Phi(NULL, arity, in, mode);
3042 }
3043 ir_node *new_Load(ir_node *store, ir_node *addr, ir_mode *mode) {
3044         return new_d_Load(NULL, store, addr, mode);
3045 }
3046 ir_node *new_Store(ir_node *store, ir_node *addr, ir_node *val) {
3047         return new_d_Store(NULL, store, addr, val);
3048 }
3049 ir_node *new_Alloc(ir_node *store, ir_node *size, ir_type *alloc_type,
3050                    ir_where_alloc where) {
3051         return new_d_Alloc(NULL, store, size, alloc_type, where);
3052 }
3053 ir_node *new_Free(ir_node *store, ir_node *ptr, ir_node *size,
3054                   ir_type *free_type, ir_where_alloc where) {
3055         return new_d_Free(NULL, store, ptr, size, free_type, where);
3056 }
3057 ir_node *new_Sync(int arity, ir_node *in[]) {
3058         return new_d_Sync(NULL, arity, in);
3059 }
3060 ir_node *new_Proj(ir_node *arg, ir_mode *mode, long proj) {
3061         return new_d_Proj(NULL, arg, mode, proj);
3062 }
3063 ir_node *new_defaultProj(ir_node *arg, long max_proj) {
3064         return new_d_defaultProj(NULL, arg, max_proj);
3065 }
3066 ir_node *new_Tuple(int arity, ir_node **in) {
3067         return new_d_Tuple(NULL, arity, in);
3068 }
3069 ir_node *new_Id(ir_node *val, ir_mode *mode) {
3070         return new_d_Id(NULL, val, mode);
3071 }
3072 ir_node *new_Bad(void) {
3073         return new_d_Bad();
3074 }
3075 ir_node *new_Confirm(ir_node *val, ir_node *bound, pn_Cmp cmp) {
3076         return new_d_Confirm(NULL, val, bound, cmp);
3077 }
3078 ir_node *new_Unknown(ir_mode *m) {
3079         return new_d_Unknown(m);
3080 }
3081 ir_node *new_CallBegin(ir_node *callee) {
3082         return new_d_CallBegin(NULL, callee);
3083 }
3084 ir_node *new_EndReg(void) {
3085         return new_d_EndReg(NULL);
3086 }
3087 ir_node *new_EndExcept(void) {
3088         return new_d_EndExcept(NULL);
3089 }
3090 ir_node *new_Break(void) {
3091         return new_d_Break(NULL);
3092 }
3093 ir_node *new_Filter(ir_node *arg, ir_mode *mode, long proj) {
3094         return new_d_Filter(NULL, arg, mode, proj);
3095 }
3096 ir_node *new_NoMem(void) {
3097         return new_d_NoMem();
3098 }
3099 ir_node *new_Mux(ir_node *sel, ir_node *ir_false, ir_node *ir_true, ir_mode *mode) {
3100         return new_d_Mux(NULL, sel, ir_false, ir_true, mode);
3101 }
3102 ir_node *new_Psi(int arity, ir_node *conds[], ir_node *vals[], ir_mode *mode) {
3103         return new_d_Psi(NULL, arity, conds, vals, mode);
3104 }
3105 ir_node *new_CopyB(ir_node *store, ir_node *dst, ir_node *src, ir_type *data_type) {
3106         return new_d_CopyB(NULL, store, dst, src, data_type);
3107 }
3108 ir_node *new_InstOf(ir_node *store, ir_node *objptr, ir_type *ent) {
3109         return new_d_InstOf(NULL, store, objptr, ent);
3110 }
3111 ir_node *new_Raise(ir_node *store, ir_node *obj) {
3112         return new_d_Raise(NULL, store, obj);
3113 }
3114 ir_node *new_Bound(ir_node *store, ir_node *idx, ir_node *lower, ir_node *upper) {
3115         return new_d_Bound(NULL, store, idx, lower, upper);
3116 }
3117 ir_node *new_Pin(ir_node *node) {
3118         return new_d_Pin(NULL, node);
3119 }
3120 ir_node *new_ASM(int arity, ir_node *in[], ir_asm_constraint *inputs,
3121                  int n_outs, ir_asm_constraint *outputs,
3122                  int n_clobber, ident *clobber[], ident *asm_text) {
3123         return new_d_ASM(NULL, arity, in, inputs, n_outs, outputs, n_clobber, clobber, asm_text);
3124 }
3125
3126 /* create a new anchor node */
3127 ir_node *new_Anchor(ir_graph *irg) {
3128         ir_node *in[anchor_last];
3129         memset(in, 0, sizeof(in));
3130         return new_ir_node(NULL, irg, NULL, op_Anchor, mode_ANY, anchor_last, in);
3131 }