02903caa7397b62ccf6669eb5f22979912e2d1dd
[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 #include "irflag_t.h"
43
44 #if USE_EXPLICIT_PHI_IN_STACK
45 /* A stack needed for the automatic Phi node construction in constructor
46    Phi_in. Redefinition in irgraph.c!! */
47 struct Phi_in_stack {
48   ir_node **stack;
49   int       pos;
50 };
51 typedef struct Phi_in_stack Phi_in_stack;
52 #endif
53
54 /* when we need verifying */
55 #ifdef NDEBUG
56 # define IRN_VRFY_IRG(res, irg)
57 #else
58 # define IRN_VRFY_IRG(res, irg)  irn_vrfy_irg(res, irg)
59 #endif /* NDEBUG */
60
61 /**
62  * Language dependent variable initialization callback.
63  */
64 static uninitialized_local_variable_func_t *default_initialize_local_variable = NULL;
65
66 /* creates a bd constructor for a binop */
67 #define NEW_BD_BINOP(instr)                                     \
68 static ir_node *                                                \
69 new_bd_##instr (dbg_info *db, ir_node *block,                   \
70        ir_node *op1, ir_node *op2, ir_mode *mode)               \
71 {                                                               \
72   ir_node  *in[2];                                              \
73   ir_node  *res;                                                \
74   ir_graph *irg = current_ir_graph;                             \
75   in[0] = op1;                                                  \
76   in[1] = op2;                                                  \
77   res = new_ir_node(db, irg, block, op_##instr, mode, 2, in);   \
78   res = optimize_node(res);                                     \
79   IRN_VRFY_IRG(res, irg);                                       \
80   return res;                                                   \
81 }
82
83 /* creates a bd constructor for an unop */
84 #define NEW_BD_UNOP(instr)                                      \
85 static ir_node *                                                \
86 new_bd_##instr (dbg_info *db, ir_node *block,                   \
87               ir_node *op, ir_mode *mode)                       \
88 {                                                               \
89   ir_node  *res;                                                \
90   ir_graph *irg = current_ir_graph;                             \
91   res = new_ir_node(db, irg, block, op_##instr, mode, 1, &op);  \
92   res = optimize_node(res);                                     \
93   IRN_VRFY_IRG(res, irg);                                       \
94   return res;                                                   \
95 }
96
97 /* creates a bd constructor for an divop */
98 #define NEW_BD_DIVOP(instr)                                     \
99 static ir_node *                                                \
100 new_bd_##instr (dbg_info *db, ir_node *block,                   \
101             ir_node *memop, ir_node *op1, ir_node *op2)         \
102 {                                                               \
103   ir_node  *in[3];                                              \
104   ir_node  *res;                                                \
105   ir_graph *irg = current_ir_graph;                             \
106   in[0] = memop;                                                \
107   in[1] = op1;                                                  \
108   in[2] = op2;                                                  \
109   res = new_ir_node(db, irg, block, op_##instr, mode_T, 3, in); \
110   res = optimize_node(res);                                     \
111   IRN_VRFY_IRG(res, irg);                                       \
112   return res;                                                   \
113 }
114
115 /* creates a rd constructor for a binop */
116 #define NEW_RD_BINOP(instr)                                     \
117 ir_node *                                                       \
118 new_rd_##instr (dbg_info *db, ir_graph *irg, ir_node *block,    \
119        ir_node *op1, ir_node *op2, ir_mode *mode)               \
120 {                                                               \
121   ir_node  *res;                                                \
122   ir_graph *rem = current_ir_graph;                             \
123   current_ir_graph = irg;                                       \
124   res = new_bd_##instr(db, block, op1, op2, mode);              \
125   current_ir_graph = rem;                                       \
126   return res;                                                   \
127 }
128
129 /* creates a rd constructor for an unop */
130 #define NEW_RD_UNOP(instr)                                      \
131 ir_node *                                                       \
132 new_rd_##instr (dbg_info *db, ir_graph *irg, ir_node *block,    \
133               ir_node *op, ir_mode *mode)                       \
134 {                                                               \
135   ir_node  *res;                                                \
136   ir_graph *rem = current_ir_graph;                             \
137   current_ir_graph = irg;                                       \
138   res = new_bd_##instr(db, block, op, mode);                    \
139   current_ir_graph = rem;                                       \
140   return res;                                                   \
141 }
142
143 /* creates a rd constructor for an divop */
144 #define NEW_RD_DIVOP(instr)                                     \
145 ir_node *                                                       \
146 new_rd_##instr (dbg_info *db, ir_graph *irg, ir_node *block,    \
147             ir_node *memop, ir_node *op1, ir_node *op2)         \
148 {                                                               \
149   ir_node  *res;                                                \
150   ir_graph *rem = current_ir_graph;                             \
151   current_ir_graph = irg;                                       \
152   res = new_bd_##instr(db, block, memop, op1, op2);             \
153   current_ir_graph = rem;                                       \
154   return res;                                                   \
155 }
156
157 /* creates a d constructor for an binop */
158 #define NEW_D_BINOP(instr)                                                    \
159 ir_node *                                                                     \
160 new_d_##instr (dbg_info *db, ir_node *op1, ir_node *op2, ir_mode *mode) {     \
161   return new_bd_##instr(db, current_ir_graph->current_block, op1, op2, mode); \
162 }
163
164 /* creates a d constructor for an unop */
165 #define NEW_D_UNOP(instr)                                                     \
166 ir_node *                                                                     \
167 new_d_##instr (dbg_info *db, ir_node *op, ir_mode *mode) {                    \
168   return new_bd_##instr(db, current_ir_graph->current_block, op, mode);         \
169 }
170
171
172 /* Constructs a Block with a fixed number of predecessors.
173    Does not set current_block.  Can not be used with automatic
174    Phi node construction. */
175 static ir_node *
176 new_bd_Block (dbg_info *db,  int arity, ir_node **in)
177 {
178   ir_node  *res;
179   ir_graph *irg = current_ir_graph;
180
181   res = new_ir_node (db, irg, NULL, op_Block, mode_BB, arity, in);
182   set_Block_matured(res, 1);
183   set_Block_block_visited(res, 0);
184
185   /* res->attr.block.exc = exc_normal; */
186   /* res->attr.block.handler_entry = 0; */
187   res->attr.block.dead        = 0;
188   res->attr.block.irg         = irg;
189   res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
190   res->attr.block.in_cg       = NULL;
191   res->attr.block.cg_backedge = NULL;
192   res->attr.block.extblk      = NULL;
193
194   IRN_VRFY_IRG(res, irg);
195   return res;
196 }
197
198 static ir_node *
199 new_bd_Start (dbg_info *db, ir_node *block)
200 {
201   ir_node  *res;
202   ir_graph *irg = current_ir_graph;
203
204   res = new_ir_node(db, irg, block, op_Start, mode_T, 0, NULL);
205   /* res->attr.start.irg = irg; */
206
207   IRN_VRFY_IRG(res, irg);
208   return res;
209 }
210
211 static ir_node *
212 new_bd_End (dbg_info *db, ir_node *block)
213 {
214   ir_node  *res;
215   ir_graph *irg = current_ir_graph;
216
217   res = new_ir_node(db, irg, block, op_End, mode_X, -1, NULL);
218
219   IRN_VRFY_IRG(res, irg);
220   return res;
221 }
222
223 /* Creates a Phi node with all predecessors.  Calling this constructor
224    is only allowed if the corresponding block is mature.  */
225 static ir_node *
226 new_bd_Phi (dbg_info *db, ir_node *block, int arity, ir_node **in, ir_mode *mode)
227 {
228   ir_node  *res;
229   ir_graph *irg = current_ir_graph;
230   int i;
231   int has_unknown = 0;
232
233   /* Don't assert that block matured: the use of this constructor is strongly
234      restricted ... */
235   if ( get_Block_matured(block) )
236     assert( get_irn_arity(block) == arity );
237
238   res = new_ir_node(db, irg, block, op_Phi, mode, arity, in);
239
240   res->attr.phi_backedge = new_backedge_arr(irg->obst, arity);
241
242   for (i = arity-1; i >= 0; i--)
243     if (get_irn_op(in[i]) == op_Unknown) {
244       has_unknown = 1;
245       break;
246     }
247
248   if (!has_unknown) res = optimize_node (res);
249   IRN_VRFY_IRG(res, irg);
250
251   /* Memory Phis in endless loops must be kept alive.
252      As we can't distinguish these easily we keep all of them alive. */
253   if ((res->op == op_Phi) && (mode == mode_M))
254     add_End_keepalive(get_irg_end(irg), res);
255   return res;
256 }
257
258 static ir_node *
259 new_bd_Const_type (dbg_info *db, ir_node *block, ir_mode *mode, tarval *con, ir_type *tp)
260 {
261   ir_node  *res;
262   ir_graph *irg = current_ir_graph;
263
264   res = new_ir_node (db, irg, get_irg_start_block(irg), op_Const, mode, 0, NULL);
265   res->attr.con.tv = con;
266   set_Const_type(res, tp);  /* Call method because of complex assertion. */
267   res = optimize_node (res);
268   assert(get_Const_type(res) == tp);
269   IRN_VRFY_IRG(res, irg);
270
271   return res;
272 }
273
274 static ir_node *
275 new_bd_Const (dbg_info *db, ir_node *block, ir_mode *mode, tarval *con)
276 {
277   ir_graph *irg = current_ir_graph;
278
279   return new_rd_Const_type (db, irg, block, mode, con, firm_unknown_type);
280 }
281
282 static ir_node *
283 new_bd_Const_long (dbg_info *db, ir_node *block, ir_mode *mode, long value)
284 {
285   ir_graph *irg = current_ir_graph;
286
287   return new_rd_Const(db, irg, block, mode, new_tarval_from_long(value, mode));
288 }
289
290 static ir_node *
291 new_bd_Id (dbg_info *db, ir_node *block, ir_node *val, ir_mode *mode)
292 {
293   ir_node  *res;
294   ir_graph *irg = current_ir_graph;
295
296   res = new_ir_node(db, irg, block, op_Id, mode, 1, &val);
297   res = optimize_node(res);
298   IRN_VRFY_IRG(res, irg);
299   return res;
300 }
301
302 static ir_node *
303 new_bd_Proj (dbg_info *db, ir_node *block, ir_node *arg, ir_mode *mode,
304         long proj)
305 {
306   ir_node  *res;
307   ir_graph *irg = current_ir_graph;
308
309   res = new_ir_node (db, irg, block, op_Proj, mode, 1, &arg);
310   res->attr.proj = proj;
311
312   assert(res);
313   assert(get_Proj_pred(res));
314   assert(get_nodes_block(get_Proj_pred(res)));
315
316   res = optimize_node(res);
317
318   IRN_VRFY_IRG(res, irg);
319   return res;
320
321 }
322
323 static ir_node *
324 new_bd_defaultProj (dbg_info *db, ir_node *block, ir_node *arg,
325            long max_proj)
326 {
327   ir_node  *res;
328   ir_graph *irg = current_ir_graph;
329
330   assert(arg->op == op_Cond);
331   arg->attr.c.kind = fragmentary;
332   arg->attr.c.default_proj = max_proj;
333   res = new_rd_Proj (db, irg, block, arg, mode_X, max_proj);
334   return res;
335 }
336
337 static ir_node *
338 new_bd_Conv (dbg_info *db, ir_node *block, ir_node *op, ir_mode *mode)
339 {
340   ir_node  *res;
341   ir_graph *irg = current_ir_graph;
342
343   res = new_ir_node(db, irg, block, op_Conv, mode, 1, &op);
344   res = optimize_node(res);
345   IRN_VRFY_IRG(res, irg);
346   return res;
347 }
348
349 static ir_node *
350 new_bd_Cast (dbg_info *db, ir_node *block, ir_node *op, ir_type *to_tp)
351 {
352   ir_node  *res;
353   ir_graph *irg = current_ir_graph;
354
355   assert(is_atomic_type(to_tp));
356
357   res = new_ir_node(db, irg, block, op_Cast, get_irn_mode(op), 1, &op);
358   res->attr.cast.totype = to_tp;
359   res = optimize_node(res);
360   IRN_VRFY_IRG(res, irg);
361   return res;
362 }
363
364 static ir_node *
365 new_bd_Tuple (dbg_info *db, ir_node *block, int arity, ir_node **in)
366 {
367   ir_node  *res;
368   ir_graph *irg = current_ir_graph;
369
370   res = new_ir_node(db, irg, block, op_Tuple, mode_T, arity, in);
371   res = optimize_node (res);
372   IRN_VRFY_IRG(res, irg);
373   return res;
374 }
375
376 NEW_BD_BINOP(Add)
377 NEW_BD_BINOP(Sub)
378 NEW_BD_UNOP(Minus)
379 NEW_BD_BINOP(Mul)
380 NEW_BD_DIVOP(Quot)
381 NEW_BD_DIVOP(DivMod)
382 NEW_BD_DIVOP(Div)
383 NEW_BD_DIVOP(Mod)
384 NEW_BD_BINOP(And)
385 NEW_BD_BINOP(Or)
386 NEW_BD_BINOP(Eor)
387 NEW_BD_UNOP(Not)
388 NEW_BD_BINOP(Shl)
389 NEW_BD_BINOP(Shr)
390 NEW_BD_BINOP(Shrs)
391 NEW_BD_BINOP(Rot)
392 NEW_BD_UNOP(Abs)
393 NEW_BD_BINOP(Carry)
394 NEW_BD_BINOP(Borrow)
395
396 static ir_node *
397 new_bd_Cmp (dbg_info *db, ir_node *block, ir_node *op1, ir_node *op2)
398 {
399   ir_node  *in[2];
400   ir_node  *res;
401   ir_graph *irg = current_ir_graph;
402   in[0] = op1;
403   in[1] = op2;
404   res = new_ir_node(db, irg, block, op_Cmp, mode_T, 2, in);
405   res = optimize_node(res);
406   IRN_VRFY_IRG(res, irg);
407   return res;
408 }
409
410 static ir_node *
411 new_bd_Jmp (dbg_info *db, ir_node *block)
412 {
413   ir_node  *res;
414   ir_graph *irg = current_ir_graph;
415
416   res = new_ir_node (db, irg, block, op_Jmp, mode_X, 0, NULL);
417   res = optimize_node (res);
418   IRN_VRFY_IRG (res, irg);
419   return res;
420 }
421
422 static ir_node *
423 new_bd_IJmp (dbg_info *db, ir_node *block, ir_node *tgt)
424 {
425   ir_node  *res;
426   ir_graph *irg = current_ir_graph;
427
428   res = new_ir_node (db, irg, block, op_IJmp, mode_X, 1, &tgt);
429   res = optimize_node (res);
430   IRN_VRFY_IRG (res, irg);
431
432   if (get_irn_op(res) == op_IJmp) /* still an IJmp */
433     keep_alive(res);
434   return res;
435 }
436
437 static ir_node *
438 new_bd_Cond (dbg_info *db, ir_node *block, ir_node *c)
439 {
440   ir_node  *res;
441   ir_graph *irg = current_ir_graph;
442
443   res = new_ir_node (db, irg, block, op_Cond, mode_T, 1, &c);
444   res->attr.c.kind         = dense;
445   res->attr.c.default_proj = 0;
446   res->attr.c.pred         = COND_JMP_PRED_NONE;
447   res = optimize_node (res);
448   IRN_VRFY_IRG(res, irg);
449   return res;
450 }
451
452 static ir_node *
453 new_bd_Call (dbg_info *db, ir_node *block, ir_node *store,
454         ir_node *callee, int arity, ir_node **in, ir_type *tp)
455 {
456   ir_node  **r_in;
457   ir_node  *res;
458   int      r_arity;
459   ir_graph *irg = current_ir_graph;
460
461   r_arity = arity+2;
462   NEW_ARR_A(ir_node *, r_in, r_arity);
463   r_in[0] = store;
464   r_in[1] = callee;
465   memcpy(&r_in[2], in, sizeof(ir_node *) * arity);
466
467   res = new_ir_node(db, irg, block, op_Call, mode_T, r_arity, r_in);
468
469   assert((get_unknown_type() == tp) || is_Method_type(tp));
470   set_Call_type(res, tp);
471   res->attr.call.exc.pin_state = op_pin_state_pinned;
472   res->attr.call.callee_arr    = NULL;
473   res = optimize_node(res);
474   IRN_VRFY_IRG(res, irg);
475   return res;
476 }
477
478 static ir_node *
479 new_bd_Return (dbg_info *db, ir_node *block,
480               ir_node *store, int arity, ir_node **in)
481 {
482   ir_node  **r_in;
483   ir_node  *res;
484   int      r_arity;
485   ir_graph *irg = current_ir_graph;
486
487   r_arity = arity+1;
488   NEW_ARR_A (ir_node *, r_in, r_arity);
489   r_in[0] = store;
490   memcpy(&r_in[1], in, sizeof(ir_node *) * arity);
491   res = new_ir_node(db, irg, block, op_Return, mode_X, r_arity, r_in);
492   res = optimize_node(res);
493   IRN_VRFY_IRG(res, irg);
494   return res;
495 }
496
497 static ir_node *
498 new_bd_Load (dbg_info *db, ir_node *block,
499         ir_node *store, ir_node *adr, ir_mode *mode)
500 {
501   ir_node  *in[2];
502   ir_node  *res;
503   ir_graph *irg = current_ir_graph;
504
505   in[0] = store;
506   in[1] = adr;
507   res = new_ir_node(db, irg, block, op_Load, mode_T, 2, in);
508   res->attr.load.exc.pin_state = op_pin_state_pinned;
509   res->attr.load.load_mode     = mode;
510   res->attr.load.volatility    = volatility_non_volatile;
511   res = optimize_node(res);
512   IRN_VRFY_IRG(res, irg);
513   return res;
514 }
515
516 static ir_node *
517 new_bd_Store (dbg_info *db, ir_node *block,
518          ir_node *store, ir_node *adr, ir_node *val)
519 {
520   ir_node  *in[3];
521   ir_node  *res;
522   ir_graph *irg = current_ir_graph;
523
524   in[0] = store;
525   in[1] = adr;
526   in[2] = val;
527   res = new_ir_node(db, irg, block, op_Store, mode_T, 3, in);
528   res->attr.store.exc.pin_state = op_pin_state_pinned;
529   res->attr.store.volatility    = volatility_non_volatile;
530   res = optimize_node(res);
531   IRN_VRFY_IRG(res, irg);
532   return res;
533 }
534
535 static ir_node *
536 new_bd_Alloc (dbg_info *db, ir_node *block, ir_node *store,
537         ir_node *size, ir_type *alloc_type, where_alloc where)
538 {
539   ir_node  *in[2];
540   ir_node  *res;
541   ir_graph *irg = current_ir_graph;
542
543   in[0] = store;
544   in[1] = size;
545   res = new_ir_node(db, irg, block, op_Alloc, mode_T, 2, in);
546   res->attr.a.exc.pin_state = op_pin_state_pinned;
547   res->attr.a.where         = where;
548   res->attr.a.type          = alloc_type;
549   res = optimize_node(res);
550   IRN_VRFY_IRG(res, irg);
551   return res;
552 }
553
554 static ir_node *
555 new_bd_Free (dbg_info *db, ir_node *block, ir_node *store,
556         ir_node *ptr, ir_node *size, ir_type *free_type, where_alloc where)
557 {
558   ir_node  *in[3];
559   ir_node  *res;
560   ir_graph *irg = current_ir_graph;
561
562   in[0] = store;
563   in[1] = ptr;
564   in[2] = size;
565   res = new_ir_node (db, irg, block, op_Free, mode_M, 3, in);
566   res->attr.f.where = where;
567   res->attr.f.type  = free_type;
568   res = optimize_node(res);
569   IRN_VRFY_IRG(res, irg);
570   return res;
571 }
572
573 static ir_node *
574 new_bd_Sel (dbg_info *db, ir_node *block, ir_node *store, ir_node *objptr,
575            int arity, ir_node **in, entity *ent)
576 {
577   ir_node  **r_in;
578   ir_node  *res;
579   int      r_arity;
580   ir_graph *irg = current_ir_graph;
581
582   assert(ent != NULL && is_entity(ent) && "entity expected in Sel construction");
583
584   r_arity = arity + 2;
585   NEW_ARR_A(ir_node *, r_in, r_arity);  /* uses alloca */
586   r_in[0] = store;
587   r_in[1] = objptr;
588   memcpy(&r_in[2], in, sizeof(ir_node *) * arity);
589   /*
590    * FIXM: Sel's can select functions which should be of mode mode_P_code.
591    */
592   res = new_ir_node(db, irg, block, op_Sel, mode_P_data, r_arity, r_in);
593   res->attr.s.ent = ent;
594   res = optimize_node(res);
595   IRN_VRFY_IRG(res, irg);
596   return res;
597 }
598
599 static ir_node *
600 new_bd_SymConst_type (dbg_info *db, ir_node *block, symconst_symbol value,
601               symconst_kind symkind, ir_type *tp) {
602   ir_node  *res;
603   ir_mode  *mode;
604   ir_graph *irg = current_ir_graph;
605
606   if ((symkind == symconst_addr_name) || (symkind == symconst_addr_ent))
607     mode = mode_P_data;   /* FIXME: can be mode_P_code */
608   else
609     mode = mode_Iu;
610
611   res = new_ir_node(db, irg, block, op_SymConst, mode, 0, NULL);
612
613   res->attr.i.num = symkind;
614   res->attr.i.sym = value;
615   res->attr.i.tp  = tp;
616
617   res = optimize_node(res);
618   IRN_VRFY_IRG(res, irg);
619   return res;
620 }
621
622 static ir_node *
623 new_bd_SymConst (dbg_info *db, ir_node *block, symconst_symbol value,
624          symconst_kind symkind)
625 {
626   ir_graph *irg = current_ir_graph;
627
628   ir_node *res = new_rd_SymConst_type(db, irg, block, value, symkind, firm_unknown_type);
629   return res;
630 }
631
632 static ir_node *
633 new_bd_Sync (dbg_info *db, ir_node *block)
634 {
635   ir_node  *res;
636   ir_graph *irg = current_ir_graph;
637
638   res = new_ir_node(db, irg, block, op_Sync, mode_M, -1, NULL);
639   /* no need to call optimize node here, Sync are always created with no predecessors */
640   IRN_VRFY_IRG(res, irg);
641   return res;
642 }
643
644 static ir_node *
645 new_bd_Confirm (dbg_info *db, ir_node *block, ir_node *val, ir_node *bound, pn_Cmp cmp)
646 {
647   ir_node  *in[2], *res;
648   ir_graph *irg = current_ir_graph;
649
650   in[0] = val;
651   in[1] = bound;
652   res = new_ir_node (db, irg, block, op_Confirm, get_irn_mode(val), 2, in);
653   res->attr.confirm_cmp = cmp;
654   res = optimize_node (res);
655   IRN_VRFY_IRG(res, irg);
656   return res;
657 }
658
659 /* this function is often called with current_ir_graph unset */
660 static ir_node *
661 new_bd_Unknown (ir_mode *m)
662 {
663   ir_node  *res;
664   ir_graph *irg = current_ir_graph;
665
666   res = new_ir_node(NULL, irg, get_irg_start_block(irg), op_Unknown, m, 0, NULL);
667   res = optimize_node(res);
668   return res;
669 }
670
671 static ir_node *
672 new_bd_CallBegin (dbg_info *db, ir_node *block, ir_node *call)
673 {
674   ir_node  *in[1];
675   ir_node  *res;
676   ir_graph *irg = current_ir_graph;
677
678   in[0] = get_Call_ptr(call);
679   res = new_ir_node(db, irg, block, op_CallBegin, mode_T, 1, in);
680   /* res->attr.callbegin.irg = irg; */
681   res->attr.callbegin.call = call;
682   res = optimize_node(res);
683   IRN_VRFY_IRG(res, irg);
684   return res;
685 }
686
687 static ir_node *
688 new_bd_EndReg (dbg_info *db, ir_node *block)
689 {
690   ir_node  *res;
691   ir_graph *irg = current_ir_graph;
692
693   res = new_ir_node(db, irg, block, op_EndReg, mode_T, -1, NULL);
694   set_irg_end_reg(irg, res);
695   IRN_VRFY_IRG(res, irg);
696   return res;
697 }
698
699 static ir_node *
700 new_bd_EndExcept (dbg_info *db, ir_node *block)
701 {
702   ir_node  *res;
703   ir_graph *irg = current_ir_graph;
704
705   res = new_ir_node(db, irg, block, op_EndExcept, mode_T, -1, NULL);
706   set_irg_end_except(irg, res);
707   IRN_VRFY_IRG (res, irg);
708   return res;
709 }
710
711 static ir_node *
712 new_bd_Break (dbg_info *db, ir_node *block)
713 {
714   ir_node  *res;
715   ir_graph *irg = current_ir_graph;
716
717   res = new_ir_node(db, irg, block, op_Break, mode_X, 0, NULL);
718   res = optimize_node(res);
719   IRN_VRFY_IRG(res, irg);
720   return res;
721 }
722
723 static ir_node *
724 new_bd_Filter (dbg_info *db, ir_node *block, ir_node *arg, ir_mode *mode,
725            long proj)
726 {
727   ir_node  *res;
728   ir_graph *irg = current_ir_graph;
729
730   res = new_ir_node(db, irg, block, op_Filter, mode, 1, &arg);
731   res->attr.filter.proj = proj;
732   res->attr.filter.in_cg = NULL;
733   res->attr.filter.backedge = NULL;
734
735   assert(res);
736   assert(get_Proj_pred(res));
737   assert(get_nodes_block(get_Proj_pred(res)));
738
739   res = optimize_node(res);
740   IRN_VRFY_IRG(res, irg);
741   return res;
742 }
743
744 static ir_node *
745 new_bd_Mux  (dbg_info *db, ir_node *block,
746     ir_node *sel, ir_node *ir_false, ir_node *ir_true, ir_mode *mode)
747 {
748   ir_node  *in[3];
749   ir_node  *res;
750   ir_graph *irg = current_ir_graph;
751
752   in[0] = sel;
753   in[1] = ir_false;
754   in[2] = ir_true;
755
756   res = new_ir_node(db, irg, block, op_Mux, mode, 3, in);
757   assert(res);
758
759   res = optimize_node(res);
760   IRN_VRFY_IRG(res, irg);
761   return res;
762 }
763
764 static ir_node *
765 new_bd_Psi (dbg_info *db, ir_node *block,
766     int arity, ir_node *cond[], ir_node *vals[], ir_mode *mode)
767 {
768   ir_node  **in;
769   ir_node  *res;
770   ir_graph *irg = current_ir_graph;
771   int i;
772
773   NEW_ARR_A(ir_node *, in, 2 * arity + 1);
774
775   for (i = 0; i < arity; ++i) {
776     in[2 * i]     = cond[i];
777     in[2 * i + 1] = vals[i];
778   }
779   in[2 * i] = vals[i];
780
781   res = new_ir_node(db, irg, block, op_Psi, mode, 2 * arity + 1, in);
782   assert(res);
783
784   res = optimize_node(res);
785   IRN_VRFY_IRG(res, irg);
786   return res;
787 }
788
789 static ir_node *
790 new_bd_CopyB  (dbg_info *db, ir_node *block,
791     ir_node *store, ir_node *dst, ir_node *src, ir_type *data_type)
792 {
793   ir_node  *in[3];
794   ir_node  *res;
795   ir_graph *irg = current_ir_graph;
796
797   in[0] = store;
798   in[1] = dst;
799   in[2] = src;
800
801   res = new_ir_node(db, irg, block, op_CopyB, mode_T, 3, in);
802
803   res->attr.copyb.exc.pin_state = op_pin_state_pinned;
804   res->attr.copyb.data_type     = data_type;
805   res = optimize_node(res);
806   IRN_VRFY_IRG(res, irg);
807   return res;
808 }
809
810 static ir_node *
811 new_bd_InstOf (dbg_info *db, ir_node *block, ir_node *store,
812            ir_node *objptr, ir_type *type)
813 {
814   ir_node  *in[2];
815   ir_node  *res;
816   ir_graph *irg = current_ir_graph;
817
818   in[0] = store;
819   in[1] = objptr;
820   res = new_ir_node(db, irg, block, op_Sel, mode_T, 2, in);
821   res->attr.io.type = type;
822   res = optimize_node(res);
823   IRN_VRFY_IRG(res, irg);
824   return res;
825 }
826
827 static ir_node *
828 new_bd_Raise (dbg_info *db, ir_node *block, ir_node *store, ir_node *obj)
829 {
830   ir_node  *in[2];
831   ir_node  *res;
832   ir_graph *irg = current_ir_graph;
833
834   in[0] = store;
835   in[1] = obj;
836   res = new_ir_node(db, irg, block, op_Raise, mode_T, 2, in);
837   res = optimize_node(res);
838   IRN_VRFY_IRG(res, irg);
839   return res;
840 }
841
842 static ir_node *
843 new_bd_Bound (dbg_info *db, ir_node *block,
844     ir_node *store, ir_node *idx, ir_node *lower, ir_node *upper)
845 {
846   ir_node  *in[4];
847   ir_node  *res;
848   ir_graph *irg = current_ir_graph;
849
850   in[0] = store;
851   in[1] = idx;
852   in[2] = lower;
853   in[3] = upper;
854   res = new_ir_node(db, irg, block, op_Bound, mode_T, 4, in);
855   res->attr.bound.exc.pin_state = op_pin_state_pinned;
856   res = optimize_node(res);
857   IRN_VRFY_IRG(res, irg);
858   return res;
859 }
860
861 /* --------------------------------------------- */
862 /* private interfaces, for professional use only */
863 /* --------------------------------------------- */
864
865 /* Constructs a Block with a fixed number of predecessors.
866    Does not set current_block.  Can not be used with automatic
867    Phi node construction. */
868 ir_node *
869 new_rd_Block (dbg_info *db, ir_graph *irg,  int arity, ir_node **in)
870 {
871   ir_graph *rem    = current_ir_graph;
872   ir_node  *res;
873
874   current_ir_graph = irg;
875   res = new_bd_Block (db, arity, in);
876   current_ir_graph = rem;
877
878   return res;
879 }
880
881 ir_node *
882 new_rd_Start (dbg_info *db, ir_graph *irg, ir_node *block)
883 {
884   ir_graph *rem = current_ir_graph;
885   ir_node  *res;
886
887   current_ir_graph = irg;
888   res = new_bd_Start (db, block);
889   current_ir_graph = rem;
890
891   return res;
892 }
893
894 ir_node *
895 new_rd_End (dbg_info *db, ir_graph *irg, ir_node *block)
896 {
897   ir_node  *res;
898   ir_graph *rem = current_ir_graph;
899
900   current_ir_graph = rem;
901   res = new_bd_End (db, block);
902   current_ir_graph = rem;
903
904   return res;
905 }
906
907 /* Creates a Phi node with all predecessors.  Calling this constructor
908    is only allowed if the corresponding block is mature.  */
909 ir_node *
910 new_rd_Phi (dbg_info *db, ir_graph *irg, ir_node *block, int arity, ir_node **in, ir_mode *mode)
911 {
912   ir_node  *res;
913   ir_graph *rem = current_ir_graph;
914
915   current_ir_graph  = irg;
916   res = new_bd_Phi (db, block,arity, in, mode);
917   current_ir_graph = rem;
918
919   return res;
920 }
921
922 ir_node *
923 new_rd_Const_type (dbg_info *db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con, ir_type *tp)
924 {
925   ir_node  *res;
926   ir_graph *rem = current_ir_graph;
927
928   current_ir_graph  = irg;
929   res = new_bd_Const_type (db, block, mode, con, tp);
930   current_ir_graph = rem;
931
932   return res;
933 }
934
935 ir_node *
936 new_rd_Const (dbg_info *db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con)
937 {
938   ir_node  *res;
939   ir_graph *rem = current_ir_graph;
940
941   current_ir_graph = irg;
942   res = new_bd_Const_type (db, block, mode, con, firm_unknown_type);
943   current_ir_graph = rem;
944
945   return res;
946 }
947
948 ir_node *
949 new_rd_Const_long (dbg_info *db, ir_graph *irg, ir_node *block, ir_mode *mode, long value)
950 {
951     return new_rd_Const(db, irg, block, mode, new_tarval_from_long(value, mode));
952 }
953
954 ir_node *
955 new_rd_Id (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *val, ir_mode *mode)
956 {
957   ir_node  *res;
958   ir_graph *rem = current_ir_graph;
959
960   current_ir_graph = irg;
961   res = new_bd_Id(db, block, val, mode);
962   current_ir_graph = rem;
963
964   return res;
965 }
966
967 ir_node *
968 new_rd_Proj (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg, ir_mode *mode,
969         long proj)
970 {
971   ir_node  *res;
972   ir_graph *rem = current_ir_graph;
973
974   current_ir_graph = irg;
975   res = new_bd_Proj(db, block, arg, mode, proj);
976   current_ir_graph = rem;
977
978   return res;
979 }
980
981 ir_node *
982 new_rd_defaultProj (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg,
983            long max_proj)
984 {
985   ir_node  *res;
986   ir_graph *rem = current_ir_graph;
987
988   current_ir_graph = irg;
989   res = new_bd_defaultProj(db, block, arg, max_proj);
990   current_ir_graph = rem;
991
992   return res;
993 }
994
995 ir_node *
996 new_rd_Conv (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *op, ir_mode *mode)
997 {
998   ir_node  *res;
999   ir_graph *rem = current_ir_graph;
1000
1001   current_ir_graph = irg;
1002   res = new_bd_Conv(db, block, op, mode);
1003   current_ir_graph = rem;
1004
1005   return res;
1006 }
1007
1008 ir_node *
1009 new_rd_Cast (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *op, ir_type *to_tp)
1010 {
1011   ir_node  *res;
1012   ir_graph *rem = current_ir_graph;
1013
1014   current_ir_graph = irg;
1015   res = new_bd_Cast(db, block, op, to_tp);
1016   current_ir_graph = rem;
1017
1018   return res;
1019 }
1020
1021 ir_node *
1022 new_rd_Tuple (dbg_info *db, ir_graph *irg, ir_node *block, int arity, ir_node **in)
1023 {
1024   ir_node  *res;
1025   ir_graph *rem = current_ir_graph;
1026
1027   current_ir_graph = irg;
1028   res = new_bd_Tuple(db, block, arity, in);
1029   current_ir_graph = rem;
1030
1031   return res;
1032 }
1033
1034 NEW_RD_BINOP(Add)
1035 NEW_RD_BINOP(Sub)
1036 NEW_RD_UNOP(Minus)
1037 NEW_RD_BINOP(Mul)
1038 NEW_RD_DIVOP(Quot)
1039 NEW_RD_DIVOP(DivMod)
1040 NEW_RD_DIVOP(Div)
1041 NEW_RD_DIVOP(Mod)
1042 NEW_RD_BINOP(And)
1043 NEW_RD_BINOP(Or)
1044 NEW_RD_BINOP(Eor)
1045 NEW_RD_UNOP(Not)
1046 NEW_RD_BINOP(Shl)
1047 NEW_RD_BINOP(Shr)
1048 NEW_RD_BINOP(Shrs)
1049 NEW_RD_BINOP(Rot)
1050 NEW_RD_UNOP(Abs)
1051 NEW_RD_BINOP(Carry)
1052 NEW_RD_BINOP(Borrow)
1053
1054 ir_node *
1055 new_rd_Cmp (dbg_info *db, ir_graph *irg, ir_node *block,
1056        ir_node *op1, ir_node *op2)
1057 {
1058   ir_node  *res;
1059   ir_graph *rem = current_ir_graph;
1060
1061   current_ir_graph = irg;
1062   res = new_bd_Cmp(db, block, op1, op2);
1063   current_ir_graph = rem;
1064
1065   return res;
1066 }
1067
1068 ir_node *
1069 new_rd_Jmp (dbg_info *db, ir_graph *irg, ir_node *block)
1070 {
1071   ir_node  *res;
1072   ir_graph *rem = current_ir_graph;
1073
1074   current_ir_graph = irg;
1075   res = new_bd_Jmp(db, block);
1076   current_ir_graph = rem;
1077
1078   return res;
1079 }
1080
1081 ir_node *
1082 new_rd_IJmp (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *tgt)
1083 {
1084   ir_node  *res;
1085   ir_graph *rem = current_ir_graph;
1086
1087   current_ir_graph = irg;
1088   res = new_bd_IJmp(db, block, tgt);
1089   current_ir_graph = rem;
1090
1091   return res;
1092 }
1093
1094 ir_node *
1095 new_rd_Cond (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *c)
1096 {
1097   ir_node  *res;
1098   ir_graph *rem = current_ir_graph;
1099
1100   current_ir_graph = irg;
1101   res = new_bd_Cond(db, block, c);
1102   current_ir_graph = rem;
1103
1104   return res;
1105 }
1106
1107 ir_node *
1108 new_rd_Call (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
1109         ir_node *callee, int arity, ir_node **in, ir_type *tp)
1110 {
1111   ir_node  *res;
1112   ir_graph *rem = current_ir_graph;
1113
1114   current_ir_graph = irg;
1115   res = new_bd_Call(db, block, store, callee, arity, in, tp);
1116   current_ir_graph = rem;
1117
1118   return res;
1119 }
1120
1121 ir_node *
1122 new_rd_Return (dbg_info *db, ir_graph *irg, ir_node *block,
1123               ir_node *store, int arity, ir_node **in)
1124 {
1125   ir_node  *res;
1126   ir_graph *rem = current_ir_graph;
1127
1128   current_ir_graph = irg;
1129   res = new_bd_Return(db, block, store, arity, in);
1130   current_ir_graph = rem;
1131
1132   return res;
1133 }
1134
1135 ir_node *
1136 new_rd_Load (dbg_info *db, ir_graph *irg, ir_node *block,
1137         ir_node *store, ir_node *adr, ir_mode *mode)
1138 {
1139   ir_node  *res;
1140   ir_graph *rem = current_ir_graph;
1141
1142   current_ir_graph = irg;
1143   res = new_bd_Load(db, block, store, adr, mode);
1144   current_ir_graph = rem;
1145
1146   return res;
1147 }
1148
1149 ir_node *
1150 new_rd_Store (dbg_info *db, ir_graph *irg, ir_node *block,
1151          ir_node *store, ir_node *adr, ir_node *val)
1152 {
1153   ir_node  *res;
1154   ir_graph *rem = current_ir_graph;
1155
1156   current_ir_graph = irg;
1157   res = new_bd_Store(db, block, store, adr, val);
1158   current_ir_graph = rem;
1159
1160   return res;
1161 }
1162
1163 ir_node *
1164 new_rd_Alloc (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
1165         ir_node *size, ir_type *alloc_type, where_alloc where)
1166 {
1167   ir_node  *res;
1168   ir_graph *rem = current_ir_graph;
1169
1170   current_ir_graph = irg;
1171   res = new_bd_Alloc (db, block, store, size, alloc_type, where);
1172   current_ir_graph = rem;
1173
1174   return res;
1175 }
1176
1177 ir_node *
1178 new_rd_Free (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
1179         ir_node *ptr, ir_node *size, ir_type *free_type, where_alloc where)
1180 {
1181   ir_node  *res;
1182   ir_graph *rem = current_ir_graph;
1183
1184   current_ir_graph = irg;
1185   res = new_bd_Free(db, block, store, ptr, size, free_type, where);
1186   current_ir_graph = rem;
1187
1188   return res;
1189 }
1190
1191 ir_node *
1192 new_rd_simpleSel (dbg_info *db, ir_graph *irg, ir_node *block,
1193                   ir_node *store, ir_node *objptr, entity *ent)
1194 {
1195   ir_node  *res;
1196   ir_graph *rem = current_ir_graph;
1197
1198   current_ir_graph = irg;
1199   res = new_bd_Sel(db, block, store, objptr, 0, NULL, ent);
1200   current_ir_graph = rem;
1201
1202   return res;
1203 }
1204
1205 ir_node *
1206 new_rd_Sel (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store, ir_node *objptr,
1207            int arity, ir_node **in, entity *ent)
1208 {
1209   ir_node  *res;
1210   ir_graph *rem = current_ir_graph;
1211
1212   current_ir_graph = irg;
1213   res = new_bd_Sel(db, block, store, objptr, arity, in, ent);
1214   current_ir_graph = rem;
1215
1216   return res;
1217 }
1218
1219 ir_node *
1220 new_rd_SymConst_type (dbg_info *db, ir_graph *irg, ir_node *block, symconst_symbol value,
1221               symconst_kind symkind, ir_type *tp)
1222 {
1223   ir_node  *res;
1224   ir_graph *rem = current_ir_graph;
1225
1226   current_ir_graph = irg;
1227   res = new_bd_SymConst_type(db, block, value, symkind, tp);
1228   current_ir_graph = rem;
1229
1230   return res;
1231 }
1232
1233 ir_node *
1234 new_rd_SymConst (dbg_info *db, ir_graph *irg, ir_node *block, symconst_symbol value,
1235          symconst_kind symkind)
1236 {
1237   ir_node *res = new_rd_SymConst_type(db, irg, block, value, symkind, firm_unknown_type);
1238   return res;
1239 }
1240
1241 ir_node *new_rd_SymConst_addr_ent (dbg_info *db, ir_graph *irg, entity *symbol, ir_type *tp)
1242 {
1243   symconst_symbol sym = {(ir_type *)symbol};
1244   return new_rd_SymConst_type(db, irg, get_irg_start_block(irg), sym, symconst_addr_ent, tp);
1245 }
1246
1247 ir_node *new_rd_SymConst_addr_name (dbg_info *db, ir_graph *irg, ident *symbol, ir_type *tp) {
1248   symconst_symbol sym = {(ir_type *)symbol};
1249   return new_rd_SymConst_type(db, irg, get_irg_start_block(irg), sym, symconst_addr_name, tp);
1250 }
1251
1252 ir_node *new_rd_SymConst_type_tag (dbg_info *db, ir_graph *irg, ir_type *symbol, ir_type *tp) {
1253   symconst_symbol sym = {symbol};
1254   return new_rd_SymConst_type(db, irg, get_irg_start_block(irg), sym, symconst_type_tag, tp);
1255 }
1256
1257 ir_node *new_rd_SymConst_size (dbg_info *db, ir_graph *irg, ir_type *symbol, ir_type *tp) {
1258   symconst_symbol sym = {symbol};
1259   return new_rd_SymConst_type(db, irg, get_irg_start_block(irg), sym, symconst_type_size, tp);
1260 }
1261
1262 ir_node *new_rd_SymConst_align (dbg_info *db, ir_graph *irg, ir_type *symbol, ir_type *tp) {
1263   symconst_symbol sym = {symbol};
1264   return new_rd_SymConst_type(db, irg, get_irg_start_block(irg), sym, symconst_type_align, tp);
1265 }
1266
1267 ir_node *
1268 new_rd_Sync (dbg_info *db, ir_graph *irg, ir_node *block, int arity, ir_node *in[])
1269 {
1270   ir_node  *res;
1271   ir_graph *rem = current_ir_graph;
1272   int      i;
1273
1274   current_ir_graph = irg;
1275   res = new_bd_Sync(db, block);
1276   current_ir_graph = rem;
1277
1278   for (i = 0; i < arity; ++i) add_Sync_pred(res, in[i]);
1279
1280   return res;
1281 }
1282
1283 ir_node *
1284 new_rd_Bad (ir_graph *irg) {
1285   return get_irg_bad(irg);
1286 }
1287
1288 ir_node *
1289 new_rd_Confirm (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *val, ir_node *bound, pn_Cmp cmp)
1290 {
1291   ir_node  *res;
1292   ir_graph *rem = current_ir_graph;
1293
1294   current_ir_graph = irg;
1295   res = new_bd_Confirm(db, block, val, bound, cmp);
1296   current_ir_graph = rem;
1297
1298   return res;
1299 }
1300
1301 /* this function is often called with current_ir_graph unset */
1302 ir_node *
1303 new_rd_Unknown (ir_graph *irg, ir_mode *m)
1304 {
1305   ir_node  *res;
1306   ir_graph *rem = current_ir_graph;
1307
1308   current_ir_graph = irg;
1309   res = new_bd_Unknown(m);
1310   current_ir_graph = rem;
1311
1312   return res;
1313 }
1314
1315 ir_node *
1316 new_rd_CallBegin (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *call)
1317 {
1318   ir_node  *res;
1319   ir_graph *rem = current_ir_graph;
1320
1321   current_ir_graph = irg;
1322   res = new_bd_CallBegin(db, block, call);
1323   current_ir_graph = rem;
1324
1325   return res;
1326 }
1327
1328 ir_node *
1329 new_rd_EndReg (dbg_info *db, ir_graph *irg, ir_node *block)
1330 {
1331   ir_node *res;
1332
1333   res = new_ir_node(db, irg, block, op_EndReg, mode_T, -1, NULL);
1334   set_irg_end_reg(irg, res);
1335   IRN_VRFY_IRG(res, irg);
1336   return res;
1337 }
1338
1339 ir_node *
1340 new_rd_EndExcept (dbg_info *db, ir_graph *irg, ir_node *block)
1341 {
1342   ir_node *res;
1343
1344   res = new_ir_node(db, irg, block, op_EndExcept, mode_T, -1, NULL);
1345   set_irg_end_except(irg, res);
1346   IRN_VRFY_IRG (res, irg);
1347   return res;
1348 }
1349
1350 ir_node *
1351 new_rd_Break (dbg_info *db, ir_graph *irg, ir_node *block)
1352 {
1353   ir_node  *res;
1354   ir_graph *rem = current_ir_graph;
1355
1356   current_ir_graph = irg;
1357   res = new_bd_Break(db, block);
1358   current_ir_graph = rem;
1359
1360   return res;
1361 }
1362
1363 ir_node *
1364 new_rd_Filter (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg, ir_mode *mode,
1365            long proj)
1366 {
1367   ir_node  *res;
1368   ir_graph *rem = current_ir_graph;
1369
1370   current_ir_graph = irg;
1371   res = new_bd_Filter(db, block, arg, mode, proj);
1372   current_ir_graph = rem;
1373
1374   return res;
1375 }
1376
1377 ir_node *
1378 new_rd_NoMem (ir_graph *irg) {
1379   return get_irg_no_mem(irg);
1380 }
1381
1382 ir_node *
1383 new_rd_Mux  (dbg_info *db, ir_graph *irg, ir_node *block,
1384     ir_node *sel, ir_node *ir_false, ir_node *ir_true, ir_mode *mode)
1385 {
1386   ir_node  *res;
1387   ir_graph *rem = current_ir_graph;
1388
1389   current_ir_graph = irg;
1390   res = new_bd_Mux(db, block, sel, ir_false, ir_true, mode);
1391   current_ir_graph = rem;
1392
1393   return res;
1394 }
1395
1396 ir_node *
1397 new_rd_Psi (dbg_info *db, ir_graph *irg, ir_node *block,
1398     int arity, ir_node *cond[], ir_node *vals[], ir_mode *mode)
1399 {
1400   ir_node  *res;
1401   ir_graph *rem = current_ir_graph;
1402
1403   current_ir_graph = irg;
1404   res = new_bd_Psi(db, block, arity, cond, vals, mode);
1405   current_ir_graph = rem;
1406
1407   return res;
1408 }
1409
1410 ir_node *new_rd_CopyB(dbg_info *db, ir_graph *irg, ir_node *block,
1411     ir_node *store, ir_node *dst, ir_node *src, ir_type *data_type)
1412 {
1413   ir_node  *res;
1414   ir_graph *rem = current_ir_graph;
1415
1416   current_ir_graph = irg;
1417   res = new_bd_CopyB(db, block, store, dst, src, data_type);
1418   current_ir_graph = rem;
1419
1420   return res;
1421 }
1422
1423 ir_node *
1424 new_rd_InstOf (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
1425            ir_node *objptr, ir_type *type)
1426 {
1427   ir_node  *res;
1428   ir_graph *rem = current_ir_graph;
1429
1430   current_ir_graph = irg;
1431   res = new_bd_InstOf(db, block, store, objptr, type);
1432   current_ir_graph = rem;
1433
1434   return res;
1435 }
1436
1437 ir_node *
1438 new_rd_Raise (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store, ir_node *obj)
1439 {
1440   ir_node  *res;
1441   ir_graph *rem = current_ir_graph;
1442
1443   current_ir_graph = irg;
1444   res = new_bd_Raise(db, block, store, obj);
1445   current_ir_graph = rem;
1446
1447   return res;
1448 }
1449
1450 ir_node *new_rd_Bound(dbg_info *db, ir_graph *irg, ir_node *block,
1451     ir_node *store, ir_node *idx, ir_node *lower, ir_node *upper)
1452 {
1453   ir_node  *res;
1454   ir_graph *rem = current_ir_graph;
1455
1456   current_ir_graph = irg;
1457   res = new_bd_Bound(db, block, store, idx, lower, upper);
1458   current_ir_graph = rem;
1459
1460   return res;
1461 }
1462
1463 ir_node *new_r_Block  (ir_graph *irg,  int arity, ir_node **in) {
1464   return new_rd_Block(NULL, irg, arity, in);
1465 }
1466 ir_node *new_r_Start  (ir_graph *irg, ir_node *block) {
1467   return new_rd_Start(NULL, irg, block);
1468 }
1469 ir_node *new_r_End    (ir_graph *irg, ir_node *block) {
1470   return new_rd_End(NULL, irg, block);
1471 }
1472 ir_node *new_r_Jmp    (ir_graph *irg, ir_node *block) {
1473   return new_rd_Jmp(NULL, irg, block);
1474 }
1475 ir_node *new_r_IJmp   (ir_graph *irg, ir_node *block, ir_node *tgt) {
1476   return new_rd_IJmp(NULL, irg, block, tgt);
1477 }
1478 ir_node *new_r_Cond   (ir_graph *irg, ir_node *block, ir_node *c) {
1479   return new_rd_Cond(NULL, irg, block, c);
1480 }
1481 ir_node *new_r_Return (ir_graph *irg, ir_node *block,
1482                ir_node *store, int arity, ir_node **in) {
1483   return new_rd_Return(NULL, irg, block, store, arity, in);
1484 }
1485 ir_node *new_r_Const  (ir_graph *irg, ir_node *block,
1486                ir_mode *mode, tarval *con) {
1487   return new_rd_Const(NULL, irg, block, mode, con);
1488 }
1489 ir_node *new_r_Const_long(ir_graph *irg, ir_node *block,
1490                ir_mode *mode, long value) {
1491   return new_rd_Const_long(NULL, irg, block, mode, value);
1492 }
1493 ir_node *new_r_Const_type(ir_graph *irg, ir_node *block,
1494                ir_mode *mode, tarval *con, ir_type *tp) {
1495   return new_rd_Const_type(NULL, irg, block, mode, con, tp);
1496 }
1497 ir_node *new_r_SymConst (ir_graph *irg, ir_node *block,
1498                        symconst_symbol value, symconst_kind symkind) {
1499   return new_rd_SymConst(NULL, irg, block, value, symkind);
1500 }
1501 ir_node *new_r_simpleSel(ir_graph *irg, ir_node *block, ir_node *store,
1502                          ir_node *objptr, entity *ent) {
1503   return new_rd_Sel(NULL, irg, block, store, objptr, 0, NULL, ent);
1504 }
1505 ir_node *new_r_Sel    (ir_graph *irg, ir_node *block, ir_node *store,
1506                   ir_node *objptr, int n_index, ir_node **index,
1507                   entity *ent) {
1508   return new_rd_Sel(NULL, irg, block, store, objptr, n_index, index, ent);
1509 }
1510 ir_node *new_r_Call   (ir_graph *irg, ir_node *block, ir_node *store,
1511                   ir_node *callee, int arity, ir_node **in,
1512                   ir_type *tp) {
1513   return new_rd_Call(NULL, irg, block, store, callee, arity, in, tp);
1514 }
1515 ir_node *new_r_Add    (ir_graph *irg, ir_node *block,
1516                   ir_node *op1, ir_node *op2, ir_mode *mode) {
1517   return new_rd_Add(NULL, irg, block, op1, op2, mode);
1518 }
1519 ir_node *new_r_Sub    (ir_graph *irg, ir_node *block,
1520                   ir_node *op1, ir_node *op2, ir_mode *mode) {
1521   return new_rd_Sub(NULL, irg, block, op1, op2, mode);
1522 }
1523 ir_node *new_r_Minus  (ir_graph *irg, ir_node *block,
1524                   ir_node *op,  ir_mode *mode) {
1525   return new_rd_Minus(NULL, irg, block,  op, mode);
1526 }
1527 ir_node *new_r_Mul    (ir_graph *irg, ir_node *block,
1528                   ir_node *op1, ir_node *op2, ir_mode *mode) {
1529   return new_rd_Mul(NULL, irg, block, op1, op2, mode);
1530 }
1531 ir_node *new_r_Quot   (ir_graph *irg, ir_node *block,
1532                   ir_node *memop, ir_node *op1, ir_node *op2) {
1533   return new_rd_Quot(NULL, irg, block, memop, op1, op2);
1534 }
1535 ir_node *new_r_DivMod (ir_graph *irg, ir_node *block,
1536                   ir_node *memop, ir_node *op1, ir_node *op2) {
1537   return new_rd_DivMod(NULL, irg, block, memop, op1, op2);
1538 }
1539 ir_node *new_r_Div    (ir_graph *irg, ir_node *block,
1540                   ir_node *memop, ir_node *op1, ir_node *op2) {
1541   return new_rd_Div(NULL, irg, block, memop, op1, op2);
1542 }
1543 ir_node *new_r_Mod    (ir_graph *irg, ir_node *block,
1544                   ir_node *memop, ir_node *op1, ir_node *op2) {
1545   return new_rd_Mod(NULL, irg, block, memop, op1, op2);
1546 }
1547 ir_node *new_r_Abs    (ir_graph *irg, ir_node *block,
1548                   ir_node *op, ir_mode *mode) {
1549   return new_rd_Abs(NULL, irg, block, op, mode);
1550 }
1551 ir_node *new_r_And    (ir_graph *irg, ir_node *block,
1552                   ir_node *op1, ir_node *op2, ir_mode *mode) {
1553   return new_rd_And(NULL, irg, block,  op1, op2, mode);
1554 }
1555 ir_node *new_r_Or     (ir_graph *irg, ir_node *block,
1556                   ir_node *op1, ir_node *op2, ir_mode *mode) {
1557   return new_rd_Or(NULL, irg, block,  op1, op2, mode);
1558 }
1559 ir_node *new_r_Eor    (ir_graph *irg, ir_node *block,
1560                   ir_node *op1, ir_node *op2, ir_mode *mode) {
1561   return new_rd_Eor(NULL, irg, block,  op1, op2, mode);
1562 }
1563 ir_node *new_r_Not    (ir_graph *irg, ir_node *block,
1564                ir_node *op, ir_mode *mode) {
1565   return new_rd_Not(NULL, irg, block, op, mode);
1566 }
1567 ir_node *new_r_Shl    (ir_graph *irg, ir_node *block,
1568                ir_node *op, ir_node *k, ir_mode *mode) {
1569   return new_rd_Shl(NULL, irg, block, op, k, mode);
1570 }
1571 ir_node *new_r_Shr    (ir_graph *irg, ir_node *block,
1572                ir_node *op, ir_node *k, ir_mode *mode) {
1573   return new_rd_Shr(NULL, irg, block, op, k, mode);
1574 }
1575 ir_node *new_r_Shrs   (ir_graph *irg, ir_node *block,
1576                ir_node *op, ir_node *k, ir_mode *mode) {
1577   return new_rd_Shrs(NULL, irg, block, op, k, mode);
1578 }
1579 ir_node *new_r_Rot    (ir_graph *irg, ir_node *block,
1580                ir_node *op, ir_node *k, ir_mode *mode) {
1581   return new_rd_Rot(NULL, irg, block, op, k, mode);
1582 }
1583 ir_node *new_r_Carry  (ir_graph *irg, ir_node *block,
1584                ir_node *op, ir_node *k, ir_mode *mode) {
1585   return new_rd_Carry(NULL, irg, block, op, k, mode);
1586 }
1587 ir_node *new_r_Borrow (ir_graph *irg, ir_node *block,
1588                ir_node *op, ir_node *k, ir_mode *mode) {
1589   return new_rd_Borrow(NULL, irg, block, op, k, mode);
1590 }
1591 ir_node *new_r_Cmp    (ir_graph *irg, ir_node *block,
1592                ir_node *op1, ir_node *op2) {
1593   return new_rd_Cmp(NULL, irg, block, op1, op2);
1594 }
1595 ir_node *new_r_Conv   (ir_graph *irg, ir_node *block,
1596                ir_node *op, ir_mode *mode) {
1597   return new_rd_Conv(NULL, irg, block, op, mode);
1598 }
1599 ir_node *new_r_Cast   (ir_graph *irg, ir_node *block, ir_node *op, ir_type *to_tp) {
1600   return new_rd_Cast(NULL, irg, block, op, to_tp);
1601 }
1602 ir_node *new_r_Phi    (ir_graph *irg, ir_node *block, int arity,
1603                ir_node **in, ir_mode *mode) {
1604   return new_rd_Phi(NULL, irg, block, arity, in, mode);
1605 }
1606 ir_node *new_r_Load   (ir_graph *irg, ir_node *block,
1607                ir_node *store, ir_node *adr, ir_mode *mode) {
1608   return new_rd_Load(NULL, irg, block, store, adr, mode);
1609 }
1610 ir_node *new_r_Store  (ir_graph *irg, ir_node *block,
1611                ir_node *store, ir_node *adr, ir_node *val) {
1612   return new_rd_Store(NULL, irg, block, store, adr, val);
1613 }
1614 ir_node *new_r_Alloc  (ir_graph *irg, ir_node *block, ir_node *store,
1615                ir_node *size, ir_type *alloc_type, where_alloc where) {
1616   return new_rd_Alloc(NULL, irg, block, store, size, alloc_type, where);
1617 }
1618 ir_node *new_r_Free   (ir_graph *irg, ir_node *block, ir_node *store,
1619                ir_node *ptr, ir_node *size, ir_type *free_type, where_alloc where) {
1620   return new_rd_Free(NULL, irg, block, store, ptr, size, free_type, where);
1621 }
1622 ir_node *new_r_Sync   (ir_graph *irg, ir_node *block, int arity, ir_node *in[]) {
1623   return new_rd_Sync(NULL, irg, block, arity, in);
1624 }
1625 ir_node *new_r_Proj   (ir_graph *irg, ir_node *block, ir_node *arg,
1626                ir_mode *mode, long proj) {
1627   return new_rd_Proj(NULL, irg, block, arg, mode, proj);
1628 }
1629 ir_node *new_r_defaultProj (ir_graph *irg, ir_node *block, ir_node *arg,
1630                 long max_proj) {
1631   return new_rd_defaultProj(NULL, irg, block, arg, max_proj);
1632 }
1633 ir_node *new_r_Tuple  (ir_graph *irg, ir_node *block,
1634                int arity, ir_node **in) {
1635   return new_rd_Tuple(NULL, irg, block, arity, in );
1636 }
1637 ir_node *new_r_Id     (ir_graph *irg, ir_node *block,
1638                ir_node *val, ir_mode *mode) {
1639   return new_rd_Id(NULL, irg, block, val, mode);
1640 }
1641 ir_node *new_r_Bad    (ir_graph *irg) {
1642   return new_rd_Bad(irg);
1643 }
1644 ir_node *new_r_Confirm (ir_graph *irg, ir_node *block, ir_node *val, ir_node *bound, pn_Cmp cmp) {
1645   return new_rd_Confirm (NULL, irg, block, val, bound, cmp);
1646 }
1647 ir_node *new_r_Unknown (ir_graph *irg, ir_mode *m) {
1648   return new_rd_Unknown(irg, m);
1649 }
1650 ir_node *new_r_CallBegin (ir_graph *irg, ir_node *block, ir_node *callee) {
1651   return new_rd_CallBegin(NULL, irg, block, callee);
1652 }
1653 ir_node *new_r_EndReg (ir_graph *irg, ir_node *block) {
1654   return new_rd_EndReg(NULL, irg, block);
1655 }
1656 ir_node *new_r_EndExcept (ir_graph *irg, ir_node *block) {
1657   return new_rd_EndExcept(NULL, irg, block);
1658 }
1659 ir_node *new_r_Break  (ir_graph *irg, ir_node *block) {
1660   return new_rd_Break(NULL, irg, block);
1661 }
1662 ir_node *new_r_Filter (ir_graph *irg, ir_node *block, ir_node *arg,
1663                ir_mode *mode, long proj) {
1664   return new_rd_Filter(NULL, irg, block, arg, mode, proj);
1665 }
1666 ir_node *new_r_NoMem  (ir_graph *irg) {
1667   return new_rd_NoMem(irg);
1668 }
1669 ir_node *new_r_Mux (ir_graph *irg, ir_node *block,
1670     ir_node *sel, ir_node *ir_false, ir_node *ir_true, ir_mode *mode) {
1671   return new_rd_Mux(NULL, irg, block, sel, ir_false, ir_true, mode);
1672 }
1673 ir_node *new_r_Psi (ir_graph *irg, ir_node *block,
1674     int arity, ir_node *conds[], ir_node *vals[], ir_mode *mode) {
1675   return new_rd_Psi(NULL, irg, block, arity, conds, vals, mode);
1676 }
1677 ir_node *new_r_CopyB(ir_graph *irg, ir_node *block,
1678     ir_node *store, ir_node *dst, ir_node *src, ir_type *data_type) {
1679   return new_rd_CopyB(NULL, irg, block, store, dst, src, data_type);
1680 }
1681 ir_node *new_r_InstOf (ir_graph *irg, ir_node *block, ir_node *store, ir_node *objptr,
1682                   ir_type *type) {
1683   return (new_rd_InstOf (NULL, irg, block, store, objptr, type));
1684 }
1685 ir_node *new_r_Raise  (ir_graph *irg, ir_node *block,
1686                ir_node *store, ir_node *obj) {
1687   return new_rd_Raise(NULL, irg, block, store, obj);
1688 }
1689 ir_node *new_r_Bound(ir_graph *irg, ir_node *block,
1690     ir_node *store, ir_node *idx, ir_node *lower, ir_node *upper) {
1691   return new_rd_Bound(NULL, irg, block, store, idx, lower, upper);
1692 }
1693
1694 /** ********************/
1695 /** public interfaces  */
1696 /** construction tools */
1697
1698 /**
1699  *
1700  *   - create a new Start node in the current block
1701  *
1702  *   @return s - pointer to the created Start node
1703  *
1704  *
1705  */
1706 ir_node *
1707 new_d_Start (dbg_info *db)
1708 {
1709   ir_node *res;
1710
1711   res = new_ir_node (db, current_ir_graph, current_ir_graph->current_block,
1712              op_Start, mode_T, 0, NULL);
1713   /* res->attr.start.irg = current_ir_graph; */
1714
1715   res = optimize_node(res);
1716   IRN_VRFY_IRG(res, current_ir_graph);
1717   return res;
1718 }
1719
1720 ir_node *
1721 new_d_End (dbg_info *db)
1722 {
1723   ir_node *res;
1724   res = new_ir_node(db, current_ir_graph,  current_ir_graph->current_block,
1725              op_End, mode_X, -1, NULL);
1726   res = optimize_node(res);
1727   IRN_VRFY_IRG(res, current_ir_graph);
1728
1729   return res;
1730 }
1731
1732 /* Constructs a Block with a fixed number of predecessors.
1733    Does set current_block.  Can be used with automatic Phi
1734    node construction. */
1735 ir_node *
1736 new_d_Block (dbg_info *db, int arity, ir_node **in)
1737 {
1738   ir_node *res;
1739   int i;
1740   int has_unknown = 0;
1741
1742   res = new_bd_Block(db, arity, in);
1743
1744   /* Create and initialize array for Phi-node construction. */
1745   if (get_irg_phase_state(current_ir_graph) == phase_building) {
1746     res->attr.block.graph_arr = NEW_ARR_D(ir_node *, current_ir_graph->obst,
1747                       current_ir_graph->n_loc);
1748     memset(res->attr.block.graph_arr, 0, sizeof(ir_node *)*current_ir_graph->n_loc);
1749   }
1750
1751   for (i = arity-1; i >= 0; i--)
1752     if (get_irn_op(in[i]) == op_Unknown) {
1753       has_unknown = 1;
1754       break;
1755     }
1756
1757   if (!has_unknown) res = optimize_node(res);
1758   current_ir_graph->current_block = res;
1759
1760   IRN_VRFY_IRG(res, current_ir_graph);
1761
1762   return res;
1763 }
1764
1765 /* ***********************************************************************/
1766 /* Methods necessary for automatic Phi node creation                     */
1767 /*
1768   ir_node *phi_merge            (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
1769   ir_node *get_r_value_internal (ir_node *block, int pos, ir_mode *mode);
1770   ir_node *new_rd_Phi0          (ir_graph *irg, ir_node *block, ir_mode *mode)
1771   ir_node *new_rd_Phi_in        (ir_graph *irg, ir_node *block, ir_mode *mode, ir_node **in, int ins)
1772
1773   Call Graph:   ( A ---> B == A "calls" B)
1774
1775        get_value         mature_immBlock
1776           |                   |
1777           |                   |
1778           |                   |
1779           |          ---> phi_merge
1780           |         /       /   \
1781           |        /       /     \
1782          \|/      /      |/_      \
1783        get_r_value_internal        |
1784                 |                  |
1785             |                  |
1786            \|/                \|/
1787         new_rd_Phi0          new_rd_Phi_in
1788
1789 * *************************************************************************** */
1790
1791 /** Creates a Phi node with 0 predecessors */
1792 static INLINE ir_node *
1793 new_rd_Phi0 (ir_graph *irg, ir_node *block, ir_mode *mode)
1794 {
1795   ir_node *res;
1796
1797   res = new_ir_node(NULL, irg, block, op_Phi, mode, 0, NULL);
1798   IRN_VRFY_IRG(res, irg);
1799   return res;
1800 }
1801
1802 /* There are two implementations of the Phi node construction.  The first
1803    is faster, but does not work for blocks with more than 2 predecessors.
1804    The second works always but is slower and causes more unnecessary Phi
1805    nodes.
1806    Select the implementations by the following preprocessor flag set in
1807    common/common.h: */
1808 #if USE_FAST_PHI_CONSTRUCTION
1809
1810 /* This is a stack used for allocating and deallocating nodes in
1811    new_rd_Phi_in.  The original implementation used the obstack
1812    to model this stack, now it is explicit.  This reduces side effects.
1813 */
1814 #if USE_EXPLICIT_PHI_IN_STACK
1815 Phi_in_stack *
1816 new_Phi_in_stack(void) {
1817   Phi_in_stack *res;
1818
1819   res = (Phi_in_stack *) malloc ( sizeof (Phi_in_stack));
1820
1821   res->stack = NEW_ARR_F (ir_node *, 0);
1822   res->pos = 0;
1823
1824   return res;
1825 }
1826
1827 void
1828 free_Phi_in_stack(Phi_in_stack *s) {
1829   DEL_ARR_F(s->stack);
1830   free(s);
1831 }
1832 static INLINE void
1833 free_to_Phi_in_stack(ir_node *phi) {
1834   if (ARR_LEN(current_ir_graph->Phi_in_stack->stack) ==
1835       current_ir_graph->Phi_in_stack->pos)
1836     ARR_APP1 (ir_node *, current_ir_graph->Phi_in_stack->stack, phi);
1837   else
1838     current_ir_graph->Phi_in_stack->stack[current_ir_graph->Phi_in_stack->pos] = phi;
1839
1840   (current_ir_graph->Phi_in_stack->pos)++;
1841 }
1842
1843 static INLINE ir_node *
1844 alloc_or_pop_from_Phi_in_stack(ir_graph *irg, ir_node *block, ir_mode *mode,
1845          int arity, ir_node **in) {
1846   ir_node *res;
1847   ir_node **stack = current_ir_graph->Phi_in_stack->stack;
1848   int pos = current_ir_graph->Phi_in_stack->pos;
1849
1850
1851   if (pos == 0) {
1852     /* We need to allocate a new node */
1853     res = new_ir_node (db, irg, block, op_Phi, mode, arity, in);
1854     res->attr.phi_backedge = new_backedge_arr(irg->obst, arity);
1855   } else {
1856     /* reuse the old node and initialize it again. */
1857     res = stack[pos-1];
1858
1859     assert (res->kind == k_ir_node);
1860     assert (res->op == op_Phi);
1861     res->mode = mode;
1862     res->visited = 0;
1863     res->link = NULL;
1864     assert (arity >= 0);
1865     /* ???!!! How to free the old in array??  Not at all: on obstack ?!! */
1866     res->in = NEW_ARR_D (ir_node *, irg->obst, (arity+1));
1867     res->in[0] = block;
1868     memcpy (&res->in[1], in, sizeof (ir_node *) * arity);
1869
1870     (current_ir_graph->Phi_in_stack->pos)--;
1871   }
1872   return res;
1873 }
1874 #endif /* USE_EXPLICIT_PHI_IN_STACK */
1875
1876 /* Creates a Phi node with a given, fixed array **in of predecessors.
1877    If the Phi node is unnecessary, as the same value reaches the block
1878    through all control flow paths, it is eliminated and the value
1879    returned directly.  This constructor is only intended for use in
1880    the automatic Phi node generation triggered by get_value or mature.
1881    The implementation is quite tricky and depends on the fact, that
1882    the nodes are allocated on a stack:
1883    The in array contains predecessors and NULLs.  The NULLs appear,
1884    if get_r_value_internal, that computed the predecessors, reached
1885    the same block on two paths.  In this case the same value reaches
1886    this block on both paths, there is no definition in between.  We need
1887    not allocate a Phi where these path's merge, but we have to communicate
1888    this fact to the caller.  This happens by returning a pointer to the
1889    node the caller _will_ allocate.  (Yes, we predict the address. We can
1890    do so because the nodes are allocated on the obstack.)  The caller then
1891    finds a pointer to itself and, when this routine is called again,
1892    eliminates itself.
1893    */
1894 static INLINE ir_node *
1895 new_rd_Phi_in (ir_graph *irg, ir_node *block, ir_mode *mode, ir_node **in, int ins)
1896 {
1897   int i;
1898   ir_node *res, *known;
1899
1900   /* Allocate a new node on the obstack.  This can return a node to
1901      which some of the pointers in the in-array already point.
1902      Attention: the constructor copies the in array, i.e., the later
1903      changes to the array in this routine do not affect the
1904      constructed node!  If the in array contains NULLs, there will be
1905      missing predecessors in the returned node.  Is this a possible
1906      internal state of the Phi node generation? */
1907 #if USE_EXPLICIT_PHI_IN_STACK
1908   res = known = alloc_or_pop_from_Phi_in_stack(irg, block, mode, ins, in);
1909 #else
1910   res = known = new_ir_node (NULL, irg, block, op_Phi, mode, ins, in);
1911   res->attr.phi_backedge = new_backedge_arr(irg->obst, ins);
1912 #endif
1913
1914   /* The in-array can contain NULLs.  These were returned by
1915      get_r_value_internal if it reached the same block/definition on a
1916      second path.  The NULLs are replaced by the node itself to
1917      simplify the test in the next loop. */
1918   for (i = 0;  i < ins;  ++i) {
1919     if (in[i] == NULL)
1920       in[i] = res;
1921   }
1922
1923   /* This loop checks whether the Phi has more than one predecessor.
1924      If so, it is a real Phi node and we break the loop.  Else the Phi
1925      node merges the same definition on several paths and therefore is
1926      not needed. */
1927   for (i = 0;  i < ins;  ++i) {
1928     if (in[i] == res || in[i] == known)
1929       continue;
1930
1931     if (known == res)
1932       known = in[i];
1933     else
1934       break;
1935   }
1936
1937   /* i==ins: there is at most one predecessor, we don't need a phi node. */
1938   if (i==ins) {
1939 #if USE_EXPLICIT_PHI_IN_STACK
1940     free_to_Phi_in_stack(res);
1941 #else
1942     edges_node_deleted(res, current_ir_graph);
1943     obstack_free(current_ir_graph->obst, res);
1944 #endif
1945     res = known;
1946   } else {
1947     res = optimize_node (res);
1948     IRN_VRFY_IRG(res, irg);
1949   }
1950
1951   /* return the pointer to the Phi node.  This node might be deallocated! */
1952   return res;
1953 }
1954
1955 static ir_node *
1956 get_r_value_internal (ir_node *block, int pos, ir_mode *mode);
1957
1958 /**
1959     allocates and returns this node.  The routine called to allocate the
1960     node might optimize it away and return a real value, or even a pointer
1961     to a deallocated Phi node on top of the obstack!
1962     This function is called with an in-array of proper size. **/
1963 static ir_node *
1964 phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
1965 {
1966   ir_node *prevBlock, *res;
1967   int i;
1968
1969   /* This loop goes to all predecessor blocks of the block the Phi node is in
1970      and there finds the operands of the Phi node by calling
1971      get_r_value_internal. */
1972   for (i = 1;  i <= ins;  ++i) {
1973     assert (block->in[i]);
1974     prevBlock = block->in[i]->in[0]; /* go past control flow op to prev block */
1975     assert (prevBlock);
1976     nin[i-1] = get_r_value_internal (prevBlock, pos, mode);
1977   }
1978
1979   /* After collecting all predecessors into the array nin a new Phi node
1980      with these predecessors is created.  This constructor contains an
1981      optimization: If all predecessors of the Phi node are identical it
1982      returns the only operand instead of a new Phi node.  If the value
1983      passes two different control flow edges without being defined, and
1984      this is the second path treated, a pointer to the node that will be
1985      allocated for the first path (recursion) is returned.  We already
1986      know the address of this node, as it is the next node to be allocated
1987      and will be placed on top of the obstack. (The obstack is a _stack_!) */
1988   res = new_rd_Phi_in (current_ir_graph, block, mode, nin, ins);
1989
1990   /* Now we now the value for "pos" and can enter it in the array with
1991      all known local variables.  Attention: this might be a pointer to
1992      a node, that later will be allocated!!! See new_rd_Phi_in().
1993      If this is called in mature, after some set_value() in the same block,
1994      the proper value must not be overwritten:
1995      The call order
1996        get_value    (makes Phi0, put's it into graph_arr)
1997        set_value    (overwrites Phi0 in graph_arr)
1998        mature_immBlock (upgrades Phi0, puts it again into graph_arr, overwriting
1999                      the proper value.)
2000      fails. */
2001   if (!block->attr.block.graph_arr[pos]) {
2002     block->attr.block.graph_arr[pos] = res;
2003   } else {
2004     /*  printf(" value already computed by %s\n",
2005         get_id_str(block->attr.block.graph_arr[pos]->op->name));  */
2006   }
2007
2008   return res;
2009 }
2010
2011 /* This function returns the last definition of a variable.  In case
2012    this variable was last defined in a previous block, Phi nodes are
2013    inserted.  If the part of the firm graph containing the definition
2014    is not yet constructed, a dummy Phi node is returned. */
2015 static ir_node *
2016 get_r_value_internal (ir_node *block, int pos, ir_mode *mode)
2017 {
2018   ir_node *res;
2019   /* There are 4 cases to treat.
2020
2021      1. The block is not mature and we visit it the first time.  We can not
2022         create a proper Phi node, therefore a Phi0, i.e., a Phi without
2023         predecessors is returned.  This node is added to the linked list (field
2024         "link") of the containing block to be completed when this block is
2025         matured. (Completion will add a new Phi and turn the Phi0 into an Id
2026         node.)
2027
2028      2. The value is already known in this block, graph_arr[pos] is set and we
2029         visit the block the first time.  We can return the value without
2030         creating any new nodes.
2031
2032      3. The block is mature and we visit it the first time.  A Phi node needs
2033         to be created (phi_merge).  If the Phi is not needed, as all it's
2034         operands are the same value reaching the block through different
2035         paths, it's optimized away and the value itself is returned.
2036
2037      4. The block is mature, and we visit it the second time.  Now two
2038         subcases are possible:
2039         * The value was computed completely the last time we were here. This
2040           is the case if there is no loop.  We can return the proper value.
2041         * The recursion that visited this node and set the flag did not
2042           return yet.  We are computing a value in a loop and need to
2043           break the recursion without knowing the result yet.
2044       @@@ strange case.  Straight forward we would create a Phi before
2045       starting the computation of it's predecessors.  In this case we will
2046       find a Phi here in any case.  The problem is that this implementation
2047       only creates a Phi after computing the predecessors, so that it is
2048       hard to compute self references of this Phi.  @@@
2049         There is no simple check for the second subcase.  Therefore we check
2050         for a second visit and treat all such cases as the second subcase.
2051         Anyways, the basic situation is the same:  we reached a block
2052         on two paths without finding a definition of the value:  No Phi
2053         nodes are needed on both paths.
2054         We return this information "Two paths, no Phi needed" by a very tricky
2055         implementation that relies on the fact that an obstack is a stack and
2056         will return a node with the same address on different allocations.
2057         Look also at phi_merge and new_rd_phi_in to understand this.
2058     @@@ Unfortunately this does not work, see testprogram
2059     three_cfpred_example.
2060
2061   */
2062
2063   /* case 4 -- already visited. */
2064   if (get_irn_visited(block) == get_irg_visited(current_ir_graph)) return NULL;
2065
2066   /* visited the first time */
2067   set_irn_visited(block, get_irg_visited(current_ir_graph));
2068
2069   /* Get the local valid value */
2070   res = block->attr.block.graph_arr[pos];
2071
2072   /* case 2 -- If the value is actually computed, return it. */
2073   if (res) return res;
2074
2075   if (block->attr.block.matured) { /* case 3 */
2076
2077     /* The Phi has the same amount of ins as the corresponding block. */
2078     int ins = get_irn_arity(block);
2079     ir_node **nin;
2080     NEW_ARR_A (ir_node *, nin, ins);
2081
2082     /* Phi merge collects the predecessors and then creates a node. */
2083     res = phi_merge (block, pos, mode, nin, ins);
2084
2085   } else {  /* case 1 */
2086     /* The block is not mature, we don't know how many in's are needed.  A Phi
2087        with zero predecessors is created.  Such a Phi node is called Phi0
2088        node.  (There is also an obsolete Phi0 opcode.) The Phi0 is then added
2089        to the list of Phi0 nodes in this block to be matured by mature_immBlock
2090        later.
2091        The Phi0 has to remember the pos of it's internal value.  If the real
2092        Phi is computed, pos is used to update the array with the local
2093        values. */
2094
2095     res = new_rd_Phi0 (current_ir_graph, block, mode);
2096     res->attr.phi0_pos = pos;
2097     res->link = block->link;
2098     block->link = res;
2099   }
2100
2101   /* If we get here, the frontend missed a use-before-definition error */
2102   if (!res) {
2103     /* Error Message */
2104     printf("Error: no value set.  Use of undefined variable.  Initializing to zero.\n");
2105     assert (mode->code >= irm_F && mode->code <= irm_P);
2106     res = new_rd_Const (NULL, current_ir_graph, block, mode,
2107                tarval_mode_null[mode->code]);
2108   }
2109
2110   /* The local valid value is available now. */
2111   block->attr.block.graph_arr[pos] = res;
2112
2113   return res;
2114 }
2115
2116 #else /* if 0 */
2117
2118 /**
2119     it starts the recursion.  This causes an Id at the entry of
2120     every block that has no definition of the value! **/
2121
2122 #if USE_EXPLICIT_PHI_IN_STACK
2123 /* Just dummies */
2124 Phi_in_stack * new_Phi_in_stack() {  return NULL; }
2125 void free_Phi_in_stack(Phi_in_stack *s) { }
2126 #endif
2127
2128 static INLINE ir_node *
2129 new_rd_Phi_in (ir_graph *irg, ir_node *block, ir_mode *mode,
2130            ir_node **in, int ins, ir_node *phi0)
2131 {
2132   int i;
2133   ir_node *res, *known;
2134
2135   /* Allocate a new node on the obstack.  The allocation copies the in
2136      array. */
2137   res = new_ir_node (NULL, irg, block, op_Phi, mode, ins, in);
2138   res->attr.phi_backedge = new_backedge_arr(irg->obst, ins);
2139
2140   /* This loop checks whether the Phi has more than one predecessor.
2141      If so, it is a real Phi node and we break the loop.  Else the
2142      Phi node merges the same definition on several paths and therefore
2143      is not needed. Don't consider Bad nodes! */
2144   known = res;
2145   for (i=0;  i < ins;  ++i)
2146   {
2147     assert(in[i]);
2148
2149     in[i] = skip_Id(in[i]);  /* increases the number of freed Phis. */
2150
2151     /* Optimize self referencing Phis:  We can't detect them yet properly, as
2152        they still refer to the Phi0 they will replace.  So replace right now. */
2153     if (phi0 && in[i] == phi0) in[i] = res;
2154
2155     if (in[i]==res || in[i]==known || is_Bad(in[i])) continue;
2156
2157     if (known==res)
2158       known = in[i];
2159     else
2160       break;
2161   }
2162
2163   /* i==ins: there is at most one predecessor, we don't need a phi node. */
2164   if (i == ins) {
2165     if (res != known) {
2166       edges_node_deleted(res, current_ir_graph);
2167       obstack_free (current_ir_graph->obst, res);
2168       if (is_Phi(known)) {
2169         /* If pred is a phi node we want to optimize it: If loops are matured in a bad
2170            order, an enclosing Phi know may get superfluous. */
2171         res = optimize_in_place_2(known);
2172         if (res != known)
2173           exchange(known, res);
2174
2175       }
2176       else
2177         res = known;
2178     } else {
2179       /* A undefined value, e.g., in unreachable code. */
2180       res = new_Bad();
2181     }
2182   } else {
2183     res = optimize_node (res);  /* This is necessary to add the node to the hash table for cse. */
2184     IRN_VRFY_IRG(res, irg);
2185     /* Memory Phis in endless loops must be kept alive.
2186        As we can't distinguish these easily we keep all of them alive. */
2187     if ((res->op == op_Phi) && (mode == mode_M))
2188       add_End_keepalive(get_irg_end(irg), res);
2189   }
2190
2191   return res;
2192 }
2193
2194 static ir_node *
2195 get_r_value_internal (ir_node *block, int pos, ir_mode *mode);
2196
2197 #if PRECISE_EXC_CONTEXT
2198 static ir_node *
2199 phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins);
2200
2201 /* Construct a new frag_array for node n.
2202    Copy the content from the current graph_arr of the corresponding block:
2203    this is the current state.
2204    Set ProjM(n) as current memory state.
2205    Further the last entry in frag_arr of current block points to n.  This
2206    constructs a chain block->last_frag_op-> ... first_frag_op of all frag ops in the block.
2207  */
2208 static INLINE ir_node ** new_frag_arr (ir_node *n)
2209 {
2210   ir_node **arr;
2211   int opt;
2212
2213   arr = NEW_ARR_D (ir_node *, current_ir_graph->obst, current_ir_graph->n_loc);
2214   memcpy(arr, current_ir_graph->current_block->attr.block.graph_arr,
2215      sizeof(ir_node *)*current_ir_graph->n_loc);
2216
2217   /* turn off optimization before allocating Proj nodes, as res isn't
2218      finished yet. */
2219   opt = get_opt_optimize(); set_optimize(0);
2220   /* Here we rely on the fact that all frag ops have Memory as first result! */
2221   if (get_irn_op(n) == op_Call)
2222     arr[0] = new_Proj(n, mode_M, pn_Call_M_except);
2223   else if (get_irn_op(n) == op_CopyB)
2224     arr[0] = new_Proj(n, mode_M, pn_CopyB_M_except);
2225   else {
2226     assert((pn_Quot_M == pn_DivMod_M) &&
2227        (pn_Quot_M == pn_Div_M)    &&
2228        (pn_Quot_M == pn_Mod_M)    &&
2229        (pn_Quot_M == pn_Load_M)   &&
2230        (pn_Quot_M == pn_Store_M)  &&
2231        (pn_Quot_M == pn_Alloc_M)  &&
2232        (pn_Quot_M == pn_Bound_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   if (get_opt_auto_create_sync()) {
3089     /* handle non-volatile Load nodes by automatically creating Sync's */
3090     load = skip_Proj(store);
3091     if (is_Load(load) && get_Load_volatility(load) == volatility_non_volatile) {
3092       pred = get_Load_mem(load);
3093
3094       if (is_Sync(pred)) {
3095         /* a Load after a Sync: move it up */
3096         ir_node *mem = skip_Proj(get_Sync_pred(pred, 0));
3097
3098         set_Load_mem(load, get_memop_mem(mem));
3099         add_Sync_pred(pred, store);
3100         store = pred;
3101       }
3102       else {
3103         pload = skip_Proj(pred);
3104         if (is_Load(pload) && get_Load_volatility(pload) == volatility_non_volatile) {
3105           /* a Load after a Load: create a new Sync */
3106           set_Load_mem(load, get_Load_mem(pload));
3107
3108           in[0] = pred;
3109           in[1] = store;
3110           store = new_Sync(2, in);
3111         }
3112       }
3113     }
3114   }
3115   current_ir_graph->current_block->attr.block.graph_arr[0] = store;
3116 }
3117
3118 void
3119 keep_alive (ir_node *ka) {
3120   add_End_keepalive(get_irg_end(current_ir_graph), ka);
3121 }
3122
3123 /* --- Useful access routines --- */
3124 /* Returns the current block of the current graph.  To set the current
3125    block use set_cur_block. */
3126 ir_node *get_cur_block(void) {
3127   return get_irg_current_block(current_ir_graph);
3128 }
3129
3130 /* Returns the frame type of the current graph */
3131 ir_type *get_cur_frame_type(void) {
3132   return get_irg_frame_type(current_ir_graph);
3133 }
3134
3135
3136 /* ********************************************************************* */
3137 /* initialize */
3138
3139 /* call once for each run of the library */
3140 void
3141 init_cons(uninitialized_local_variable_func_t *func)
3142 {
3143   default_initialize_local_variable = func;
3144 }
3145
3146 void
3147 irp_finalize_cons (void) {
3148   int i;
3149   for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
3150     irg_finalize_cons(get_irp_irg(i));
3151   }
3152   irp->phase_state = phase_high;
3153 }
3154
3155
3156 ir_node *new_Block(int arity, ir_node **in) {
3157   return new_d_Block(NULL, arity, in);
3158 }
3159 ir_node *new_Start  (void) {
3160   return new_d_Start(NULL);
3161 }
3162 ir_node *new_End    (void) {
3163   return new_d_End(NULL);
3164 }
3165 ir_node *new_Jmp    (void) {
3166   return new_d_Jmp(NULL);
3167 }
3168 ir_node *new_IJmp   (ir_node *tgt) {
3169   return new_d_IJmp(NULL, tgt);
3170 }
3171 ir_node *new_Cond   (ir_node *c) {
3172   return new_d_Cond(NULL, c);
3173 }
3174 ir_node *new_Return (ir_node *store, int arity, ir_node *in[]) {
3175   return new_d_Return(NULL, store, arity, in);
3176 }
3177 ir_node *new_Const  (ir_mode *mode, tarval *con) {
3178   return new_d_Const(NULL, mode, con);
3179 }
3180
3181 ir_node *new_Const_long(ir_mode *mode, long value)
3182 {
3183     return new_d_Const_long(NULL, mode, value);
3184 }
3185
3186 ir_node *new_Const_type(tarval *con, ir_type *tp) {
3187   return new_d_Const_type(NULL, get_type_mode(tp), con, tp);
3188 }
3189
3190 ir_node *new_SymConst (symconst_symbol value, symconst_kind kind) {
3191   return new_d_SymConst(NULL, value, kind);
3192 }
3193 ir_node *new_simpleSel(ir_node *store, ir_node *objptr, entity *ent) {
3194   return new_d_simpleSel(NULL, store, objptr, ent);
3195 }
3196 ir_node *new_Sel    (ir_node *store, ir_node *objptr, int arity, ir_node **in,
3197                      entity *ent) {
3198   return new_d_Sel(NULL, store, objptr, arity, in, ent);
3199 }
3200 ir_node *new_Call   (ir_node *store, ir_node *callee, int arity, ir_node **in,
3201              ir_type *tp) {
3202   return new_d_Call(NULL, store, callee, arity, in, tp);
3203 }
3204 ir_node *new_Add    (ir_node *op1, ir_node *op2, ir_mode *mode) {
3205   return new_d_Add(NULL, op1, op2, mode);
3206 }
3207 ir_node *new_Sub    (ir_node *op1, ir_node *op2, ir_mode *mode) {
3208   return new_d_Sub(NULL, op1, op2, mode);
3209 }
3210 ir_node *new_Minus  (ir_node *op,  ir_mode *mode) {
3211   return new_d_Minus(NULL, op, mode);
3212 }
3213 ir_node *new_Mul    (ir_node *op1, ir_node *op2, ir_mode *mode) {
3214   return new_d_Mul(NULL, op1, op2, mode);
3215 }
3216 ir_node *new_Quot   (ir_node *memop, ir_node *op1, ir_node *op2) {
3217   return new_d_Quot(NULL, memop, op1, op2);
3218 }
3219 ir_node *new_DivMod (ir_node *memop, ir_node *op1, ir_node *op2) {
3220   return new_d_DivMod(NULL, memop, op1, op2);
3221 }
3222 ir_node *new_Div    (ir_node *memop, ir_node *op1, ir_node *op2) {
3223   return new_d_Div(NULL, memop, op1, op2);
3224 }
3225 ir_node *new_Mod    (ir_node *memop, ir_node *op1, ir_node *op2) {
3226   return new_d_Mod(NULL, memop, op1, op2);
3227 }
3228 ir_node *new_Abs    (ir_node *op, ir_mode *mode) {
3229   return new_d_Abs(NULL, op, mode);
3230 }
3231 ir_node *new_And    (ir_node *op1, ir_node *op2, ir_mode *mode) {
3232   return new_d_And(NULL, op1, op2, mode);
3233 }
3234 ir_node *new_Or     (ir_node *op1, ir_node *op2, ir_mode *mode) {
3235   return new_d_Or(NULL, op1, op2, mode);
3236 }
3237 ir_node *new_Eor    (ir_node *op1, ir_node *op2, ir_mode *mode) {
3238   return new_d_Eor(NULL, op1, op2, mode);
3239 }
3240 ir_node *new_Not    (ir_node *op,                ir_mode *mode) {
3241   return new_d_Not(NULL, op, mode);
3242 }
3243 ir_node *new_Shl    (ir_node *op,  ir_node *k,   ir_mode *mode) {
3244   return new_d_Shl(NULL, op, k, mode);
3245 }
3246 ir_node *new_Shr    (ir_node *op,  ir_node *k,   ir_mode *mode) {
3247   return new_d_Shr(NULL, op, k, mode);
3248 }
3249 ir_node *new_Shrs   (ir_node *op,  ir_node *k,   ir_mode *mode) {
3250   return new_d_Shrs(NULL, op, k, mode);
3251 }
3252 ir_node *new_Rot    (ir_node *op,  ir_node *k,   ir_mode *mode) {
3253   return new_d_Rot(NULL, op, k, mode);
3254 }
3255 ir_node *new_Carry  (ir_node *op1, ir_node *op2, ir_mode *mode) {
3256   return new_d_Carry(NULL, op1, op2, mode);
3257 }
3258 ir_node *new_Borrow (ir_node *op1, ir_node *op2, ir_mode *mode) {
3259   return new_d_Borrow(NULL, op1, op2, mode);
3260 }
3261 ir_node *new_Cmp    (ir_node *op1, ir_node *op2) {
3262   return new_d_Cmp(NULL, op1, op2);
3263 }
3264 ir_node *new_Conv   (ir_node *op, ir_mode *mode) {
3265   return new_d_Conv(NULL, op, mode);
3266 }
3267 ir_node *new_Cast   (ir_node *op, ir_type *to_tp) {
3268   return new_d_Cast(NULL, op, to_tp);
3269 }
3270 ir_node *new_Phi    (int arity, ir_node **in, ir_mode *mode) {
3271   return new_d_Phi(NULL, arity, in, mode);
3272 }
3273 ir_node *new_Load   (ir_node *store, ir_node *addr, ir_mode *mode) {
3274   return new_d_Load(NULL, store, addr, mode);
3275 }
3276 ir_node *new_Store  (ir_node *store, ir_node *addr, ir_node *val) {
3277   return new_d_Store(NULL, store, addr, val);
3278 }
3279 ir_node *new_Alloc  (ir_node *store, ir_node *size, ir_type *alloc_type,
3280                      where_alloc where) {
3281   return new_d_Alloc(NULL, store, size, alloc_type, where);
3282 }
3283 ir_node *new_Free   (ir_node *store, ir_node *ptr, ir_node *size,
3284              ir_type *free_type, where_alloc where) {
3285   return new_d_Free(NULL, store, ptr, size, free_type, where);
3286 }
3287 ir_node *new_Sync   (int arity, ir_node *in[]) {
3288   return new_d_Sync(NULL, arity, in);
3289 }
3290 ir_node *new_Proj   (ir_node *arg, ir_mode *mode, long proj) {
3291   return new_d_Proj(NULL, arg, mode, proj);
3292 }
3293 ir_node *new_defaultProj (ir_node *arg, long max_proj) {
3294   return new_d_defaultProj(NULL, arg, max_proj);
3295 }
3296 ir_node *new_Tuple  (int arity, ir_node **in) {
3297   return new_d_Tuple(NULL, arity, in);
3298 }
3299 ir_node *new_Id     (ir_node *val, ir_mode *mode) {
3300   return new_d_Id(NULL, val, mode);
3301 }
3302 ir_node *new_Bad    (void) {
3303   return new_d_Bad();
3304 }
3305 ir_node *new_Confirm (ir_node *val, ir_node *bound, pn_Cmp cmp) {
3306   return new_d_Confirm (NULL, val, bound, cmp);
3307 }
3308 ir_node *new_Unknown(ir_mode *m) {
3309   return new_d_Unknown(m);
3310 }
3311 ir_node *new_CallBegin (ir_node *callee) {
3312   return new_d_CallBegin(NULL, callee);
3313 }
3314 ir_node *new_EndReg (void) {
3315   return new_d_EndReg(NULL);
3316 }
3317 ir_node *new_EndExcept (void) {
3318   return new_d_EndExcept(NULL);
3319 }
3320 ir_node *new_Break  (void) {
3321   return new_d_Break(NULL);
3322 }
3323 ir_node *new_Filter (ir_node *arg, ir_mode *mode, long proj) {
3324   return new_d_Filter(NULL, arg, mode, proj);
3325 }
3326 ir_node *new_NoMem  (void) {
3327   return new_d_NoMem();
3328 }
3329 ir_node *new_Mux (ir_node *sel, ir_node *ir_false, ir_node *ir_true, ir_mode *mode) {
3330   return new_d_Mux(NULL, sel, ir_false, ir_true, mode);
3331 }
3332 ir_node *new_Psi (int arity, ir_node *conds[], ir_node *vals[], ir_mode *mode) {
3333   return new_d_Psi(NULL, arity, conds, vals, mode);
3334 }
3335 ir_node *new_CopyB(ir_node *store, ir_node *dst, ir_node *src, ir_type *data_type) {
3336   return new_d_CopyB(NULL, store, dst, src, data_type);
3337 }
3338 ir_node *new_InstOf (ir_node *store, ir_node *objptr, ir_type *ent) {
3339   return new_d_InstOf (NULL, store, objptr, ent);
3340 }
3341 ir_node *new_Raise  (ir_node *store, ir_node *obj) {
3342   return new_d_Raise(NULL, store, obj);
3343 }
3344 ir_node *new_Bound(ir_node *store, ir_node *idx, ir_node *lower, ir_node *upper) {
3345   return new_d_Bound(NULL, store, idx, lower, upper);
3346 }