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