1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Martin Trapp, Christian Schaefer
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
19 /* memset belongs to string.h */
23 #if USE_EXPICIT_PHI_IN_STACK
24 /* A stack needed for the automatic Phi node construction in constructor
32 /*********************************************** */
33 /** privat interfaces, for professional use only */
35 /* Constructs a Block with a fixed number of predecessors.*/
38 new_r_Block (ir_graph *irg, int arity, ir_node **in)
42 res = new_ir_node (current_ir_graph, NULL, op_Block, mode_R, arity, in);
48 new_r_Start (ir_graph *irg, ir_node *block)
52 res = new_ir_node (irg, block, op_Start, mode_T, 0, NULL);
59 new_r_End (ir_graph *irg, ir_node *block)
63 res = new_ir_node (irg, block, op_End, mode_X, -1, NULL);
69 /* Creates a Phi node with 0 predecessors */
71 new_r_Phi0 (ir_graph *irg, ir_node *block, ir_mode *mode)
75 res = new_ir_node (irg, block, op_Phi, mode, 0, NULL);
77 /* GL I'm not sure whether we should optimize this guy. *
78 res = optimize (res); ??? */
83 /* Creates a Phi node with all predecessors. Calling this constructor
84 is only allowed if the corresponding block is mature. */
86 new_r_Phi (ir_graph *irg, ir_node *block, int arity, ir_node **in, ir_mode *mode)
90 assert( get_Block_matured(block) );
91 assert( get_irn_arity(block) == arity );
93 res = new_ir_node (irg, block, op_Phi, mode, arity, in);
100 /* This is a stack used for allocating and deallocating nodes in
101 new_r_Phi_in. The original implementation used the obstack
102 to model this stack, now it is explicit. This reduces side effects.
104 #if USE_EXPICIT_PHI_IN_STACK
109 res = (Phi_in_stack *) malloc ( sizeof (Phi_in_stack));
111 res->stack = NEW_ARR_F (ir_node *, 1);
117 void free_to_Phi_in_stack(ir_node *phi) {
118 assert(get_irn_opcode(phi) == iro_Phi);
120 if (ARR_LEN(current_ir_graph->Phi_in_stack->stack) ==
121 current_ir_graph->Phi_in_stack->pos)
122 ARR_APP1 (ir_node *, current_ir_graph->Phi_in_stack->stack, phi);
124 current_ir_graph->Phi_in_stack->stack[current_ir_graph->Phi_in_stack->pos] = phi;
126 (current_ir_graph->Phi_in_stack->pos)++;
130 alloc_or_pop_from_Phi_in_stack(ir_graph *irg, ir_node *block, ir_mode *mode,
131 int arity, ir_node **in) {
133 ir_node **stack = current_ir_graph->Phi_in_stack->stack;
134 int pos = current_ir_graph->Phi_in_stack->pos;
138 /* We need to allocate a new node */
139 res = new_ir_node (irg, block, op_Phi, mode, arity, in);
141 /* reuse the old node and initialize it again. */
144 assert (res->kind == k_ir_node);
145 assert (res->op == op_Phi);
150 /* ???!!! How to free the old in array?? */
151 res->in = NEW_ARR_D (ir_node *, irg->obst, (arity+1));
153 memcpy (&res->in[1], in, sizeof (ir_node *) * arity);
155 (current_ir_graph->Phi_in_stack->pos)--;
162 /* Creates a Phi node with a given, fixed array **in of predecessors.
163 If the Phi node is unnecessary, as the same value reaches the block
164 through all control flow paths, it is eliminated and the value
165 returned directly. This constructor is only intended for use in
166 the automatic Phi node generation triggered by get_value or mature.
167 The implementation is quite tricky and depends on the fact, that
168 the nodes are allocated on a stack:
169 The in array contains predecessors and NULLs. The NULLs appear,
170 if get_r_value_internal, that computed the predecessors, reached
171 the same block on two paths. In this case the same value reaches
172 this block on both paths, there is no definition in between. We need
173 not allocate a Phi where these path's merge, but we have to communicate
174 this fact to the caller. This happens by returning a pointer to the
175 node the caller _will_ allocate. (Yes, we predict the address. We can
176 do so because the nodes are allocated on the obstack.) The caller then
177 finds a pointer to itself and, when this routine is called again,
181 new_r_Phi_in (ir_graph *irg, ir_node *block, ir_mode *mode,
182 ir_node **in, int ins)
185 ir_node *res, *known;
187 /* allocate a new node on the obstack.
188 This can return a node to which some of the pointers in the in-array
190 Attention: the constructor copies the in array, i.e., the later changes
191 to the array in this routine do not affect the constructed node! If
192 the in array contains NULLs, there will be missing predecessors in the
194 Is this a possible internal state of the Phi node generation? */
195 #if USE_EXPICIT_PHI_IN_STACK
196 res = known = alloc_or_pop_from_Phi_in_stack(irg, block, mode, ins, in);
198 res = known = new_ir_node (irg, block, op_Phi, mode, ins, in);
200 /* The in-array can contain NULLs. These were returned by get_r_value_internal
201 if it reached the same block/definition on a second path.
202 The NULLs are replaced by the node itself to simplify the test in the
204 for (i=0; i < ins; ++i)
205 if (in[i] == NULL) in[i] = res;
207 /* This loop checks whether the Phi has more than one predecessor.
208 If so, it is a real Phi node and we break the loop. Else the
209 Phi node merges the same definition on several paths and therefore
211 for (i=0; i < ins; ++i)
213 if (in[i]==res || in[i]==known) continue;
221 /* i==ins: there is at most one predecessor, we don't need a phi node. */
223 #if USE_EXPICIT_PHI_IN_STACK
224 free_to_Phi_in_stack(res);
226 obstack_free (current_ir_graph->obst, res);
230 res = optimize (res);
234 /* return the pointer to the Phi node. This node might be deallocated! */
239 new_r_Const (ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con)
242 res = new_ir_node (irg, block, op_Const, mode, 0, NULL);
244 res = optimize (res);
248 res = local_optimize_newby (res);
255 new_r_Id (ir_graph *irg, ir_node *block, ir_node *val, ir_mode *mode)
257 ir_node *in[1] = {val};
259 res = new_ir_node (irg, block, op_Id, mode, 1, in);
260 res = optimize (res);
266 new_r_Proj (ir_graph *irg, ir_node *block, ir_node *arg, ir_mode *mode,
269 ir_node *in[1] = {arg};
271 res = new_ir_node (irg, block, op_Proj, mode, 1, in);
272 res->attr.proj = proj;
275 assert(get_Proj_pred(res));
276 assert(get_nodes_Block(get_Proj_pred(res)));
278 res = optimize (res);
286 new_r_Conv (ir_graph *irg, ir_node *block, ir_node *op, ir_mode *mode)
288 ir_node *in[1] = {op};
290 res = new_ir_node (irg, block, op_Conv, mode, 1, in);
291 res = optimize (res);
298 new_r_Tuple (ir_graph *irg, ir_node *block, int arity, ir_node **in)
302 res = new_ir_node (irg, block, op_Tuple, mode_T, arity, in);
303 res = optimize (res);
309 new_r_Add (ir_graph *irg, ir_node *block,
310 ir_node *op1, ir_node *op2, ir_mode *mode)
312 ir_node *in[2] = {op1, op2};
314 res = new_ir_node (irg, block, op_Add, mode, 2, in);
315 res = optimize (res);
321 new_r_Sub (ir_graph *irg, ir_node *block,
322 ir_node *op1, ir_node *op2, ir_mode *mode)
324 ir_node *in[2] = {op1, op2};
326 res = new_ir_node (irg, block, op_Sub, mode, 2, in);
327 res = optimize (res);
333 new_r_Minus (ir_graph *irg, ir_node *block,
334 ir_node *op, ir_mode *mode)
336 ir_node *in[1] = {op};
338 res = new_ir_node (irg, block, op_Minus, mode, 1, in);
339 res = optimize (res);
345 new_r_Mul (ir_graph *irg, ir_node *block,
346 ir_node *op1, ir_node *op2, ir_mode *mode)
348 ir_node *in[2] = {op1, op2};
350 res = new_ir_node (irg, block, op_Mul, mode, 2, in);
351 res = optimize (res);
357 new_r_Quot (ir_graph *irg, ir_node *block,
358 ir_node *memop, ir_node *op1, ir_node *op2)
360 ir_node *in[3] = {memop, op1, op2};
362 res = new_ir_node (irg, block, op_Quot, mode_T, 3, in);
363 res = optimize (res);
369 new_r_DivMod (ir_graph *irg, ir_node *block,
370 ir_node *memop, ir_node *op1, ir_node *op2)
372 ir_node *in[3] = {memop, op1, op2};
374 res = new_ir_node (irg, block, op_DivMod, mode_T, 3, in);
375 res = optimize (res);
381 new_r_Div (ir_graph *irg, ir_node *block,
382 ir_node *memop, ir_node *op1, ir_node *op2)
384 ir_node *in[3] = {memop, op1, op2};
386 res = new_ir_node (irg, block, op_Div, mode_T, 3, in);
387 res = optimize (res);
393 new_r_Mod (ir_graph *irg, ir_node *block,
394 ir_node *memop, ir_node *op1, ir_node *op2)
396 ir_node *in[3] = {memop, op1, op2};
398 res = new_ir_node (irg, block, op_Mod, mode_T, 3, in);
399 res = optimize (res);
405 new_r_And (ir_graph *irg, ir_node *block,
406 ir_node *op1, ir_node *op2, ir_mode *mode)
408 ir_node *in[2] = {op1, op2};
410 res = new_ir_node (irg, block, op_And, mode, 2, in);
411 res = optimize (res);
417 new_r_Or (ir_graph *irg, ir_node *block,
418 ir_node *op1, ir_node *op2, ir_mode *mode)
420 ir_node *in[2] = {op1, op2};
422 res = new_ir_node (irg, block, op_Or, mode, 2, in);
423 res = optimize (res);
429 new_r_Eor (ir_graph *irg, ir_node *block,
430 ir_node *op1, ir_node *op2, ir_mode *mode)
432 ir_node *in[2] = {op1, op2};
434 res = new_ir_node (irg, block, op_Eor, mode, 2, in);
435 res = optimize (res);
441 new_r_Not (ir_graph *irg, ir_node *block,
442 ir_node *op, ir_mode *mode)
444 ir_node *in[1] = {op};
446 res = new_ir_node (irg, block, op_Not, mode, 1, in);
447 res = optimize (res);
453 new_r_Shl (ir_graph *irg, ir_node *block,
454 ir_node *op, ir_node *k, ir_mode *mode)
456 ir_node *in[2] = {op, k};
458 res = new_ir_node (irg, block, op_Shl, mode, 2, in);
459 res = optimize (res);
465 new_r_Shr (ir_graph *irg, ir_node *block,
466 ir_node *op, ir_node *k, ir_mode *mode)
468 ir_node *in[2] = {op, k};
470 res = new_ir_node (irg, block, op_Shr, mode, 2, in);
471 res = optimize (res);
477 new_r_Shrs (ir_graph *irg, ir_node *block,
478 ir_node *op, ir_node *k, ir_mode *mode)
480 ir_node *in[2] = {op, k};
482 res = new_ir_node (irg, block, op_Shrs, mode, 2, in);
483 res = optimize (res);
489 new_r_Rot (ir_graph *irg, ir_node *block,
490 ir_node *op, ir_node *k, ir_mode *mode)
492 ir_node *in[2] = {op, k};
494 res = new_ir_node (irg, block, op_Rot, mode, 2, in);
495 res = optimize (res);
501 new_r_Abs (ir_graph *irg, ir_node *block,
502 ir_node *op, ir_mode *mode)
504 ir_node *in[1] = {op};
506 res = new_ir_node (irg, block, op_Abs, mode, 1, in);
507 res = optimize (res);
513 new_r_Cmp (ir_graph *irg, ir_node *block,
514 ir_node *op1, ir_node *op2)
516 ir_node *in[2] = {op1, op2};
518 res = new_ir_node (irg, block, op_Cmp, mode_T, 2, in);
519 res = optimize (res);
525 new_r_Jmp (ir_graph *irg, ir_node *block)
529 res = new_ir_node (irg, block, op_Jmp, mode_X, 0, in);
530 res = optimize (res);
536 new_r_Cond (ir_graph *irg, ir_node *block, ir_node *c)
538 ir_node *in[1] = {c};
540 res = new_ir_node (irg, block, op_Cond, mode_T, 1, in);
541 res = optimize (res);
547 new_r_Call (ir_graph *irg, ir_node *block, ir_node *store,
548 ir_node *callee, int arity, ir_node **in, type_method *type)
555 NEW_ARR_A (ir_node *, r_in, r_arity);
558 memcpy (&r_in[2], in, sizeof (ir_node *) * arity);
560 res = new_ir_node (irg, block, op_Call, mode_T, r_arity, r_in);
562 set_Call_type(res, type);
563 res = optimize (res);
569 new_r_Return (ir_graph *irg, ir_node *block,
570 ir_node *store, int arity, ir_node **in)
577 NEW_ARR_A (ir_node *, r_in, r_arity);
579 memcpy (&r_in[1], in, sizeof (ir_node *) * arity);
580 res = new_ir_node (irg, block, op_Return, mode_X, r_arity, r_in);
581 res = optimize (res);
587 new_r_Raise (ir_graph *irg, ir_node *block, ir_node *store, ir_node *obj)
589 ir_node *in[2] = {store, obj};
591 res = new_ir_node (irg, block, op_Raise, mode_X, 2, in);
593 res = optimize (res);
599 new_r_Load (ir_graph *irg, ir_node *block,
600 ir_node *store, ir_node *adr)
602 ir_node *in[2] = {store, adr};
604 res = new_ir_node (irg, block, op_Load, mode_T, 2, in);
606 res = optimize (res);
612 new_r_Store (ir_graph *irg, ir_node *block,
613 ir_node *store, ir_node *adr, ir_node *val)
615 ir_node *in[3] = {store, adr, val};
617 res = new_ir_node (irg, block, op_Store, mode_T, 3, in);
619 res = optimize (res);
625 new_r_Alloc (ir_graph *irg, ir_node *block, ir_node *store,
626 ir_node *size, type *alloc_type, where_alloc where)
628 ir_node *in[2] = {store, size};
630 res = new_ir_node (irg, block, op_Alloc, mode_T, 2, in);
632 res->attr.a.where = where;
633 res->attr.a.type = alloc_type;
635 res = optimize (res);
641 new_r_Free (ir_graph *irg, ir_node *block, ir_node *store,
642 ir_node *ptr, ir_node *size, type *free_type)
644 ir_node *in[3] = {store, ptr, size};
646 res = new_ir_node (irg, block, op_Free, mode_T, 3, in);
648 res->attr.f = free_type;
650 res = optimize (res);
656 new_r_Sel (ir_graph *irg, ir_node *block, ir_node *store, ir_node *objptr,
657 int arity, ir_node **in, entity *ent)
664 NEW_ARR_A (ir_node *, r_in, r_arity);
667 memcpy (&r_in[2], in, sizeof (ir_node *) * arity);
668 res = new_ir_node (irg, block, op_Sel, mode_p, r_arity, r_in);
670 res->attr.s.ltyp = static_linkage;
671 res->attr.s.ent = ent;
673 res = optimize (res);
679 new_r_SymConst (ir_graph *irg, ir_node *block, type_or_id *value,
680 symconst_kind symkind)
684 res = new_ir_node (irg, block, op_SymConst, mode_I, 0, in);
686 res->attr.i.num = symkind;
687 if (symkind == linkage_ptr_info) {
688 res->attr.i.tori.ptrinfo = (ident *)value;
690 assert ( ( (symkind == type_tag)
691 || (symkind == size))
692 && (is_type(value)));
693 res->attr.i.tori.typ = (type *)value;
695 res = optimize (res);
701 new_r_Sync (ir_graph *irg, ir_node *block, int arity, ir_node **in)
705 res = new_ir_node (irg, block, op_Sync, mode_M, arity, in);
707 res = optimize (res);
713 new_r_Bad (ir_node *block)
715 return current_ir_graph->bad;
718 /***********************/
719 /** public interfaces */
720 /** construction tools */
727 res = new_ir_node (current_ir_graph, current_ir_graph->current_block,
728 op_Start, mode_T, 0, NULL);
730 res = optimize (res);
740 res = new_ir_node (current_ir_graph, current_ir_graph->current_block,
741 op_End, mode_X, -1, NULL);
743 res = optimize (res);
753 res = new_ir_node (current_ir_graph, NULL, op_Block, mode_R, -1, NULL);
754 current_ir_graph->current_block = res;
755 res->attr.block.matured = 0;
756 set_Block_block_visit(res, 0);
758 /* forget this optimization. use this only if mature !!!!
759 res = optimize (res); */
762 /** create a new dynamic array, which stores all parameters in irnodes */
763 /** using the same obstack as the whole irgraph */
764 res->attr.block.graph_arr = NEW_ARR_D (ir_node *, current_ir_graph->obst,
765 current_ir_graph->params);
767 /** initialize the parameter array */
768 memset(res->attr.block.graph_arr, 0, sizeof(ir_node *)*current_ir_graph->params);
774 get_r_value_internal (ir_node *block, int pos, ir_mode *mode);
776 /** This function computes the predecessors for a real Phi node, and then
777 allocates and returns this node. The routine called to allocate the
778 node might optimize it away and return a real value, or even a pointer
779 to a deallocated Phi node on top of the obstack!
780 This function is called with an in-array of proper size. **/
781 static inline ir_node *
782 phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
784 ir_node *prevBlock, *res;
787 /* This loop goes to all predecessor blocks of the block the Phi node is in
788 and there finds the operands of the Phi node by calling
789 get_r_value_internal. */
790 for (i = 1; i <= ins; ++i) {
791 assert (block->in[i]);
792 prevBlock = block->in[i]->in[0]; /* go past control flow op to prev block */
794 nin[i-1] = get_r_value_internal (prevBlock, pos, mode);
797 /* After collecting all predecessors into the array nin a new Phi node
798 with these predecessors is created. This constructor contains an
799 optimization: If all predecessors of the Phi node are identical it
800 returns the only operand instead of a new Phi node. If the value
801 passes two different control flow edges without being defined, and
802 this is the second path treated, a pointer to the node that will be
803 allocated for the first path (recurstion) is returned. We already
804 know the address of this node, as it is the next node to be allocated
805 and will be placed on top of the obstack. (The obstack is a _stack_!) */
806 res = new_r_Phi_in (current_ir_graph, block, mode, nin, ins);
808 /* Now we now the value "pos" and can enter it in the array with
809 all known local variables. Attention: this might be a pointer to
810 a node, that later will be allocated!!! See new_r_Phi_in.
811 If this is called in mature, after some set_value in the same block,
812 the proper value must not be overwritten:
814 get_value (makes Phi0, put's it into graph_arr)
815 set_value (overwrites Phi0 in graph_arr)
816 mature_block (upgrades Phi0, puts it again into graph_arr, overwriting
819 if (!block->attr.block.graph_arr[pos]) {
820 block->attr.block.graph_arr[pos] = res;
822 // printf(" value already computed by %s\n",
823 // id_to_str(block->attr.block.graph_arr[pos]->op->name));
829 /* This function returns the last definition of a variable. In case
830 this variable was last defined in a previous block, Phi nodes are
831 inserted. If the part of the firm graph containing the definition
832 is not yet constructed, a dummy Phi node is returned. */
834 get_r_value_internal (ir_node *block, int pos, ir_mode *mode)
837 /* There are 4 cases to treat.
839 1. The block is not mature and we visit it the first time. We can not
840 create a proper Phi node, therefore a Phi0, i.e., a Phi without
841 predecessors is returned. This node is added to the linked list (field
842 "link") of the containing block to be completed when this block is
843 matured. (Comlpletion will add a new Phi and turn the Phi0 into a Id
846 2. The value is already known in this block, graph_arr[pos] is set and we
847 visit the block the first time. We can return the value without
848 creating any new nodes.
850 3. The block is mature and we visit it the first time. A Phi node needs
851 to be created (phi_merge). If the Phi is not needed, as all it's
852 operands are the same value reaching the block through different
853 paths, it's optimizes away and the value itself is returned.
855 4. The block is mature, and we visit it the second time. Now two
856 subcases are possible:
857 * The value was computed completely the last time we were here.
858 This is the case if there is no loop. We can return the proper value.
859 * The recursion that visited this node and set the flag did not
860 return yet. We are computing a value in a loop and need to
861 break the recursion without knowing the result yet.
862 There is no simple check for the second subcase. Therefore we check
863 for a second visit and treat all such cases as the second subcase.
864 Anyways, the basic situation is the same: we reached a block
865 on two paths without finding a definition of the value: No Phi
866 nodes are needed on both paths.
867 We return this information "Two paths, no Phi needed" by a very tricky
868 implementation that relies on the fact that an obstack is a stack and
869 will return a node with the same address on different allocations.
870 Look also at phi_merge and get_r_phi_in to understand this.
873 /* case 4 -- already visited. */
874 if (get_irn_visited(block) == get_irg_visited(current_ir_graph)) return NULL;
876 /* visited the first time */
877 set_irn_visited(block, get_irg_visited(current_ir_graph));
879 /* Get the local valid value */
880 res = block->attr.block.graph_arr[pos];
882 /* case 2 -- If the value is actually computed, return it. */
883 if (res) { return res;};
885 if (block->attr.block.matured) { /* case 3 */
887 /* The Phi has the same amount of ins as the corresponding block. */
888 int ins = get_irn_arity(block); // ARR_LEN (block->in)-1;
890 NEW_ARR_A (ir_node *, nin, ins);
892 /* Phi merge collects the predecessors and then creates a node. */
893 res = phi_merge (block, pos, mode, nin, ins);
895 } else { /* case 1 */
896 /* The block is not mature, we don't know how many in's are needed. A Phi
897 with zero predecessors is created. Such a Phi node is called Phi0
898 node. (There is also an obsolete Phi0 opcode.) The Phi0 is then added
899 to the list of Phi0 nodes in this block to be matured by mature_block
901 The Phi0 has to remember the pos of it's internal value. If the real
902 Phi is computed, pos is used to update the array with the local
905 res = new_r_Phi0 (current_ir_graph, block, mode);
906 res->attr.phi0_pos = pos;
907 res->link = block->link;
911 /* If we get here, the frontend missed a use-before-definition error */
914 printf("Error: no value set\n");
915 assert (mode->code >= irm_f && mode->code <= irm_p);
916 res = new_r_Const (current_ir_graph, block, mode,
917 tarval_mode_null[mode->code]);
920 /* The local valid value is available now. */
921 block->attr.block.graph_arr[pos] = res;
926 /** Finalize a Block node, when all control flows are known. */
927 /** Acceptable parameters are only Block nodes. */
929 mature_block (ir_node *block)
936 assert (get_irn_opcode(block) == iro_Block);
938 if (!get_Block_matured(block)) {
940 /* turn the dynamic in-array into a static one. */
941 ins = ARR_LEN (block->in)-1;
942 NEW_ARR_A (ir_node *, nin, ins);
944 /* Traverse a chain of Phi nodes attached to this block and mature
946 for (n = block->link; n; n=next) {
947 inc_irg_visited(current_ir_graph);
949 exchange (n, phi_merge (block, n->attr.phi0_pos, n->mode, nin, ins));
952 block->attr.block.matured = 1;
954 block = optimize_in_place(block);
961 new_Phi (int arity, ir_node **in, ir_mode *mode)
963 return new_r_Phi (current_ir_graph, current_ir_graph->current_block,
968 new_Const (ir_mode *mode, tarval *con)
970 return new_r_Const (current_ir_graph, current_ir_graph->start_block,
975 new_Id (ir_node *val, ir_mode *mode)
977 return new_r_Id (current_ir_graph, current_ir_graph->current_block,
982 new_Proj (ir_node *arg, ir_mode *mode, long proj)
984 return new_r_Proj (current_ir_graph, current_ir_graph->current_block,
989 new_Conv (ir_node *op, ir_mode *mode)
991 return new_r_Conv (current_ir_graph, current_ir_graph->current_block,
996 new_Tuple (int arity, ir_node **in)
998 return new_r_Tuple (current_ir_graph, current_ir_graph->current_block,
1003 new_Add (ir_node *op1, ir_node *op2, ir_mode *mode)
1005 return new_r_Add (current_ir_graph, current_ir_graph->current_block,
1010 new_Sub (ir_node *op1, ir_node *op2, ir_mode *mode)
1012 return new_r_Sub (current_ir_graph, current_ir_graph->current_block,
1018 new_Minus (ir_node *op, ir_mode *mode)
1020 return new_r_Minus (current_ir_graph, current_ir_graph->current_block,
1025 new_Mul (ir_node *op1, ir_node *op2, ir_mode *mode)
1027 return new_r_Mul (current_ir_graph, current_ir_graph->current_block,
1032 new_Quot (ir_node *memop, ir_node *op1, ir_node *op2)
1034 return new_r_Quot (current_ir_graph, current_ir_graph->current_block,
1039 new_DivMod (ir_node *memop, ir_node *op1, ir_node *op2)
1041 return new_r_DivMod (current_ir_graph, current_ir_graph->current_block,
1046 new_Div (ir_node *memop, ir_node *op1, ir_node *op2)
1048 return new_r_Div (current_ir_graph, current_ir_graph->current_block,
1053 new_Mod (ir_node *memop, ir_node *op1, ir_node *op2)
1055 return new_r_Mod (current_ir_graph, current_ir_graph->current_block,
1060 new_And (ir_node *op1, ir_node *op2, ir_mode *mode)
1062 return new_r_And (current_ir_graph, current_ir_graph->current_block,
1067 new_Or (ir_node *op1, ir_node *op2, ir_mode *mode)
1069 return new_r_Or (current_ir_graph, current_ir_graph->current_block,
1074 new_Eor (ir_node *op1, ir_node *op2, ir_mode *mode)
1076 return new_r_Eor (current_ir_graph, current_ir_graph->current_block,
1081 new_Not (ir_node *op, ir_mode *mode)
1083 return new_r_Not (current_ir_graph, current_ir_graph->current_block,
1088 new_Shl (ir_node *op, ir_node *k, ir_mode *mode)
1090 return new_r_Shl (current_ir_graph, current_ir_graph->current_block,
1095 new_Shr (ir_node *op, ir_node *k, ir_mode *mode)
1097 return new_r_Shr (current_ir_graph, current_ir_graph->current_block,
1102 new_Shrs (ir_node *op, ir_node *k, ir_mode *mode)
1104 return new_r_Shrs (current_ir_graph, current_ir_graph->current_block,
1109 new_Rotate (ir_node *op, ir_node *k, ir_mode *mode)
1111 return new_r_Rot (current_ir_graph, current_ir_graph->current_block,
1116 new_Abs (ir_node *op, ir_mode *mode)
1118 return new_r_Abs (current_ir_graph, current_ir_graph->current_block,
1123 new_Cmp (ir_node *op1, ir_node *op2)
1125 return new_r_Cmp (current_ir_graph, current_ir_graph->current_block,
1132 return new_r_Jmp (current_ir_graph, current_ir_graph->current_block);
1136 new_Cond (ir_node *c)
1138 return new_r_Cond (current_ir_graph, current_ir_graph->current_block, c);
1142 new_Call (ir_node *store, ir_node *callee, int arity, ir_node **in,
1145 return new_r_Call (current_ir_graph, current_ir_graph->current_block,
1146 store, callee, arity, in, type);
1150 new_Return (ir_node* store, int arity, ir_node **in)
1152 return new_r_Return (current_ir_graph, current_ir_graph->current_block,
1157 new_Raise (ir_node *store, ir_node *obj)
1159 return new_r_Raise (current_ir_graph, current_ir_graph->current_block,
1164 new_Load (ir_node *store, ir_node *addr)
1166 return new_r_Load (current_ir_graph, current_ir_graph->current_block,
1171 new_Store (ir_node *store, ir_node *addr, ir_node *val)
1173 return new_r_Store (current_ir_graph, current_ir_graph->current_block,
1178 new_Alloc (ir_node *store, ir_node *size, type *alloc_type,
1181 return new_r_Alloc (current_ir_graph, current_ir_graph->current_block,
1182 store, size, alloc_type, where);
1186 new_Free (ir_node *store, ir_node *ptr, ir_node *size, type *free_type)
1188 return new_r_Free (current_ir_graph, current_ir_graph->current_block,
1189 store, ptr, size, free_type);
1193 new_simpleSel (ir_node *store, ir_node *objptr, entity *ent)
1194 /* GL: objptr was called frame before. Frame was a bad choice for the name
1195 as the operand could as well be a pointer to a dynamic object. */
1197 return new_r_Sel (current_ir_graph, current_ir_graph->current_block,
1198 store, objptr, 0, NULL, ent);
1202 new_Sel (ir_node *store, ir_node *objptr, int n_index, ir_node **index, entity *sel)
1204 return new_r_Sel (current_ir_graph, current_ir_graph->current_block,
1205 store, objptr, n_index, index, sel);
1209 new_SymConst (type_or_id *value, symconst_kind kind)
1211 return new_r_SymConst (current_ir_graph, current_ir_graph->current_block,
1216 new_Sync (int arity, ir_node** in)
1218 return new_r_Sync (current_ir_graph, current_ir_graph->current_block,
1226 return current_ir_graph->bad;
1229 /*************************************************************************/
1230 /* Comfortable interface with automatic Phi node construction. */
1231 /* (Uses also constructors of ?? interface, except new_Block. */
1232 /* add an adge to a jmp node */
1234 add_in_edge (ir_node *block, ir_node *jmp)
1236 if (block->attr.block.matured) {
1237 printf("Error: Block already matured!\n");
1240 assert (jmp != NULL);
1241 ARR_APP1 (ir_node *, block->in, jmp);
1245 /* changing the current block */
1247 switch_block (ir_node *target)
1249 current_ir_graph->current_block = target;
1252 /****************************/
1253 /* parameter administration */
1255 /* get a value from the parameter array from the current block by its index */
1257 get_value (int pos, ir_mode *mode)
1259 inc_irg_visited(current_ir_graph);
1260 return get_r_value_internal (current_ir_graph->current_block, pos + 1, mode);
1263 /* set a value at position pos in the parameter array from the current block */
1265 set_value (int pos, ir_node *value)
1267 current_ir_graph->current_block->attr.block.graph_arr[pos + 1] = value;
1270 /* get the current store */
1274 /* GL: one could call get_value instead */
1275 inc_irg_visited(current_ir_graph);
1276 return get_r_value_internal (current_ir_graph->current_block, 0, mode_M);
1279 /* set the current store */
1281 set_store (ir_node *store)
1283 /* GL: one could call set_value instead */
1284 current_ir_graph->current_block->attr.block.graph_arr[0] = store;
1287 /*************************************************************************/
1290 /* call once for each run of the library */