Use only public irnode interface
[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 "irgraph_t.h"
29 # include "irnode_t.h"
30 # include "irmode_t.h"
31 # include "ircons_t.h"
32 # include "firm_common_t.h"
33 # include "irvrfy.h"
34 # include "irop_t.h"
35 # include "iropt_t.h"
36 # include "irgmod.h"
37 # include "array.h"
38 # include "irbackedge_t.h"
39 # include "irflag_t.h"
40
41 #if USE_EXPLICIT_PHI_IN_STACK
42 /* A stack needed for the automatic Phi node construction in constructor
43    Phi_in. Redefinition in irgraph.c!! */
44 struct Phi_in_stack {
45   ir_node **stack;
46   int       pos;
47 };
48 typedef struct Phi_in_stack Phi_in_stack;
49 #endif
50
51 /* when we need verifying */
52 #ifdef NDEBUG
53 # define IRN_VRFY_IRG(res, irg)
54 #else
55 # define IRN_VRFY_IRG(res, irg)  irn_vrfy_irg(res, irg)
56 #endif
57
58 /*
59  * language dependant initialization variable
60  */
61 static default_initialize_local_variable_func_t *default_initialize_local_variable = NULL;
62
63 /* -------------------------------------------- */
64 /* privat interfaces, for professional use only */
65 /* -------------------------------------------- */
66
67 /* Constructs a Block with a fixed number of predecessors.
68    Does not set current_block.  Can not be used with automatic
69    Phi node construction. */
70 ir_node *
71 new_rd_Block (dbg_info* db, ir_graph *irg,  int arity, ir_node **in)
72 {
73   ir_node *res;
74
75   res = new_ir_node (db, irg, NULL, op_Block, mode_BB, arity, in);
76   set_Block_matured(res, 1);
77   set_Block_block_visited(res, 0);
78
79   /* res->attr.block.exc = exc_normal; */
80   /* res->attr.block.handler_entry = 0; */
81   res->attr.block.dead        = 0;
82   res->attr.block.irg         = irg;
83   res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
84   res->attr.block.in_cg       = NULL;
85   res->attr.block.cg_backedge = NULL;
86
87   IRN_VRFY_IRG(res, irg);
88   return res;
89 }
90
91 ir_node *
92 new_rd_Start (dbg_info* db, ir_graph *irg, ir_node *block)
93 {
94   ir_node *res;
95
96   res = new_ir_node(db, irg, block, op_Start, mode_T, 0, NULL);
97   /* res->attr.start.irg = irg; */
98
99   IRN_VRFY_IRG(res, irg);
100   return res;
101 }
102
103 ir_node *
104 new_rd_End (dbg_info* db, ir_graph *irg, ir_node *block)
105 {
106   ir_node *res;
107
108   res = new_ir_node(db, irg, block, op_End, mode_X, -1, NULL);
109
110   IRN_VRFY_IRG(res, irg);
111   return res;
112 }
113
114 /* Creates a Phi node with all predecessors.  Calling this constructor
115    is only allowed if the corresponding block is mature.  */
116 ir_node *
117 new_rd_Phi (dbg_info* db, ir_graph *irg, ir_node *block, int arity, ir_node **in, ir_mode *mode)
118 {
119   ir_node *res;
120   int i;
121   bool has_unknown = false;
122
123   /* Don't assert that block matured: the use of this constructor is strongly
124      restricted ... */
125   if ( get_Block_matured(block) )
126     assert( get_irn_arity(block) == arity );
127
128   res = new_ir_node(db, irg, block, op_Phi, mode, arity, in);
129
130   res->attr.phi_backedge = new_backedge_arr(irg->obst, arity);
131
132   for (i = arity-1; i >= 0; i--)
133     if (get_irn_op(in[i]) == op_Unknown) {
134       has_unknown = true;
135       break;
136     }
137
138   if (!has_unknown) res = optimize_node (res);
139   IRN_VRFY_IRG(res, irg);
140
141   /* Memory Phis in endless loops must be kept alive.
142      As we can't distinguish these easily we keep all of them alive. */
143   if ((res->op == op_Phi) && (mode == mode_M))
144     add_End_keepalive(irg->end, res);
145   return res;
146 }
147
148 ir_node *
149 new_rd_Const_type (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con, type *tp)
150 {
151   ir_node *res;
152
153   res = new_ir_node (db, irg, irg->start_block, op_Const, mode, 0, NULL);
154   res->attr.con.tv = con;
155   set_Const_type(res, tp);  /* Call method because of complex assertion. */
156   res = optimize_node (res);
157   assert(get_Const_type(res) == tp);
158   IRN_VRFY_IRG(res, irg);
159
160   return res;
161 }
162
163 ir_node *
164 new_rd_Const (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con)
165 {
166   return new_rd_Const_type (db, irg, block, mode, con, firm_unknown_type);
167 }
168
169 ir_node *
170 new_rd_Id (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *val, ir_mode *mode)
171 {
172   ir_node *res;
173
174   res = new_ir_node(db, irg, block, op_Id, mode, 1, &val);
175   res = optimize_node(res);
176   IRN_VRFY_IRG(res, irg);
177   return res;
178 }
179
180 ir_node *
181 new_rd_Proj (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *arg, ir_mode *mode,
182         long proj)
183 {
184   ir_node *res;
185
186   res = new_ir_node (db, irg, block, op_Proj, mode, 1, &arg);
187   res->attr.proj = proj;
188
189   assert(res);
190   assert(get_Proj_pred(res));
191   assert(get_nodes_block(get_Proj_pred(res)));
192
193   res = optimize_node(res);
194
195   IRN_VRFY_IRG(res, irg);
196   return res;
197
198 }
199
200 ir_node *
201 new_rd_defaultProj (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *arg,
202            long max_proj)
203 {
204   ir_node *res;
205   assert(arg->op == op_Cond);
206   arg->attr.c.kind = fragmentary;
207   arg->attr.c.default_proj = max_proj;
208   res = new_rd_Proj (db, irg, block, arg, mode_X, max_proj);
209   return res;
210 }
211
212 ir_node *
213 new_rd_Conv (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *op, ir_mode *mode)
214 {
215   ir_node *res;
216
217   res = new_ir_node(db, irg, block, op_Conv, mode, 1, &op);
218   res = optimize_node(res);
219   IRN_VRFY_IRG(res, irg);
220   return res;
221 }
222
223 ir_node *
224 new_rd_Cast (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *op, type *to_tp)
225 {
226   ir_node *res;
227
228   assert(is_atomic_type(to_tp));
229
230   res = new_ir_node(db, irg, block, op_Cast, get_irn_mode(op), 1, &op);
231   res->attr.cast.totype = to_tp;
232   res = optimize_node(res);
233   IRN_VRFY_IRG(res, irg);
234   return res;
235 }
236
237 ir_node *
238 new_rd_Tuple (dbg_info* db, ir_graph *irg, ir_node *block, int arity, ir_node **in)
239 {
240   ir_node *res;
241
242   res = new_ir_node(db, irg, block, op_Tuple, mode_T, arity, in);
243   res = optimize_node (res);
244   IRN_VRFY_IRG(res, irg);
245   return res;
246 }
247
248 ir_node *
249 new_rd_Add (dbg_info* db, ir_graph *irg, ir_node *block,
250        ir_node *op1, ir_node *op2, ir_mode *mode)
251 {
252   ir_node *in[2];
253   ir_node *res;
254
255   in[0] = op1;
256   in[1] = op2;
257   res = new_ir_node(db, irg, block, op_Add, mode, 2, in);
258   res = optimize_node(res);
259   IRN_VRFY_IRG(res, irg);
260   return res;
261 }
262
263 ir_node *
264 new_rd_Sub (dbg_info* db, ir_graph *irg, ir_node *block,
265        ir_node *op1, ir_node *op2, ir_mode *mode)
266 {
267   ir_node *in[2];
268   ir_node *res;
269
270   in[0] = op1;
271   in[1] = op2;
272   res = new_ir_node (db, irg, block, op_Sub, mode, 2, in);
273   res = optimize_node (res);
274   IRN_VRFY_IRG(res, irg);
275   return res;
276 }
277
278 ir_node *
279 new_rd_Minus (dbg_info* db, ir_graph *irg, ir_node *block,
280          ir_node *op, ir_mode *mode)
281 {
282   ir_node *res;
283
284   res = new_ir_node(db, irg, block, op_Minus, mode, 1, &op);
285   res = optimize_node(res);
286   IRN_VRFY_IRG(res, irg);
287   return res;
288 }
289
290 ir_node *
291 new_rd_Mul (dbg_info* db, ir_graph *irg, ir_node *block,
292        ir_node *op1, ir_node *op2, ir_mode *mode)
293 {
294   ir_node *in[2];
295   ir_node *res;
296
297   in[0] = op1;
298   in[1] = op2;
299   res = new_ir_node(db, irg, block, op_Mul, mode, 2, in);
300   res = optimize_node(res);
301   IRN_VRFY_IRG(res, irg);
302   return res;
303 }
304
305 ir_node *
306 new_rd_Quot (dbg_info* db, ir_graph *irg, ir_node *block,
307             ir_node *memop, ir_node *op1, ir_node *op2)
308 {
309   ir_node *in[3];
310   ir_node *res;
311
312   in[0] = memop;
313   in[1] = op1;
314   in[2] = op2;
315   res = new_ir_node(db, irg, block, op_Quot, mode_T, 3, in);
316   res = optimize_node(res);
317   IRN_VRFY_IRG(res, irg);
318   return res;
319 }
320
321 ir_node *
322 new_rd_DivMod (dbg_info* db, ir_graph *irg, ir_node *block,
323           ir_node *memop, ir_node *op1, ir_node *op2)
324 {
325   ir_node *in[3];
326   ir_node *res;
327
328   in[0] = memop;
329   in[1] = op1;
330   in[2] = op2;
331   res = new_ir_node(db, irg, block, op_DivMod, mode_T, 3, in);
332   res = optimize_node(res);
333   IRN_VRFY_IRG(res, irg);
334   return res;
335 }
336
337 ir_node *
338 new_rd_Div (dbg_info* db, ir_graph *irg, ir_node *block,
339            ir_node *memop, ir_node *op1, ir_node *op2)
340 {
341   ir_node *in[3];
342   ir_node *res;
343
344   in[0] = memop;
345   in[1] = op1;
346   in[2] = op2;
347   res = new_ir_node(db, irg, block, op_Div, mode_T, 3, in);
348   res = optimize_node(res);
349   IRN_VRFY_IRG(res, irg);
350   return res;
351 }
352
353 ir_node *
354 new_rd_Mod (dbg_info* db, ir_graph *irg, ir_node *block,
355            ir_node *memop, ir_node *op1, ir_node *op2)
356 {
357   ir_node *in[3];
358   ir_node *res;
359
360   in[0] = memop;
361   in[1] = op1;
362   in[2] = op2;
363   res = new_ir_node(db, irg, block, op_Mod, mode_T, 3, in);
364   res = optimize_node(res);
365   IRN_VRFY_IRG(res, irg);
366   return res;
367 }
368
369 ir_node *
370 new_rd_And (dbg_info* db, ir_graph *irg, ir_node *block,
371            ir_node *op1, ir_node *op2, ir_mode *mode)
372 {
373   ir_node *in[2];
374   ir_node *res;
375
376   in[0] = op1;
377   in[1] = op2;
378   res = new_ir_node(db, irg, block, op_And, mode, 2, in);
379   res = optimize_node(res);
380   IRN_VRFY_IRG(res, irg);
381   return res;
382 }
383
384 ir_node *
385 new_rd_Or (dbg_info* db, ir_graph *irg, ir_node *block,
386           ir_node *op1, ir_node *op2, ir_mode *mode)
387 {
388   ir_node *in[2];
389   ir_node *res;
390
391   in[0] = op1;
392   in[1] = op2;
393   res = new_ir_node(db, irg, block, op_Or, mode, 2, in);
394   res = optimize_node(res);
395   IRN_VRFY_IRG(res, irg);
396   return res;
397 }
398
399 ir_node *
400 new_rd_Eor (dbg_info* db, ir_graph *irg, ir_node *block,
401           ir_node *op1, ir_node *op2, ir_mode *mode)
402 {
403   ir_node *in[2];
404   ir_node *res;
405
406   in[0] = op1;
407   in[1] = op2;
408   res = new_ir_node (db, irg, block, op_Eor, mode, 2, in);
409   res = optimize_node (res);
410   IRN_VRFY_IRG(res, irg);
411   return res;
412 }
413
414 ir_node *
415 new_rd_Not    (dbg_info* db, ir_graph *irg, ir_node *block,
416           ir_node *op, ir_mode *mode)
417 {
418   ir_node *res;
419
420   res = new_ir_node(db, irg, block, op_Not, mode, 1, &op);
421   res = optimize_node(res);
422   IRN_VRFY_IRG(res, irg);
423   return res;
424 }
425
426 ir_node *
427 new_rd_Shl (dbg_info* db, ir_graph *irg, ir_node *block,
428           ir_node *op, ir_node *k, ir_mode *mode)
429 {
430   ir_node *in[2];
431   ir_node *res;
432
433   in[0] = op;
434   in[1] = k;
435   res = new_ir_node(db, irg, block, op_Shl, mode, 2, in);
436   res = optimize_node(res);
437   IRN_VRFY_IRG(res, irg);
438   return res;
439 }
440
441 ir_node *
442 new_rd_Shr (dbg_info* db, ir_graph *irg, ir_node *block,
443        ir_node *op, ir_node *k, ir_mode *mode)
444 {
445   ir_node *in[2];
446   ir_node *res;
447
448   in[0] = op;
449   in[1] = k;
450   res = new_ir_node(db, irg, block, op_Shr, mode, 2, in);
451   res = optimize_node(res);
452   IRN_VRFY_IRG(res, irg);
453   return res;
454 }
455
456 ir_node *
457 new_rd_Shrs (dbg_info* db, ir_graph *irg, ir_node *block,
458        ir_node *op, ir_node *k, ir_mode *mode)
459 {
460   ir_node *in[2];
461   ir_node *res;
462
463   in[0] = op;
464   in[1] = k;
465   res = new_ir_node(db, irg, block, op_Shrs, mode, 2, in);
466   res = optimize_node(res);
467   IRN_VRFY_IRG(res, irg);
468   return res;
469 }
470
471 ir_node *
472 new_rd_Rot (dbg_info* db, ir_graph *irg, ir_node *block,
473        ir_node *op, ir_node *k, ir_mode *mode)
474 {
475   ir_node *in[2];
476   ir_node *res;
477
478   in[0] = op;
479   in[1] = k;
480   res = new_ir_node(db, irg, block, op_Rot, mode, 2, in);
481   res = optimize_node(res);
482   IRN_VRFY_IRG(res, irg);
483   return res;
484 }
485
486 ir_node *
487 new_rd_Abs (dbg_info* db, ir_graph *irg, ir_node *block,
488        ir_node *op, ir_mode *mode)
489 {
490   ir_node *res;
491
492   res = new_ir_node(db, irg, block, op_Abs, mode, 1, &op);
493   res = optimize_node (res);
494   IRN_VRFY_IRG(res, irg);
495   return res;
496 }
497
498 ir_node *
499 new_rd_Cmp (dbg_info* db, ir_graph *irg, ir_node *block,
500        ir_node *op1, ir_node *op2)
501 {
502   ir_node *in[2];
503   ir_node *res;
504   in[0] = op1;
505   in[1] = op2;
506
507   res = new_ir_node(db, irg, block, op_Cmp, mode_T, 2, in);
508   res = optimize_node(res);
509   IRN_VRFY_IRG(res, irg);
510   return res;
511 }
512
513 ir_node *
514 new_rd_Jmp (dbg_info* db, ir_graph *irg, ir_node *block)
515 {
516   ir_node *res;
517
518   res = new_ir_node (db, irg, block, op_Jmp, mode_X, 0, NULL);
519   res = optimize_node (res);
520   IRN_VRFY_IRG (res, irg);
521   return res;
522 }
523
524 ir_node *
525 new_rd_Cond (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *c)
526 {
527   ir_node *res;
528
529   res = new_ir_node (db, irg, block, op_Cond, mode_T, 1, &c);
530   res->attr.c.kind         = dense;
531   res->attr.c.default_proj = 0;
532   res = optimize_node (res);
533   IRN_VRFY_IRG(res, irg);
534   return res;
535 }
536
537 ir_node *
538 new_rd_Call (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store,
539         ir_node *callee, int arity, ir_node **in, type *tp)
540 {
541   ir_node **r_in;
542   ir_node *res;
543   int r_arity;
544
545   r_arity = arity+2;
546   NEW_ARR_A(ir_node *, r_in, r_arity);
547   r_in[0] = store;
548   r_in[1] = callee;
549   memcpy(&r_in[2], in, sizeof(ir_node *) * arity);
550
551   res = new_ir_node(db, irg, block, op_Call, mode_T, r_arity, r_in);
552
553   assert((get_unknown_type() == tp) || is_Method_type(tp));
554   set_Call_type(res, tp);
555   res->attr.call.exc.pin_state = op_pin_state_pinned;
556   res->attr.call.callee_arr    = NULL;
557   res = optimize_node(res);
558   IRN_VRFY_IRG(res, irg);
559   return res;
560 }
561
562 ir_node *
563 new_rd_Return (dbg_info* db, ir_graph *irg, ir_node *block,
564               ir_node *store, int arity, ir_node **in)
565 {
566   ir_node **r_in;
567   ir_node *res;
568   int r_arity;
569
570   r_arity = arity+1;
571   NEW_ARR_A (ir_node *, r_in, r_arity);
572   r_in[0] = store;
573   memcpy(&r_in[1], in, sizeof(ir_node *) * arity);
574   res = new_ir_node(db, irg, block, op_Return, mode_X, r_arity, r_in);
575   res = optimize_node(res);
576   IRN_VRFY_IRG(res, irg);
577   return res;
578 }
579
580 ir_node *
581 new_rd_Raise (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store, ir_node *obj)
582 {
583   ir_node *in[2];
584   ir_node *res;
585
586   in[0] = store;
587   in[1] = obj;
588   res = new_ir_node(db, irg, block, op_Raise, mode_T, 2, in);
589   res = optimize_node(res);
590   IRN_VRFY_IRG(res, irg);
591   return res;
592 }
593
594 ir_node *
595 new_rd_Load (dbg_info* db, ir_graph *irg, ir_node *block,
596         ir_node *store, ir_node *adr, ir_mode *mode)
597 {
598   ir_node *in[2];
599   ir_node *res;
600
601   in[0] = store;
602   in[1] = adr;
603   res = new_ir_node(db, irg, block, op_Load, mode_T, 2, in);
604   res->attr.load.exc.pin_state = op_pin_state_pinned;
605   res->attr.load.load_mode     = mode;
606   res->attr.load.volatility    = volatility_non_volatile;
607   res = optimize_node(res);
608   IRN_VRFY_IRG(res, irg);
609   return res;
610 }
611
612 ir_node *
613 new_rd_Store (dbg_info* db, ir_graph *irg, ir_node *block,
614          ir_node *store, ir_node *adr, ir_node *val)
615 {
616   ir_node *in[3];
617   ir_node *res;
618
619   in[0] = store;
620   in[1] = adr;
621   in[2] = val;
622   res = new_ir_node(db, irg, block, op_Store, mode_T, 3, in);
623   res->attr.store.exc.pin_state = op_pin_state_pinned;
624   res->attr.store.volatility    = volatility_non_volatile;
625   res = optimize_node(res);
626   IRN_VRFY_IRG(res, irg);
627   return res;
628 }
629
630 ir_node *
631 new_rd_Alloc (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store,
632         ir_node *size, type *alloc_type, where_alloc where)
633 {
634   ir_node *in[2];
635   ir_node *res;
636
637   in[0] = store;
638   in[1] = size;
639   res = new_ir_node(db, irg, block, op_Alloc, mode_T, 2, in);
640   res->attr.a.exc.pin_state = op_pin_state_pinned;
641   res->attr.a.where         = where;
642   res->attr.a.type          = alloc_type;
643   res = optimize_node(res);
644   IRN_VRFY_IRG(res, irg);
645   return res;
646 }
647
648 ir_node *
649 new_rd_Free (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store,
650         ir_node *ptr, ir_node *size, type *free_type)
651 {
652   ir_node *in[3];
653   ir_node *res;
654
655   in[0] = store;
656   in[1] = ptr;
657   in[2] = size;
658   res = new_ir_node (db, irg, block, op_Free, mode_T, 3, in);
659   res->attr.f = free_type;
660   res = optimize_node(res);
661   IRN_VRFY_IRG(res, irg);
662   return res;
663 }
664
665 ir_node *
666 new_rd_Sel (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store, ir_node *objptr,
667            int arity, ir_node **in, entity *ent)
668 {
669   ir_node **r_in;
670   ir_node *res;
671   int r_arity;
672
673   assert(ent != NULL && is_entity(ent) && "entity expected in Sel construction");
674
675   r_arity = arity + 2;
676   NEW_ARR_A(ir_node *, r_in, r_arity);  /* uses alloca */
677   r_in[0] = store;
678   r_in[1] = objptr;
679   memcpy(&r_in[2], in, sizeof(ir_node *) * arity);
680   res = new_ir_node(db, irg, block, op_Sel, mode_P_mach, r_arity, r_in);
681   res->attr.s.ent = ent;
682   res = optimize_node(res);
683   IRN_VRFY_IRG(res, irg);
684   return res;
685 }
686
687 ir_node *
688 new_rd_InstOf (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
689            ir_node *objptr, type *ent)
690 {
691   ir_node **r_in;
692   ir_node *res;
693   int r_arity;
694
695   r_arity = 2;
696   NEW_ARR_A(ir_node *, r_in, r_arity);
697   r_in[0] = store;
698   r_in[1] = objptr;
699
700   res = new_ir_node(db, irg, block, op_Sel, mode_T, r_arity, r_in);
701   res->attr.io.ent = ent;
702
703   /* res = optimize(res); */
704   IRN_VRFY_IRG(res, irg);
705   return res;
706 }
707
708 ir_node *
709 new_rd_SymConst_type (dbg_info* db, ir_graph *irg, ir_node *block, symconst_symbol value,
710                       symconst_kind symkind, type *tp) {
711   ir_node *res;
712   ir_mode *mode;
713
714   if ((symkind == symconst_addr_name) || (symkind == symconst_addr_ent))
715     mode = mode_P_mach;
716   else
717     mode = mode_Iu;
718
719   res = new_ir_node(db, irg, block, op_SymConst, mode, 0, NULL);
720
721   res->attr.i.num = symkind;
722   res->attr.i.sym = value;
723   res->attr.i.tp  = tp;
724
725   res = optimize_node(res);
726   IRN_VRFY_IRG(res, irg);
727   return res;
728 }
729
730 ir_node *
731 new_rd_SymConst (dbg_info* db, ir_graph *irg, ir_node *block, symconst_symbol value,
732                  symconst_kind symkind)
733 {
734   ir_node *res = new_rd_SymConst_type(db, irg, block, value, symkind, firm_unknown_type);
735   return res;
736 }
737
738 ir_node *new_rd_SymConst_addr_ent (dbg_info *db, ir_graph *irg, entity *symbol, type *tp) {
739   symconst_symbol sym = {(type *)symbol};
740   return new_rd_SymConst_type(db, irg, irg->start_block, sym, symconst_addr_ent, tp);
741 }
742
743 ir_node *new_rd_SymConst_addr_name (dbg_info *db, ir_graph *irg, ident *symbol, type *tp) {
744   symconst_symbol sym = {(type *)symbol};
745   return new_rd_SymConst_type(db, irg, irg->start_block, sym, symconst_addr_name, tp);
746 }
747
748 ir_node *new_rd_SymConst_type_tag (dbg_info *db, ir_graph *irg, type *symbol, type *tp) {
749   symconst_symbol sym = {symbol};
750   return new_rd_SymConst_type(db, irg, irg->start_block, sym, symconst_type_tag, tp);
751 }
752
753 ir_node *new_rd_SymConst_size (dbg_info *db, ir_graph *irg, type *symbol, type *tp) {
754   symconst_symbol sym = {symbol};
755   return new_rd_SymConst_type(db, irg, irg->start_block, sym, symconst_size, tp);
756 }
757
758 ir_node *
759 new_rd_Sync (dbg_info* db, ir_graph *irg, ir_node *block, int arity, ir_node **in)
760 {
761   ir_node *res;
762
763   res = new_ir_node(db, irg, block, op_Sync, mode_M, arity, in);
764   res = optimize_node(res);
765   IRN_VRFY_IRG(res, irg);
766   return res;
767 }
768
769 ir_node *
770 new_rd_Bad (ir_graph *irg)
771 {
772   return irg->bad;
773 }
774
775 ir_node *
776 new_rd_Confirm (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *val, ir_node *bound, pn_Cmp cmp)
777 {
778   ir_node *in[2], *res;
779
780   in[0] = val;
781   in[1] = bound;
782   res = new_ir_node (db, irg, block, op_Confirm, get_irn_mode(val), 2, in);
783   res->attr.confirm_cmp = cmp;
784   res = optimize_node (res);
785   IRN_VRFY_IRG(res, irg);
786   return res;
787 }
788
789 ir_node *
790 new_rd_Unknown (ir_graph *irg, ir_mode *m)
791 {
792   return new_ir_node(NULL, irg, irg->start_block, op_Unknown, m, 0, NULL);
793 }
794
795 ir_node *
796 new_rd_CallBegin (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *call)
797 {
798   ir_node *in[1];
799   ir_node *res;
800
801   in[0] = get_Call_ptr(call);
802   res = new_ir_node(db, irg, block, op_CallBegin, mode_T, 1, in);
803   /* res->attr.callbegin.irg = irg; */
804   res->attr.callbegin.call = call;
805   res = optimize_node(res);
806   IRN_VRFY_IRG(res, irg);
807   return res;
808 }
809
810 ir_node *
811 new_rd_EndReg (dbg_info *db, ir_graph *irg, ir_node *block)
812 {
813   ir_node *res;
814
815   res = new_ir_node(db, irg, block, op_EndReg, mode_T, -1, NULL);
816   irg->end_reg = res;
817   IRN_VRFY_IRG(res, irg);
818   return res;
819 }
820
821 ir_node *
822 new_rd_EndExcept (dbg_info *db, ir_graph *irg, ir_node *block)
823 {
824   ir_node *res;
825
826   res = new_ir_node(db, irg, block, op_EndExcept, mode_T, -1, NULL);
827   irg->end_except = res;
828   IRN_VRFY_IRG (res, irg);
829   return res;
830 }
831
832 ir_node *
833 new_rd_Break (dbg_info *db, ir_graph *irg, ir_node *block)
834 {
835   ir_node *res;
836
837   res = new_ir_node(db, irg, block, op_Break, mode_X, 0, NULL);
838   res = optimize_node(res);
839   IRN_VRFY_IRG(res, irg);
840   return res;
841 }
842
843 ir_node *
844 new_rd_Filter (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg, ir_mode *mode,
845            long proj)
846 {
847   ir_node *res;
848
849   res = new_ir_node(db, irg, block, op_Filter, mode, 1, &arg);
850   res->attr.filter.proj = proj;
851   res->attr.filter.in_cg = NULL;
852   res->attr.filter.backedge = NULL;
853
854   assert(res);
855   assert(get_Proj_pred(res));
856   assert(get_nodes_block(get_Proj_pred(res)));
857
858   res = optimize_node(res);
859   IRN_VRFY_IRG(res, irg);
860   return res;
861 }
862
863 ir_node *
864 new_rd_NoMem (ir_graph *irg) {
865   return irg->no_mem;
866 }
867
868 ir_node *
869 new_rd_Mux  (dbg_info *db, ir_graph *irg, ir_node *block,
870     ir_node *sel, ir_node *ir_false, ir_node *ir_true, ir_mode *mode)
871 {
872   ir_node *in[3];
873   ir_node *res;
874
875   in[0] = sel;
876   in[1] = ir_false;
877   in[2] = ir_true;
878
879   res = new_ir_node(db, irg, block, op_Mux, mode, 3, in);
880   assert(res);
881
882   res = optimize_node(res);
883   IRN_VRFY_IRG(res, irg);
884   return res;
885 }
886
887
888 ir_node *new_r_Block  (ir_graph *irg,  int arity, ir_node **in) {
889   return new_rd_Block(NULL, irg, arity, in);
890 }
891 ir_node *new_r_Start  (ir_graph *irg, ir_node *block) {
892   return new_rd_Start(NULL, irg, block);
893 }
894 ir_node *new_r_End    (ir_graph *irg, ir_node *block) {
895   return new_rd_End(NULL, irg, block);
896 }
897 ir_node *new_r_Jmp    (ir_graph *irg, ir_node *block) {
898   return new_rd_Jmp(NULL, irg, block);
899 }
900 ir_node *new_r_Cond   (ir_graph *irg, ir_node *block, ir_node *c) {
901   return new_rd_Cond(NULL, irg, block, c);
902 }
903 ir_node *new_r_Return (ir_graph *irg, ir_node *block,
904                ir_node *store, int arity, ir_node **in) {
905   return new_rd_Return(NULL, irg, block, store, arity, in);
906 }
907 ir_node *new_r_Raise  (ir_graph *irg, ir_node *block,
908                ir_node *store, ir_node *obj) {
909   return new_rd_Raise(NULL, irg, block, store, obj);
910 }
911 ir_node *new_r_Const  (ir_graph *irg, ir_node *block,
912                ir_mode *mode, tarval *con) {
913   return new_rd_Const(NULL, irg, block, mode, con);
914 }
915 ir_node *new_r_SymConst (ir_graph *irg, ir_node *block,
916                        symconst_symbol value, symconst_kind symkind) {
917   return new_rd_SymConst(NULL, irg, block, value, symkind);
918 }
919 ir_node *new_r_Sel    (ir_graph *irg, ir_node *block, ir_node *store,
920                   ir_node *objptr, int n_index, ir_node **index,
921                   entity *ent) {
922   return new_rd_Sel(NULL, irg, block, store, objptr, n_index, index, ent);
923 }
924 ir_node *new_r_InstOf (ir_graph *irg, ir_node *block, ir_node *store, ir_node *objptr,
925                   type *ent) {
926   return (new_rd_InstOf (NULL, irg, block, store, objptr, ent));
927 }
928 ir_node *new_r_Call   (ir_graph *irg, ir_node *block, ir_node *store,
929                   ir_node *callee, int arity, ir_node **in,
930                   type *tp) {
931   return new_rd_Call(NULL, irg, block, store, callee, arity, in, tp);
932 }
933 ir_node *new_r_Add    (ir_graph *irg, ir_node *block,
934                   ir_node *op1, ir_node *op2, ir_mode *mode) {
935   return new_rd_Add(NULL, irg, block, op1, op2, mode);
936 }
937 ir_node *new_r_Sub    (ir_graph *irg, ir_node *block,
938                   ir_node *op1, ir_node *op2, ir_mode *mode) {
939   return new_rd_Sub(NULL, irg, block, op1, op2, mode);
940 }
941 ir_node *new_r_Minus  (ir_graph *irg, ir_node *block,
942                   ir_node *op,  ir_mode *mode) {
943   return new_rd_Minus(NULL, irg, block,  op, mode);
944 }
945 ir_node *new_r_Mul    (ir_graph *irg, ir_node *block,
946                   ir_node *op1, ir_node *op2, ir_mode *mode) {
947   return new_rd_Mul(NULL, irg, block, op1, op2, mode);
948 }
949 ir_node *new_r_Quot   (ir_graph *irg, ir_node *block,
950                   ir_node *memop, ir_node *op1, ir_node *op2) {
951   return new_rd_Quot(NULL, irg, block, memop, op1, op2);
952 }
953 ir_node *new_r_DivMod (ir_graph *irg, ir_node *block,
954                   ir_node *memop, ir_node *op1, ir_node *op2) {
955   return new_rd_DivMod(NULL, irg, block, memop, op1, op2);
956 }
957 ir_node *new_r_Div    (ir_graph *irg, ir_node *block,
958                   ir_node *memop, ir_node *op1, ir_node *op2) {
959   return new_rd_Div(NULL, irg, block, memop, op1, op2);
960 }
961 ir_node *new_r_Mod    (ir_graph *irg, ir_node *block,
962                   ir_node *memop, ir_node *op1, ir_node *op2) {
963   return new_rd_Mod(NULL, irg, block, memop, op1, op2);
964 }
965 ir_node *new_r_Abs    (ir_graph *irg, ir_node *block,
966                   ir_node *op, ir_mode *mode) {
967   return new_rd_Abs(NULL, irg, block, op, mode);
968 }
969 ir_node *new_r_And    (ir_graph *irg, ir_node *block,
970                   ir_node *op1, ir_node *op2, ir_mode *mode) {
971   return new_rd_And(NULL, irg, block,  op1, op2, mode);
972 }
973 ir_node *new_r_Or     (ir_graph *irg, ir_node *block,
974                   ir_node *op1, ir_node *op2, ir_mode *mode) {
975   return new_rd_Or(NULL, irg, block,  op1, op2, mode);
976 }
977 ir_node *new_r_Eor    (ir_graph *irg, ir_node *block,
978                   ir_node *op1, ir_node *op2, ir_mode *mode) {
979   return new_rd_Eor(NULL, irg, block,  op1, op2, mode);
980 }
981 ir_node *new_r_Not    (ir_graph *irg, ir_node *block,
982                ir_node *op, ir_mode *mode) {
983   return new_rd_Not(NULL, irg, block, op, mode);
984 }
985 ir_node *new_r_Cmp    (ir_graph *irg, ir_node *block,
986                ir_node *op1, ir_node *op2) {
987   return new_rd_Cmp(NULL, irg, block, op1, op2);
988 }
989 ir_node *new_r_Shl    (ir_graph *irg, ir_node *block,
990                ir_node *op, ir_node *k, ir_mode *mode) {
991   return new_rd_Shl(NULL, irg, block, op, k, mode);
992 }
993 ir_node *new_r_Shr    (ir_graph *irg, ir_node *block,
994                ir_node *op, ir_node *k, ir_mode *mode) {
995   return new_rd_Shr(NULL, irg, block, op, k, mode);
996 }
997 ir_node *new_r_Shrs   (ir_graph *irg, ir_node *block,
998                ir_node *op, ir_node *k, ir_mode *mode) {
999   return new_rd_Shrs(NULL, irg, block, op, k, mode);
1000 }
1001 ir_node *new_r_Rot    (ir_graph *irg, ir_node *block,
1002                ir_node *op, ir_node *k, ir_mode *mode) {
1003   return new_rd_Rot(NULL, irg, block, op, k, mode);
1004 }
1005 ir_node *new_r_Conv   (ir_graph *irg, ir_node *block,
1006                ir_node *op, ir_mode *mode) {
1007   return new_rd_Conv(NULL, irg, block, op, mode);
1008 }
1009 ir_node *new_r_Cast   (ir_graph *irg, ir_node *block, ir_node *op, type *to_tp) {
1010   return new_rd_Cast(NULL, irg, block, op, to_tp);
1011 }
1012 ir_node *new_r_Phi    (ir_graph *irg, ir_node *block, int arity,
1013                ir_node **in, ir_mode *mode) {
1014   return new_rd_Phi(NULL, irg, block, arity, in, mode);
1015 }
1016 ir_node *new_r_Load   (ir_graph *irg, ir_node *block,
1017                ir_node *store, ir_node *adr, ir_mode *mode) {
1018   return new_rd_Load(NULL, irg, block, store, adr, mode);
1019 }
1020 ir_node *new_r_Store  (ir_graph *irg, ir_node *block,
1021                ir_node *store, ir_node *adr, ir_node *val) {
1022   return new_rd_Store(NULL, irg, block, store, adr, val);
1023 }
1024 ir_node *new_r_Alloc  (ir_graph *irg, ir_node *block, ir_node *store,
1025                ir_node *size, type *alloc_type, where_alloc where) {
1026   return new_rd_Alloc(NULL, irg, block, store, size, alloc_type, where);
1027 }
1028 ir_node *new_r_Free   (ir_graph *irg, ir_node *block, ir_node *store,
1029                ir_node *ptr, ir_node *size, type *free_type) {
1030   return new_rd_Free(NULL, irg, block, store, ptr, size, free_type);
1031 }
1032 ir_node *new_r_Sync   (ir_graph *irg, ir_node *block, int arity, ir_node **in) {
1033   return new_rd_Sync(NULL, irg, block, arity, in);
1034 }
1035 ir_node *new_r_Proj   (ir_graph *irg, ir_node *block, ir_node *arg,
1036                ir_mode *mode, long proj) {
1037   return new_rd_Proj(NULL, irg, block, arg, mode, proj);
1038 }
1039 ir_node *new_r_defaultProj (ir_graph *irg, ir_node *block, ir_node *arg,
1040                 long max_proj) {
1041   return new_rd_defaultProj(NULL, irg, block, arg, max_proj);
1042 }
1043 ir_node *new_r_Tuple  (ir_graph *irg, ir_node *block,
1044                int arity, ir_node **in) {
1045   return new_rd_Tuple(NULL, irg, block, arity, in );
1046 }
1047 ir_node *new_r_Id     (ir_graph *irg, ir_node *block,
1048                ir_node *val, ir_mode *mode) {
1049   return new_rd_Id(NULL, irg, block, val, mode);
1050 }
1051 ir_node *new_r_Bad    (ir_graph *irg) {
1052   return new_rd_Bad(irg);
1053 }
1054 ir_node *new_r_Confirm (ir_graph *irg, ir_node *block, ir_node *val, ir_node *bound, pn_Cmp cmp) {
1055   return new_rd_Confirm (NULL, irg, block, val, bound, cmp);
1056 }
1057 ir_node *new_r_Unknown (ir_graph *irg, ir_mode *m) {
1058   return new_rd_Unknown(irg, m);
1059 }
1060 ir_node *new_r_CallBegin (ir_graph *irg, ir_node *block, ir_node *callee) {
1061   return new_rd_CallBegin(NULL, irg, block, callee);
1062 }
1063 ir_node *new_r_EndReg (ir_graph *irg, ir_node *block) {
1064   return new_rd_EndReg(NULL, irg, block);
1065 }
1066 ir_node *new_r_EndExcept (ir_graph *irg, ir_node *block) {
1067   return new_rd_EndExcept(NULL, irg, block);
1068 }
1069 ir_node *new_r_Break  (ir_graph *irg, ir_node *block) {
1070   return new_rd_Break(NULL, irg, block);
1071 }
1072 ir_node *new_r_Filter (ir_graph *irg, ir_node *block, ir_node *arg,
1073                ir_mode *mode, long proj) {
1074   return new_rd_Filter(NULL, irg, block, arg, mode, proj);
1075 }
1076 ir_node *new_r_NoMem  (ir_graph *irg) {
1077   return new_rd_NoMem(irg);
1078 }
1079 ir_node *new_r_Mux (ir_graph *irg, ir_node *block,
1080     ir_node *sel, ir_node *ir_false, ir_node *ir_true, ir_mode *mode) {
1081   return new_rd_Mux(NULL, irg, block, sel, ir_false, ir_true, mode);
1082 }
1083
1084
1085 /** ********************/
1086 /** public interfaces  */
1087 /** construction tools */
1088
1089 /**
1090  *
1091  *   - create a new Start node in the current block
1092  *
1093  *   @return s - pointer to the created Start node
1094  *
1095  *
1096  */
1097 ir_node *
1098 new_d_Start (dbg_info* db)
1099 {
1100   ir_node *res;
1101
1102   res = new_ir_node (db, current_ir_graph, current_ir_graph->current_block,
1103              op_Start, mode_T, 0, NULL);
1104   /* res->attr.start.irg = current_ir_graph; */
1105
1106   res = optimize_node(res);
1107   IRN_VRFY_IRG(res, current_ir_graph);
1108   return res;
1109 }
1110
1111 ir_node *
1112 new_d_End (dbg_info* db)
1113 {
1114   ir_node *res;
1115   res = new_ir_node(db, current_ir_graph,  current_ir_graph->current_block,
1116              op_End, mode_X, -1, NULL);
1117   res = optimize_node(res);
1118   IRN_VRFY_IRG(res, current_ir_graph);
1119
1120   return res;
1121 }
1122
1123 /* Constructs a Block with a fixed number of predecessors.
1124    Does set current_block.  Can be used with automatic Phi
1125    node construction. */
1126 ir_node *
1127 new_d_Block (dbg_info* db, int arity, ir_node **in)
1128 {
1129   ir_node *res;
1130   int i;
1131   bool has_unknown = false;
1132
1133   res = new_rd_Block(db, current_ir_graph, arity, in);
1134
1135   /* Create and initialize array for Phi-node construction. */
1136   if (get_irg_phase_state(current_ir_graph) == phase_building) {
1137     res->attr.block.graph_arr = NEW_ARR_D(ir_node *, current_ir_graph->obst,
1138                                           current_ir_graph->n_loc);
1139     memset(res->attr.block.graph_arr, 0, sizeof(ir_node *)*current_ir_graph->n_loc);
1140   }
1141
1142   for (i = arity-1; i >= 0; i--)
1143     if (get_irn_op(in[i]) == op_Unknown) {
1144       has_unknown = true;
1145       break;
1146     }
1147
1148   if (!has_unknown) res = optimize_node(res);
1149   current_ir_graph->current_block = res;
1150
1151   IRN_VRFY_IRG(res, current_ir_graph);
1152
1153   return res;
1154 }
1155
1156 /* ***********************************************************************/
1157 /* Methods necessary for automatic Phi node creation                     */
1158 /*
1159   ir_node *phi_merge            (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
1160   ir_node *get_r_value_internal (ir_node *block, int pos, ir_mode *mode);
1161   ir_node *new_rd_Phi0           (ir_graph *irg, ir_node *block, ir_mode *mode)
1162   ir_node *new_rd_Phi_in         (ir_graph *irg, ir_node *block, ir_mode *mode,  ir_node **in, int ins)
1163
1164   Call Graph:   ( A ---> B == A "calls" B)
1165
1166        get_value         mature_immBlock
1167           |                   |
1168           |                   |
1169           |                   |
1170           |          ---> phi_merge
1171           |         /       /   \
1172           |        /       /     \
1173          \|/      /      |/_      \
1174        get_r_value_internal        |
1175                 |                  |
1176             |                  |
1177            \|/                \|/
1178         new_rd_Phi0          new_rd_Phi_in
1179
1180 * *************************************************************************** */
1181
1182 /** Creates a Phi node with 0 predecessors */
1183 static INLINE ir_node *
1184 new_rd_Phi0 (ir_graph *irg, ir_node *block, ir_mode *mode)
1185 {
1186   ir_node *res;
1187
1188   res = new_ir_node(NULL, irg, block, op_Phi, mode, 0, NULL);
1189   IRN_VRFY_IRG(res, irg);
1190   return res;
1191 }
1192
1193 /* There are two implementations of the Phi node construction.  The first
1194    is faster, but does not work for blocks with more than 2 predecessors.
1195    The second works always but is slower and causes more unnecessary Phi
1196    nodes.
1197    Select the implementations by the following preprocessor flag set in
1198    common/common.h: */
1199 #if USE_FAST_PHI_CONSTRUCTION
1200
1201 /* This is a stack used for allocating and deallocating nodes in
1202    new_rd_Phi_in.  The original implementation used the obstack
1203    to model this stack, now it is explicit.  This reduces side effects.
1204 */
1205 #if USE_EXPLICIT_PHI_IN_STACK
1206 Phi_in_stack *
1207 new_Phi_in_stack(void) {
1208   Phi_in_stack *res;
1209
1210   res = (Phi_in_stack *) malloc ( sizeof (Phi_in_stack));
1211
1212   res->stack = NEW_ARR_F (ir_node *, 0);
1213   res->pos = 0;
1214
1215   return res;
1216 }
1217
1218 void
1219 free_Phi_in_stack(Phi_in_stack *s) {
1220   DEL_ARR_F(s->stack);
1221   free(s);
1222 }
1223 static INLINE void
1224 free_to_Phi_in_stack(ir_node *phi) {
1225   if (ARR_LEN(current_ir_graph->Phi_in_stack->stack) ==
1226       current_ir_graph->Phi_in_stack->pos)
1227     ARR_APP1 (ir_node *, current_ir_graph->Phi_in_stack->stack, phi);
1228   else
1229     current_ir_graph->Phi_in_stack->stack[current_ir_graph->Phi_in_stack->pos] = phi;
1230
1231   (current_ir_graph->Phi_in_stack->pos)++;
1232 }
1233
1234 static INLINE ir_node *
1235 alloc_or_pop_from_Phi_in_stack(ir_graph *irg, ir_node *block, ir_mode *mode,
1236          int arity, ir_node **in) {
1237   ir_node *res;
1238   ir_node **stack = current_ir_graph->Phi_in_stack->stack;
1239   int pos = current_ir_graph->Phi_in_stack->pos;
1240
1241
1242   if (pos == 0) {
1243     /* We need to allocate a new node */
1244     res = new_ir_node (db, irg, block, op_Phi, mode, arity, in);
1245     res->attr.phi_backedge = new_backedge_arr(irg->obst, arity);
1246   } else {
1247     /* reuse the old node and initialize it again. */
1248     res = stack[pos-1];
1249
1250     assert (res->kind == k_ir_node);
1251     assert (res->op == op_Phi);
1252     res->mode = mode;
1253     res->visited = 0;
1254     res->link = NULL;
1255     assert (arity >= 0);
1256     /* ???!!! How to free the old in array??  Not at all: on obstack ?!! */
1257     res->in = NEW_ARR_D (ir_node *, irg->obst, (arity+1));
1258     res->in[0] = block;
1259     memcpy (&res->in[1], in, sizeof (ir_node *) * arity);
1260
1261     (current_ir_graph->Phi_in_stack->pos)--;
1262   }
1263   return res;
1264 }
1265 #endif /* USE_EXPLICIT_PHI_IN_STACK */
1266
1267 /* Creates a Phi node with a given, fixed array **in of predecessors.
1268    If the Phi node is unnecessary, as the same value reaches the block
1269    through all control flow paths, it is eliminated and the value
1270    returned directly.  This constructor is only intended for use in
1271    the automatic Phi node generation triggered by get_value or mature.
1272    The implementation is quite tricky and depends on the fact, that
1273    the nodes are allocated on a stack:
1274    The in array contains predecessors and NULLs.  The NULLs appear,
1275    if get_r_value_internal, that computed the predecessors, reached
1276    the same block on two paths.  In this case the same value reaches
1277    this block on both paths, there is no definition in between.  We need
1278    not allocate a Phi where these path's merge, but we have to communicate
1279    this fact to the caller.  This happens by returning a pointer to the
1280    node the caller _will_ allocate.  (Yes, we predict the address. We can
1281    do so because the nodes are allocated on the obstack.)  The caller then
1282    finds a pointer to itself and, when this routine is called again,
1283    eliminates itself.
1284    */
1285 static INLINE ir_node *
1286 new_rd_Phi_in (ir_graph *irg, ir_node *block, ir_mode *mode, ir_node **in, int ins)
1287 {
1288   int i;
1289   ir_node *res, *known;
1290
1291   /* Allocate a new node on the obstack.  This can return a node to
1292      which some of the pointers in the in-array already point.
1293      Attention: the constructor copies the in array, i.e., the later
1294      changes to the array in this routine do not affect the
1295      constructed node!  If the in array contains NULLs, there will be
1296      missing predecessors in the returned node.  Is this a possible
1297      internal state of the Phi node generation? */
1298 #if USE_EXPLICIT_PHI_IN_STACK
1299   res = known = alloc_or_pop_from_Phi_in_stack(irg, block, mode, ins, in);
1300 #else
1301   res = known = new_ir_node (NULL, irg, block, op_Phi, mode, ins, in);
1302   res->attr.phi_backedge = new_backedge_arr(irg->obst, ins);
1303 #endif
1304
1305   /* The in-array can contain NULLs.  These were returned by
1306      get_r_value_internal if it reached the same block/definition on a
1307      second path.  The NULLs are replaced by the node itself to
1308      simplify the test in the next loop. */
1309   for (i = 0;  i < ins;  ++i) {
1310     if (in[i] == NULL)
1311       in[i] = res;
1312   }
1313
1314   /* This loop checks whether the Phi has more than one predecessor.
1315      If so, it is a real Phi node and we break the loop.  Else the Phi
1316      node merges the same definition on several paths and therefore is
1317      not needed. */
1318   for (i = 0;  i < ins;  ++i)
1319   {
1320     if (in[i] == res || in[i] == known) continue;
1321
1322     if (known == res)
1323       known = in[i];
1324     else
1325       break;
1326   }
1327
1328   /* i==ins: there is at most one predecessor, we don't need a phi node. */
1329   if (i==ins) {
1330 #if USE_EXPLICIT_PHI_IN_STACK
1331     free_to_Phi_in_stack(res);
1332 #else
1333     obstack_free (current_ir_graph->obst, res);
1334 #endif
1335     res = known;
1336   } else {
1337     res = optimize_node (res);
1338     IRN_VRFY_IRG(res, irg);
1339   }
1340
1341   /* return the pointer to the Phi node.  This node might be deallocated! */
1342   return res;
1343 }
1344
1345 static ir_node *
1346 get_r_value_internal (ir_node *block, int pos, ir_mode *mode);
1347
1348 /**
1349     allocates and returns this node.  The routine called to allocate the
1350     node might optimize it away and return a real value, or even a pointer
1351     to a deallocated Phi node on top of the obstack!
1352     This function is called with an in-array of proper size. **/
1353 static ir_node *
1354 phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
1355 {
1356   ir_node *prevBlock, *res;
1357   int i;
1358
1359   /* This loop goes to all predecessor blocks of the block the Phi node is in
1360      and there finds the operands of the Phi node by calling
1361      get_r_value_internal. */
1362   for (i = 1;  i <= ins;  ++i) {
1363     assert (block->in[i]);
1364     prevBlock = block->in[i]->in[0]; /* go past control flow op to prev block */
1365     assert (prevBlock);
1366     nin[i-1] = get_r_value_internal (prevBlock, pos, mode);
1367   }
1368
1369   /* After collecting all predecessors into the array nin a new Phi node
1370      with these predecessors is created.  This constructor contains an
1371      optimization: If all predecessors of the Phi node are identical it
1372      returns the only operand instead of a new Phi node.  If the value
1373      passes two different control flow edges without being defined, and
1374      this is the second path treated, a pointer to the node that will be
1375      allocated for the first path (recursion) is returned.  We already
1376      know the address of this node, as it is the next node to be allocated
1377      and will be placed on top of the obstack. (The obstack is a _stack_!) */
1378   res = new_rd_Phi_in (current_ir_graph, block, mode, nin, ins);
1379
1380   /* Now we now the value for "pos" and can enter it in the array with
1381      all known local variables.  Attention: this might be a pointer to
1382      a node, that later will be allocated!!! See new_rd_Phi_in.
1383      If this is called in mature, after some set_value in the same block,
1384      the proper value must not be overwritten:
1385      The call order
1386        get_value    (makes Phi0, put's it into graph_arr)
1387        set_value    (overwrites Phi0 in graph_arr)
1388        mature_immBlock (upgrades Phi0, puts it again into graph_arr, overwriting
1389                      the proper value.)
1390      fails. */
1391   if (!block->attr.block.graph_arr[pos]) {
1392     block->attr.block.graph_arr[pos] = res;
1393   } else {
1394     /*  printf(" value already computed by %s\n",
1395         get_id_str(block->attr.block.graph_arr[pos]->op->name));  */
1396   }
1397
1398   return res;
1399 }
1400
1401 /* This function returns the last definition of a variable.  In case
1402    this variable was last defined in a previous block, Phi nodes are
1403    inserted.  If the part of the firm graph containing the definition
1404    is not yet constructed, a dummy Phi node is returned. */
1405 static ir_node *
1406 get_r_value_internal (ir_node *block, int pos, ir_mode *mode)
1407 {
1408   ir_node *res;
1409   /* There are 4 cases to treat.
1410
1411      1. The block is not mature and we visit it the first time.  We can not
1412         create a proper Phi node, therefore a Phi0, i.e., a Phi without
1413         predecessors is returned.  This node is added to the linked list (field
1414         "link") of the containing block to be completed when this block is
1415         matured. (Completion will add a new Phi and turn the Phi0 into an Id
1416         node.)
1417
1418      2. The value is already known in this block, graph_arr[pos] is set and we
1419         visit the block the first time.  We can return the value without
1420         creating any new nodes.
1421
1422      3. The block is mature and we visit it the first time.  A Phi node needs
1423         to be created (phi_merge).  If the Phi is not needed, as all it's
1424         operands are the same value reaching the block through different
1425         paths, it's optimized away and the value itself is returned.
1426
1427      4. The block is mature, and we visit it the second time.  Now two
1428         subcases are possible:
1429         * The value was computed completely the last time we were here. This
1430           is the case if there is no loop.  We can return the proper value.
1431         * The recursion that visited this node and set the flag did not
1432           return yet.  We are computing a value in a loop and need to
1433           break the recursion without knowing the result yet.
1434       @@@ strange case.  Straight forward we would create a Phi before
1435       starting the computation of it's predecessors.  In this case we will
1436       find a Phi here in any case.  The problem is that this implementation
1437       only creates a Phi after computing the predecessors, so that it is
1438       hard to compute self references of this Phi.  @@@
1439         There is no simple check for the second subcase.  Therefore we check
1440         for a second visit and treat all such cases as the second subcase.
1441         Anyways, the basic situation is the same:  we reached a block
1442         on two paths without finding a definition of the value:  No Phi
1443         nodes are needed on both paths.
1444         We return this information "Two paths, no Phi needed" by a very tricky
1445         implementation that relies on the fact that an obstack is a stack and
1446         will return a node with the same address on different allocations.
1447         Look also at phi_merge and new_rd_phi_in to understand this.
1448     @@@ Unfortunately this does not work, see testprogram
1449     three_cfpred_example.
1450
1451   */
1452
1453   /* case 4 -- already visited. */
1454   if (get_irn_visited(block) == get_irg_visited(current_ir_graph)) return NULL;
1455
1456   /* visited the first time */
1457   set_irn_visited(block, get_irg_visited(current_ir_graph));
1458
1459   /* Get the local valid value */
1460   res = block->attr.block.graph_arr[pos];
1461
1462   /* case 2 -- If the value is actually computed, return it. */
1463   if (res) return res;
1464
1465   if (block->attr.block.matured) { /* case 3 */
1466
1467     /* The Phi has the same amount of ins as the corresponding block. */
1468     int ins = get_irn_arity(block);
1469     ir_node **nin;
1470     NEW_ARR_A (ir_node *, nin, ins);
1471
1472     /* Phi merge collects the predecessors and then creates a node. */
1473     res = phi_merge (block, pos, mode, nin, ins);
1474
1475   } else {  /* case 1 */
1476     /* The block is not mature, we don't know how many in's are needed.  A Phi
1477        with zero predecessors is created.  Such a Phi node is called Phi0
1478        node.  (There is also an obsolete Phi0 opcode.) The Phi0 is then added
1479        to the list of Phi0 nodes in this block to be matured by mature_immBlock
1480        later.
1481        The Phi0 has to remember the pos of it's internal value.  If the real
1482        Phi is computed, pos is used to update the array with the local
1483        values. */
1484
1485     res = new_rd_Phi0 (current_ir_graph, block, mode);
1486     res->attr.phi0_pos = pos;
1487     res->link = block->link;
1488     block->link = res;
1489   }
1490
1491   /* If we get here, the frontend missed a use-before-definition error */
1492   if (!res) {
1493     /* Error Message */
1494     printf("Error: no value set.  Use of undefined variable.  Initializing to zero.\n");
1495     assert (mode->code >= irm_F && mode->code <= irm_P);
1496     res = new_rd_Const (NULL, current_ir_graph, block, mode,
1497                tarval_mode_null[mode->code]);
1498   }
1499
1500   /* The local valid value is available now. */
1501   block->attr.block.graph_arr[pos] = res;
1502
1503   return res;
1504 }
1505
1506 #else /* if 0 */
1507
1508 /**
1509     it starts the recursion.  This causes an Id at the entry of
1510     every block that has no definition of the value! **/
1511
1512 #if USE_EXPLICIT_PHI_IN_STACK
1513 /* Just dummies */
1514 Phi_in_stack * new_Phi_in_stack() {  return NULL; }
1515 void free_Phi_in_stack(Phi_in_stack *s) { }
1516 #endif
1517
1518 static INLINE ir_node *
1519 new_rd_Phi_in (ir_graph *irg, ir_node *block, ir_mode *mode,
1520                ir_node **in, int ins, ir_node *phi0)
1521 {
1522   int i;
1523   ir_node *res, *known;
1524
1525   /* Allocate a new node on the obstack.  The allocation copies the in
1526      array. */
1527   res = new_ir_node (NULL, irg, block, op_Phi, mode, ins, in);
1528   res->attr.phi_backedge = new_backedge_arr(irg->obst, ins);
1529
1530   /* This loop checks whether the Phi has more than one predecessor.
1531      If so, it is a real Phi node and we break the loop.  Else the
1532      Phi node merges the same definition on several paths and therefore
1533      is not needed. Don't consider Bad nodes! */
1534   known = res;
1535   for (i=0;  i < ins;  ++i)
1536   {
1537     assert(in[i]);
1538
1539     in[i] = skip_Id(in[i]);  /* increasses the number of freed Phis. */
1540
1541     /* Optimize self referencing Phis:  We can't detect them yet properly, as
1542        they still refer to the Phi0 they will replace.  So replace right now. */
1543     if (phi0 && in[i] == phi0) in[i] = res;
1544
1545     if (in[i]==res || in[i]==known || is_Bad(in[i])) continue;
1546
1547     if (known==res)
1548       known = in[i];
1549     else
1550       break;
1551   }
1552
1553   /* i==ins: there is at most one predecessor, we don't need a phi node. */
1554   if (i == ins) {
1555     if (res != known) {
1556       obstack_free (current_ir_graph->obst, res);
1557       if (is_Phi(known)) {
1558         /* If pred is a phi node we want to optmize it: If loops are matured in a bad
1559            order, an enclosing Phi know may get superfluous. */
1560         res = optimize_in_place_2(known);
1561         if (res != known) { exchange(known, res); }
1562       } else {
1563         res = known;
1564       }
1565     } else {
1566       /* A undefined value, e.g., in unreachable code. */
1567       res = new_Bad();
1568     }
1569   } else {
1570     res = optimize_node (res);  /* This is necessary to add the node to the hash table for cse. */
1571     IRN_VRFY_IRG(res, irg);
1572     /* Memory Phis in endless loops must be kept alive.
1573        As we can't distinguish these easily we keep all of them alive. */
1574     if ((res->op == op_Phi) && (mode == mode_M))
1575       add_End_keepalive(irg->end, res);
1576   }
1577
1578   return res;
1579 }
1580
1581 static ir_node *
1582 get_r_value_internal (ir_node *block, int pos, ir_mode *mode);
1583
1584 #if PRECISE_EXC_CONTEXT
1585 static ir_node *
1586 phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins);
1587
1588 /* Construct a new frag_array for node n.
1589    Copy the content from the current graph_arr of the corresponding block:
1590    this is the current state.
1591    Set ProjM(n) as current memory state.
1592    Further the last entry in frag_arr of current block points to n.  This
1593    constructs a chain block->last_frag_op-> ... first_frag_op of all frag ops in the block.
1594  */
1595 static INLINE ir_node ** new_frag_arr (ir_node *n)
1596 {
1597   ir_node **arr;
1598   int opt;
1599
1600   arr = NEW_ARR_D (ir_node *, current_ir_graph->obst, current_ir_graph->n_loc);
1601   memcpy(arr, current_ir_graph->current_block->attr.block.graph_arr,
1602      sizeof(ir_node *)*current_ir_graph->n_loc);
1603
1604   /* turn off optimization before allocating Proj nodes, as res isn't
1605      finished yet. */
1606   opt = get_opt_optimize(); set_optimize(0);
1607   /* Here we rely on the fact that all frag ops have Memory as first result! */
1608   if (get_irn_op(n) == op_Call)
1609     arr[0] = new_Proj(n, mode_M, pn_Call_M_except);
1610   else {
1611     assert((pn_Quot_M == pn_DivMod_M) &&
1612            (pn_Quot_M == pn_Div_M)    &&
1613            (pn_Quot_M == pn_Mod_M)    &&
1614            (pn_Quot_M == pn_Load_M)   &&
1615            (pn_Quot_M == pn_Store_M)  &&
1616            (pn_Quot_M == pn_Alloc_M)    );
1617     arr[0] = new_Proj(n, mode_M, pn_Alloc_M);
1618   }
1619   set_optimize(opt);
1620
1621   current_ir_graph->current_block->attr.block.graph_arr[current_ir_graph->n_loc-1] = n;
1622   return arr;
1623 }
1624
1625 /**
1626  * returns the frag_arr from a node
1627  */
1628 static INLINE ir_node **
1629 get_frag_arr (ir_node *n) {
1630   switch (get_irn_opcode(n)) {
1631   case iro_Call:
1632     return n->attr.call.exc.frag_arr;
1633   case iro_Alloc:
1634     return n->attr.a.exc.frag_arr;
1635   case iro_Load:
1636     return n->attr.load.exc.frag_arr;
1637   case iro_Store:
1638     return n->attr.store.exc.frag_arr;
1639   default:
1640     return n->attr.except.frag_arr;
1641   }
1642 }
1643
1644 static void
1645 set_frag_value(ir_node **frag_arr, int pos, ir_node *val) {
1646 #if 0
1647   if (!frag_arr[pos]) frag_arr[pos] = val;
1648   if (frag_arr[current_ir_graph->n_loc - 1]) {
1649     ir_node **arr = get_frag_arr(frag_arr[current_ir_graph->n_loc - 1]);
1650     assert(arr != frag_arr && "Endless recursion detected");
1651     set_frag_value(arr, pos, val);
1652   }
1653 #else
1654   int i;
1655
1656   for (i = 0; i < 1000; ++i) {
1657     if (!frag_arr[pos]) {
1658       frag_arr[pos] = val;
1659     }
1660     if (frag_arr[current_ir_graph->n_loc - 1]) {
1661       ir_node **arr = get_frag_arr(frag_arr[current_ir_graph->n_loc - 1]);
1662       frag_arr = arr;
1663     }
1664     else
1665       return;
1666   }
1667   assert(0 && "potential endless recursion");
1668 #endif
1669 }
1670
1671 static ir_node *
1672 get_r_frag_value_internal (ir_node *block, ir_node *cfOp, int pos, ir_mode *mode) {
1673   ir_node *res;
1674   ir_node **frag_arr;
1675
1676   assert(is_fragile_op(cfOp) && (get_irn_op(cfOp) != op_Bad));
1677
1678   frag_arr = get_frag_arr(cfOp);
1679   res = frag_arr[pos];
1680   if (!res) {
1681     if (block->attr.block.graph_arr[pos]) {
1682       /* There was a set_value after the cfOp and no get_value before that
1683          set_value.  We must build a Phi node now. */
1684       if (block->attr.block.matured) {
1685         int ins = get_irn_arity(block);
1686         ir_node **nin;
1687         NEW_ARR_A (ir_node *, nin, ins);
1688         res = phi_merge(block, pos, mode, nin, ins);
1689       } else {
1690         res = new_rd_Phi0 (current_ir_graph, block, mode);
1691         res->attr.phi0_pos = pos;
1692         res->link = block->link;
1693         block->link = res;
1694       }
1695       assert(res);
1696       /* @@@ tested by Flo: set_frag_value(frag_arr, pos, res);
1697          but this should be better: (remove comment if this works) */
1698       /* It's a Phi, we can write this into all graph_arrs with NULL */
1699       set_frag_value(block->attr.block.graph_arr, pos, res);
1700     } else {
1701       res = get_r_value_internal(block, pos, mode);
1702       set_frag_value(block->attr.block.graph_arr, pos, res);
1703     }
1704   }
1705   return res;
1706 }
1707 #endif
1708
1709 /**
1710     computes the predecessors for the real phi node, and then
1711     allocates and returns this node.  The routine called to allocate the
1712     node might optimize it away and return a real value.
1713     This function must be called with an in-array of proper size. **/
1714 static ir_node *
1715 phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
1716 {
1717   ir_node *prevBlock, *prevCfOp, *res, *phi0, *phi0_all;
1718   int i;
1719
1720   /* If this block has no value at pos create a Phi0 and remember it
1721      in graph_arr to break recursions.
1722      Else we may not set graph_arr as there a later value is remembered. */
1723   phi0 = NULL;
1724   if (!block->attr.block.graph_arr[pos]) {
1725     if (block == get_irg_start_block(current_ir_graph)) {
1726       /* Collapsing to Bad tarvals is no good idea.
1727          So we call a user-supplied routine here that deals with this case as
1728          appropriate for the given language. Sorryly the only help we can give
1729          here is the position.
1730
1731          Even if all variables are defined before use, it can happen that
1732          we get to the start block, if a cond has been replaced by a tuple
1733          (bad, jmp).  In this case we call the function needlessly, eventually
1734          generating an non existant error.
1735          However, this SHOULD NOT HAPPEN, as bad control flow nodes are intercepted
1736          before recuring.
1737       */
1738       if (default_initialize_local_variable)
1739         block->attr.block.graph_arr[pos] = default_initialize_local_variable(mode, pos - 1);
1740       else
1741         block->attr.block.graph_arr[pos] = new_Const(mode, tarval_bad);
1742       /* We don't need to care about exception ops in the start block.
1743          There are none by definition. */
1744       return block->attr.block.graph_arr[pos];
1745     } else {
1746       phi0 = new_rd_Phi0(current_ir_graph, block, mode);
1747       block->attr.block.graph_arr[pos] = phi0;
1748 #if PRECISE_EXC_CONTEXT
1749       if (get_opt_precise_exc_context()) {
1750         /* Set graph_arr for fragile ops.  Also here we should break recursion.
1751            We could choose a cyclic path through an cfop.  But the recursion would
1752            break at some point. */
1753         set_frag_value(block->attr.block.graph_arr, pos, phi0);
1754       }
1755 #endif
1756     }
1757   }
1758
1759   /* This loop goes to all predecessor blocks of the block the Phi node
1760      is in and there finds the operands of the Phi node by calling
1761      get_r_value_internal.  */
1762   for (i = 1;  i <= ins;  ++i) {
1763     prevCfOp = skip_Proj(block->in[i]);
1764     assert (prevCfOp);
1765     if (is_Bad(prevCfOp)) {
1766       /* In case a Cond has been optimized we would get right to the start block
1767      with an invalid definition. */
1768       nin[i-1] = new_Bad();
1769       continue;
1770     }
1771     prevBlock = block->in[i]->in[0]; /* go past control flow op to prev block */
1772     assert (prevBlock);
1773     if (!is_Bad(prevBlock)) {
1774 #if PRECISE_EXC_CONTEXT
1775       if (get_opt_precise_exc_context() &&
1776           is_fragile_op(prevCfOp) && (get_irn_op (prevCfOp) != op_Bad)) {
1777         assert(get_r_frag_value_internal (prevBlock, prevCfOp, pos, mode));
1778         nin[i-1] = get_r_frag_value_internal (prevBlock, prevCfOp, pos, mode);
1779       } else
1780 #endif
1781       nin[i-1] = get_r_value_internal (prevBlock, pos, mode);
1782     } else {
1783       nin[i-1] = new_Bad();
1784     }
1785   }
1786
1787   /* We want to pass the Phi0 node to the constructor: this finds additional
1788      optimization possibilities.
1789      The Phi0 node either is allocated in this function, or it comes from
1790      a former call to get_r_value_internal. In this case we may not yet
1791      exchange phi0, as this is done in mature_immBlock. */
1792   if (!phi0) {
1793     phi0_all = block->attr.block.graph_arr[pos];
1794     if (!((get_irn_op(phi0_all) == op_Phi) &&
1795           (get_irn_arity(phi0_all) == 0)   &&
1796           (get_nodes_block(phi0_all) == block)))
1797       phi0_all = NULL;
1798   } else {
1799     phi0_all = phi0;
1800   }
1801
1802   /* After collecting all predecessors into the array nin a new Phi node
1803      with these predecessors is created.  This constructor contains an
1804      optimization: If all predecessors of the Phi node are identical it
1805      returns the only operand instead of a new Phi node.  */
1806   res = new_rd_Phi_in (current_ir_graph, block, mode, nin, ins, phi0_all);
1807
1808   /* In case we allocated a Phi0 node at the beginning of this procedure,
1809      we need to exchange this Phi0 with the real Phi. */
1810   if (phi0) {
1811     exchange(phi0, res);
1812     block->attr.block.graph_arr[pos] = res;
1813     /* Don't set_frag_value as it does not overwrite.  Doesn't matter, is
1814        only an optimization. */
1815   }
1816
1817   return res;
1818 }
1819
1820 /* This function returns the last definition of a variable.  In case
1821    this variable was last defined in a previous block, Phi nodes are
1822    inserted.  If the part of the firm graph containing the definition
1823    is not yet constructed, a dummy Phi node is returned. */
1824 static ir_node *
1825 get_r_value_internal (ir_node *block, int pos, ir_mode *mode)
1826 {
1827   ir_node *res;
1828   /* There are 4 cases to treat.
1829
1830      1. The block is not mature and we visit it the first time.  We can not
1831         create a proper Phi node, therefore a Phi0, i.e., a Phi without
1832         predecessors is returned.  This node is added to the linked list (field
1833         "link") of the containing block to be completed when this block is
1834         matured. (Comlpletion will add a new Phi and turn the Phi0 into an Id
1835         node.)
1836
1837      2. The value is already known in this block, graph_arr[pos] is set and we
1838         visit the block the first time.  We can return the value without
1839         creating any new nodes.
1840
1841      3. The block is mature and we visit it the first time.  A Phi node needs
1842         to be created (phi_merge).  If the Phi is not needed, as all it's
1843         operands are the same value reaching the block through different
1844         paths, it's optimized away and the value itself is returned.
1845
1846      4. The block is mature, and we visit it the second time.  Now two
1847         subcases are possible:
1848         * The value was computed completely the last time we were here. This
1849           is the case if there is no loop.  We can return the proper value.
1850         * The recursion that visited this node and set the flag did not
1851           return yet.  We are computing a value in a loop and need to
1852           break the recursion.  This case only happens if we visited
1853       the same block with phi_merge before, which inserted a Phi0.
1854       So we return the Phi0.
1855   */
1856
1857   /* case 4 -- already visited. */
1858   if (get_irn_visited(block) == get_irg_visited(current_ir_graph)) {
1859     /* As phi_merge allocates a Phi0 this value is always defined. Here
1860      is the critical difference of the two algorithms. */
1861     assert(block->attr.block.graph_arr[pos]);
1862     return block->attr.block.graph_arr[pos];
1863   }
1864
1865   /* visited the first time */
1866   set_irn_visited(block, get_irg_visited(current_ir_graph));
1867
1868   /* Get the local valid value */
1869   res = block->attr.block.graph_arr[pos];
1870
1871   /* case 2 -- If the value is actually computed, return it. */
1872   if (res) { return res; };
1873
1874   if (block->attr.block.matured) { /* case 3 */
1875
1876     /* The Phi has the same amount of ins as the corresponding block. */
1877     int ins = get_irn_arity(block);
1878     ir_node **nin;
1879     NEW_ARR_A (ir_node *, nin, ins);
1880
1881     /* Phi merge collects the predecessors and then creates a node. */
1882     res = phi_merge (block, pos, mode, nin, ins);
1883
1884   } else {  /* case 1 */
1885     /* The block is not mature, we don't know how many in's are needed.  A Phi
1886        with zero predecessors is created.  Such a Phi node is called Phi0
1887        node.  The Phi0 is then added to the list of Phi0 nodes in this block
1888        to be matured by mature_immBlock later.
1889        The Phi0 has to remember the pos of it's internal value.  If the real
1890        Phi is computed, pos is used to update the array with the local
1891        values. */
1892     res = new_rd_Phi0 (current_ir_graph, block, mode);
1893     res->attr.phi0_pos = pos;
1894     res->link = block->link;
1895     block->link = res;
1896   }
1897
1898   /* If we get here, the frontend missed a use-before-definition error */
1899   if (!res) {
1900     /* Error Message */
1901     printf("Error: no value set.  Use of undefined variable.  Initializing to zero.\n");
1902     assert (mode->code >= irm_F && mode->code <= irm_P);
1903     res = new_rd_Const (NULL, current_ir_graph, block, mode,
1904                         get_mode_null(mode));
1905   }
1906
1907   /* The local valid value is available now. */
1908   block->attr.block.graph_arr[pos] = res;
1909
1910   return res;
1911 }
1912
1913 #endif /* USE_FAST_PHI_CONSTRUCTION */
1914
1915 /* ************************************************************************** */
1916
1917 /** Finalize a Block node, when all control flows are known.  */
1918 /** Acceptable parameters are only Block nodes.               */
1919 void
1920 mature_immBlock (ir_node *block)
1921 {
1922
1923   int ins;
1924   ir_node *n, **nin;
1925   ir_node *next;
1926
1927   assert (get_irn_opcode(block) == iro_Block);
1928   /* @@@ should be commented in
1929      assert (!get_Block_matured(block) && "Block already matured"); */
1930
1931   if (!get_Block_matured(block)) {
1932     ins = ARR_LEN (block->in)-1;
1933     /* Fix block parameters */
1934     block->attr.block.backedge = new_backedge_arr(current_ir_graph->obst, ins);
1935
1936     /* An array for building the Phi nodes. */
1937     NEW_ARR_A (ir_node *, nin, ins);
1938
1939     /* Traverse a chain of Phi nodes attached to this block and mature
1940        these, too. **/
1941     for (n = block->link;  n;  n=next) {
1942       inc_irg_visited(current_ir_graph);
1943       next = n->link;
1944       exchange (n, phi_merge (block, n->attr.phi0_pos, n->mode, nin, ins));
1945     }
1946
1947     block->attr.block.matured = 1;
1948
1949     /* Now, as the block is a finished firm node, we can optimize it.
1950        Since other nodes have been allocated since the block was created
1951        we can not free the node on the obstack.  Therefore we have to call
1952        optimize_in_place.
1953        Unfortunately the optimization does not change a lot, as all allocated
1954        nodes refer to the unoptimized node.
1955        We can call _2, as global cse has no effect on blocks. */
1956     block = optimize_in_place_2(block);
1957     IRN_VRFY_IRG(block, current_ir_graph);
1958   }
1959 }
1960
1961 ir_node *
1962 new_d_Phi (dbg_info* db, int arity, ir_node **in, ir_mode *mode)
1963 {
1964   return new_rd_Phi(db, current_ir_graph, current_ir_graph->current_block,
1965             arity, in, mode);
1966 }
1967
1968 ir_node *
1969 new_d_Const (dbg_info* db, ir_mode *mode, tarval *con)
1970 {
1971   return new_rd_Const(db, current_ir_graph, current_ir_graph->start_block,
1972               mode, con);
1973 }
1974
1975 ir_node *
1976 new_d_Const_type (dbg_info* db, ir_mode *mode, tarval *con, type *tp)
1977 {
1978   return new_rd_Const_type(db, current_ir_graph, current_ir_graph->start_block,
1979                 mode, con, tp);
1980 }
1981
1982
1983 ir_node *
1984 new_d_Id (dbg_info* db, ir_node *val, ir_mode *mode)
1985 {
1986   return new_rd_Id(db, current_ir_graph, current_ir_graph->current_block,
1987            val, mode);
1988 }
1989
1990 ir_node *
1991 new_d_Proj (dbg_info* db, ir_node *arg, ir_mode *mode, long proj)
1992 {
1993   return new_rd_Proj(db, current_ir_graph, current_ir_graph->current_block,
1994              arg, mode, proj);
1995 }
1996
1997 ir_node *
1998 new_d_defaultProj (dbg_info* db, ir_node *arg, long max_proj)
1999 {
2000   ir_node *res;
2001   assert(arg->op == op_Cond);
2002   arg->attr.c.kind = fragmentary;
2003   arg->attr.c.default_proj = max_proj;
2004   res = new_Proj (arg, mode_X, max_proj);
2005   return res;
2006 }
2007
2008 ir_node *
2009 new_d_Conv (dbg_info* db, ir_node *op, ir_mode *mode)
2010 {
2011   return new_rd_Conv(db, current_ir_graph, current_ir_graph->current_block,
2012              op, mode);
2013 }
2014
2015 ir_node *
2016 new_d_Cast (dbg_info* db, ir_node *op, type *to_tp)
2017 {
2018   return new_rd_Cast(db, current_ir_graph, current_ir_graph->current_block, op, to_tp);
2019 }
2020
2021 ir_node *
2022 new_d_Tuple (dbg_info* db, int arity, ir_node **in)
2023 {
2024   return new_rd_Tuple(db, current_ir_graph, current_ir_graph->current_block,
2025               arity, in);
2026 }
2027
2028 ir_node *
2029 new_d_Add (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode)
2030 {
2031   return new_rd_Add(db, current_ir_graph, current_ir_graph->current_block,
2032             op1, op2, mode);
2033 }
2034
2035 ir_node *
2036 new_d_Sub (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode)
2037 {
2038   return new_rd_Sub(db, current_ir_graph, current_ir_graph->current_block,
2039             op1, op2, mode);
2040 }
2041
2042
2043 ir_node *
2044 new_d_Minus (dbg_info* db, ir_node *op,  ir_mode *mode)
2045 {
2046   return new_rd_Minus(db, current_ir_graph, current_ir_graph->current_block,
2047               op, mode);
2048 }
2049
2050 ir_node *
2051 new_d_Mul (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode)
2052 {
2053   return new_rd_Mul(db, current_ir_graph, current_ir_graph->current_block,
2054             op1, op2, mode);
2055 }
2056
2057 /**
2058  * allocate the frag array
2059  */
2060 static void allocate_frag_arr(ir_node *res, ir_op *op, ir_node ***frag_store) {
2061   if (get_opt_precise_exc_context()) {
2062     if ((current_ir_graph->phase_state == phase_building) &&
2063         (get_irn_op(res) == op) && /* Could be optimized away. */
2064         !*frag_store)    /* Could be a cse where the arr is already set. */ {
2065       *frag_store = new_frag_arr(res);
2066     }
2067   }
2068 }
2069
2070
2071 ir_node *
2072 new_d_Quot (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2)
2073 {
2074   ir_node *res;
2075   res = new_rd_Quot (db, current_ir_graph, current_ir_graph->current_block,
2076              memop, op1, op2);
2077   res->attr.except.pin_state = op_pin_state_pinned;
2078 #if PRECISE_EXC_CONTEXT
2079   allocate_frag_arr(res, op_Quot, &res->attr.except.frag_arr);  /* Could be optimized away. */
2080 #endif
2081
2082   return res;
2083 }
2084
2085 ir_node *
2086 new_d_DivMod (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2)
2087 {
2088   ir_node *res;
2089   res = new_rd_DivMod (db, current_ir_graph, current_ir_graph->current_block,
2090                memop, op1, op2);
2091   res->attr.except.pin_state = op_pin_state_pinned;
2092 #if PRECISE_EXC_CONTEXT
2093   allocate_frag_arr(res, op_DivMod, &res->attr.except.frag_arr);  /* Could be optimized away. */
2094 #endif
2095
2096   return res;
2097 }
2098
2099 ir_node *
2100 new_d_Div (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2)
2101 {
2102   ir_node *res;
2103   res = new_rd_Div (db, current_ir_graph, current_ir_graph->current_block,
2104             memop, op1, op2);
2105   res->attr.except.pin_state = op_pin_state_pinned;
2106 #if PRECISE_EXC_CONTEXT
2107   allocate_frag_arr(res, op_Div, &res->attr.except.frag_arr);  /* Could be optimized away. */
2108 #endif
2109
2110   return res;
2111 }
2112
2113 ir_node *
2114 new_d_Mod (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2)
2115 {
2116   ir_node *res;
2117   res = new_rd_Mod (db, current_ir_graph, current_ir_graph->current_block,
2118             memop, op1, op2);
2119   res->attr.except.pin_state = op_pin_state_pinned;
2120 #if PRECISE_EXC_CONTEXT
2121   allocate_frag_arr(res, op_Mod, &res->attr.except.frag_arr);  /* Could be optimized away. */
2122 #endif
2123
2124   return res;
2125 }
2126
2127 ir_node *
2128 new_d_And (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode)
2129 {
2130   return new_rd_And (db, current_ir_graph, current_ir_graph->current_block,
2131             op1, op2, mode);
2132 }
2133
2134 ir_node *
2135 new_d_Or (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode)
2136 {
2137   return new_rd_Or (db, current_ir_graph, current_ir_graph->current_block,
2138            op1, op2, mode);
2139 }
2140
2141 ir_node *
2142 new_d_Eor (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode)
2143 {
2144   return new_rd_Eor (db, current_ir_graph, current_ir_graph->current_block,
2145             op1, op2, mode);
2146 }
2147
2148 ir_node *
2149 new_d_Not (dbg_info* db, ir_node *op, ir_mode *mode)
2150 {
2151   return new_rd_Not (db, current_ir_graph, current_ir_graph->current_block,
2152             op, mode);
2153 }
2154
2155 ir_node *
2156 new_d_Shl (dbg_info* db, ir_node *op, ir_node *k, ir_mode *mode)
2157 {
2158   return new_rd_Shl (db, current_ir_graph, current_ir_graph->current_block,
2159             op, k, mode);
2160 }
2161
2162 ir_node *
2163 new_d_Shr (dbg_info* db, ir_node *op, ir_node *k, ir_mode *mode)
2164 {
2165   return new_rd_Shr (db, current_ir_graph, current_ir_graph->current_block,
2166             op, k, mode);
2167 }
2168
2169 ir_node *
2170 new_d_Shrs (dbg_info* db, ir_node *op, ir_node *k, ir_mode *mode)
2171 {
2172   return new_rd_Shrs (db, current_ir_graph, current_ir_graph->current_block,
2173              op, k, mode);
2174 }
2175
2176 ir_node *
2177 new_d_Rot (dbg_info* db, ir_node *op, ir_node *k, ir_mode *mode)
2178 {
2179   return new_rd_Rot (db, current_ir_graph, current_ir_graph->current_block,
2180              op, k, mode);
2181 }
2182
2183 ir_node *
2184 new_d_Abs (dbg_info* db, ir_node *op, ir_mode *mode)
2185 {
2186   return new_rd_Abs (db, current_ir_graph, current_ir_graph->current_block,
2187             op, mode);
2188 }
2189
2190 ir_node *
2191 new_d_Cmp (dbg_info* db, ir_node *op1, ir_node *op2)
2192 {
2193   return new_rd_Cmp (db, current_ir_graph, current_ir_graph->current_block,
2194             op1, op2);
2195 }
2196
2197 ir_node *
2198 new_d_Jmp (dbg_info* db)
2199 {
2200   return new_rd_Jmp (db, current_ir_graph, current_ir_graph->current_block);
2201 }
2202
2203 ir_node *
2204 new_d_Cond (dbg_info* db, ir_node *c)
2205 {
2206   return new_rd_Cond (db, current_ir_graph, current_ir_graph->current_block, c);
2207 }
2208
2209 ir_node *
2210 new_d_Call (dbg_info* db, ir_node *store, ir_node *callee, int arity, ir_node **in,
2211       type *tp)
2212 {
2213   ir_node *res;
2214   res = new_rd_Call (db, current_ir_graph, current_ir_graph->current_block,
2215              store, callee, arity, in, tp);
2216 #if PRECISE_EXC_CONTEXT
2217   allocate_frag_arr(res, op_Call, &res->attr.call.exc.frag_arr);  /* Could be optimized away. */
2218 #endif
2219
2220   return res;
2221 }
2222
2223 ir_node *
2224 new_d_Return (dbg_info* db, ir_node* store, int arity, ir_node **in)
2225 {
2226   return new_rd_Return (db, current_ir_graph, current_ir_graph->current_block,
2227                store, arity, in);
2228 }
2229
2230 ir_node *
2231 new_d_Raise (dbg_info* db, ir_node *store, ir_node *obj)
2232 {
2233   return new_rd_Raise (db, current_ir_graph, current_ir_graph->current_block,
2234               store, obj);
2235 }
2236
2237 ir_node *
2238 new_d_Load (dbg_info* db, ir_node *store, ir_node *addr, ir_mode *mode)
2239 {
2240   ir_node *res;
2241   res = new_rd_Load (db, current_ir_graph, current_ir_graph->current_block,
2242              store, addr, mode);
2243 #if PRECISE_EXC_CONTEXT
2244   allocate_frag_arr(res, op_Load, &res->attr.load.exc.frag_arr);  /* Could be optimized away. */
2245 #endif
2246
2247   return res;
2248 }
2249
2250 ir_node *
2251 new_d_Store (dbg_info* db, ir_node *store, ir_node *addr, ir_node *val)
2252 {
2253   ir_node *res;
2254   res = new_rd_Store (db, current_ir_graph, current_ir_graph->current_block,
2255               store, addr, val);
2256 #if PRECISE_EXC_CONTEXT
2257   allocate_frag_arr(res, op_Store, &res->attr.store.exc.frag_arr);  /* Could be optimized away. */
2258 #endif
2259
2260   return res;
2261 }
2262
2263 ir_node *
2264 new_d_Alloc (dbg_info* db, ir_node *store, ir_node *size, type *alloc_type,
2265            where_alloc where)
2266 {
2267   ir_node *res;
2268   res = new_rd_Alloc (db, current_ir_graph, current_ir_graph->current_block,
2269               store, size, alloc_type, where);
2270 #if PRECISE_EXC_CONTEXT
2271   allocate_frag_arr(res, op_Alloc, &res->attr.a.exc.frag_arr);  /* Could be optimized away. */
2272 #endif
2273
2274   return res;
2275 }
2276
2277 ir_node *
2278 new_d_Free (dbg_info* db, ir_node *store, ir_node *ptr, ir_node *size, type *free_type)
2279 {
2280   return new_rd_Free (db, current_ir_graph, current_ir_graph->current_block,
2281              store, ptr, size, free_type);
2282 }
2283
2284 ir_node *
2285 new_d_simpleSel (dbg_info* db, ir_node *store, ir_node *objptr, entity *ent)
2286 /* GL: objptr was called frame before.  Frame was a bad choice for the name
2287    as the operand could as well be a pointer to a dynamic object. */
2288 {
2289   return new_rd_Sel (db, current_ir_graph, current_ir_graph->current_block,
2290             store, objptr, 0, NULL, ent);
2291 }
2292
2293 ir_node *
2294 new_d_Sel (dbg_info* db, ir_node *store, ir_node *objptr, int n_index, ir_node **index, entity *sel)
2295 {
2296   return new_rd_Sel (db, current_ir_graph, current_ir_graph->current_block,
2297             store, objptr, n_index, index, sel);
2298 }
2299
2300 ir_node *
2301 new_d_InstOf (dbg_info *db, ir_node *store, ir_node *objptr, type *ent)
2302 {
2303   return (new_rd_InstOf (db, current_ir_graph, current_ir_graph->current_block,
2304                          store, objptr, ent));
2305 }
2306
2307 ir_node *
2308 new_d_SymConst_type (dbg_info* db, symconst_symbol value, symconst_kind kind, type *tp)
2309 {
2310   return new_rd_SymConst_type (db, current_ir_graph, current_ir_graph->start_block,
2311                          value, kind, tp);
2312 }
2313
2314 ir_node *
2315 new_d_SymConst (dbg_info* db, symconst_symbol value, symconst_kind kind)
2316 {
2317   return new_rd_SymConst (db, current_ir_graph, current_ir_graph->start_block,
2318                          value, kind);
2319 }
2320
2321 ir_node *
2322 new_d_Sync (dbg_info* db, int arity, ir_node** in)
2323 {
2324   return new_rd_Sync (db, current_ir_graph, current_ir_graph->current_block,
2325               arity, in);
2326 }
2327
2328
2329 ir_node *
2330 (new_d_Bad)(void)
2331 {
2332   return __new_d_Bad();
2333 }
2334
2335 ir_node *
2336 new_d_Confirm (dbg_info *db, ir_node *val, ir_node *bound, pn_Cmp cmp)
2337 {
2338   return new_rd_Confirm (db, current_ir_graph, current_ir_graph->current_block,
2339              val, bound, cmp);
2340 }
2341
2342 ir_node *
2343 new_d_Unknown (ir_mode *m)
2344 {
2345   return new_rd_Unknown(current_ir_graph, m);
2346 }
2347
2348 ir_node *
2349 new_d_CallBegin (dbg_info *db, ir_node *call)
2350 {
2351   ir_node *res;
2352   res = new_rd_CallBegin (db, current_ir_graph, current_ir_graph->current_block, call);
2353   return res;
2354 }
2355
2356 ir_node *
2357 new_d_EndReg (dbg_info *db)
2358 {
2359   ir_node *res;
2360   res = new_rd_EndReg(db, current_ir_graph, current_ir_graph->current_block);
2361   return res;
2362 }
2363
2364 ir_node *
2365 new_d_EndExcept (dbg_info *db)
2366 {
2367   ir_node *res;
2368   res = new_rd_EndExcept(db, current_ir_graph, current_ir_graph->current_block);
2369   return res;
2370 }
2371
2372 ir_node *
2373 new_d_Break (dbg_info *db)
2374 {
2375   return new_rd_Break (db, current_ir_graph, current_ir_graph->current_block);
2376 }
2377
2378 ir_node *
2379 new_d_Filter (dbg_info *db, ir_node *arg, ir_mode *mode, long proj)
2380 {
2381   return new_rd_Filter (db, current_ir_graph, current_ir_graph->current_block,
2382             arg, mode, proj);
2383 }
2384
2385 ir_node *
2386 (new_d_NoMem)(void)
2387 {
2388   return __new_d_NoMem();
2389 }
2390
2391 ir_node *
2392 new_d_Mux (dbg_info *db, ir_node *sel, ir_node *ir_false,
2393     ir_node *ir_true, ir_mode *mode) {
2394   return new_rd_Mux (db, current_ir_graph, current_ir_graph->current_block,
2395       sel, ir_false, ir_true, mode);
2396 }
2397
2398 /* ********************************************************************* */
2399 /* Comfortable interface with automatic Phi node construction.           */
2400 /* (Uses also constructors of ?? interface, except new_Block.            */
2401 /* ********************************************************************* */
2402
2403 /* * Block construction **/
2404 /* immature Block without predecessors */
2405 ir_node *new_d_immBlock (dbg_info* db) {
2406   ir_node *res;
2407
2408   assert(get_irg_phase_state (current_ir_graph) == phase_building);
2409   /* creates a new dynamic in-array as length of in is -1 */
2410   res = new_ir_node (db, current_ir_graph, NULL, op_Block, mode_BB, -1, NULL);
2411   current_ir_graph->current_block = res;
2412   res->attr.block.matured     = 0;
2413   res->attr.block.dead        = 0;
2414   /* res->attr.block.exc = exc_normal; */
2415   /* res->attr.block.handler_entry = 0; */
2416   res->attr.block.irg         = current_ir_graph;
2417   res->attr.block.backedge    = NULL;
2418   res->attr.block.in_cg       = NULL;
2419   res->attr.block.cg_backedge = NULL;
2420   set_Block_block_visited(res, 0);
2421
2422   /* Create and initialize array for Phi-node construction. */
2423   res->attr.block.graph_arr = NEW_ARR_D (ir_node *, current_ir_graph->obst,
2424                                          current_ir_graph->n_loc);
2425   memset(res->attr.block.graph_arr, 0, sizeof(ir_node *)*current_ir_graph->n_loc);
2426
2427   /* Immature block may not be optimized! */
2428   IRN_VRFY_IRG(res, current_ir_graph);
2429
2430   return res;
2431 }
2432
2433 ir_node *
2434 new_immBlock (void) {
2435   return new_d_immBlock(NULL);
2436 }
2437
2438 /* add an adge to a jmp/control flow node */
2439 void
2440 add_immBlock_pred (ir_node *block, ir_node *jmp)
2441 {
2442   if (block->attr.block.matured) {
2443     assert(0 && "Error: Block already matured!\n");
2444   }
2445   else {
2446     assert(jmp != NULL);
2447     ARR_APP1(ir_node *, block->in, jmp);
2448   }
2449 }
2450
2451 /* changing the current block */
2452 void
2453 set_cur_block (ir_node *target)
2454 {
2455   current_ir_graph->current_block = target;
2456 }
2457
2458 /* ************************ */
2459 /* parameter administration */
2460
2461 /* get a value from the parameter array from the current block by its index */
2462 ir_node *
2463 get_d_value (dbg_info* db, int pos, ir_mode *mode)
2464 {
2465   assert(get_irg_phase_state (current_ir_graph) == phase_building);
2466   inc_irg_visited(current_ir_graph);
2467
2468   return get_r_value_internal (current_ir_graph->current_block, pos + 1, mode);
2469 }
2470 /* get a value from the parameter array from the current block by its index */
2471 ir_node *
2472 get_value (int pos, ir_mode *mode)
2473 {
2474   return get_d_value(NULL, pos, mode);
2475 }
2476
2477 /* set a value at position pos in the parameter array from the current block */
2478 void
2479 set_value (int pos, ir_node *value)
2480 {
2481   assert(get_irg_phase_state (current_ir_graph) == phase_building);
2482   assert(pos+1 < current_ir_graph->n_loc);
2483   current_ir_graph->current_block->attr.block.graph_arr[pos + 1] = value;
2484 }
2485
2486 /* get the current store */
2487 ir_node *
2488 get_store (void)
2489 {
2490   assert(get_irg_phase_state (current_ir_graph) == phase_building);
2491   /* GL: one could call get_value instead */
2492   inc_irg_visited(current_ir_graph);
2493   return get_r_value_internal (current_ir_graph->current_block, 0, mode_M);
2494 }
2495
2496 /* set the current store */
2497 void
2498 set_store (ir_node *store)
2499 {
2500   /* GL: one could call set_value instead */
2501   assert(get_irg_phase_state (current_ir_graph) == phase_building);
2502   current_ir_graph->current_block->attr.block.graph_arr[0] = store;
2503 }
2504
2505 void
2506 keep_alive (ir_node *ka)
2507 {
2508   add_End_keepalive(current_ir_graph->end, ka);
2509 }
2510
2511 /** Useful access routines **/
2512 /* Returns the current block of the current graph.  To set the current
2513    block use set_cur_block. */
2514 ir_node *get_cur_block() {
2515   return get_irg_current_block(current_ir_graph);
2516 }
2517
2518 /* Returns the frame type of the current graph */
2519 type *get_cur_frame_type() {
2520   return get_irg_frame_type(current_ir_graph);
2521 }
2522
2523
2524 /* ********************************************************************* */
2525 /* initialize */
2526
2527 /* call once for each run of the library */
2528 void
2529 init_cons (default_initialize_local_variable_func_t *func)
2530 {
2531   default_initialize_local_variable = func;
2532 }
2533
2534 /* call for each graph */
2535 void
2536 finalize_cons (ir_graph *irg) {
2537   irg->phase_state = phase_high;
2538 }
2539
2540
2541 ir_node *new_Block(int arity, ir_node **in) {
2542   return new_d_Block(NULL, arity, in);
2543 }
2544 ir_node *new_Start  (void) {
2545   return new_d_Start(NULL);
2546 }
2547 ir_node *new_End    (void) {
2548   return new_d_End(NULL);
2549 }
2550 ir_node *new_Jmp    (void) {
2551   return new_d_Jmp(NULL);
2552 }
2553 ir_node *new_Cond   (ir_node *c) {
2554   return new_d_Cond(NULL, c);
2555 }
2556 ir_node *new_Return (ir_node *store, int arity, ir_node *in[]) {
2557   return new_d_Return(NULL, store, arity, in);
2558 }
2559 ir_node *new_Raise  (ir_node *store, ir_node *obj) {
2560   return new_d_Raise(NULL, store, obj);
2561 }
2562 ir_node *new_Const  (ir_mode *mode, tarval *con) {
2563   return new_d_Const(NULL, mode, con);
2564 }
2565
2566 ir_node *new_Const_type(tarval *con, type *tp) {
2567   return new_d_Const_type(NULL, get_type_mode(tp), con, tp);
2568 }
2569
2570 ir_node *new_SymConst (symconst_symbol value, symconst_kind kind) {
2571   return new_d_SymConst(NULL, value, kind);
2572 }
2573 ir_node *new_simpleSel(ir_node *store, ir_node *objptr, entity *ent) {
2574   return new_d_simpleSel(NULL, store, objptr, ent);
2575 }
2576 ir_node *new_Sel    (ir_node *store, ir_node *objptr, int arity, ir_node **in,
2577                      entity *ent) {
2578   return new_d_Sel(NULL, store, objptr, arity, in, ent);
2579 }
2580 ir_node *new_InstOf (ir_node *store, ir_node *objptr, type *ent) {
2581   return new_d_InstOf (NULL, store, objptr, ent);
2582 }
2583 ir_node *new_Call   (ir_node *store, ir_node *callee, int arity, ir_node **in,
2584              type *tp) {
2585   return new_d_Call(NULL, store, callee, arity, in, tp);
2586 }
2587 ir_node *new_Add    (ir_node *op1, ir_node *op2, ir_mode *mode) {
2588   return new_d_Add(NULL, op1, op2, mode);
2589 }
2590 ir_node *new_Sub    (ir_node *op1, ir_node *op2, ir_mode *mode) {
2591   return new_d_Sub(NULL, op1, op2, mode);
2592 }
2593 ir_node *new_Minus  (ir_node *op,  ir_mode *mode) {
2594   return new_d_Minus(NULL, op, mode);
2595 }
2596 ir_node *new_Mul    (ir_node *op1, ir_node *op2, ir_mode *mode) {
2597   return new_d_Mul(NULL, op1, op2, mode);
2598 }
2599 ir_node *new_Quot   (ir_node *memop, ir_node *op1, ir_node *op2) {
2600   return new_d_Quot(NULL, memop, op1, op2);
2601 }
2602 ir_node *new_DivMod (ir_node *memop, ir_node *op1, ir_node *op2) {
2603   return new_d_DivMod(NULL, memop, op1, op2);
2604 }
2605 ir_node *new_Div    (ir_node *memop, ir_node *op1, ir_node *op2) {
2606   return new_d_Div(NULL, memop, op1, op2);
2607 }
2608 ir_node *new_Mod    (ir_node *memop, ir_node *op1, ir_node *op2) {
2609   return new_d_Mod(NULL, memop, op1, op2);
2610 }
2611 ir_node *new_Abs    (ir_node *op, ir_mode *mode) {
2612   return new_d_Abs(NULL, op, mode);
2613 }
2614 ir_node *new_And    (ir_node *op1, ir_node *op2, ir_mode *mode) {
2615   return new_d_And(NULL, op1, op2, mode);
2616 }
2617 ir_node *new_Or     (ir_node *op1, ir_node *op2, ir_mode *mode) {
2618   return new_d_Or(NULL, op1, op2, mode);
2619 }
2620 ir_node *new_Eor    (ir_node *op1, ir_node *op2, ir_mode *mode) {
2621   return new_d_Eor(NULL, op1, op2, mode);
2622 }
2623 ir_node *new_Not    (ir_node *op,                ir_mode *mode) {
2624   return new_d_Not(NULL, op, mode);
2625 }
2626 ir_node *new_Shl    (ir_node *op,  ir_node *k,   ir_mode *mode) {
2627   return new_d_Shl(NULL, op, k, mode);
2628 }
2629 ir_node *new_Shr    (ir_node *op,  ir_node *k,   ir_mode *mode) {
2630   return new_d_Shr(NULL, op, k, mode);
2631 }
2632 ir_node *new_Shrs   (ir_node *op,  ir_node *k,   ir_mode *mode) {
2633   return new_d_Shrs(NULL, op, k, mode);
2634 }
2635 #define new_Rotate new_Rot
2636 ir_node *new_Rot    (ir_node *op,  ir_node *k,   ir_mode *mode) {
2637   return new_d_Rot(NULL, op, k, mode);
2638 }
2639 ir_node *new_Cmp    (ir_node *op1, ir_node *op2) {
2640   return new_d_Cmp(NULL, op1, op2);
2641 }
2642 ir_node *new_Conv   (ir_node *op, ir_mode *mode) {
2643   return new_d_Conv(NULL, op, mode);
2644 }
2645 ir_node *new_Cast   (ir_node *op, type *to_tp) {
2646   return new_d_Cast(NULL, op, to_tp);
2647 }
2648 ir_node *new_Phi    (int arity, ir_node **in, ir_mode *mode) {
2649   return new_d_Phi(NULL, arity, in, mode);
2650 }
2651 ir_node *new_Load   (ir_node *store, ir_node *addr, ir_mode *mode) {
2652   return new_d_Load(NULL, store, addr, mode);
2653 }
2654 ir_node *new_Store  (ir_node *store, ir_node *addr, ir_node *val) {
2655   return new_d_Store(NULL, store, addr, val);
2656 }
2657 ir_node *new_Alloc  (ir_node *store, ir_node *size, type *alloc_type,
2658                      where_alloc where) {
2659   return new_d_Alloc(NULL, store, size, alloc_type, where);
2660 }
2661 ir_node *new_Free   (ir_node *store, ir_node *ptr, ir_node *size,
2662              type *free_type) {
2663   return new_d_Free(NULL, store, ptr, size, free_type);
2664 }
2665 ir_node *new_Sync   (int arity, ir_node **in) {
2666   return new_d_Sync(NULL, arity, in);
2667 }
2668 ir_node *new_Proj   (ir_node *arg, ir_mode *mode, long proj) {
2669   return new_d_Proj(NULL, arg, mode, proj);
2670 }
2671 ir_node *new_defaultProj (ir_node *arg, long max_proj) {
2672   return new_d_defaultProj(NULL, arg, max_proj);
2673 }
2674 ir_node *new_Tuple  (int arity, ir_node **in) {
2675   return new_d_Tuple(NULL, arity, in);
2676 }
2677 ir_node *new_Id     (ir_node *val, ir_mode *mode) {
2678   return new_d_Id(NULL, val, mode);
2679 }
2680 ir_node *new_Bad    (void) {
2681   return new_d_Bad();
2682 }
2683 ir_node *new_Confirm (ir_node *val, ir_node *bound, pn_Cmp cmp) {
2684   return new_d_Confirm (NULL, val, bound, cmp);
2685 }
2686 ir_node *new_Unknown(ir_mode *m) {
2687   return new_d_Unknown(m);
2688 }
2689 ir_node *new_CallBegin (ir_node *callee) {
2690   return new_d_CallBegin(NULL, callee);
2691 }
2692 ir_node *new_EndReg (void) {
2693   return new_d_EndReg(NULL);
2694 }
2695 ir_node *new_EndExcept (void) {
2696   return new_d_EndExcept(NULL);
2697 }
2698 ir_node *new_Break  (void) {
2699   return new_d_Break(NULL);
2700 }
2701 ir_node *new_Filter (ir_node *arg, ir_mode *mode, long proj) {
2702   return new_d_Filter(NULL, arg, mode, proj);
2703 }
2704 ir_node *new_NoMem  (void) {
2705   return new_d_NoMem();
2706 }
2707 ir_node *new_Mux (ir_node *sel, ir_node *ir_false, ir_node *ir_true, ir_mode *mode) {
2708   return new_d_Mux(NULL, sel, ir_false, ir_true, mode);
2709 }