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