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