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