fa689ca06628f30297b0e5282176772e5af342ef
[libfirm] / ir / ir / ircons.c
1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
3 **
4 ** Authors: Martin Trapp, Christian Schaefer
5 **
6 ** ircons.c: basic and more detailed irnode constructors
7 **           store, block and parameter administration.
8 ** Adapted to extended FIRM nodes (exceptions...) and commented
9 **   by Goetz Lindenmaier
10 */
11
12 # include "ircons.h"
13 # include "common.h"
14 # include "irvrfy.h"
15 # include "irop.h"
16 # include "iropt.h"
17 # include "irgmod.h"
18 # include "array.h"
19 /* memset belongs to string.h */
20 # include "string.h"
21 # include "irnode_t.h"
22
23 #if USE_EXPICIT_PHI_IN_STACK
24 /* A stack needed for the automatic Phi node construction in constructor
25    Phi_in. */
26 struct Phi_in_stack {
27   ir_node **stack;
28   int       pos;
29 };
30 #endif
31
32 /*********************************************** */
33 /** privat interfaces, for professional use only */
34
35 /* Constructs a Block with a fixed number of predecessors.
36    Does not set current_block. */
37
38 inline ir_node *
39 new_r_Block (ir_graph *irg,  int arity, ir_node **in)
40 {
41   ir_node *res;
42
43   res = new_ir_node (irg, NULL, op_Block, mode_R, arity, in);
44   set_Block_matured(res, 1);
45
46   irn_vrfy (res);
47   return res;
48 }
49
50 ir_node *
51 new_r_Start (ir_graph *irg, ir_node *block)
52 {
53   ir_node *res;
54
55   res = new_ir_node (irg, block, op_Start, mode_T, 0, NULL);
56
57   irn_vrfy (res);
58   return res;
59 }
60
61 ir_node *
62 new_r_End (ir_graph *irg, ir_node *block)
63 {
64   ir_node *res;
65
66   res = new_ir_node (irg, block, op_End, mode_X, -1, NULL);
67
68   irn_vrfy (res);
69   return res;
70 }
71
72 /* Creates a Phi node with all predecessors.  Calling this constructor
73    is only allowed if the corresponding block is mature.  */
74 ir_node *
75 new_r_Phi (ir_graph *irg, ir_node *block, int arity, ir_node **in, ir_mode *mode)
76 {
77   ir_node *res;
78
79   assert( get_Block_matured(block) );
80   assert( get_irn_arity(block) == arity );
81
82   res = new_ir_node (irg, block, op_Phi, mode, arity, in);
83
84   res = optimize (res);
85   irn_vrfy (res);
86   return res;
87 }
88
89 ir_node *
90 new_r_Const (ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con)
91 {
92   ir_node *res;
93   res = new_ir_node (irg, block, op_Const, mode, 0, NULL);
94   res->attr.con = con;
95   res = optimize (res);
96   irn_vrfy (res);
97
98 #if 0
99   res = local_optimize_newby (res);
100 # endif
101
102   return res;
103 }
104
105 ir_node *
106 new_r_Id (ir_graph *irg, ir_node *block, ir_node *val, ir_mode *mode)
107 {
108   ir_node *in[1] = {val};
109   ir_node *res;
110   res = new_ir_node (irg, block, op_Id, mode, 1, in);
111   res = optimize (res);
112   irn_vrfy (res);
113   return res;
114 }
115
116 ir_node *
117 new_r_Proj (ir_graph *irg, ir_node *block, ir_node *arg, ir_mode *mode,
118             long proj)
119 {
120   ir_node *in[1] = {arg};
121   ir_node *res;
122   res = new_ir_node (irg, block, op_Proj, mode, 1, in);
123   res->attr.proj = proj;
124
125   assert(res);
126   assert(get_Proj_pred(res));
127   assert(get_nodes_Block(get_Proj_pred(res)));
128
129   res = optimize (res);
130
131   irn_vrfy (res);
132   return res;
133
134 }
135
136 ir_node *
137 new_r_Conv (ir_graph *irg, ir_node *block, ir_node *op, ir_mode *mode)
138 {
139   ir_node *in[1] = {op};
140   ir_node *res;
141   res = new_ir_node (irg, block, op_Conv, mode, 1, in);
142   res = optimize (res);
143   irn_vrfy (res);
144   return res;
145
146 }
147
148 ir_node *
149 new_r_Tuple (ir_graph *irg, ir_node *block, int arity, ir_node **in)
150 {
151   ir_node *res;
152
153   res = new_ir_node (irg, block, op_Tuple, mode_T, arity, in);
154   res = optimize (res);
155   irn_vrfy (res);
156   return res;
157 }
158
159 inline ir_node *
160 new_r_Add (ir_graph *irg, ir_node *block,
161            ir_node *op1, ir_node *op2, ir_mode *mode)
162 {
163   ir_node *in[2] = {op1, op2};
164   ir_node *res;
165   res = new_ir_node (irg, block, op_Add, mode, 2, in);
166   res = optimize (res);
167   irn_vrfy (res);
168   return res;
169 }
170
171 inline ir_node *
172 new_r_Sub (ir_graph *irg, ir_node *block,
173            ir_node *op1, ir_node *op2, ir_mode *mode)
174 {
175   ir_node *in[2] = {op1, op2};
176   ir_node *res;
177   res = new_ir_node (irg, block, op_Sub, mode, 2, in);
178   res = optimize (res);
179   irn_vrfy (res);
180   return res;
181 }
182
183 inline ir_node *
184 new_r_Minus (ir_graph *irg, ir_node *block,
185              ir_node *op,  ir_mode *mode)
186 {
187   ir_node *in[1] = {op};
188   ir_node *res;
189   res = new_ir_node (irg, block, op_Minus, mode, 1, in);
190   res = optimize (res);
191   irn_vrfy (res);
192   return res;
193 }
194
195 inline ir_node *
196 new_r_Mul (ir_graph *irg, ir_node *block,
197            ir_node *op1, ir_node *op2, ir_mode *mode)
198 {
199   ir_node *in[2] = {op1, op2};
200   ir_node *res;
201   res = new_ir_node (irg, block, op_Mul, mode, 2, in);
202   res = optimize (res);
203   irn_vrfy (res);
204   return res;
205 }
206
207 inline ir_node *
208 new_r_Quot (ir_graph *irg, ir_node *block,
209             ir_node *memop, ir_node *op1, ir_node *op2)
210 {
211   ir_node *in[3] = {memop, op1, op2};
212   ir_node *res;
213   res = new_ir_node (irg, block, op_Quot, mode_T, 3, in);
214   res = optimize (res);
215   irn_vrfy (res);
216   return res;
217 }
218
219 inline ir_node *
220 new_r_DivMod (ir_graph *irg, ir_node *block,
221               ir_node *memop, ir_node *op1, ir_node *op2)
222 {
223   ir_node *in[3] = {memop, op1, op2};
224   ir_node *res;
225   res = new_ir_node (irg, block, op_DivMod, mode_T, 3, in);
226   res = optimize (res);
227   irn_vrfy (res);
228   return res;
229 }
230
231 inline ir_node *
232 new_r_Div (ir_graph *irg, ir_node *block,
233            ir_node *memop, ir_node *op1, ir_node *op2)
234 {
235   ir_node *in[3] = {memop, op1, op2};
236   ir_node *res;
237   res = new_ir_node (irg, block, op_Div, mode_T, 3, in);
238   res = optimize (res);
239   irn_vrfy (res);
240   return res;
241 }
242
243 inline ir_node *
244 new_r_Mod (ir_graph *irg, ir_node *block,
245            ir_node *memop, ir_node *op1, ir_node *op2)
246 {
247   ir_node *in[3] = {memop, op1, op2};
248   ir_node *res;
249   res = new_ir_node (irg, block, op_Mod, mode_T, 3, in);
250   res = optimize (res);
251   irn_vrfy (res);
252   return res;
253 }
254
255 inline ir_node *
256 new_r_And (ir_graph *irg, ir_node *block,
257            ir_node *op1, ir_node *op2, ir_mode *mode)
258 {
259   ir_node *in[2] = {op1, op2};
260   ir_node *res;
261   res = new_ir_node (irg, block, op_And, mode, 2, in);
262   res = optimize (res);
263   irn_vrfy (res);
264   return res;
265 }
266
267 inline ir_node *
268 new_r_Or (ir_graph *irg, ir_node *block,
269           ir_node *op1, ir_node *op2, ir_mode *mode)
270 {
271   ir_node *in[2] = {op1, op2};
272   ir_node *res;
273   res = new_ir_node (irg, block, op_Or, mode, 2, in);
274   res = optimize (res);
275   irn_vrfy (res);
276   return res;
277 }
278
279 inline ir_node *
280 new_r_Eor (ir_graph *irg, ir_node *block,
281           ir_node *op1, ir_node *op2, ir_mode *mode)
282 {
283   ir_node *in[2] = {op1, op2};
284   ir_node *res;
285   res = new_ir_node (irg, block, op_Eor, mode, 2, in);
286   res = optimize (res);
287   irn_vrfy (res);
288   return res;
289 }
290
291 inline ir_node *
292 new_r_Not    (ir_graph *irg, ir_node *block,
293               ir_node *op, ir_mode *mode)
294 {
295   ir_node *in[1] = {op};
296   ir_node *res;
297   res = new_ir_node (irg, block, op_Not, mode, 1, in);
298   res = optimize (res);
299   irn_vrfy (res);
300   return res;
301 }
302
303 inline ir_node *
304 new_r_Shl (ir_graph *irg, ir_node *block,
305           ir_node *op, ir_node *k, ir_mode *mode)
306 {
307   ir_node *in[2] = {op, k};
308   ir_node *res;
309   res = new_ir_node (irg, block, op_Shl, mode, 2, in);
310   res = optimize (res);
311   irn_vrfy (res);
312   return res;
313 }
314
315 inline ir_node *
316 new_r_Shr (ir_graph *irg, ir_node *block,
317            ir_node *op, ir_node *k, ir_mode *mode)
318 {
319   ir_node *in[2] = {op, k};
320   ir_node *res;
321   res = new_ir_node (irg, block, op_Shr, mode, 2, in);
322   res = optimize (res);
323   irn_vrfy (res);
324   return res;
325 }
326
327 inline ir_node *
328 new_r_Shrs (ir_graph *irg, ir_node *block,
329            ir_node *op, ir_node *k, ir_mode *mode)
330 {
331   ir_node *in[2] = {op, k};
332   ir_node *res;
333   res = new_ir_node (irg, block, op_Shrs, mode, 2, in);
334   res = optimize (res);
335   irn_vrfy (res);
336   return res;
337 }
338
339 inline ir_node *
340 new_r_Rot (ir_graph *irg, ir_node *block,
341            ir_node *op, ir_node *k, ir_mode *mode)
342 {
343   ir_node *in[2] = {op, k};
344   ir_node *res;
345   res = new_ir_node (irg, block, op_Rot, mode, 2, in);
346   res = optimize (res);
347   irn_vrfy (res);
348   return res;
349 }
350
351 inline ir_node *
352 new_r_Abs (ir_graph *irg, ir_node *block,
353            ir_node *op, ir_mode *mode)
354 {
355   ir_node *in[1] = {op};
356   ir_node *res;
357   res = new_ir_node (irg, block, op_Abs, mode, 1, in);
358   res = optimize (res);
359   irn_vrfy (res);
360   return res;
361 }
362
363 inline ir_node *
364 new_r_Cmp (ir_graph *irg, ir_node *block,
365            ir_node *op1, ir_node *op2)
366 {
367   ir_node *in[2] = {op1, op2};
368   ir_node *res;
369   res = new_ir_node (irg, block, op_Cmp, mode_T, 2, in);
370   res = optimize (res);
371   irn_vrfy (res);
372   return res;
373 }
374
375 inline ir_node *
376 new_r_Jmp (ir_graph *irg, ir_node *block)
377 {
378   ir_node *in[0] = {};
379   ir_node *res;
380   res = new_ir_node (irg, block, op_Jmp, mode_X, 0, in);
381   res = optimize (res);
382   irn_vrfy (res);
383   return res;
384 }
385
386 inline ir_node *
387 new_r_Cond (ir_graph *irg, ir_node *block, ir_node *c)
388 {
389   ir_node *in[1] = {c};
390   ir_node *res;
391   res = new_ir_node (irg, block, op_Cond, mode_T, 1, in);
392   res = optimize (res);
393   irn_vrfy (res);
394   return res;
395 }
396
397 ir_node *
398 new_r_Call (ir_graph *irg, ir_node *block, ir_node *store,
399             ir_node *callee, int arity, ir_node **in, type_method *type)
400 {
401   ir_node **r_in;
402   ir_node *res;
403   int r_arity;
404
405   r_arity = arity+2;
406   NEW_ARR_A (ir_node *, r_in, r_arity);
407   r_in[0] = store;
408   r_in[1] = callee;
409   memcpy (&r_in[2], in, sizeof (ir_node *) * arity);
410
411   res = new_ir_node (irg, block, op_Call, mode_T, r_arity, r_in);
412
413   set_Call_type(res, type);
414   res = optimize (res);
415   irn_vrfy (res);
416   return res;
417 }
418
419 ir_node *
420 new_r_Return (ir_graph *irg, ir_node *block,
421               ir_node *store, int arity, ir_node **in)
422 {
423   ir_node **r_in;
424   ir_node *res;
425   int r_arity;
426
427   r_arity = arity+1;
428   NEW_ARR_A (ir_node *, r_in, r_arity);
429   r_in[0] = store;
430   memcpy (&r_in[1], in, sizeof (ir_node *) * arity);
431   res = new_ir_node (irg, block, op_Return, mode_X, r_arity, r_in);
432   res = optimize (res);
433   irn_vrfy (res);
434   return res;
435 }
436
437 inline ir_node *
438 new_r_Raise (ir_graph *irg, ir_node *block, ir_node *store, ir_node *obj)
439 {
440   ir_node *in[2] = {store, obj};
441   ir_node *res;
442   res = new_ir_node (irg, block, op_Raise, mode_X, 2, in);
443
444   res = optimize (res);
445   irn_vrfy (res);
446   return res;
447 }
448
449 inline ir_node *
450 new_r_Load (ir_graph *irg, ir_node *block,
451             ir_node *store, ir_node *adr)
452 {
453   ir_node *in[2] = {store, adr};
454   ir_node *res;
455   res = new_ir_node (irg, block, op_Load, mode_T, 2, in);
456
457   res = optimize (res);
458   irn_vrfy (res);
459   return res;
460 }
461
462 inline ir_node *
463 new_r_Store (ir_graph *irg, ir_node *block,
464              ir_node *store, ir_node *adr, ir_node *val)
465 {
466   ir_node *in[3] = {store, adr, val};
467   ir_node *res;
468   res = new_ir_node (irg, block, op_Store, mode_T, 3, in);
469
470   res = optimize (res);
471   irn_vrfy (res);
472   return res;
473 }
474
475 inline ir_node *
476 new_r_Alloc (ir_graph *irg, ir_node *block, ir_node *store,
477             ir_node *size, type *alloc_type, where_alloc where)
478 {
479   ir_node *in[2] = {store, size};
480   ir_node *res;
481   res = new_ir_node (irg, block, op_Alloc, mode_T, 2, in);
482
483   res->attr.a.where = where;
484   res->attr.a.type = alloc_type;
485
486   res = optimize (res);
487   irn_vrfy (res);
488   return res;
489 }
490
491 inline ir_node *
492 new_r_Free (ir_graph *irg, ir_node *block, ir_node *store,
493             ir_node *ptr, ir_node *size, type *free_type)
494 {
495   ir_node *in[3] = {store, ptr, size};
496   ir_node *res;
497   res = new_ir_node (irg, block, op_Free, mode_T, 3, in);
498
499   res->attr.f = free_type;
500
501   res = optimize (res);
502   irn_vrfy (res);
503   return res;
504 }
505
506 inline ir_node *
507 new_r_Sel (ir_graph *irg, ir_node *block, ir_node *store, ir_node *objptr,
508            int arity, ir_node **in, entity *ent)
509 {
510   ir_node **r_in;
511   ir_node *res;
512   int r_arity;
513
514   r_arity = arity + 2;
515   NEW_ARR_A (ir_node *, r_in, r_arity);
516   r_in[0] = store;
517   r_in[1] = objptr;
518   memcpy (&r_in[2], in, sizeof (ir_node *) * arity);
519   res = new_ir_node (irg, block, op_Sel, mode_p, r_arity, r_in);
520
521   res->attr.s.ltyp = static_linkage;
522   res->attr.s.ent = ent;
523
524   res = optimize (res);
525   irn_vrfy (res);
526   return res;
527 }
528
529 inline ir_node *
530 new_r_SymConst (ir_graph *irg, ir_node *block, type_or_id_p value,
531                 symconst_kind symkind)
532 {
533   ir_node *in[0] = {};
534   ir_node *res;
535   ir_mode *mode;
536   if (symkind == linkage_ptr_info)
537     mode = mode_p;
538   else
539     mode = mode_I;
540   res = new_ir_node (irg, block, op_SymConst, mode, 0, in);
541
542   res->attr.i.num = symkind;
543   if (symkind == linkage_ptr_info) {
544     res->attr.i.tori.ptrinfo = (ident *)value;
545   } else {
546     assert (   (   (symkind == type_tag)
547                 || (symkind == size))
548             && (is_type(value)));
549     res->attr.i.tori.typ = (type *)value;
550   }
551   res = optimize (res);
552   irn_vrfy (res);
553   return res;
554 }
555
556 ir_node *
557 new_r_Sync (ir_graph *irg, ir_node *block, int arity, ir_node **in)
558 {
559   ir_node *res;
560
561   res = new_ir_node (irg, block, op_Sync, mode_M, arity, in);
562
563   res = optimize (res);
564   irn_vrfy (res);
565   return res;
566 }
567
568 ir_node *
569 new_r_Bad ()
570 {
571   return current_ir_graph->bad;
572 }
573
574 /***********************/
575 /** public interfaces  */
576 /** construction tools */
577
578 ir_node *
579 new_Start (void)
580 {
581   ir_node *res;
582
583   res = new_ir_node (current_ir_graph, current_ir_graph->current_block,
584                      op_Start, mode_T, 0, NULL);
585
586   res = optimize (res);
587   irn_vrfy (res);
588   return res;
589 }
590
591 ir_node *
592 new_End (void)
593 {
594   ir_node *res;
595
596   res = new_ir_node (current_ir_graph,  current_ir_graph->current_block,
597                      op_End, mode_X, -1, NULL);
598
599   res = optimize (res);
600   irn_vrfy (res);
601
602   return res;
603 }
604
605 ir_node *
606 new_Block (void)
607 {
608   ir_node *res;
609
610   res = new_ir_node (current_ir_graph, NULL, op_Block, mode_R, -1, NULL);
611   current_ir_graph->current_block = res;
612   res->attr.block.matured = 0;
613   set_Block_block_visited(res, 0);
614
615   /* forget this optimization. use this only if mature !!!!
616   res = optimize (res); */
617   irn_vrfy (res);
618
619   /** create a new dynamic array, which stores all parameters in irnodes */
620   /** using the same obstack as the whole irgraph */
621   res->attr.block.graph_arr = NEW_ARR_D (ir_node *, current_ir_graph->obst,
622                                          current_ir_graph->params);
623
624   /** initialize the parameter array */
625   memset(res->attr.block.graph_arr, 0, sizeof(ir_node *)*current_ir_graph->params);
626
627   return res;
628 }
629
630 /*************************************************************************/
631 /* Methods necessary for automatic Phi node creation                     */
632 /*
633   ir_node *phi_merge            (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
634   ir_node *get_r_value_internal (ir_node *block, int pos, ir_mode *mode);
635   ir_node *new_r_Phi0           (ir_graph *irg, ir_node *block, ir_mode *mode)
636   ir_node *new_r_Phi_in         (ir_graph *irg, ir_node *block, ir_mode *mode,  ir_node **in, int ins)
637
638   Call Graph:   ( A ---> B == A "calls" B)
639
640        get_value         mature_block
641           |                   |
642           |                   |
643           |                   |
644           |          ---> phi_merge
645           |         /       /   \
646           |        /       /     \
647          \|/      /      |/_      \
648        get_r_value_internal        |
649                 |                  |
650                 |                  |
651                \|/                \|/
652             new_r_Phi0          new_r_Phi_in
653
654 *****************************************************************************/
655
656 /* Creates a Phi node with 0 predecessors */
657 inline ir_node *
658 new_r_Phi0 (ir_graph *irg, ir_node *block, ir_mode *mode)
659 {
660   ir_node *res;
661   res = new_ir_node (irg, block, op_Phi, mode, 0, NULL);
662   irn_vrfy (res);
663   return res;
664 }
665
666 /* There are two implementations of the Phi node construction.  The first
667    is faster, but does not work for blocks with more than 2 predecessors.
668    The second works always but is slower and causes more unnecessary Phi
669    nodes.
670    Select the implementations by the following preprocessor flag set in
671    common/common.h: */
672 #if USE_FAST_PHI_CONSTRUCTION
673
674 /* This is a stack used for allocating and deallocating nodes in
675    new_r_Phi_in.  The original implementation used the obstack
676    to model this stack, now it is explicit.  This reduces side effects.
677 */
678 #if USE_EXPICIT_PHI_IN_STACK
679 Phi_in_stack *
680 new_Phi_in_stack() {
681   Phi_in_stack *res;
682
683   res = (Phi_in_stack *) malloc ( sizeof (Phi_in_stack));
684
685   res->stack = NEW_ARR_F (ir_node *, 1);
686   res->pos = 0;
687
688   return res;
689 }
690
691 void free_to_Phi_in_stack(ir_node *phi) {
692   assert(get_irn_opcode(phi) == iro_Phi);
693
694   if (ARR_LEN(current_ir_graph->Phi_in_stack->stack) ==
695       current_ir_graph->Phi_in_stack->pos)
696     ARR_APP1 (ir_node *, current_ir_graph->Phi_in_stack->stack, phi);
697   else
698     current_ir_graph->Phi_in_stack->stack[current_ir_graph->Phi_in_stack->pos] = phi;
699
700   (current_ir_graph->Phi_in_stack->pos)++;
701 }
702
703 ir_node *
704 alloc_or_pop_from_Phi_in_stack(ir_graph *irg, ir_node *block, ir_mode *mode,
705              int arity, ir_node **in) {
706   ir_node *res;
707   ir_node **stack = current_ir_graph->Phi_in_stack->stack;
708   int pos = current_ir_graph->Phi_in_stack->pos;
709
710
711   if (pos == 0) {
712     /* We need to allocate a new node */
713     res = new_ir_node (irg, block, op_Phi, mode, arity, in);
714   } else {
715     /* reuse the old node and initialize it again. */
716     res = stack[pos-1];
717
718     assert (res->kind == k_ir_node);
719     assert (res->op == op_Phi);
720     res->mode = mode;
721     res->visited = 0;
722     res->link = NULL;
723     assert (arity >= 0);
724     /* ???!!! How to free the old in array??  */
725     res->in = NEW_ARR_D (ir_node *, irg->obst, (arity+1));
726     res->in[0] = block;
727     memcpy (&res->in[1], in, sizeof (ir_node *) * arity);
728
729     (current_ir_graph->Phi_in_stack->pos)--;
730   }
731   return res;
732 }
733 #endif /* USE_EXPICIT_PHI_IN_STACK */
734
735 /* Creates a Phi node with a given, fixed array **in of predecessors.
736    If the Phi node is unnecessary, as the same value reaches the block
737    through all control flow paths, it is eliminated and the value
738    returned directly.  This constructor is only intended for use in
739    the automatic Phi node generation triggered by get_value or mature.
740    The implementation is quite tricky and depends on the fact, that
741    the nodes are allocated on a stack:
742    The in array contains predecessors and NULLs.  The NULLs appear,
743    if get_r_value_internal, that computed the predecessors, reached
744    the same block on two paths.  In this case the same value reaches
745    this block on both paths, there is no definition in between.  We need
746    not allocate a Phi where these path's merge, but we have to communicate
747    this fact to the caller.  This happens by returning a pointer to the
748    node the caller _will_ allocate.  (Yes, we predict the address. We can
749    do so because the nodes are allocated on the obstack.)  The caller then
750    finds a pointer to itself and, when this routine is called again,
751    eliminates itself.
752    */
753 inline ir_node *
754 new_r_Phi_in (ir_graph *irg, ir_node *block, ir_mode *mode,
755               ir_node **in, int ins)
756 {
757   int i;
758   ir_node *res, *known;
759
760   /* allocate a new node on the obstack.
761      This can return a node to which some of the pointers in the in-array
762      already point.
763      Attention: the constructor copies the in array, i.e., the later changes
764      to the array in this routine do not affect the constructed node!  If
765      the in array contains NULLs, there will be missing predecessors in the
766      returned node.
767      Is this a possible internal state of the Phi node generation? */
768 #if USE_EXPICIT_PHI_IN_STACK
769   res = known = alloc_or_pop_from_Phi_in_stack(irg, block, mode, ins, in);
770 #else
771   res = known = new_ir_node (irg, block, op_Phi, mode, ins, in);
772 #endif
773   /* The in-array can contain NULLs.  These were returned by
774      get_r_value_internal if it reached the same block/definition on a
775      second path.
776      The NULLs are replaced by the node itself to simplify the test in the
777      next loop. */
778   for (i=0;  i < ins;  ++i)
779     if (in[i] == NULL) in[i] = res;
780
781   /* This loop checks whether the Phi has more than one predecessor.
782      If so, it is a real Phi node and we break the loop.  Else the
783      Phi node merges the same definition on several paths and therefore
784      is not needed. */
785   for (i=0;  i < ins;  ++i)
786   {
787     if (in[i]==res || in[i]==known) continue;
788
789     if (known==res)
790       known = in[i];
791     else
792       break;
793   }
794
795   /* i==ins: there is at most one predecessor, we don't need a phi node. */
796   if (i==ins) {
797 #if USE_EXPICIT_PHI_IN_STACK
798     free_to_Phi_in_stack(res);
799 #else
800     obstack_free (current_ir_graph->obst, res);
801 #endif
802     res = known;
803   } else {
804     res = optimize (res);
805     irn_vrfy (res);
806   }
807
808   /* return the pointer to the Phi node.  This node might be deallocated! */
809   return res;
810 }
811
812 inline ir_node *
813 get_r_value_internal (ir_node *block, int pos, ir_mode *mode);
814
815 /** This function computes the predecessors for a real Phi node, and then
816     allocates and returns this node.  The routine called to allocate the
817     node might optimize it away and return a real value, or even a pointer
818     to a deallocated Phi node on top of the obstack!
819     This function is called with an in-array of proper size. **/
820 static inline ir_node *
821 phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
822 {
823   ir_node *prevBlock, *res;
824   int i;
825
826   /* This loop goes to all predecessor blocks of the block the Phi node is in
827      and there finds the operands of the Phi node by calling
828      get_r_value_internal. */
829   for (i = 1;  i <= ins;  ++i) {
830     assert (block->in[i]);
831     prevBlock = block->in[i]->in[0]; /* go past control flow op to prev block */
832     assert (prevBlock);
833     nin[i-1] = get_r_value_internal (prevBlock, pos, mode);
834   }
835
836   /* After collecting all predecessors into the array nin a new Phi node
837      with these predecessors is created.  This constructor contains an
838      optimization: If all predecessors of the Phi node are identical it
839      returns the only operand instead of a new Phi node.  If the value
840      passes two different control flow edges without being defined, and
841      this is the second path treated, a pointer to the node that will be
842      allocated for the first path (recursion) is returned.  We already
843      know the address of this node, as it is the next node to be allocated
844      and will be placed on top of the obstack. (The obstack is a _stack_!) */
845   res = new_r_Phi_in (current_ir_graph, block, mode, nin, ins);
846
847   /* Now we now the value for "pos" and can enter it in the array with
848      all known local variables.  Attention: this might be a pointer to
849      a node, that later will be allocated!!! See new_r_Phi_in.
850      If this is called in mature, after some set_value in the same block,
851      the proper value must not be overwritten:
852      The call order
853        get_value    (makes Phi0, put's it into graph_arr)
854        set_value    (overwrites Phi0 in graph_arr)
855        mature_block (upgrades Phi0, puts it again into graph_arr, overwriting
856                      the proper value.)
857      fails. */
858   if (!block->attr.block.graph_arr[pos]) {
859     block->attr.block.graph_arr[pos] = res;
860   } else {
861     /*  printf(" value already computed by %s\n",
862         id_to_str(block->attr.block.graph_arr[pos]->op->name));  */
863   }
864
865   return res;
866 }
867
868 /* This function returns the last definition of a variable.  In case
869    this variable was last defined in a previous block, Phi nodes are
870    inserted.  If the part of the firm graph containing the definition
871    is not yet constructed, a dummy Phi node is returned. */
872 inline ir_node *
873 get_r_value_internal (ir_node *block, int pos, ir_mode *mode)
874 {
875   ir_node *res;
876   /* There are 4 cases to treat.
877
878      1. The block is not mature and we visit it the first time.  We can not
879         create a proper Phi node, therefore a Phi0, i.e., a Phi without
880         predecessors is returned.  This node is added to the linked list (field
881         "link") of the containing block to be completed when this block is
882         matured. (Comlpletion will add a new Phi and turn the Phi0 into an Id
883         node.)
884
885      2. The value is already known in this block, graph_arr[pos] is set and we
886         visit the block the first time.  We can return the value without
887         creating any new nodes.
888
889      3. The block is mature and we visit it the first time.  A Phi node needs
890         to be created (phi_merge).  If the Phi is not needed, as all it's
891         operands are the same value reaching the block through different
892         paths, it's optimized away and the value itself is returned.
893
894      4. The block is mature, and we visit it the second time.  Now two
895         subcases are possible:
896         * The value was computed completely the last time we were here. This
897           is the case if there is no loop.  We can return the proper value.
898         * The recursion that visited this node and set the flag did not
899           return yet.  We are computing a value in a loop and need to
900           break the recursion without knowing the result yet.
901           @@@ strange case.  Straight forward we would create a Phi before
902           starting the computation of it's predecessors.  In this case we will find
903           a Phi here in any case.  The problem is that this implementation only
904           creates a Phi after computing the predecessors, so that it is hard to
905           compute self references of this Phi.  @@@
906         There is no simple check for the second subcase.  Therefore we check
907         for a second visit and treat all such cases as the second subcase.
908         Anyways, the basic situation is the same:  we reached a block
909         on two paths without finding a definition of the value:  No Phi
910         nodes are needed on both paths.
911         We return this information "Two paths, no Phi needed" by a very tricky
912         implementation that relies on the fact that an obstack is a stack and
913         will return a node with the same address on different allocations.
914         Look also at phi_merge and new_r_phi_in to understand this.
915         @@@ Unfortunately this does not work, see testprogram three_cfpred_example.
916
917   */
918
919   /* case 4 -- already visited. */
920   if (get_irn_visited(block) == get_irg_visited(current_ir_graph)) return NULL;
921
922   /* visited the first time */
923   set_irn_visited(block, get_irg_visited(current_ir_graph));
924
925   /* Get the local valid value */
926   res = block->attr.block.graph_arr[pos];
927
928   /* case 2 -- If the value is actually computed, return it. */
929   if (res) { return res;};
930
931   if (block->attr.block.matured) { /* case 3 */
932
933     /* The Phi has the same amount of ins as the corresponding block. */
934     int ins = get_irn_arity(block);
935     ir_node **nin;
936     NEW_ARR_A (ir_node *, nin, ins);
937
938     /* Phi merge collects the predecessors and then creates a node. */
939     res = phi_merge (block, pos, mode, nin, ins);
940
941   } else {  /* case 1 */
942     /* The block is not mature, we don't know how many in's are needed.  A Phi
943        with zero predecessors is created.  Such a Phi node is called Phi0
944        node.  (There is also an obsolete Phi0 opcode.) The Phi0 is then added
945        to the list of Phi0 nodes in this block to be matured by mature_block
946        later.
947        The Phi0 has to remember the pos of it's internal value.  If the real
948        Phi is computed, pos is used to update the array with the local
949        values. */
950
951     res = new_r_Phi0 (current_ir_graph, block, mode);
952     res->attr.phi0_pos = pos;
953     res->link = block->link;
954     block->link = res;
955   }
956
957   /* If we get here, the frontend missed a use-before-definition error */
958   if (!res) {
959     /* Error Message */
960     printf("Error: no value set.  Use of undefined variable.  Initializing
961             to zero.\n");
962     assert (mode->code >= irm_f && mode->code <= irm_p);
963     res = new_r_Const (current_ir_graph, block, mode,
964                        tarval_mode_null[mode->code]);
965   }
966
967   /* The local valid value is available now. */
968   block->attr.block.graph_arr[pos] = res;
969
970   return res;
971 }
972
973 #else /* if 0 */
974
975 /** This is the simple algorithm.  If first generates a Phi0, then
976     it starts the recursion.  This causes an Id at the entry of
977     every block that has no definition of the value! **/
978
979 #if USE_EXPICIT_PHI_IN_STACK
980 /* Just a dummy */
981 Phi_in_stack * new_Phi_in_stack() {  return NULL; }
982 #endif
983
984 inline ir_node *
985 new_r_Phi_in (ir_graph *irg, ir_node *block, ir_mode *mode,
986               ir_node **in, int ins)
987 {
988   int i;
989   ir_node *res, *known;
990
991   /* Allocate a new node on the obstack.  The allocation copies the in
992      array. */
993   res = new_ir_node (irg, block, op_Phi, mode, ins, in);
994
995   /* This loop checks whether the Phi has more than one predecessor.
996      If so, it is a real Phi node and we break the loop.  Else the
997      Phi node merges the same definition on several paths and therefore
998      is not needed. Don't consider Bad nodes! */
999   known = res;
1000   for (i=0;  i < ins;  ++i)
1001   {
1002     if (in[i]==res || in[i]==known || is_Bad(in[i])) continue;
1003
1004     if (known==res)
1005       known = in[i];
1006     else
1007       break;
1008   }
1009
1010   /* i==ins: there is at most one predecessor, we don't need a phi node. */
1011   if (i==ins) {
1012     if (res != known) {
1013       obstack_free (current_ir_graph->obst, res);
1014       res = known;
1015     } else {
1016       /* A undefined value, e.g., in unreachable code. */
1017       res = new_Bad();
1018     }
1019   } else {
1020     res = optimize (res);
1021     irn_vrfy (res);
1022   }
1023
1024   return res;
1025 }
1026
1027 inline ir_node *
1028 get_r_value_internal (ir_node *block, int pos, ir_mode *mode);
1029
1030 /** This function allocates a dummy Phi node to break recursions,
1031     computes the predecessors for the real phi node, and then
1032     allocates and returns this node.  The routine called to allocate the
1033     node might optimize it away and return a real value.
1034     This function is called with an in-array of proper size. **/
1035 static inline ir_node *
1036 phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
1037 {
1038   ir_node *prevBlock, *res, *phi0;
1039   int i;
1040
1041
1042   /* If this block has no value at pos create a Phi0 and remember it
1043      in graph_arr to break recursions. */
1044   phi0 = NULL;
1045   if (!block->attr.block.graph_arr[pos]) {
1046     /* Even if all variables are defined before use, it can happen that
1047        we get to the start block, if a cond has been replaced by a tuple
1048        (bad, jmp).  As the start has a self referencing control flow edge,
1049        we get a self referencing Id, which is hard to optimize away.  We avoid
1050        this by defining the value as a Bad node. *
1051     if (block == get_irg_start_block(current_ir_graph)) {
1052       block->attr.block.graph_arr[pos] = new_Bad();
1053       return new_Bad();
1054       } else */ {
1055       phi0 = new_r_Phi0(current_ir_graph, block, mode);
1056       block->attr.block.graph_arr[pos] = phi0;
1057     }
1058   }
1059
1060   /* This loop goes to all predecessor blocks of the block the Phi node
1061      is in and there finds the operands of the Phi node by calling
1062      get_r_value_internal.  */
1063   for (i = 1;  i <= ins;  ++i) {
1064     assert (block->in[i]);
1065     if (is_Bad(block->in[i])) {
1066       /* In case a Cond has been optimized we would get right to the start block
1067          with an invalid definition. */
1068       nin[i-1] = new_Bad();
1069       continue;
1070     }
1071     prevBlock = block->in[i]->in[0]; /* go past control flow op to prev block */
1072     assert (prevBlock);
1073     if (!is_Bad(prevBlock)) {
1074       nin[i-1] = get_r_value_internal (prevBlock, pos, mode);
1075     } else {
1076       nin[i-1] = new_Bad();
1077     }
1078   }
1079
1080   /* After collecting all predecessors into the array nin a new Phi node
1081      with these predecessors is created.  This constructor contains an
1082      optimization: If all predecessors of the Phi node are identical it
1083      returns the only operand instead of a new Phi node.  */
1084   res = new_r_Phi_in (current_ir_graph, block, mode, nin, ins);
1085
1086   /* In case we allocated a Phi0 node at the beginning of this procedure,
1087      we need to exchange this Phi0 with the real Phi. */
1088   if (phi0) {
1089     exchange(phi0, res);
1090     block->attr.block.graph_arr[pos] = res;
1091   }
1092
1093   return res;
1094 }
1095
1096 /* This function returns the last definition of a variable.  In case
1097    this variable was last defined in a previous block, Phi nodes are
1098    inserted.  If the part of the firm graph containing the definition
1099    is not yet constructed, a dummy Phi node is returned. */
1100 inline ir_node *
1101 get_r_value_internal (ir_node *block, int pos, ir_mode *mode)
1102 {
1103   ir_node *res;
1104   /* There are 4 cases to treat.
1105
1106      1. The block is not mature and we visit it the first time.  We can not
1107         create a proper Phi node, therefore a Phi0, i.e., a Phi without
1108         predecessors is returned.  This node is added to the linked list (field
1109         "link") of the containing block to be completed when this block is
1110         matured. (Comlpletion will add a new Phi and turn the Phi0 into an Id
1111         node.)
1112
1113      2. The value is already known in this block, graph_arr[pos] is set and we
1114         visit the block the first time.  We can return the value without
1115         creating any new nodes.
1116
1117      3. The block is mature and we visit it the first time.  A Phi node needs
1118         to be created (phi_merge).  If the Phi is not needed, as all it's
1119         operands are the same value reaching the block through different
1120         paths, it's optimized away and the value itself is returned.
1121
1122      4. The block is mature, and we visit it the second time.  Now two
1123         subcases are possible:
1124         * The value was computed completely the last time we were here. This
1125           is the case if there is no loop.  We can return the proper value.
1126         * The recursion that visited this node and set the flag did not
1127           return yet.  We are computing a value in a loop and need to
1128           break the recursion.  This case only happens if we visited
1129           the same block with phi_merge before, which inserted a Phi0.
1130           So we return the Phi0.
1131   */
1132
1133   /* case 4 -- already visited. */
1134   if (get_irn_visited(block) == get_irg_visited(current_ir_graph)) {
1135     /* As phi_merge allocates a Phi0 this value is always defined. Here
1136      is the critical difference of the two algorithms. */
1137     assert(block->attr.block.graph_arr[pos]);
1138     return block->attr.block.graph_arr[pos];
1139   }
1140
1141   /* visited the first time */
1142   set_irn_visited(block, get_irg_visited(current_ir_graph));
1143
1144   /* Get the local valid value */
1145   res = block->attr.block.graph_arr[pos];
1146
1147   /* case 2 -- If the value is actually computed, return it. */
1148   if (res) { return res; };
1149
1150   if (block->attr.block.matured) { /* case 3 */
1151
1152     /* The Phi has the same amount of ins as the corresponding block. */
1153     int ins = get_irn_arity(block);
1154     ir_node **nin;
1155     NEW_ARR_A (ir_node *, nin, ins);
1156
1157     /* Phi merge collects the predecessors and then creates a node. */
1158     res = phi_merge (block, pos, mode, nin, ins);
1159
1160   } else {  /* case 1 */
1161     /* The block is not mature, we don't know how many in's are needed.  A Phi
1162        with zero predecessors is created.  Such a Phi node is called Phi0
1163        node.  The Phi0 is then added to the list of Phi0 nodes in this block
1164        to be matured by mature_block later.
1165        The Phi0 has to remember the pos of it's internal value.  If the real
1166        Phi is computed, pos is used to update the array with the local
1167        values. */
1168     res = new_r_Phi0 (current_ir_graph, block, mode);
1169     res->attr.phi0_pos = pos;
1170     res->link = block->link;
1171     block->link = res;
1172   }
1173
1174   /* If we get here, the frontend missed a use-before-definition error */
1175   if (!res) {
1176     /* Error Message */
1177     printf("Error: no value set.  Use of undefined variable.  Initializing
1178             to zero.\n");
1179     assert (mode->code >= irm_f && mode->code <= irm_p);
1180     res = new_r_Const (current_ir_graph, block, mode,
1181                        tarval_mode_null[mode->code]);
1182   }
1183
1184   /* The local valid value is available now. */
1185   block->attr.block.graph_arr[pos] = res;
1186
1187   return res;
1188 }
1189
1190 #endif /* USE_FAST_PHI_CONSTRUCTION */
1191
1192 /****************************************************************************/
1193
1194 /** Finalize a Block node, when all control flows are known.  */
1195 /** Acceptable parameters are only Block nodes.               */
1196 void
1197 mature_block (ir_node *block)
1198 {
1199
1200   int ins;
1201   ir_node *n, **nin;
1202   ir_node *next;
1203
1204   assert (get_irn_opcode(block) == iro_Block);
1205
1206   if (!get_Block_matured(block)) {
1207
1208     /* turn the dynamic in-array into a static one. */
1209     ins = ARR_LEN (block->in)-1;
1210     NEW_ARR_A (ir_node *, nin, ins);
1211
1212     /* Traverse a chain of Phi nodes attached to this block and mature
1213        these, too. **/
1214     for (n = block->link;  n;  n=next) {
1215       inc_irg_visited(current_ir_graph);
1216       next = n->link;
1217       exchange (n, phi_merge (block, n->attr.phi0_pos, n->mode, nin, ins));
1218     }
1219
1220     block->attr.block.matured = 1;
1221
1222     /* Now, as the block is a finished firm node, we can optimize it.
1223        Since other nodes have been allocated since the block was created
1224        we can not free the node on the obstack.  Therefore we have to call
1225        optimize_in_place.
1226        Unfortunately the optimization does not change a lot, as all allocated
1227        nodes refer to the unoptimized node. */
1228     block = optimize_in_place(block);
1229     irn_vrfy(block);
1230   }
1231 }
1232
1233 ir_node *
1234 new_Phi (int arity, ir_node **in, ir_mode *mode)
1235 {
1236   return new_r_Phi (current_ir_graph, current_ir_graph->current_block,
1237                     arity, in, mode);
1238 }
1239
1240 ir_node *
1241 new_Const (ir_mode *mode, tarval *con)
1242 {
1243   return new_r_Const (current_ir_graph, current_ir_graph->start_block,
1244                       mode, con);
1245 }
1246
1247 ir_node *
1248 new_Id (ir_node *val, ir_mode *mode)
1249 {
1250   return new_r_Id (current_ir_graph, current_ir_graph->current_block,
1251                    val, mode);
1252 }
1253
1254 ir_node *
1255 new_Proj (ir_node *arg, ir_mode *mode, long proj)
1256 {
1257   return new_r_Proj (current_ir_graph, current_ir_graph->current_block,
1258                      arg, mode, proj);
1259 }
1260
1261 ir_node *
1262 new_Conv (ir_node *op, ir_mode *mode)
1263 {
1264   return new_r_Conv (current_ir_graph, current_ir_graph->current_block,
1265                      op, mode);
1266 }
1267
1268 ir_node *
1269 new_Tuple (int arity, ir_node **in)
1270 {
1271   return new_r_Tuple (current_ir_graph, current_ir_graph->current_block,
1272                       arity, in);
1273 }
1274
1275 ir_node *
1276 new_Add (ir_node *op1, ir_node *op2, ir_mode *mode)
1277 {
1278   return new_r_Add (current_ir_graph, current_ir_graph->current_block,
1279                     op1, op2, mode);
1280 }
1281
1282 ir_node *
1283 new_Sub (ir_node *op1, ir_node *op2, ir_mode *mode)
1284 {
1285   return new_r_Sub (current_ir_graph, current_ir_graph->current_block,
1286                     op1, op2, mode);
1287 }
1288
1289
1290 ir_node *
1291 new_Minus  (ir_node *op,  ir_mode *mode)
1292 {
1293   return new_r_Minus (current_ir_graph, current_ir_graph->current_block,
1294                       op, mode);
1295 }
1296
1297 ir_node *
1298 new_Mul (ir_node *op1, ir_node *op2, ir_mode *mode)
1299 {
1300   return new_r_Mul (current_ir_graph, current_ir_graph->current_block,
1301                     op1, op2, mode);
1302 }
1303
1304 ir_node *
1305 new_Quot (ir_node *memop, ir_node *op1, ir_node *op2)
1306 {
1307   return new_r_Quot (current_ir_graph, current_ir_graph->current_block,
1308                      memop, op1, op2);
1309 }
1310
1311 ir_node *
1312 new_DivMod (ir_node *memop, ir_node *op1, ir_node *op2)
1313 {
1314   return new_r_DivMod (current_ir_graph, current_ir_graph->current_block,
1315                        memop, op1, op2);
1316 }
1317
1318 ir_node *
1319 new_Div (ir_node *memop, ir_node *op1, ir_node *op2)
1320 {
1321   return new_r_Div (current_ir_graph, current_ir_graph->current_block,
1322                     memop, op1, op2);
1323 }
1324
1325 ir_node *
1326 new_Mod (ir_node *memop, ir_node *op1, ir_node *op2)
1327 {
1328   return new_r_Mod (current_ir_graph, current_ir_graph->current_block,
1329                     memop, op1, op2);
1330 }
1331
1332 ir_node *
1333 new_And (ir_node *op1, ir_node *op2, ir_mode *mode)
1334 {
1335   return new_r_And (current_ir_graph, current_ir_graph->current_block,
1336                     op1, op2, mode);
1337 }
1338
1339 ir_node *
1340 new_Or (ir_node *op1, ir_node *op2, ir_mode *mode)
1341 {
1342   return new_r_Or (current_ir_graph, current_ir_graph->current_block,
1343                    op1, op2, mode);
1344 }
1345
1346 ir_node *
1347 new_Eor (ir_node *op1, ir_node *op2, ir_mode *mode)
1348 {
1349   return new_r_Eor (current_ir_graph, current_ir_graph->current_block,
1350                     op1, op2, mode);
1351 }
1352
1353 ir_node *
1354 new_Not (ir_node *op, ir_mode *mode)
1355 {
1356   return new_r_Not (current_ir_graph, current_ir_graph->current_block,
1357                     op, mode);
1358 }
1359
1360 ir_node *
1361 new_Shl (ir_node *op, ir_node *k, ir_mode *mode)
1362 {
1363   return new_r_Shl (current_ir_graph, current_ir_graph->current_block,
1364                     op, k, mode);
1365 }
1366
1367 ir_node *
1368 new_Shr (ir_node *op, ir_node *k, ir_mode *mode)
1369 {
1370   return new_r_Shr (current_ir_graph, current_ir_graph->current_block,
1371                     op, k, mode);
1372 }
1373
1374 ir_node *
1375 new_Shrs (ir_node *op, ir_node *k, ir_mode *mode)
1376 {
1377   return new_r_Shrs (current_ir_graph, current_ir_graph->current_block,
1378                      op, k, mode);
1379 }
1380
1381 ir_node *
1382 new_Rotate (ir_node *op, ir_node *k, ir_mode *mode)
1383 {
1384   return new_r_Rot (current_ir_graph, current_ir_graph->current_block,
1385                      op, k, mode);
1386 }
1387
1388 ir_node *
1389 new_Abs (ir_node *op, ir_mode *mode)
1390 {
1391   return new_r_Abs (current_ir_graph, current_ir_graph->current_block,
1392                     op, mode);
1393 }
1394
1395 ir_node *
1396 new_Cmp (ir_node *op1, ir_node *op2)
1397 {
1398   return new_r_Cmp (current_ir_graph, current_ir_graph->current_block,
1399                     op1, op2);
1400 }
1401
1402 ir_node *
1403 new_Jmp (void)
1404 {
1405   return new_r_Jmp (current_ir_graph, current_ir_graph->current_block);
1406 }
1407
1408 ir_node *
1409 new_Cond (ir_node *c)
1410 {
1411   return new_r_Cond (current_ir_graph, current_ir_graph->current_block, c);
1412 }
1413
1414 ir_node *
1415 new_Call (ir_node *store, ir_node *callee, int arity, ir_node **in,
1416           type_method *type)
1417 {
1418   return new_r_Call (current_ir_graph, current_ir_graph->current_block,
1419                      store, callee, arity, in, type);
1420 }
1421
1422 ir_node *
1423 new_Return (ir_node* store, int arity, ir_node **in)
1424 {
1425   return new_r_Return (current_ir_graph, current_ir_graph->current_block,
1426                        store, arity, in);
1427 }
1428
1429 ir_node *
1430 new_Raise (ir_node *store, ir_node *obj)
1431 {
1432   return new_r_Raise (current_ir_graph, current_ir_graph->current_block,
1433                       store, obj);
1434 }
1435
1436 ir_node *
1437 new_Load (ir_node *store, ir_node *addr)
1438 {
1439   return new_r_Load (current_ir_graph, current_ir_graph->current_block,
1440                      store, addr);
1441 }
1442
1443 ir_node *
1444 new_Store (ir_node *store, ir_node *addr, ir_node *val)
1445 {
1446   return new_r_Store (current_ir_graph, current_ir_graph->current_block,
1447                       store, addr, val);
1448 }
1449
1450 ir_node *
1451 new_Alloc (ir_node *store, ir_node *size, type *alloc_type,
1452            where_alloc where)
1453 {
1454   return new_r_Alloc (current_ir_graph, current_ir_graph->current_block,
1455                       store, size, alloc_type, where);
1456 }
1457
1458 ir_node *
1459 new_Free (ir_node *store, ir_node *ptr, ir_node *size, type *free_type)
1460 {
1461   return new_r_Free (current_ir_graph, current_ir_graph->current_block,
1462                      store, ptr, size, free_type);
1463 }
1464
1465 ir_node *
1466 new_simpleSel (ir_node *store, ir_node *objptr, entity *ent)
1467 /* GL: objptr was called frame before.  Frame was a bad choice for the name
1468    as the operand could as well be a pointer to a dynamic object. */
1469 {
1470   return new_r_Sel (current_ir_graph, current_ir_graph->current_block,
1471                     store, objptr, 0, NULL, ent);
1472 }
1473
1474 ir_node *
1475 new_Sel (ir_node *store, ir_node *objptr, int n_index, ir_node **index, entity *sel)
1476 {
1477   return new_r_Sel (current_ir_graph, current_ir_graph->current_block,
1478                     store, objptr, n_index, index, sel);
1479 }
1480
1481 ir_node *
1482 new_SymConst (type_or_id_p value, symconst_kind kind)
1483 {
1484   return new_r_SymConst (current_ir_graph, current_ir_graph->current_block,
1485                          value, kind);
1486 }
1487
1488 ir_node *
1489 new_Sync (int arity, ir_node** in)
1490 {
1491   return new_r_Sync (current_ir_graph, current_ir_graph->current_block,
1492                      arity, in);
1493 }
1494
1495
1496 ir_node *
1497 new_Bad (void)
1498 {
1499   return current_ir_graph->bad;
1500 }
1501
1502 /*************************************************************************/
1503 /* Comfortable interface with automatic Phi node construction.           */
1504 /* (Uses also constructors of ?? interface, except new_Block.            */
1505 /* add an adge to a jmp node */
1506 void
1507 add_in_edge (ir_node *block, ir_node *jmp)
1508 {
1509   if (block->attr.block.matured) {
1510     printf("Error: Block already matured!\n");
1511   }
1512   else {
1513     assert (jmp != NULL);
1514     ARR_APP1 (ir_node *, block->in, jmp);
1515   }
1516 }
1517
1518 /* changing the current block */
1519 void
1520 switch_block (ir_node *target)
1521 {
1522   current_ir_graph->current_block = target;
1523 }
1524
1525 /****************************/
1526 /* parameter administration */
1527
1528 /* get a value from the parameter array from the current block by its index */
1529 ir_node *
1530 get_value (int pos, ir_mode *mode)
1531 {
1532   inc_irg_visited(current_ir_graph);
1533   return get_r_value_internal (current_ir_graph->current_block, pos + 1, mode);
1534 }
1535
1536 /* set a value at position pos in the parameter array from the current block */
1537 inline void
1538 set_value (int pos, ir_node *value)
1539 {
1540   current_ir_graph->current_block->attr.block.graph_arr[pos + 1] = value;
1541 }
1542
1543 /* get the current store */
1544 inline ir_node *
1545 get_store (void)
1546 {
1547   /* GL: one could call get_value instead */
1548   inc_irg_visited(current_ir_graph);
1549   return get_r_value_internal (current_ir_graph->current_block, 0, mode_M);
1550 }
1551
1552 /* set the current store */
1553 inline void
1554 set_store (ir_node *store)
1555 {
1556   /* GL: one could call set_value instead */
1557   current_ir_graph->current_block->attr.block.graph_arr[0] = store;
1558 }
1559
1560 /*************************************************************************/
1561 /* initialize */
1562
1563 /* call once for each run of the library */
1564 void
1565 init_cons (void)
1566 {
1567 }