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
10 * Copyright: (c) 1998-2003 Universität Karlsruhe
11 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
18 # include "irgraph_t.h"
19 # include "irnode_t.h"
20 # include "irmode_t.h"
22 # include "firm_common_t.h"
28 /* memset belongs to string.h */
30 # include "irbackedge_t.h"
31 # include "irflag_t.h"
33 #if USE_EXPLICIT_PHI_IN_STACK
34 /* A stack needed for the automatic Phi node construction in constructor
35 Phi_in. Redefinition in irgraph.c!! */
40 typedef struct Phi_in_stack Phi_in_stack;
44 * language dependant initialization variable
46 static default_initialize_local_variable_func_t *default_initialize_local_variable = NULL;
48 /*** ******************************************** */
49 /** privat interfaces, for professional use only */
51 /* Constructs a Block with a fixed number of predecessors.
52 Does not set current_block. Can not be used with automatic
53 Phi node construction. */
55 new_rd_Block (dbg_info* db, ir_graph *irg, int arity, ir_node **in)
59 res = new_ir_node (db, irg, NULL, op_Block, mode_BB, arity, in);
60 set_Block_matured(res, 1);
61 set_Block_block_visited(res, 0);
63 /* res->attr.block.exc = exc_normal; */
64 /* res->attr.block.handler_entry = 0; */
65 res->attr.block.irg = irg;
66 res->attr.block.backedge = new_backedge_arr(irg->obst, arity);
67 res->attr.block.in_cg = NULL;
68 res->attr.block.cg_backedge = NULL;
70 irn_vrfy_irg (res, irg);
75 new_rd_Start (dbg_info* db, ir_graph *irg, ir_node *block)
79 res = new_ir_node (db, irg, block, op_Start, mode_T, 0, NULL);
80 /* res->attr.start.irg = irg; */
82 irn_vrfy_irg (res, irg);
87 new_rd_End (dbg_info* db, ir_graph *irg, ir_node *block)
91 res = new_ir_node (db, irg, block, op_End, mode_X, -1, NULL);
93 irn_vrfy_irg (res, irg);
97 /* Creates a Phi node with all predecessors. Calling this constructor
98 is only allowed if the corresponding block is mature. */
100 new_rd_Phi (dbg_info* db, ir_graph *irg, ir_node *block, int arity, ir_node **in, ir_mode *mode)
104 bool has_unknown = false;
106 /* Don't assert that block matured: the use of this constructor is strongly
108 if ( get_Block_matured(block) )
109 assert( intern_get_irn_arity(block) == arity );
111 res = new_ir_node (db, irg, block, op_Phi, mode, arity, in);
113 res->attr.phi_backedge = new_backedge_arr(irg->obst, arity);
115 for (i = arity-1; i >= 0; i--)
116 if (intern_get_irn_op(in[i]) == op_Unknown) {
121 if (!has_unknown) res = optimize_node (res);
122 irn_vrfy_irg (res, irg);
124 /* Memory Phis in endless loops must be kept alive.
125 As we can't distinguish these easily we keep all of them alive. */
126 if ((res->op == op_Phi) && (mode == mode_M))
127 add_End_keepalive(irg->end, res);
132 new_rd_Const_type (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con, type *tp)
135 res = new_ir_node (db, irg, block, op_Const, mode, 0, NULL);
136 res->attr.con.tv = con;
137 set_Const_type(res, tp); /* Call method because of complex assertion. */
138 res = optimize_node (res);
139 assert(get_Const_type(res) == tp);
140 irn_vrfy_irg (res, irg);
143 res = local_optimize_newby (res);
150 new_rd_Const (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con)
152 type *tp = unknown_type;
153 if (tarval_is_entity(con))
154 tp = find_pointer_type_to_type(get_entity_type(get_tarval_entity(con)));
155 return new_rd_Const_type (db, irg, block, mode, con, tp);
159 new_rd_Id (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *val, ir_mode *mode)
164 res = new_ir_node (db, irg, block, op_Id, mode, 1, in);
165 res = optimize_node (res);
166 irn_vrfy_irg (res, irg);
171 new_rd_Proj (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *arg, ir_mode *mode,
177 res = new_ir_node (db, irg, block, op_Proj, mode, 1, in);
178 res->attr.proj = proj;
181 assert(get_Proj_pred(res));
182 assert(get_nodes_Block(get_Proj_pred(res)));
184 res = optimize_node (res);
186 irn_vrfy_irg (res, irg);
192 new_rd_defaultProj (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *arg,
196 assert(arg->op == op_Cond);
197 arg->attr.c.kind = fragmentary;
198 arg->attr.c.default_proj = max_proj;
199 res = new_rd_Proj (db, irg, block, arg, mode_X, max_proj);
204 new_rd_Conv (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *op, ir_mode *mode)
209 res = new_ir_node (db, irg, block, op_Conv, mode, 1, in);
210 res = optimize_node (res);
211 irn_vrfy_irg (res, irg);
216 new_rd_Cast (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *op, type *to_tp)
219 res = new_ir_node (db, irg, block, op_Cast, intern_get_irn_mode(op), 1, &op);
220 res->attr.cast.totype = to_tp;
221 res = optimize_node (res);
222 irn_vrfy_irg (res, irg);
227 new_rd_Tuple (dbg_info* db, ir_graph *irg, ir_node *block, int arity, ir_node **in)
231 res = new_ir_node (db, irg, block, op_Tuple, mode_T, arity, in);
232 res = optimize_node (res);
233 irn_vrfy_irg (res, irg);
238 new_rd_Add (dbg_info* db, ir_graph *irg, ir_node *block,
239 ir_node *op1, ir_node *op2, ir_mode *mode)
245 res = new_ir_node (db, irg, block, op_Add, mode, 2, in);
246 res = optimize_node (res);
247 irn_vrfy_irg (res, irg);
252 new_rd_Sub (dbg_info* db, ir_graph *irg, ir_node *block,
253 ir_node *op1, ir_node *op2, ir_mode *mode)
259 res = new_ir_node (db, irg, block, op_Sub, mode, 2, in);
260 res = optimize_node (res);
261 irn_vrfy_irg (res, irg);
266 new_rd_Minus (dbg_info* db, ir_graph *irg, ir_node *block,
267 ir_node *op, ir_mode *mode)
272 res = new_ir_node (db, irg, block, op_Minus, mode, 1, in);
273 res = optimize_node (res);
274 irn_vrfy_irg (res, irg);
279 new_rd_Mul (dbg_info* db, ir_graph *irg, ir_node *block,
280 ir_node *op1, ir_node *op2, ir_mode *mode)
286 res = new_ir_node (db, irg, block, op_Mul, mode, 2, in);
287 res = optimize_node (res);
288 irn_vrfy_irg (res, irg);
293 new_rd_Quot (dbg_info* db, ir_graph *irg, ir_node *block,
294 ir_node *memop, ir_node *op1, ir_node *op2)
301 res = new_ir_node (db, irg, block, op_Quot, mode_T, 3, in);
302 res = optimize_node (res);
303 irn_vrfy_irg (res, irg);
308 new_rd_DivMod (dbg_info* db, ir_graph *irg, ir_node *block,
309 ir_node *memop, ir_node *op1, ir_node *op2)
316 res = new_ir_node (db, irg, block, op_DivMod, mode_T, 3, in);
317 res = optimize_node (res);
318 irn_vrfy_irg (res, irg);
323 new_rd_Div (dbg_info* db, ir_graph *irg, ir_node *block,
324 ir_node *memop, ir_node *op1, ir_node *op2)
331 res = new_ir_node (db, irg, block, op_Div, mode_T, 3, in);
332 res = optimize_node (res);
333 irn_vrfy_irg (res, irg);
338 new_rd_Mod (dbg_info* db, ir_graph *irg, ir_node *block,
339 ir_node *memop, ir_node *op1, ir_node *op2)
346 res = new_ir_node (db, irg, block, op_Mod, mode_T, 3, in);
347 res = optimize_node (res);
348 irn_vrfy_irg (res, irg);
353 new_rd_And (dbg_info* db, ir_graph *irg, ir_node *block,
354 ir_node *op1, ir_node *op2, ir_mode *mode)
360 res = new_ir_node (db, irg, block, op_And, mode, 2, in);
361 res = optimize_node (res);
362 irn_vrfy_irg (res, irg);
367 new_rd_Or (dbg_info* db, ir_graph *irg, ir_node *block,
368 ir_node *op1, ir_node *op2, ir_mode *mode)
374 res = new_ir_node (db, irg, block, op_Or, mode, 2, in);
375 res = optimize_node (res);
376 irn_vrfy_irg (res, irg);
381 new_rd_Eor (dbg_info* db, ir_graph *irg, ir_node *block,
382 ir_node *op1, ir_node *op2, ir_mode *mode)
388 res = new_ir_node (db, irg, block, op_Eor, mode, 2, in);
389 res = optimize_node (res);
390 irn_vrfy_irg (res, irg);
395 new_rd_Not (dbg_info* db, ir_graph *irg, ir_node *block,
396 ir_node *op, ir_mode *mode)
401 res = new_ir_node (db, irg, block, op_Not, mode, 1, in);
402 res = optimize_node (res);
403 irn_vrfy_irg (res, irg);
408 new_rd_Shl (dbg_info* db, ir_graph *irg, ir_node *block,
409 ir_node *op, ir_node *k, ir_mode *mode)
415 res = new_ir_node (db, irg, block, op_Shl, mode, 2, in);
416 res = optimize_node (res);
417 irn_vrfy_irg (res, irg);
422 new_rd_Shr (dbg_info* db, ir_graph *irg, ir_node *block,
423 ir_node *op, ir_node *k, ir_mode *mode)
429 res = new_ir_node (db, irg, block, op_Shr, mode, 2, in);
430 res = optimize_node (res);
431 irn_vrfy_irg (res, irg);
436 new_rd_Shrs (dbg_info* db, ir_graph *irg, ir_node *block,
437 ir_node *op, ir_node *k, ir_mode *mode)
443 res = new_ir_node (db, irg, block, op_Shrs, mode, 2, in);
444 res = optimize_node (res);
445 irn_vrfy_irg (res, irg);
450 new_rd_Rot (dbg_info* db, ir_graph *irg, ir_node *block,
451 ir_node *op, ir_node *k, ir_mode *mode)
457 res = new_ir_node (db, irg, block, op_Rot, mode, 2, in);
458 res = optimize_node (res);
459 irn_vrfy_irg (res, irg);
464 new_rd_Abs (dbg_info* db, ir_graph *irg, ir_node *block,
465 ir_node *op, ir_mode *mode)
470 res = new_ir_node (db, irg, block, op_Abs, mode, 1, in);
471 res = optimize_node (res);
472 irn_vrfy_irg (res, irg);
477 new_rd_Cmp (dbg_info* db, ir_graph *irg, ir_node *block,
478 ir_node *op1, ir_node *op2)
484 res = new_ir_node (db, irg, block, op_Cmp, mode_T, 2, in);
485 res = optimize_node (res);
486 irn_vrfy_irg (res, irg);
491 new_rd_Jmp (dbg_info* db, ir_graph *irg, ir_node *block)
494 res = new_ir_node (db, irg, block, op_Jmp, mode_X, 0, NULL);
495 res = optimize_node (res);
496 irn_vrfy_irg (res, irg);
501 new_rd_Cond (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *c)
506 res = new_ir_node (db, irg, block, op_Cond, mode_T, 1, in);
507 res->attr.c.kind = dense;
508 res->attr.c.default_proj = 0;
509 res = optimize_node (res);
510 irn_vrfy_irg (res, irg);
515 new_rd_Call (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store,
516 ir_node *callee, int arity, ir_node **in, type *tp)
523 NEW_ARR_A (ir_node *, r_in, r_arity);
526 memcpy (&r_in[2], in, sizeof (ir_node *) * arity);
528 res = new_ir_node (db, irg, block, op_Call, mode_T, r_arity, r_in);
530 assert(is_method_type(tp));
531 set_Call_type(res, tp);
532 res->attr.call.callee_arr = NULL;
533 res = optimize_node (res);
534 irn_vrfy_irg (res, irg);
539 new_rd_Return (dbg_info* db, ir_graph *irg, ir_node *block,
540 ir_node *store, int arity, ir_node **in)
547 NEW_ARR_A (ir_node *, r_in, r_arity);
549 memcpy (&r_in[1], in, sizeof (ir_node *) * arity);
550 res = new_ir_node (db, irg, block, op_Return, mode_X, r_arity, r_in);
551 res = optimize_node (res);
552 irn_vrfy_irg (res, irg);
557 new_rd_Raise (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store, ir_node *obj)
563 res = new_ir_node (db, irg, block, op_Raise, mode_T, 2, in);
564 res = optimize_node (res);
565 irn_vrfy_irg (res, irg);
570 new_rd_Load (dbg_info* db, ir_graph *irg, ir_node *block,
571 ir_node *store, ir_node *adr)
577 res = new_ir_node (db, irg, block, op_Load, mode_T, 2, in);
579 res = optimize_node (res);
580 irn_vrfy_irg (res, irg);
585 new_rd_Store (dbg_info* db, ir_graph *irg, ir_node *block,
586 ir_node *store, ir_node *adr, ir_node *val)
593 res = new_ir_node (db, irg, block, op_Store, mode_T, 3, in);
595 res = optimize_node (res);
597 irn_vrfy_irg (res, irg);
602 new_rd_Alloc (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store,
603 ir_node *size, type *alloc_type, where_alloc where)
609 res = new_ir_node (db, irg, block, op_Alloc, mode_T, 2, in);
611 res->attr.a.where = where;
612 res->attr.a.type = alloc_type;
614 res = optimize_node (res);
615 irn_vrfy_irg (res, irg);
620 new_rd_Free (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store,
621 ir_node *ptr, ir_node *size, type *free_type)
628 res = new_ir_node (db, irg, block, op_Free, mode_T, 3, in);
630 res->attr.f = free_type;
632 res = optimize_node (res);
633 irn_vrfy_irg (res, irg);
638 new_rd_Sel (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store, ir_node *objptr,
639 int arity, ir_node **in, entity *ent)
645 assert(ent != NULL && is_entity(ent) && "entity expected in Sel construction");
648 NEW_ARR_A (ir_node *, r_in, r_arity); /* uses alloca */
651 memcpy (&r_in[2], in, sizeof (ir_node *) * arity);
652 res = new_ir_node (db, irg, block, op_Sel, mode_P_mach, r_arity, r_in);
654 res->attr.s.ent = ent;
656 res = optimize_node (res);
657 irn_vrfy_irg (res, irg);
662 new_rd_InstOf (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
663 ir_node *objptr, type *ent)
670 NEW_ARR_A (ir_node *, r_in, r_arity);
674 res = new_ir_node (db, irg, block, op_Sel, mode_T, r_arity, r_in);
676 res->attr.io.ent = ent;
678 /* res = optimize (res);
679 * irn_vrfy_irg (res, irg); */
684 new_rd_SymConst (dbg_info* db, ir_graph *irg, ir_node *block, type_or_id_p value,
685 symconst_kind symkind)
689 if (symkind == linkage_ptr_info)
693 res = new_ir_node (db, irg, block, op_SymConst, mode, 0, NULL);
695 res->attr.i.num = symkind;
696 if (symkind == linkage_ptr_info) {
697 res->attr.i.tori.ptrinfo = (ident *)value;
699 assert ( ( (symkind == type_tag)
700 || (symkind == size))
701 && (is_type(value)));
702 res->attr.i.tori.typ = (type *)value;
704 res = optimize_node (res);
705 irn_vrfy_irg (res, irg);
710 new_rd_Sync (dbg_info* db, ir_graph *irg, ir_node *block, int arity, ir_node **in)
714 res = new_ir_node (db, irg, block, op_Sync, mode_M, arity, in);
716 res = optimize_node (res);
717 irn_vrfy_irg (res, irg);
722 new_rd_Bad (ir_graph *irg)
728 new_rd_Confirm (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *val, ir_node *bound, pn_Cmp cmp)
730 ir_node *in[2], *res;
734 res = new_ir_node (db, irg, block, op_Confirm, intern_get_irn_mode(val), 2, in);
736 res->attr.confirm_cmp = cmp;
738 res = optimize_node (res);
739 irn_vrfy_irg(res, irg);
744 new_rd_Unknown (ir_graph *irg, ir_mode *m)
746 return new_ir_node (NULL, irg, irg->start_block, op_Unknown, m, 0, NULL);
750 new_rd_CallBegin (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *call)
754 in[0] = get_Call_ptr(call);
755 res = new_ir_node (db, irg, block, op_CallBegin, mode_T, 1, in);
756 /* res->attr.callbegin.irg = irg; */
757 res->attr.callbegin.call = call;
758 res = optimize_node (res);
759 irn_vrfy_irg (res, irg);
764 new_rd_EndReg (dbg_info *db, ir_graph *irg, ir_node *block)
768 res = new_ir_node (db, irg, block, op_EndReg, mode_T, -1, NULL);
771 irn_vrfy_irg (res, irg);
776 new_rd_EndExcept (dbg_info *db, ir_graph *irg, ir_node *block)
780 res = new_ir_node (db, irg, block, op_EndExcept, mode_T, -1, NULL);
781 irg->end_except = res;
783 irn_vrfy_irg (res, irg);
788 new_rd_Break (dbg_info *db, ir_graph *irg, ir_node *block)
791 res = new_ir_node (db, irg, block, op_Break, mode_X, 0, NULL);
792 res = optimize_node (res);
793 irn_vrfy_irg (res, irg);
798 new_rd_Filter (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg, ir_mode *mode,
804 res = new_ir_node (db, irg, block, op_Filter, mode, 1, in);
805 res->attr.filter.proj = proj;
806 res->attr.filter.in_cg = NULL;
807 res->attr.filter.backedge = NULL;
810 assert(get_Proj_pred(res));
811 assert(get_nodes_Block(get_Proj_pred(res)));
813 res = optimize_node (res);
815 irn_vrfy_irg (res, irg);
821 new_rd_FuncCall (dbg_info* db, ir_graph *irg, ir_node *block,
822 ir_node *callee, int arity, ir_node **in, type *tp)
829 NEW_ARR_A (ir_node *, r_in, r_arity);
831 memcpy (&r_in[1], in, sizeof (ir_node *) * arity);
833 res = new_ir_node (db, irg, block, op_FuncCall, mode_T, r_arity, r_in);
835 assert(is_method_type(tp));
836 set_FuncCall_type(res, tp);
837 res->attr.call.callee_arr = NULL;
838 res = optimize_node (res);
839 irn_vrfy_irg (res, irg);
844 INLINE ir_node *new_r_Block (ir_graph *irg, int arity, ir_node **in) {
845 return new_rd_Block(NULL, irg, arity, in);
847 INLINE ir_node *new_r_Start (ir_graph *irg, ir_node *block) {
848 return new_rd_Start(NULL, irg, block);
850 INLINE ir_node *new_r_End (ir_graph *irg, ir_node *block) {
851 return new_rd_End(NULL, irg, block);
853 INLINE ir_node *new_r_Jmp (ir_graph *irg, ir_node *block) {
854 return new_rd_Jmp(NULL, irg, block);
856 INLINE ir_node *new_r_Cond (ir_graph *irg, ir_node *block, ir_node *c) {
857 return new_rd_Cond(NULL, irg, block, c);
859 INLINE ir_node *new_r_Return (ir_graph *irg, ir_node *block,
860 ir_node *store, int arity, ir_node **in) {
861 return new_rd_Return(NULL, irg, block, store, arity, in);
863 INLINE ir_node *new_r_Raise (ir_graph *irg, ir_node *block,
864 ir_node *store, ir_node *obj) {
865 return new_rd_Raise(NULL, irg, block, store, obj);
867 INLINE ir_node *new_r_Const (ir_graph *irg, ir_node *block,
868 ir_mode *mode, tarval *con) {
869 return new_rd_Const(NULL, irg, block, mode, con);
871 INLINE ir_node *new_r_SymConst (ir_graph *irg, ir_node *block,
872 type_or_id_p value, symconst_kind symkind) {
873 return new_rd_SymConst(NULL, irg, block, value, symkind);
875 INLINE ir_node *new_r_Sel (ir_graph *irg, ir_node *block, ir_node *store,
876 ir_node *objptr, int n_index, ir_node **index,
878 return new_rd_Sel(NULL, irg, block, store, objptr, n_index, index, ent);
880 INLINE ir_node *new_r_InstOf (ir_graph *irg, ir_node *block, ir_node *store, ir_node *objptr,
882 return (new_rd_InstOf (NULL, irg, block, store, objptr, ent));
884 INLINE ir_node *new_r_Call (ir_graph *irg, ir_node *block, ir_node *store,
885 ir_node *callee, int arity, ir_node **in,
887 return new_rd_Call(NULL, irg, block, store, callee, arity, in, tp);
889 INLINE ir_node *new_r_Add (ir_graph *irg, ir_node *block,
890 ir_node *op1, ir_node *op2, ir_mode *mode) {
891 return new_rd_Add(NULL, irg, block, op1, op2, mode);
893 INLINE ir_node *new_r_Sub (ir_graph *irg, ir_node *block,
894 ir_node *op1, ir_node *op2, ir_mode *mode) {
895 return new_rd_Sub(NULL, irg, block, op1, op2, mode);
897 INLINE ir_node *new_r_Minus (ir_graph *irg, ir_node *block,
898 ir_node *op, ir_mode *mode) {
899 return new_rd_Minus(NULL, irg, block, op, mode);
901 INLINE ir_node *new_r_Mul (ir_graph *irg, ir_node *block,
902 ir_node *op1, ir_node *op2, ir_mode *mode) {
903 return new_rd_Mul(NULL, irg, block, op1, op2, mode);
905 INLINE ir_node *new_r_Quot (ir_graph *irg, ir_node *block,
906 ir_node *memop, ir_node *op1, ir_node *op2) {
907 return new_rd_Quot(NULL, irg, block, memop, op1, op2);
909 INLINE ir_node *new_r_DivMod (ir_graph *irg, ir_node *block,
910 ir_node *memop, ir_node *op1, ir_node *op2) {
911 return new_rd_DivMod(NULL, irg, block, memop, op1, op2);
913 INLINE ir_node *new_r_Div (ir_graph *irg, ir_node *block,
914 ir_node *memop, ir_node *op1, ir_node *op2) {
915 return new_rd_Div(NULL, irg, block, memop, op1, op2);
917 INLINE ir_node *new_r_Mod (ir_graph *irg, ir_node *block,
918 ir_node *memop, ir_node *op1, ir_node *op2) {
919 return new_rd_Mod(NULL, irg, block, memop, op1, op2);
921 INLINE ir_node *new_r_Abs (ir_graph *irg, ir_node *block,
922 ir_node *op, ir_mode *mode) {
923 return new_rd_Abs(NULL, irg, block, op, mode);
925 INLINE ir_node *new_r_And (ir_graph *irg, ir_node *block,
926 ir_node *op1, ir_node *op2, ir_mode *mode) {
927 return new_rd_And(NULL, irg, block, op1, op2, mode);
929 INLINE ir_node *new_r_Or (ir_graph *irg, ir_node *block,
930 ir_node *op1, ir_node *op2, ir_mode *mode) {
931 return new_rd_Or(NULL, irg, block, op1, op2, mode);
933 INLINE ir_node *new_r_Eor (ir_graph *irg, ir_node *block,
934 ir_node *op1, ir_node *op2, ir_mode *mode) {
935 return new_rd_Eor(NULL, irg, block, op1, op2, mode);
937 INLINE ir_node *new_r_Not (ir_graph *irg, ir_node *block,
938 ir_node *op, ir_mode *mode) {
939 return new_rd_Not(NULL, irg, block, op, mode);
941 INLINE ir_node *new_r_Cmp (ir_graph *irg, ir_node *block,
942 ir_node *op1, ir_node *op2) {
943 return new_rd_Cmp(NULL, irg, block, op1, op2);
945 INLINE ir_node *new_r_Shl (ir_graph *irg, ir_node *block,
946 ir_node *op, ir_node *k, ir_mode *mode) {
947 return new_rd_Shl(NULL, irg, block, op, k, mode);
949 INLINE ir_node *new_r_Shr (ir_graph *irg, ir_node *block,
950 ir_node *op, ir_node *k, ir_mode *mode) {
951 return new_rd_Shr(NULL, irg, block, op, k, mode);
953 INLINE ir_node *new_r_Shrs (ir_graph *irg, ir_node *block,
954 ir_node *op, ir_node *k, ir_mode *mode) {
955 return new_rd_Shrs(NULL, irg, block, op, k, mode);
957 INLINE ir_node *new_r_Rot (ir_graph *irg, ir_node *block,
958 ir_node *op, ir_node *k, ir_mode *mode) {
959 return new_rd_Rot(NULL, irg, block, op, k, mode);
961 INLINE ir_node *new_r_Conv (ir_graph *irg, ir_node *block,
962 ir_node *op, ir_mode *mode) {
963 return new_rd_Conv(NULL, irg, block, op, mode);
965 INLINE ir_node *new_r_Cast (ir_graph *irg, ir_node *block, ir_node *op, type *to_tp) {
966 return new_rd_Cast(NULL, irg, block, op, to_tp);
968 INLINE ir_node *new_r_Phi (ir_graph *irg, ir_node *block, int arity,
969 ir_node **in, ir_mode *mode) {
970 return new_rd_Phi(NULL, irg, block, arity, in, mode);
972 INLINE ir_node *new_r_Load (ir_graph *irg, ir_node *block,
973 ir_node *store, ir_node *adr) {
974 return new_rd_Load(NULL, irg, block, store, adr);
976 INLINE ir_node *new_r_Store (ir_graph *irg, ir_node *block,
977 ir_node *store, ir_node *adr, ir_node *val) {
978 return new_rd_Store(NULL, irg, block, store, adr, val);
980 INLINE ir_node *new_r_Alloc (ir_graph *irg, ir_node *block, ir_node *store,
981 ir_node *size, type *alloc_type, where_alloc where) {
982 return new_rd_Alloc(NULL, irg, block, store, size, alloc_type, where);
984 INLINE ir_node *new_r_Free (ir_graph *irg, ir_node *block, ir_node *store,
985 ir_node *ptr, ir_node *size, type *free_type) {
986 return new_rd_Free(NULL, irg, block, store, ptr, size, free_type);
988 INLINE ir_node *new_r_Sync (ir_graph *irg, ir_node *block, int arity, ir_node **in) {
989 return new_rd_Sync(NULL, irg, block, arity, in);
991 INLINE ir_node *new_r_Proj (ir_graph *irg, ir_node *block, ir_node *arg,
992 ir_mode *mode, long proj) {
993 return new_rd_Proj(NULL, irg, block, arg, mode, proj);
995 INLINE ir_node *new_r_defaultProj (ir_graph *irg, ir_node *block, ir_node *arg,
997 return new_rd_defaultProj(NULL, irg, block, arg, max_proj);
999 INLINE ir_node *new_r_Tuple (ir_graph *irg, ir_node *block,
1000 int arity, ir_node **in) {
1001 return new_rd_Tuple(NULL, irg, block, arity, in );
1003 INLINE ir_node *new_r_Id (ir_graph *irg, ir_node *block,
1004 ir_node *val, ir_mode *mode) {
1005 return new_rd_Id(NULL, irg, block, val, mode);
1007 INLINE ir_node *new_r_Bad (ir_graph *irg) {
1008 return new_rd_Bad(irg);
1010 INLINE ir_node *new_r_Confirm (ir_graph *irg, ir_node *block, ir_node *val, ir_node *bound, pn_Cmp cmp) {
1011 return new_rd_Confirm (NULL, irg, block, val, bound, cmp);
1013 INLINE ir_node *new_r_Unknown (ir_graph *irg, ir_mode *m) {
1014 return new_rd_Unknown(irg, m);
1016 INLINE ir_node *new_r_CallBegin (ir_graph *irg, ir_node *block, ir_node *callee) {
1017 return new_rd_CallBegin(NULL, irg, block, callee);
1019 INLINE ir_node *new_r_EndReg (ir_graph *irg, ir_node *block) {
1020 return new_rd_EndReg(NULL, irg, block);
1022 INLINE ir_node *new_r_EndExcept (ir_graph *irg, ir_node *block) {
1023 return new_rd_EndExcept(NULL, irg, block);
1025 INLINE ir_node *new_r_Break (ir_graph *irg, ir_node *block) {
1026 return new_rd_Break(NULL, irg, block);
1028 INLINE ir_node *new_r_Filter (ir_graph *irg, ir_node *block, ir_node *arg,
1029 ir_mode *mode, long proj) {
1030 return new_rd_Filter(NULL, irg, block, arg, mode, proj);
1032 INLINE ir_node *new_r_FuncCall (ir_graph *irg, ir_node *block,
1033 ir_node *callee, int arity, ir_node **in,
1035 return new_rd_FuncCall(NULL, irg, block, callee, arity, in, tp);
1039 /** ********************/
1040 /** public interfaces */
1041 /** construction tools */
1045 * - create a new Start node in the current block
1047 * @return s - pointer to the created Start node
1052 new_d_Start (dbg_info* db)
1056 res = new_ir_node (db, current_ir_graph, current_ir_graph->current_block,
1057 op_Start, mode_T, 0, NULL);
1058 /* res->attr.start.irg = current_ir_graph; */
1060 res = optimize_node (res);
1061 irn_vrfy_irg (res, current_ir_graph);
1066 new_d_End (dbg_info* db)
1069 res = new_ir_node (db, current_ir_graph, current_ir_graph->current_block,
1070 op_End, mode_X, -1, NULL);
1071 res = optimize_node (res);
1072 irn_vrfy_irg (res, current_ir_graph);
1077 /* Constructs a Block with a fixed number of predecessors.
1078 Does set current_block. Can be used with automatic Phi
1079 node construction. */
1081 new_d_Block (dbg_info* db, int arity, ir_node **in)
1085 bool has_unknown = false;
1087 res = new_rd_Block (db, current_ir_graph, arity, in);
1089 /* Create and initialize array for Phi-node construction. */
1090 res->attr.block.graph_arr = NEW_ARR_D (ir_node *, current_ir_graph->obst,
1091 current_ir_graph->n_loc);
1092 memset(res->attr.block.graph_arr, 0, sizeof(ir_node *)*current_ir_graph->n_loc);
1094 for (i = arity-1; i >= 0; i--) if (intern_get_irn_op(in[i]) == op_Unknown) has_unknown = true;
1096 if (!has_unknown) res = optimize_node (res);
1097 current_ir_graph->current_block = res;
1099 irn_vrfy_irg (res, current_ir_graph);
1104 /* ***********************************************************************/
1105 /* Methods necessary for automatic Phi node creation */
1107 ir_node *phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
1108 ir_node *get_r_value_internal (ir_node *block, int pos, ir_mode *mode);
1109 ir_node *new_rd_Phi0 (ir_graph *irg, ir_node *block, ir_mode *mode)
1110 ir_node *new_rd_Phi_in (ir_graph *irg, ir_node *block, ir_mode *mode, ir_node **in, int ins)
1112 Call Graph: ( A ---> B == A "calls" B)
1114 get_value mature_block
1122 get_r_value_internal |
1126 new_rd_Phi0 new_rd_Phi_in
1128 * *************************************************************************** */
1130 /** Creates a Phi node with 0 predecessors */
1131 static INLINE ir_node *
1132 new_rd_Phi0 (ir_graph *irg, ir_node *block, ir_mode *mode)
1135 res = new_ir_node (NULL, irg, block, op_Phi, mode, 0, NULL);
1136 irn_vrfy_irg (res, irg);
1140 /* There are two implementations of the Phi node construction. The first
1141 is faster, but does not work for blocks with more than 2 predecessors.
1142 The second works always but is slower and causes more unnecessary Phi
1144 Select the implementations by the following preprocessor flag set in
1146 #if USE_FAST_PHI_CONSTRUCTION
1148 /* This is a stack used for allocating and deallocating nodes in
1149 new_rd_Phi_in. The original implementation used the obstack
1150 to model this stack, now it is explicit. This reduces side effects.
1152 #if USE_EXPLICIT_PHI_IN_STACK
1153 INLINE Phi_in_stack *
1154 new_Phi_in_stack(void) {
1157 res = (Phi_in_stack *) malloc ( sizeof (Phi_in_stack));
1159 res->stack = NEW_ARR_F (ir_node *, 1);
1166 free_Phi_in_stack(Phi_in_stack *s) {
1167 DEL_ARR_F(s->stack);
1171 free_to_Phi_in_stack(ir_node *phi) {
1172 if (ARR_LEN(current_ir_graph->Phi_in_stack->stack) ==
1173 current_ir_graph->Phi_in_stack->pos)
1174 ARR_APP1 (ir_node *, current_ir_graph->Phi_in_stack->stack, phi);
1176 current_ir_graph->Phi_in_stack->stack[current_ir_graph->Phi_in_stack->pos] = phi;
1178 (current_ir_graph->Phi_in_stack->pos)++;
1181 static INLINE ir_node *
1182 alloc_or_pop_from_Phi_in_stack(ir_graph *irg, ir_node *block, ir_mode *mode,
1183 int arity, ir_node **in) {
1185 ir_node **stack = current_ir_graph->Phi_in_stack->stack;
1186 int pos = current_ir_graph->Phi_in_stack->pos;
1190 /* We need to allocate a new node */
1191 res = new_ir_node (db, irg, block, op_Phi, mode, arity, in);
1192 res->attr.phi_backedge = new_backedge_arr(irg->obst, arity);
1194 /* reuse the old node and initialize it again. */
1197 assert (res->kind == k_ir_node);
1198 assert (res->op == op_Phi);
1202 assert (arity >= 0);
1203 /* ???!!! How to free the old in array?? Not at all: on obstack ?!! */
1204 res->in = NEW_ARR_D (ir_node *, irg->obst, (arity+1));
1206 memcpy (&res->in[1], in, sizeof (ir_node *) * arity);
1208 (current_ir_graph->Phi_in_stack->pos)--;
1212 #endif /* USE_EXPLICIT_PHI_IN_STACK */
1214 /* Creates a Phi node with a given, fixed array **in of predecessors.
1215 If the Phi node is unnecessary, as the same value reaches the block
1216 through all control flow paths, it is eliminated and the value
1217 returned directly. This constructor is only intended for use in
1218 the automatic Phi node generation triggered by get_value or mature.
1219 The implementation is quite tricky and depends on the fact, that
1220 the nodes are allocated on a stack:
1221 The in array contains predecessors and NULLs. The NULLs appear,
1222 if get_r_value_internal, that computed the predecessors, reached
1223 the same block on two paths. In this case the same value reaches
1224 this block on both paths, there is no definition in between. We need
1225 not allocate a Phi where these path's merge, but we have to communicate
1226 this fact to the caller. This happens by returning a pointer to the
1227 node the caller _will_ allocate. (Yes, we predict the address. We can
1228 do so because the nodes are allocated on the obstack.) The caller then
1229 finds a pointer to itself and, when this routine is called again,
1232 static INLINE ir_node *
1233 new_rd_Phi_in (ir_graph *irg, ir_node *block, ir_mode *mode,
1234 ir_node **in, int ins)
1237 ir_node *res, *known;
1239 /* allocate a new node on the obstack.
1240 This can return a node to which some of the pointers in the in-array
1242 Attention: the constructor copies the in array, i.e., the later changes
1243 to the array in this routine do not affect the constructed node! If
1244 the in array contains NULLs, there will be missing predecessors in the
1246 Is this a possible internal state of the Phi node generation? */
1247 #if USE_EXPLICIT_PHI_IN_STACK
1248 res = known = alloc_or_pop_from_Phi_in_stack(irg, block, mode, ins, in);
1250 res = known = new_ir_node (NULL, irg, block, op_Phi, mode, ins, in);
1251 res->attr.phi_backedge = new_backedge_arr(irg->obst, ins);
1253 /* The in-array can contain NULLs. These were returned by
1254 get_r_value_internal if it reached the same block/definition on a
1256 The NULLs are replaced by the node itself to simplify the test in the
1258 for (i=0; i < ins; ++i)
1259 if (in[i] == NULL) in[i] = res;
1261 /* This loop checks whether the Phi has more than one predecessor.
1262 If so, it is a real Phi node and we break the loop. Else the
1263 Phi node merges the same definition on several paths and therefore
1265 for (i=0; i < ins; ++i)
1267 if (in[i]==res || in[i]==known) continue;
1275 /* i==ins: there is at most one predecessor, we don't need a phi node. */
1277 #if USE_EXPLICIT_PHI_IN_STACK
1278 free_to_Phi_in_stack(res);
1280 obstack_free (current_ir_graph->obst, res);
1284 res = optimize_node (res);
1285 irn_vrfy_irg (res, irg);
1288 /* return the pointer to the Phi node. This node might be deallocated! */
1293 get_r_value_internal (ir_node *block, int pos, ir_mode *mode);
1296 allocates and returns this node. The routine called to allocate the
1297 node might optimize it away and return a real value, or even a pointer
1298 to a deallocated Phi node on top of the obstack!
1299 This function is called with an in-array of proper size. **/
1301 phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
1303 ir_node *prevBlock, *res;
1306 /* This loop goes to all predecessor blocks of the block the Phi node is in
1307 and there finds the operands of the Phi node by calling
1308 get_r_value_internal. */
1309 for (i = 1; i <= ins; ++i) {
1310 assert (block->in[i]);
1311 prevBlock = block->in[i]->in[0]; /* go past control flow op to prev block */
1313 nin[i-1] = get_r_value_internal (prevBlock, pos, mode);
1316 /* After collecting all predecessors into the array nin a new Phi node
1317 with these predecessors is created. This constructor contains an
1318 optimization: If all predecessors of the Phi node are identical it
1319 returns the only operand instead of a new Phi node. If the value
1320 passes two different control flow edges without being defined, and
1321 this is the second path treated, a pointer to the node that will be
1322 allocated for the first path (recursion) is returned. We already
1323 know the address of this node, as it is the next node to be allocated
1324 and will be placed on top of the obstack. (The obstack is a _stack_!) */
1325 res = new_rd_Phi_in (current_ir_graph, block, mode, nin, ins);
1327 /* Now we now the value for "pos" and can enter it in the array with
1328 all known local variables. Attention: this might be a pointer to
1329 a node, that later will be allocated!!! See new_rd_Phi_in.
1330 If this is called in mature, after some set_value in the same block,
1331 the proper value must not be overwritten:
1333 get_value (makes Phi0, put's it into graph_arr)
1334 set_value (overwrites Phi0 in graph_arr)
1335 mature_block (upgrades Phi0, puts it again into graph_arr, overwriting
1338 if (!block->attr.block.graph_arr[pos]) {
1339 block->attr.block.graph_arr[pos] = res;
1341 /* printf(" value already computed by %s\n",
1342 get_id_str(block->attr.block.graph_arr[pos]->op->name)); */
1348 /* This function returns the last definition of a variable. In case
1349 this variable was last defined in a previous block, Phi nodes are
1350 inserted. If the part of the firm graph containing the definition
1351 is not yet constructed, a dummy Phi node is returned. */
1353 get_r_value_internal (ir_node *block, int pos, ir_mode *mode)
1356 /* There are 4 cases to treat.
1358 1. The block is not mature and we visit it the first time. We can not
1359 create a proper Phi node, therefore a Phi0, i.e., a Phi without
1360 predecessors is returned. This node is added to the linked list (field
1361 "link") of the containing block to be completed when this block is
1362 matured. (Completion will add a new Phi and turn the Phi0 into an Id
1365 2. The value is already known in this block, graph_arr[pos] is set and we
1366 visit the block the first time. We can return the value without
1367 creating any new nodes.
1369 3. The block is mature and we visit it the first time. A Phi node needs
1370 to be created (phi_merge). If the Phi is not needed, as all it's
1371 operands are the same value reaching the block through different
1372 paths, it's optimized away and the value itself is returned.
1374 4. The block is mature, and we visit it the second time. Now two
1375 subcases are possible:
1376 * The value was computed completely the last time we were here. This
1377 is the case if there is no loop. We can return the proper value.
1378 * The recursion that visited this node and set the flag did not
1379 return yet. We are computing a value in a loop and need to
1380 break the recursion without knowing the result yet.
1381 @@@ strange case. Straight forward we would create a Phi before
1382 starting the computation of it's predecessors. In this case we will
1383 find a Phi here in any case. The problem is that this implementation
1384 only creates a Phi after computing the predecessors, so that it is
1385 hard to compute self references of this Phi. @@@
1386 There is no simple check for the second subcase. Therefore we check
1387 for a second visit and treat all such cases as the second subcase.
1388 Anyways, the basic situation is the same: we reached a block
1389 on two paths without finding a definition of the value: No Phi
1390 nodes are needed on both paths.
1391 We return this information "Two paths, no Phi needed" by a very tricky
1392 implementation that relies on the fact that an obstack is a stack and
1393 will return a node with the same address on different allocations.
1394 Look also at phi_merge and new_rd_phi_in to understand this.
1395 @@@ Unfortunately this does not work, see testprogram
1396 three_cfpred_example.
1400 /* case 4 -- already visited. */
1401 if (get_irn_visited(block) == get_irg_visited(current_ir_graph)) return NULL;
1403 /* visited the first time */
1404 set_irn_visited(block, get_irg_visited(current_ir_graph));
1406 /* Get the local valid value */
1407 res = block->attr.block.graph_arr[pos];
1409 /* case 2 -- If the value is actually computed, return it. */
1410 if (res) return res;
1412 if (block->attr.block.matured) { /* case 3 */
1414 /* The Phi has the same amount of ins as the corresponding block. */
1415 int ins = intern_get_irn_arity(block);
1417 NEW_ARR_A (ir_node *, nin, ins);
1419 /* Phi merge collects the predecessors and then creates a node. */
1420 res = phi_merge (block, pos, mode, nin, ins);
1422 } else { /* case 1 */
1423 /* The block is not mature, we don't know how many in's are needed. A Phi
1424 with zero predecessors is created. Such a Phi node is called Phi0
1425 node. (There is also an obsolete Phi0 opcode.) The Phi0 is then added
1426 to the list of Phi0 nodes in this block to be matured by mature_block
1428 The Phi0 has to remember the pos of it's internal value. If the real
1429 Phi is computed, pos is used to update the array with the local
1432 res = new_rd_Phi0 (current_ir_graph, block, mode);
1433 res->attr.phi0_pos = pos;
1434 res->link = block->link;
1438 /* If we get here, the frontend missed a use-before-definition error */
1441 printf("Error: no value set. Use of undefined variable. Initializing to zero.\n");
1442 assert (mode->code >= irm_F && mode->code <= irm_P);
1443 res = new_rd_Const (NULL, current_ir_graph, block, mode,
1444 tarval_mode_null[mode->code]);
1447 /* The local valid value is available now. */
1448 block->attr.block.graph_arr[pos] = res;
1456 it starts the recursion. This causes an Id at the entry of
1457 every block that has no definition of the value! **/
1459 #if USE_EXPLICIT_PHI_IN_STACK
1461 INLINE Phi_in_stack * new_Phi_in_stack() { return NULL; }
1462 INLINE void free_Phi_in_stack(Phi_in_stack *s) { }
1465 static INLINE ir_node *
1466 new_rd_Phi_in (ir_graph *irg, ir_node *block, ir_mode *mode,
1467 ir_node **in, int ins)
1470 ir_node *res, *known;
1472 /* Allocate a new node on the obstack. The allocation copies the in
1474 res = new_ir_node (NULL, irg, block, op_Phi, mode, ins, in);
1475 res->attr.phi_backedge = new_backedge_arr(irg->obst, ins);
1477 /* This loop checks whether the Phi has more than one predecessor.
1478 If so, it is a real Phi node and we break the loop. Else the
1479 Phi node merges the same definition on several paths and therefore
1480 is not needed. Don't consider Bad nodes! */
1482 for (i=0; i < ins; ++i)
1486 if (in[i]==res || in[i]==known || is_Bad(in[i])) continue;
1494 /* i==ins: there is at most one predecessor, we don't need a phi node. */
1497 obstack_free (current_ir_graph->obst, res);
1500 /* A undefined value, e.g., in unreachable code. */
1504 res = optimize_node (res);
1505 irn_vrfy_irg (res, irg);
1506 /* Memory Phis in endless loops must be kept alive.
1507 As we can't distinguish these easily we keep all of the alive. */
1508 if ((res->op == op_Phi) && (mode == mode_M))
1509 add_End_keepalive(irg->end, res);
1516 get_r_value_internal (ir_node *block, int pos, ir_mode *mode);
1518 #if PRECISE_EXC_CONTEXT
1520 phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins);
1522 /* Construct a new frag_array for node n.
1523 Copy the content from the current graph_arr of the corresponding block:
1524 this is the current state.
1525 Set ProjM(n) as current memory state.
1526 Further the last entry in frag_arr of current block points to n. This
1527 constructs a chain block->last_frag_op-> ... first_frag_op of all frag ops in the block.
1529 static INLINE ir_node ** new_frag_arr (ir_node *n)
1533 arr = NEW_ARR_D (ir_node *, current_ir_graph->obst, current_ir_graph->n_loc);
1534 memcpy(arr, current_ir_graph->current_block->attr.block.graph_arr,
1535 sizeof(ir_node *)*current_ir_graph->n_loc);
1536 /* turn off optimization before allocating Proj nodes, as res isn't
1538 opt = get_opt_optimize(); set_optimize(0);
1539 /* Here we rely on the fact that all frag ops have Memory as first result! */
1540 if (intern_get_irn_op(n) == op_Call)
1541 arr[0] = new_Proj(n, mode_M, 3);
1543 arr[0] = new_Proj(n, mode_M, 0);
1545 current_ir_graph->current_block->attr.block.graph_arr[current_ir_graph->n_loc-1] = n;
1549 static INLINE ir_node **
1550 get_frag_arr (ir_node *n) {
1551 if (intern_get_irn_op(n) == op_Call) {
1552 return n->attr.call.frag_arr;
1553 } else if (intern_get_irn_op(n) == op_Alloc) {
1554 return n->attr.a.frag_arr;
1556 return n->attr.frag_arr;
1561 set_frag_value(ir_node **frag_arr, int pos, ir_node *val) {
1562 if (!frag_arr[pos]) frag_arr[pos] = val;
1563 if (frag_arr[current_ir_graph->n_loc - 1]) {
1564 ir_node **arr = get_frag_arr(frag_arr[current_ir_graph->n_loc - 1]);
1565 set_frag_value(arr, pos, val);
1570 get_r_frag_value_internal (ir_node *block, ir_node *cfOp, int pos, ir_mode *mode) {
1574 assert(is_fragile_op(cfOp) && (get_irn_op(cfOp) != op_Bad));
1576 frag_arr = get_frag_arr(cfOp);
1577 res = frag_arr[pos];
1579 if (block->attr.block.graph_arr[pos]) {
1580 /* There was a set_value after the cfOp and no get_value before that
1581 set_value. We must build a Phi node now. */
1582 if (block->attr.block.matured) {
1583 int ins = intern_get_irn_arity(block);
1585 NEW_ARR_A (ir_node *, nin, ins);
1586 res = phi_merge(block, pos, mode, nin, ins);
1588 res = new_rd_Phi0 (current_ir_graph, block, mode);
1589 res->attr.phi0_pos = pos;
1590 res->link = block->link;
1594 /* @@@ tested by Flo: set_frag_value(frag_arr, pos, res);
1595 but this should be better: (remove comment if this works) */
1596 /* It's a Phi, we can write this into all graph_arrs with NULL */
1597 set_frag_value(block->attr.block.graph_arr, pos, res);
1599 res = get_r_value_internal(block, pos, mode);
1600 set_frag_value(block->attr.block.graph_arr, pos, res);
1608 computes the predecessors for the real phi node, and then
1609 allocates and returns this node. The routine called to allocate the
1610 node might optimize it away and return a real value.
1611 This function must be called with an in-array of proper size. **/
1613 phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
1615 ir_node *prevBlock, *prevCfOp, *res, *phi0;
1618 /* If this block has no value at pos create a Phi0 and remember it
1619 in graph_arr to break recursions.
1620 Else we may not set graph_arr as there a later value is remembered. */
1622 if (!block->attr.block.graph_arr[pos]) {
1623 if (block == get_irg_start_block(current_ir_graph)) {
1624 /* Collapsing to Bad tarvals is no good idea.
1625 So we call a user-supplied routine here that deals with this case as
1626 appropriate for the given language. Sorryly the only help we can give
1627 here is the position.
1629 Even if all variables are defined before use, it can happen that
1630 we get to the start block, if a cond has been replaced by a tuple
1631 (bad, jmp). In this case we call the function needlessly, eventually
1632 generating an non existant error.
1633 However, this SHOULD NOT HAPPEN, as bad control flow nodes are intercepted
1636 if (default_initialize_local_variable)
1637 block->attr.block.graph_arr[pos] = default_initialize_local_variable(mode, pos);
1639 block->attr.block.graph_arr[pos] = new_Const(mode, tarval_bad);
1640 /* We don't need to care about exception ops in the start block.
1641 There are none by definition. */
1642 return block->attr.block.graph_arr[pos];
1644 phi0 = new_rd_Phi0(current_ir_graph, block, mode);
1645 block->attr.block.graph_arr[pos] = phi0;
1646 #if PRECISE_EXC_CONTEXT
1647 /* Set graph_arr for fragile ops. Also here we should break recursion.
1648 We could choose a cyclic path through an cfop. But the recursion would
1649 break at some point. */
1650 set_frag_value(block->attr.block.graph_arr, pos, phi0);
1655 /* This loop goes to all predecessor blocks of the block the Phi node
1656 is in and there finds the operands of the Phi node by calling
1657 get_r_value_internal. */
1658 for (i = 1; i <= ins; ++i) {
1659 prevCfOp = skip_Proj(block->in[i]);
1661 if (is_Bad(prevCfOp)) {
1662 /* In case a Cond has been optimized we would get right to the start block
1663 with an invalid definition. */
1664 nin[i-1] = new_Bad();
1667 prevBlock = block->in[i]->in[0]; /* go past control flow op to prev block */
1669 if (!is_Bad(prevBlock)) {
1670 #if PRECISE_EXC_CONTEXT
1671 if (is_fragile_op(prevCfOp) && (intern_get_irn_op (prevCfOp) != op_Bad)) {
1672 assert(get_r_frag_value_internal (prevBlock, prevCfOp, pos, mode));
1673 nin[i-1] = get_r_frag_value_internal (prevBlock, prevCfOp, pos, mode);
1676 nin[i-1] = get_r_value_internal (prevBlock, pos, mode);
1678 nin[i-1] = new_Bad();
1682 /* After collecting all predecessors into the array nin a new Phi node
1683 with these predecessors is created. This constructor contains an
1684 optimization: If all predecessors of the Phi node are identical it
1685 returns the only operand instead of a new Phi node. */
1686 res = new_rd_Phi_in (current_ir_graph, block, mode, nin, ins);
1688 /* In case we allocated a Phi0 node at the beginning of this procedure,
1689 we need to exchange this Phi0 with the real Phi. */
1691 exchange(phi0, res);
1692 block->attr.block.graph_arr[pos] = res;
1693 /* Don't set_frag_value as it does not overwrite. Doesn't matter, is
1694 only an optimization. */
1700 /* This function returns the last definition of a variable. In case
1701 this variable was last defined in a previous block, Phi nodes are
1702 inserted. If the part of the firm graph containing the definition
1703 is not yet constructed, a dummy Phi node is returned. */
1705 get_r_value_internal (ir_node *block, int pos, ir_mode *mode)
1708 /* There are 4 cases to treat.
1710 1. The block is not mature and we visit it the first time. We can not
1711 create a proper Phi node, therefore a Phi0, i.e., a Phi without
1712 predecessors is returned. This node is added to the linked list (field
1713 "link") of the containing block to be completed when this block is
1714 matured. (Comlpletion will add a new Phi and turn the Phi0 into an Id
1717 2. The value is already known in this block, graph_arr[pos] is set and we
1718 visit the block the first time. We can return the value without
1719 creating any new nodes.
1721 3. The block is mature and we visit it the first time. A Phi node needs
1722 to be created (phi_merge). If the Phi is not needed, as all it's
1723 operands are the same value reaching the block through different
1724 paths, it's optimized away and the value itself is returned.
1726 4. The block is mature, and we visit it the second time. Now two
1727 subcases are possible:
1728 * The value was computed completely the last time we were here. This
1729 is the case if there is no loop. We can return the proper value.
1730 * The recursion that visited this node and set the flag did not
1731 return yet. We are computing a value in a loop and need to
1732 break the recursion. This case only happens if we visited
1733 the same block with phi_merge before, which inserted a Phi0.
1734 So we return the Phi0.
1737 /* case 4 -- already visited. */
1738 if (get_irn_visited(block) == get_irg_visited(current_ir_graph)) {
1739 /* As phi_merge allocates a Phi0 this value is always defined. Here
1740 is the critical difference of the two algorithms. */
1741 assert(block->attr.block.graph_arr[pos]);
1742 return block->attr.block.graph_arr[pos];
1745 /* visited the first time */
1746 set_irn_visited(block, get_irg_visited(current_ir_graph));
1748 /* Get the local valid value */
1749 res = block->attr.block.graph_arr[pos];
1751 /* case 2 -- If the value is actually computed, return it. */
1752 if (res) { return res; };
1754 if (block->attr.block.matured) { /* case 3 */
1756 /* The Phi has the same amount of ins as the corresponding block. */
1757 int ins = intern_get_irn_arity(block);
1759 NEW_ARR_A (ir_node *, nin, ins);
1761 /* Phi merge collects the predecessors and then creates a node. */
1762 res = phi_merge (block, pos, mode, nin, ins);
1764 } else { /* case 1 */
1765 /* The block is not mature, we don't know how many in's are needed. A Phi
1766 with zero predecessors is created. Such a Phi node is called Phi0
1767 node. The Phi0 is then added to the list of Phi0 nodes in this block
1768 to be matured by mature_block later.
1769 The Phi0 has to remember the pos of it's internal value. If the real
1770 Phi is computed, pos is used to update the array with the local
1772 res = new_rd_Phi0 (current_ir_graph, block, mode);
1773 res->attr.phi0_pos = pos;
1774 res->link = block->link;
1778 /* If we get here, the frontend missed a use-before-definition error */
1781 printf("Error: no value set. Use of undefined variable. Initializing to zero.\n");
1782 assert (mode->code >= irm_F && mode->code <= irm_P);
1783 res = new_rd_Const (NULL, current_ir_graph, block, mode,
1784 get_mode_null(mode));
1787 /* The local valid value is available now. */
1788 block->attr.block.graph_arr[pos] = res;
1793 #endif /* USE_FAST_PHI_CONSTRUCTION */
1795 /* ************************************************************************** */
1797 /** Finalize a Block node, when all control flows are known. */
1798 /** Acceptable parameters are only Block nodes. */
1800 mature_block (ir_node *block)
1807 assert (get_irn_opcode(block) == iro_Block);
1808 /* @@@ should be commented in
1809 assert (!get_Block_matured(block) && "Block already matured"); */
1811 if (!get_Block_matured(block)) {
1812 ins = ARR_LEN (block->in)-1;
1813 /* Fix block parameters */
1814 block->attr.block.backedge = new_backedge_arr(current_ir_graph->obst, ins);
1816 /* An array for building the Phi nodes. */
1817 NEW_ARR_A (ir_node *, nin, ins);
1819 /* Traverse a chain of Phi nodes attached to this block and mature
1821 for (n = block->link; n; n=next) {
1822 inc_irg_visited(current_ir_graph);
1824 exchange (n, phi_merge (block, n->attr.phi0_pos, n->mode, nin, ins));
1827 block->attr.block.matured = 1;
1829 /* Now, as the block is a finished firm node, we can optimize it.
1830 Since other nodes have been allocated since the block was created
1831 we can not free the node on the obstack. Therefore we have to call
1833 Unfortunately the optimization does not change a lot, as all allocated
1834 nodes refer to the unoptimized node.
1835 We can call _2, as global cse has no effect on blocks. */
1836 block = optimize_in_place_2(block);
1837 irn_vrfy_irg(block, current_ir_graph);
1842 new_d_Phi (dbg_info* db, int arity, ir_node **in, ir_mode *mode)
1844 return new_rd_Phi (db, current_ir_graph, current_ir_graph->current_block,
1849 new_d_Const (dbg_info* db, ir_mode *mode, tarval *con)
1851 return new_rd_Const (db, current_ir_graph, current_ir_graph->start_block,
1856 new_d_Const_type (dbg_info* db, ir_mode *mode, tarval *con, type *tp)
1858 return new_rd_Const_type (db, current_ir_graph, current_ir_graph->start_block,
1864 new_d_Id (dbg_info* db, ir_node *val, ir_mode *mode)
1866 return new_rd_Id (db, current_ir_graph, current_ir_graph->current_block,
1871 new_d_Proj (dbg_info* db, ir_node *arg, ir_mode *mode, long proj)
1873 return new_rd_Proj (db, current_ir_graph, current_ir_graph->current_block,
1878 new_d_defaultProj (dbg_info* db, ir_node *arg, long max_proj)
1881 assert(arg->op == op_Cond);
1882 arg->attr.c.kind = fragmentary;
1883 arg->attr.c.default_proj = max_proj;
1884 res = new_Proj (arg, mode_X, max_proj);
1889 new_d_Conv (dbg_info* db, ir_node *op, ir_mode *mode)
1891 return new_rd_Conv (db, current_ir_graph, current_ir_graph->current_block,
1896 new_d_Cast (dbg_info* db, ir_node *op, type *to_tp)
1898 return new_rd_Cast (db, current_ir_graph, current_ir_graph->current_block, op, to_tp);
1902 new_d_Tuple (dbg_info* db, int arity, ir_node **in)
1904 return new_rd_Tuple (db, current_ir_graph, current_ir_graph->current_block,
1909 new_d_Add (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode)
1911 return new_rd_Add (db, current_ir_graph, current_ir_graph->current_block,
1916 new_d_Sub (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode)
1918 return new_rd_Sub (db, current_ir_graph, current_ir_graph->current_block,
1924 new_d_Minus (dbg_info* db, ir_node *op, ir_mode *mode)
1926 return new_rd_Minus (db, current_ir_graph, current_ir_graph->current_block,
1931 new_d_Mul (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode)
1933 return new_rd_Mul (db, current_ir_graph, current_ir_graph->current_block,
1938 new_d_Quot (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2)
1941 res = new_rd_Quot (db, current_ir_graph, current_ir_graph->current_block,
1943 #if PRECISE_EXC_CONTEXT
1944 if ((current_ir_graph->phase_state == phase_building) &&
1945 (intern_get_irn_op(res) == op_Quot)) /* Could be optimized away. */
1946 res->attr.frag_arr = new_frag_arr(res);
1953 new_d_DivMod (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2)
1956 res = new_rd_DivMod (db, current_ir_graph, current_ir_graph->current_block,
1958 #if PRECISE_EXC_CONTEXT
1959 if ((current_ir_graph->phase_state == phase_building) &&
1960 (intern_get_irn_op(res) == op_DivMod)) /* Could be optimized away. */
1961 res->attr.frag_arr = new_frag_arr(res);
1968 new_d_Div (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2)
1971 res = new_rd_Div (db, current_ir_graph, current_ir_graph->current_block,
1973 #if PRECISE_EXC_CONTEXT
1974 if ((current_ir_graph->phase_state == phase_building) &&
1975 (intern_get_irn_op(res) == op_Div)) /* Could be optimized away. */
1976 res->attr.frag_arr = new_frag_arr(res);
1983 new_d_Mod (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2)
1986 res = new_rd_Mod (db, current_ir_graph, current_ir_graph->current_block,
1988 #if PRECISE_EXC_CONTEXT
1989 if ((current_ir_graph->phase_state == phase_building) &&
1990 (intern_get_irn_op(res) == op_Mod)) /* Could be optimized away. */
1991 res->attr.frag_arr = new_frag_arr(res);
1998 new_d_And (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode)
2000 return new_rd_And (db, current_ir_graph, current_ir_graph->current_block,
2005 new_d_Or (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode)
2007 return new_rd_Or (db, current_ir_graph, current_ir_graph->current_block,
2012 new_d_Eor (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode)
2014 return new_rd_Eor (db, current_ir_graph, current_ir_graph->current_block,
2019 new_d_Not (dbg_info* db, ir_node *op, ir_mode *mode)
2021 return new_rd_Not (db, current_ir_graph, current_ir_graph->current_block,
2026 new_d_Shl (dbg_info* db, ir_node *op, ir_node *k, ir_mode *mode)
2028 return new_rd_Shl (db, current_ir_graph, current_ir_graph->current_block,
2033 new_d_Shr (dbg_info* db, ir_node *op, ir_node *k, ir_mode *mode)
2035 return new_rd_Shr (db, current_ir_graph, current_ir_graph->current_block,
2040 new_d_Shrs (dbg_info* db, ir_node *op, ir_node *k, ir_mode *mode)
2042 return new_rd_Shrs (db, current_ir_graph, current_ir_graph->current_block,
2047 new_d_Rot (dbg_info* db, ir_node *op, ir_node *k, ir_mode *mode)
2049 return new_rd_Rot (db, current_ir_graph, current_ir_graph->current_block,
2054 new_d_Abs (dbg_info* db, ir_node *op, ir_mode *mode)
2056 return new_rd_Abs (db, current_ir_graph, current_ir_graph->current_block,
2061 new_d_Cmp (dbg_info* db, ir_node *op1, ir_node *op2)
2063 return new_rd_Cmp (db, current_ir_graph, current_ir_graph->current_block,
2068 new_d_Jmp (dbg_info* db)
2070 return new_rd_Jmp (db, current_ir_graph, current_ir_graph->current_block);
2074 new_d_Cond (dbg_info* db, ir_node *c)
2076 return new_rd_Cond (db, current_ir_graph, current_ir_graph->current_block, c);
2080 new_d_Call (dbg_info* db, ir_node *store, ir_node *callee, int arity, ir_node **in,
2084 res = new_rd_Call (db, current_ir_graph, current_ir_graph->current_block,
2085 store, callee, arity, in, tp);
2086 #if PRECISE_EXC_CONTEXT
2087 if ((current_ir_graph->phase_state == phase_building) &&
2088 (intern_get_irn_op(res) == op_Call)) /* Could be optimized away. */
2089 res->attr.call.frag_arr = new_frag_arr(res);
2096 new_d_Return (dbg_info* db, ir_node* store, int arity, ir_node **in)
2098 return new_rd_Return (db, current_ir_graph, current_ir_graph->current_block,
2103 new_d_Raise (dbg_info* db, ir_node *store, ir_node *obj)
2105 return new_rd_Raise (db, current_ir_graph, current_ir_graph->current_block,
2110 new_d_Load (dbg_info* db, ir_node *store, ir_node *addr)
2113 res = new_rd_Load (db, current_ir_graph, current_ir_graph->current_block,
2115 #if PRECISE_EXC_CONTEXT
2116 if ((current_ir_graph->phase_state == phase_building) &&
2117 (intern_get_irn_op(res) == op_Load)) /* Could be optimized away. */
2118 res->attr.frag_arr = new_frag_arr(res);
2125 new_d_Store (dbg_info* db, ir_node *store, ir_node *addr, ir_node *val)
2128 res = new_rd_Store (db, current_ir_graph, current_ir_graph->current_block,
2130 #if PRECISE_EXC_CONTEXT
2131 if ((current_ir_graph->phase_state == phase_building) &&
2132 (intern_get_irn_op(res) == op_Store)) /* Could be optimized away. */
2133 res->attr.frag_arr = new_frag_arr(res);
2140 new_d_Alloc (dbg_info* db, ir_node *store, ir_node *size, type *alloc_type,
2144 res = new_rd_Alloc (db, current_ir_graph, current_ir_graph->current_block,
2145 store, size, alloc_type, where);
2146 #if PRECISE_EXC_CONTEXT
2147 if ((current_ir_graph->phase_state == phase_building) &&
2148 (intern_get_irn_op(res) == op_Alloc)) /* Could be optimized away. */
2149 res->attr.a.frag_arr = new_frag_arr(res);
2156 new_d_Free (dbg_info* db, ir_node *store, ir_node *ptr, ir_node *size, type *free_type)
2158 return new_rd_Free (db, current_ir_graph, current_ir_graph->current_block,
2159 store, ptr, size, free_type);
2163 new_d_simpleSel (dbg_info* db, ir_node *store, ir_node *objptr, entity *ent)
2164 /* GL: objptr was called frame before. Frame was a bad choice for the name
2165 as the operand could as well be a pointer to a dynamic object. */
2167 return new_rd_Sel (db, current_ir_graph, current_ir_graph->current_block,
2168 store, objptr, 0, NULL, ent);
2172 new_d_Sel (dbg_info* db, ir_node *store, ir_node *objptr, int n_index, ir_node **index, entity *sel)
2174 return new_rd_Sel (db, current_ir_graph, current_ir_graph->current_block,
2175 store, objptr, n_index, index, sel);
2179 new_d_InstOf (dbg_info *db, ir_node *store, ir_node *objptr, type *ent)
2181 return (new_rd_InstOf (db, current_ir_graph, current_ir_graph->current_block,
2182 store, objptr, ent));
2186 new_d_SymConst (dbg_info* db, type_or_id_p value, symconst_kind kind)
2188 return new_rd_SymConst (db, current_ir_graph, current_ir_graph->start_block,
2193 new_d_Sync (dbg_info* db, int arity, ir_node** in)
2195 return new_rd_Sync (db, current_ir_graph, current_ir_graph->current_block,
2203 return current_ir_graph->bad;
2207 new_d_Confirm (dbg_info *db, ir_node *val, ir_node *bound, pn_Cmp cmp)
2209 return new_rd_Confirm (db, current_ir_graph, current_ir_graph->current_block,
2214 new_d_Unknown (ir_mode *m)
2216 return new_rd_Unknown(current_ir_graph, m);
2220 new_d_CallBegin (dbg_info *db, ir_node *call)
2223 res = new_rd_CallBegin (db, current_ir_graph, current_ir_graph->current_block, call);
2228 new_d_EndReg (dbg_info *db)
2231 res = new_rd_EndReg(db, current_ir_graph, current_ir_graph->current_block);
2236 new_d_EndExcept (dbg_info *db)
2239 res = new_rd_EndExcept(db, current_ir_graph, current_ir_graph->current_block);
2244 new_d_Break (dbg_info *db)
2246 return new_rd_Break (db, current_ir_graph, current_ir_graph->current_block);
2250 new_d_Filter (dbg_info *db, ir_node *arg, ir_mode *mode, long proj)
2252 return new_rd_Filter (db, current_ir_graph, current_ir_graph->current_block,
2257 new_d_FuncCall (dbg_info* db, ir_node *callee, int arity, ir_node **in,
2261 res = new_rd_FuncCall (db, current_ir_graph, current_ir_graph->current_block,
2262 callee, arity, in, tp);
2267 /* ********************************************************************* */
2268 /* Comfortable interface with automatic Phi node construction. */
2269 /* (Uses also constructors of ?? interface, except new_Block. */
2270 /* ********************************************************************* */
2272 /* * Block construction **/
2273 /* immature Block without predecessors */
2274 ir_node *new_d_immBlock (dbg_info* db) {
2277 assert(get_irg_phase_state (current_ir_graph) == phase_building);
2278 /* creates a new dynamic in-array as length of in is -1 */
2279 res = new_ir_node (db, current_ir_graph, NULL, op_Block, mode_BB, -1, NULL);
2280 current_ir_graph->current_block = res;
2281 res->attr.block.matured = 0;
2282 /* res->attr.block.exc = exc_normal; */
2283 /* res->attr.block.handler_entry = 0; */
2284 res->attr.block.irg = current_ir_graph;
2285 res->attr.block.backedge = NULL;
2286 res->attr.block.in_cg = NULL;
2287 res->attr.block.cg_backedge = NULL;
2288 set_Block_block_visited(res, 0);
2290 /* Create and initialize array for Phi-node construction. */
2291 res->attr.block.graph_arr = NEW_ARR_D (ir_node *, current_ir_graph->obst,
2292 current_ir_graph->n_loc);
2293 memset(res->attr.block.graph_arr, 0, sizeof(ir_node *)*current_ir_graph->n_loc);
2295 /* Immature block may not be optimized! */
2296 irn_vrfy_irg (res, current_ir_graph);
2303 return new_d_immBlock(NULL);
2306 /* add an adge to a jmp/control flow node */
2308 add_in_edge (ir_node *block, ir_node *jmp)
2310 if (block->attr.block.matured) {
2311 assert(0 && "Error: Block already matured!\n");
2314 assert (jmp != NULL);
2315 ARR_APP1 (ir_node *, block->in, jmp);
2319 /* changing the current block */
2321 switch_block (ir_node *target)
2323 current_ir_graph->current_block = target;
2326 /* ************************ */
2327 /* parameter administration */
2329 /* get a value from the parameter array from the current block by its index */
2331 get_d_value (dbg_info* db, int pos, ir_mode *mode)
2333 assert(get_irg_phase_state (current_ir_graph) == phase_building);
2334 inc_irg_visited(current_ir_graph);
2336 return get_r_value_internal (current_ir_graph->current_block, pos + 1, mode);
2338 /* get a value from the parameter array from the current block by its index */
2340 get_value (int pos, ir_mode *mode)
2342 return get_d_value(NULL, pos, mode);
2345 /* set a value at position pos in the parameter array from the current block */
2347 set_value (int pos, ir_node *value)
2349 assert(get_irg_phase_state (current_ir_graph) == phase_building);
2350 assert(pos+1 < current_ir_graph->n_loc);
2351 current_ir_graph->current_block->attr.block.graph_arr[pos + 1] = value;
2354 /* get the current store */
2358 assert(get_irg_phase_state (current_ir_graph) == phase_building);
2359 /* GL: one could call get_value instead */
2360 inc_irg_visited(current_ir_graph);
2361 return get_r_value_internal (current_ir_graph->current_block, 0, mode_M);
2364 /* set the current store */
2366 set_store (ir_node *store)
2368 /* GL: one could call set_value instead */
2369 assert(get_irg_phase_state (current_ir_graph) == phase_building);
2370 current_ir_graph->current_block->attr.block.graph_arr[0] = store;
2374 keep_alive (ir_node *ka)
2376 add_End_keepalive(current_ir_graph->end, ka);
2379 /** Useful access routines **/
2380 /* Returns the current block of the current graph. To set the current
2381 block use switch_block(). */
2382 ir_node *get_cur_block() {
2383 return get_irg_current_block(current_ir_graph);
2386 /* Returns the frame type of the current graph */
2387 type *get_cur_frame_type() {
2388 return get_irg_frame_type(current_ir_graph);
2392 /* ********************************************************************* */
2395 /* call once for each run of the library */
2397 init_cons (default_initialize_local_variable_func_t *func)
2399 default_initialize_local_variable = func;
2402 /* call for each graph */
2404 finalize_cons (ir_graph *irg) {
2405 irg->phase_state = phase_high;
2409 ir_node *new_Block(int arity, ir_node **in) {
2410 return new_d_Block(NULL, arity, in);
2412 ir_node *new_Start (void) {
2413 return new_d_Start(NULL);
2415 ir_node *new_End (void) {
2416 return new_d_End(NULL);
2418 ir_node *new_Jmp (void) {
2419 return new_d_Jmp(NULL);
2421 ir_node *new_Cond (ir_node *c) {
2422 return new_d_Cond(NULL, c);
2424 ir_node *new_Return (ir_node *store, int arity, ir_node *in[]) {
2425 return new_d_Return(NULL, store, arity, in);
2427 ir_node *new_Raise (ir_node *store, ir_node *obj) {
2428 return new_d_Raise(NULL, store, obj);
2430 ir_node *new_Const (ir_mode *mode, tarval *con) {
2431 return new_d_Const(NULL, mode, con);
2433 ir_node *new_SymConst (type_or_id_p value, symconst_kind kind) {
2434 return new_d_SymConst(NULL, value, kind);
2436 ir_node *new_simpleSel(ir_node *store, ir_node *objptr, entity *ent) {
2437 return new_d_simpleSel(NULL, store, objptr, ent);
2439 ir_node *new_Sel (ir_node *store, ir_node *objptr, int arity, ir_node **in,
2441 return new_d_Sel(NULL, store, objptr, arity, in, ent);
2443 ir_node *new_InstOf (ir_node *store, ir_node *objptr, type *ent) {
2444 return new_d_InstOf (NULL, store, objptr, ent);
2446 ir_node *new_Call (ir_node *store, ir_node *callee, int arity, ir_node **in,
2448 return new_d_Call(NULL, store, callee, arity, in, tp);
2450 ir_node *new_Add (ir_node *op1, ir_node *op2, ir_mode *mode) {
2451 return new_d_Add(NULL, op1, op2, mode);
2453 ir_node *new_Sub (ir_node *op1, ir_node *op2, ir_mode *mode) {
2454 return new_d_Sub(NULL, op1, op2, mode);
2456 ir_node *new_Minus (ir_node *op, ir_mode *mode) {
2457 return new_d_Minus(NULL, op, mode);
2459 ir_node *new_Mul (ir_node *op1, ir_node *op2, ir_mode *mode) {
2460 return new_d_Mul(NULL, op1, op2, mode);
2462 ir_node *new_Quot (ir_node *memop, ir_node *op1, ir_node *op2) {
2463 return new_d_Quot(NULL, memop, op1, op2);
2465 ir_node *new_DivMod (ir_node *memop, ir_node *op1, ir_node *op2) {
2466 return new_d_DivMod(NULL, memop, op1, op2);
2468 ir_node *new_Div (ir_node *memop, ir_node *op1, ir_node *op2) {
2469 return new_d_Div(NULL, memop, op1, op2);
2471 ir_node *new_Mod (ir_node *memop, ir_node *op1, ir_node *op2) {
2472 return new_d_Mod(NULL, memop, op1, op2);
2474 ir_node *new_Abs (ir_node *op, ir_mode *mode) {
2475 return new_d_Abs(NULL, op, mode);
2477 ir_node *new_And (ir_node *op1, ir_node *op2, ir_mode *mode) {
2478 return new_d_And(NULL, op1, op2, mode);
2480 ir_node *new_Or (ir_node *op1, ir_node *op2, ir_mode *mode) {
2481 return new_d_Or(NULL, op1, op2, mode);
2483 ir_node *new_Eor (ir_node *op1, ir_node *op2, ir_mode *mode) {
2484 return new_d_Eor(NULL, op1, op2, mode);
2486 ir_node *new_Not (ir_node *op, ir_mode *mode) {
2487 return new_d_Not(NULL, op, mode);
2489 ir_node *new_Shl (ir_node *op, ir_node *k, ir_mode *mode) {
2490 return new_d_Shl(NULL, op, k, mode);
2492 ir_node *new_Shr (ir_node *op, ir_node *k, ir_mode *mode) {
2493 return new_d_Shr(NULL, op, k, mode);
2495 ir_node *new_Shrs (ir_node *op, ir_node *k, ir_mode *mode) {
2496 return new_d_Shrs(NULL, op, k, mode);
2498 #define new_Rotate new_Rot
2499 ir_node *new_Rot (ir_node *op, ir_node *k, ir_mode *mode) {
2500 return new_d_Rot(NULL, op, k, mode);
2502 ir_node *new_Cmp (ir_node *op1, ir_node *op2) {
2503 return new_d_Cmp(NULL, op1, op2);
2505 ir_node *new_Conv (ir_node *op, ir_mode *mode) {
2506 return new_d_Conv(NULL, op, mode);
2508 ir_node *new_Cast (ir_node *op, type *to_tp) {
2509 return new_d_Cast(NULL, op, to_tp);
2511 ir_node *new_Phi (int arity, ir_node **in, ir_mode *mode) {
2512 return new_d_Phi(NULL, arity, in, mode);
2514 ir_node *new_Load (ir_node *store, ir_node *addr) {
2515 return new_d_Load(NULL, store, addr);
2517 ir_node *new_Store (ir_node *store, ir_node *addr, ir_node *val) {
2518 return new_d_Store(NULL, store, addr, val);
2520 ir_node *new_Alloc (ir_node *store, ir_node *size, type *alloc_type,
2521 where_alloc where) {
2522 return new_d_Alloc(NULL, store, size, alloc_type, where);
2524 ir_node *new_Free (ir_node *store, ir_node *ptr, ir_node *size,
2526 return new_d_Free(NULL, store, ptr, size, free_type);
2528 ir_node *new_Sync (int arity, ir_node **in) {
2529 return new_d_Sync(NULL, arity, in);
2531 ir_node *new_Proj (ir_node *arg, ir_mode *mode, long proj) {
2532 return new_d_Proj(NULL, arg, mode, proj);
2534 ir_node *new_defaultProj (ir_node *arg, long max_proj) {
2535 return new_d_defaultProj(NULL, arg, max_proj);
2537 ir_node *new_Tuple (int arity, ir_node **in) {
2538 return new_d_Tuple(NULL, arity, in);
2540 ir_node *new_Id (ir_node *val, ir_mode *mode) {
2541 return new_d_Id(NULL, val, mode);
2543 ir_node *new_Bad (void) {
2546 ir_node *new_Confirm (ir_node *val, ir_node *bound, pn_Cmp cmp) {
2547 return new_d_Confirm (NULL, val, bound, cmp);
2549 ir_node *new_Unknown(ir_mode *m) {
2550 return new_d_Unknown(m);
2552 ir_node *new_CallBegin (ir_node *callee) {
2553 return new_d_CallBegin(NULL, callee);
2555 ir_node *new_EndReg (void) {
2556 return new_d_EndReg(NULL);
2558 ir_node *new_EndExcept (void) {
2559 return new_d_EndExcept(NULL);
2561 ir_node *new_Break (void) {
2562 return new_d_Break(NULL);
2564 ir_node *new_Filter (ir_node *arg, ir_mode *mode, long proj) {
2565 return new_d_Filter(NULL, arg, mode, proj);
2567 ir_node *new_FuncCall (ir_node *callee, int arity, ir_node **in, type *tp) {
2568 return new_d_FuncCall(NULL, callee, arity, in, tp);