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