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