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