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);
49 new_r_Start (ir_graph *irg, ir_node *block)
53 res = new_ir_node (irg, block, op_Start, mode_T, 0, NULL);
60 new_r_End (ir_graph *irg, ir_node *block)
64 res = new_ir_node (irg, block, op_End, mode_X, -1, NULL);
70 /* Creates a Phi node with 0 predecessors */
72 new_r_Phi0 (ir_graph *irg, ir_node *block, ir_mode *mode)
76 res = new_ir_node (irg, block, op_Phi, mode, 0, NULL);
78 /* GL I'm not sure whether we should optimize this guy. *
79 res = optimize (res); ??? */
84 /* Creates a Phi node with all predecessors. Calling this constructor
85 is only allowed if the corresponding block is mature. */
87 new_r_Phi (ir_graph *irg, ir_node *block, int arity, ir_node **in, ir_mode *mode)
91 assert( get_Block_matured(block) );
92 assert( get_irn_arity(block) == arity );
94 res = new_ir_node (irg, block, op_Phi, mode, arity, in);
101 /* This is a stack used for allocating and deallocating nodes in
102 new_r_Phi_in. The original implementation used the obstack
103 to model this stack, now it is explicit. This reduces side effects.
105 #if USE_EXPICIT_PHI_IN_STACK
110 res = (Phi_in_stack *) malloc ( sizeof (Phi_in_stack));
112 res->stack = NEW_ARR_F (ir_node *, 1);
118 void free_to_Phi_in_stack(ir_node *phi) {
119 assert(get_irn_opcode(phi) == iro_Phi);
121 if (ARR_LEN(current_ir_graph->Phi_in_stack->stack) ==
122 current_ir_graph->Phi_in_stack->pos)
123 ARR_APP1 (ir_node *, current_ir_graph->Phi_in_stack->stack, phi);
125 current_ir_graph->Phi_in_stack->stack[current_ir_graph->Phi_in_stack->pos] = phi;
127 (current_ir_graph->Phi_in_stack->pos)++;
131 alloc_or_pop_from_Phi_in_stack(ir_graph *irg, ir_node *block, ir_mode *mode,
132 int arity, ir_node **in) {
134 ir_node **stack = current_ir_graph->Phi_in_stack->stack;
135 int pos = current_ir_graph->Phi_in_stack->pos;
139 /* We need to allocate a new node */
140 res = new_ir_node (irg, block, op_Phi, mode, arity, in);
142 /* reuse the old node and initialize it again. */
145 assert (res->kind == k_ir_node);
146 assert (res->op == op_Phi);
151 /* ???!!! How to free the old in array?? */
152 res->in = NEW_ARR_D (ir_node *, irg->obst, (arity+1));
154 memcpy (&res->in[1], in, sizeof (ir_node *) * arity);
156 (current_ir_graph->Phi_in_stack->pos)--;
163 /* Creates a Phi node with a given, fixed array **in of predecessors.
164 If the Phi node is unnecessary, as the same value reaches the block
165 through all control flow paths, it is eliminated and the value
166 returned directly. This constructor is only intended for use in
167 the automatic Phi node generation triggered by get_value or mature.
168 The implementation is quite tricky and depends on the fact, that
169 the nodes are allocated on a stack:
170 The in array contains predecessors and NULLs. The NULLs appear,
171 if get_r_value_internal, that computed the predecessors, reached
172 the same block on two paths. In this case the same value reaches
173 this block on both paths, there is no definition in between. We need
174 not allocate a Phi where these path's merge, but we have to communicate
175 this fact to the caller. This happens by returning a pointer to the
176 node the caller _will_ allocate. (Yes, we predict the address. We can
177 do so because the nodes are allocated on the obstack.) The caller then
178 finds a pointer to itself and, when this routine is called again,
182 new_r_Phi_in (ir_graph *irg, ir_node *block, ir_mode *mode,
183 ir_node **in, int ins)
186 ir_node *res, *known;
188 /* allocate a new node on the obstack.
189 This can return a node to which some of the pointers in the in-array
191 Attention: the constructor copies the in array, i.e., the later changes
192 to the array in this routine do not affect the constructed node! If
193 the in array contains NULLs, there will be missing predecessors in the
195 Is this a possible internal state of the Phi node generation? */
196 #if USE_EXPICIT_PHI_IN_STACK
197 res = known = alloc_or_pop_from_Phi_in_stack(irg, block, mode, ins, in);
199 res = known = new_ir_node (irg, block, op_Phi, mode, ins, in);
201 /* The in-array can contain NULLs. These were returned by
202 get_r_value_internal if it reached the same block/definition on a
204 The NULLs are replaced by the node itself to simplify the test in the
206 for (i=0; i < ins; ++i)
207 if (in[i] == NULL) in[i] = res;
209 /* This loop checks whether the Phi has more than one predecessor.
210 If so, it is a real Phi node and we break the loop. Else the
211 Phi node merges the same definition on several paths and therefore
213 for (i=0; i < ins; ++i)
215 if (in[i]==res || in[i]==known) continue;
223 /* i==ins: there is at most one predecessor, we don't need a phi node. */
225 #if USE_EXPICIT_PHI_IN_STACK
226 free_to_Phi_in_stack(res);
228 obstack_free (current_ir_graph->obst, res);
232 res = optimize (res);
236 /* return the pointer to the Phi node. This node might be deallocated! */
241 new_r_Const (ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con)
244 res = new_ir_node (irg, block, op_Const, mode, 0, NULL);
246 res = optimize (res);
250 res = local_optimize_newby (res);
257 new_r_Id (ir_graph *irg, ir_node *block, ir_node *val, ir_mode *mode)
259 ir_node *in[1] = {val};
261 res = new_ir_node (irg, block, op_Id, mode, 1, in);
262 res = optimize (res);
268 new_r_Proj (ir_graph *irg, ir_node *block, ir_node *arg, ir_mode *mode,
271 ir_node *in[1] = {arg};
273 res = new_ir_node (irg, block, op_Proj, mode, 1, in);
274 res->attr.proj = proj;
277 assert(get_Proj_pred(res));
278 assert(get_nodes_Block(get_Proj_pred(res)));
280 res = optimize (res);
288 new_r_Conv (ir_graph *irg, ir_node *block, ir_node *op, ir_mode *mode)
290 ir_node *in[1] = {op};
292 res = new_ir_node (irg, block, op_Conv, mode, 1, in);
293 res = optimize (res);
300 new_r_Tuple (ir_graph *irg, ir_node *block, int arity, ir_node **in)
304 res = new_ir_node (irg, block, op_Tuple, mode_T, arity, in);
305 res = optimize (res);
311 new_r_Add (ir_graph *irg, ir_node *block,
312 ir_node *op1, ir_node *op2, ir_mode *mode)
314 ir_node *in[2] = {op1, op2};
316 res = new_ir_node (irg, block, op_Add, mode, 2, in);
317 res = optimize (res);
323 new_r_Sub (ir_graph *irg, ir_node *block,
324 ir_node *op1, ir_node *op2, ir_mode *mode)
326 ir_node *in[2] = {op1, op2};
328 res = new_ir_node (irg, block, op_Sub, mode, 2, in);
329 res = optimize (res);
335 new_r_Minus (ir_graph *irg, ir_node *block,
336 ir_node *op, ir_mode *mode)
338 ir_node *in[1] = {op};
340 res = new_ir_node (irg, block, op_Minus, mode, 1, in);
341 res = optimize (res);
347 new_r_Mul (ir_graph *irg, ir_node *block,
348 ir_node *op1, ir_node *op2, ir_mode *mode)
350 ir_node *in[2] = {op1, op2};
352 res = new_ir_node (irg, block, op_Mul, mode, 2, in);
353 res = optimize (res);
359 new_r_Quot (ir_graph *irg, ir_node *block,
360 ir_node *memop, ir_node *op1, ir_node *op2)
362 ir_node *in[3] = {memop, op1, op2};
364 res = new_ir_node (irg, block, op_Quot, mode_T, 3, in);
365 res = optimize (res);
371 new_r_DivMod (ir_graph *irg, ir_node *block,
372 ir_node *memop, ir_node *op1, ir_node *op2)
374 ir_node *in[3] = {memop, op1, op2};
376 res = new_ir_node (irg, block, op_DivMod, mode_T, 3, in);
377 res = optimize (res);
383 new_r_Div (ir_graph *irg, ir_node *block,
384 ir_node *memop, ir_node *op1, ir_node *op2)
386 ir_node *in[3] = {memop, op1, op2};
388 res = new_ir_node (irg, block, op_Div, mode_T, 3, in);
389 res = optimize (res);
395 new_r_Mod (ir_graph *irg, ir_node *block,
396 ir_node *memop, ir_node *op1, ir_node *op2)
398 ir_node *in[3] = {memop, op1, op2};
400 res = new_ir_node (irg, block, op_Mod, mode_T, 3, in);
401 res = optimize (res);
407 new_r_And (ir_graph *irg, ir_node *block,
408 ir_node *op1, ir_node *op2, ir_mode *mode)
410 ir_node *in[2] = {op1, op2};
412 res = new_ir_node (irg, block, op_And, mode, 2, in);
413 res = optimize (res);
419 new_r_Or (ir_graph *irg, ir_node *block,
420 ir_node *op1, ir_node *op2, ir_mode *mode)
422 ir_node *in[2] = {op1, op2};
424 res = new_ir_node (irg, block, op_Or, mode, 2, in);
425 res = optimize (res);
431 new_r_Eor (ir_graph *irg, ir_node *block,
432 ir_node *op1, ir_node *op2, ir_mode *mode)
434 ir_node *in[2] = {op1, op2};
436 res = new_ir_node (irg, block, op_Eor, mode, 2, in);
437 res = optimize (res);
443 new_r_Not (ir_graph *irg, ir_node *block,
444 ir_node *op, ir_mode *mode)
446 ir_node *in[1] = {op};
448 res = new_ir_node (irg, block, op_Not, mode, 1, in);
449 res = optimize (res);
455 new_r_Shl (ir_graph *irg, ir_node *block,
456 ir_node *op, ir_node *k, ir_mode *mode)
458 ir_node *in[2] = {op, k};
460 res = new_ir_node (irg, block, op_Shl, mode, 2, in);
461 res = optimize (res);
467 new_r_Shr (ir_graph *irg, ir_node *block,
468 ir_node *op, ir_node *k, ir_mode *mode)
470 ir_node *in[2] = {op, k};
472 res = new_ir_node (irg, block, op_Shr, mode, 2, in);
473 res = optimize (res);
479 new_r_Shrs (ir_graph *irg, ir_node *block,
480 ir_node *op, ir_node *k, ir_mode *mode)
482 ir_node *in[2] = {op, k};
484 res = new_ir_node (irg, block, op_Shrs, mode, 2, in);
485 res = optimize (res);
491 new_r_Rot (ir_graph *irg, ir_node *block,
492 ir_node *op, ir_node *k, ir_mode *mode)
494 ir_node *in[2] = {op, k};
496 res = new_ir_node (irg, block, op_Rot, mode, 2, in);
497 res = optimize (res);
503 new_r_Abs (ir_graph *irg, ir_node *block,
504 ir_node *op, ir_mode *mode)
506 ir_node *in[1] = {op};
508 res = new_ir_node (irg, block, op_Abs, mode, 1, in);
509 res = optimize (res);
515 new_r_Cmp (ir_graph *irg, ir_node *block,
516 ir_node *op1, ir_node *op2)
518 ir_node *in[2] = {op1, op2};
520 res = new_ir_node (irg, block, op_Cmp, mode_T, 2, in);
521 res = optimize (res);
527 new_r_Jmp (ir_graph *irg, ir_node *block)
531 res = new_ir_node (irg, block, op_Jmp, mode_X, 0, in);
532 res = optimize (res);
538 new_r_Cond (ir_graph *irg, ir_node *block, ir_node *c)
540 ir_node *in[1] = {c};
542 res = new_ir_node (irg, block, op_Cond, mode_T, 1, in);
543 res = optimize (res);
549 new_r_Call (ir_graph *irg, ir_node *block, ir_node *store,
550 ir_node *callee, int arity, ir_node **in, type_method *type)
557 NEW_ARR_A (ir_node *, r_in, r_arity);
560 memcpy (&r_in[2], in, sizeof (ir_node *) * arity);
562 res = new_ir_node (irg, block, op_Call, mode_T, r_arity, r_in);
564 set_Call_type(res, type);
565 res = optimize (res);
571 new_r_Return (ir_graph *irg, ir_node *block,
572 ir_node *store, int arity, ir_node **in)
579 NEW_ARR_A (ir_node *, r_in, r_arity);
581 memcpy (&r_in[1], in, sizeof (ir_node *) * arity);
582 res = new_ir_node (irg, block, op_Return, mode_X, r_arity, r_in);
583 res = optimize (res);
589 new_r_Raise (ir_graph *irg, ir_node *block, ir_node *store, ir_node *obj)
591 ir_node *in[2] = {store, obj};
593 res = new_ir_node (irg, block, op_Raise, mode_X, 2, in);
595 res = optimize (res);
601 new_r_Load (ir_graph *irg, ir_node *block,
602 ir_node *store, ir_node *adr)
604 ir_node *in[2] = {store, adr};
606 res = new_ir_node (irg, block, op_Load, mode_T, 2, in);
608 res = optimize (res);
614 new_r_Store (ir_graph *irg, ir_node *block,
615 ir_node *store, ir_node *adr, ir_node *val)
617 ir_node *in[3] = {store, adr, val};
619 res = new_ir_node (irg, block, op_Store, mode_T, 3, in);
621 res = optimize (res);
627 new_r_Alloc (ir_graph *irg, ir_node *block, ir_node *store,
628 ir_node *size, type *alloc_type, where_alloc where)
630 ir_node *in[2] = {store, size};
632 res = new_ir_node (irg, block, op_Alloc, mode_T, 2, in);
634 res->attr.a.where = where;
635 res->attr.a.type = alloc_type;
637 res = optimize (res);
643 new_r_Free (ir_graph *irg, ir_node *block, ir_node *store,
644 ir_node *ptr, ir_node *size, type *free_type)
646 ir_node *in[3] = {store, ptr, size};
648 res = new_ir_node (irg, block, op_Free, mode_T, 3, in);
650 res->attr.f = free_type;
652 res = optimize (res);
658 new_r_Sel (ir_graph *irg, ir_node *block, ir_node *store, ir_node *objptr,
659 int arity, ir_node **in, entity *ent)
666 NEW_ARR_A (ir_node *, r_in, r_arity);
669 memcpy (&r_in[2], in, sizeof (ir_node *) * arity);
670 res = new_ir_node (irg, block, op_Sel, mode_p, r_arity, r_in);
672 res->attr.s.ltyp = static_linkage;
673 res->attr.s.ent = ent;
675 res = optimize (res);
681 new_r_SymConst (ir_graph *irg, ir_node *block, type_or_id *value,
682 symconst_kind symkind)
686 res = new_ir_node (irg, block, op_SymConst, mode_I, 0, in);
688 res->attr.i.num = symkind;
689 if (symkind == linkage_ptr_info) {
690 res->attr.i.tori.ptrinfo = (ident *)value;
692 assert ( ( (symkind == type_tag)
693 || (symkind == size))
694 && (is_type(value)));
695 res->attr.i.tori.typ = (type *)value;
697 res = optimize (res);
703 new_r_Sync (ir_graph *irg, ir_node *block, int arity, ir_node **in)
707 res = new_ir_node (irg, block, op_Sync, mode_M, arity, in);
709 res = optimize (res);
717 return current_ir_graph->bad;
720 /***********************/
721 /** public interfaces */
722 /** construction tools */
729 res = new_ir_node (current_ir_graph, current_ir_graph->current_block,
730 op_Start, mode_T, 0, NULL);
732 res = optimize (res);
742 res = new_ir_node (current_ir_graph, current_ir_graph->current_block,
743 op_End, mode_X, -1, NULL);
745 res = optimize (res);
756 res = new_ir_node (current_ir_graph, NULL, op_Block, mode_R, -1, NULL);
757 current_ir_graph->current_block = res;
758 res->attr.block.matured = 0;
759 set_Block_block_visited(res, 0);
761 /* forget this optimization. use this only if mature !!!!
762 res = optimize (res); */
765 /** create a new dynamic array, which stores all parameters in irnodes */
766 /** using the same obstack as the whole irgraph */
767 res->attr.block.graph_arr = NEW_ARR_D (ir_node *, current_ir_graph->obst,
768 current_ir_graph->params);
770 /** initialize the parameter array */
771 memset(res->attr.block.graph_arr, 0, sizeof(ir_node *)*current_ir_graph->params);
777 get_r_value_internal (ir_node *block, int pos, ir_mode *mode);
779 /** This function computes the predecessors for a real Phi node, and then
780 allocates and returns this node. The routine called to allocate the
781 node might optimize it away and return a real value, or even a pointer
782 to a deallocated Phi node on top of the obstack!
783 This function is called with an in-array of proper size. **/
784 static inline ir_node *
785 phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
787 ir_node *prevBlock, *res;
790 /* This loop goes to all predecessor blocks of the block the Phi node is in
791 and there finds the operands of the Phi node by calling
792 get_r_value_internal. */
793 for (i = 1; i <= ins; ++i) {
794 assert (block->in[i]);
795 prevBlock = block->in[i]->in[0]; /* go past control flow op to prev block */
797 nin[i-1] = get_r_value_internal (prevBlock, pos, mode);
800 /* After collecting all predecessors into the array nin a new Phi node
801 with these predecessors is created. This constructor contains an
802 optimization: If all predecessors of the Phi node are identical it
803 returns the only operand instead of a new Phi node. If the value
804 passes two different control flow edges without being defined, and
805 this is the second path treated, a pointer to the node that will be
806 allocated for the first path (recurstion) is returned. We already
807 know the address of this node, as it is the next node to be allocated
808 and will be placed on top of the obstack. (The obstack is a _stack_!) */
809 res = new_r_Phi_in (current_ir_graph, block, mode, nin, ins);
811 /* Now we now the value "pos" and can enter it in the array with
812 all known local variables. Attention: this might be a pointer to
813 a node, that later will be allocated!!! See new_r_Phi_in.
814 If this is called in mature, after some set_value in the same block,
815 the proper value must not be overwritten:
817 get_value (makes Phi0, put's it into graph_arr)
818 set_value (overwrites Phi0 in graph_arr)
819 mature_block (upgrades Phi0, puts it again into graph_arr, overwriting
822 if (!block->attr.block.graph_arr[pos]) {
823 block->attr.block.graph_arr[pos] = res;
825 // printf(" value already computed by %s\n",
826 // id_to_str(block->attr.block.graph_arr[pos]->op->name));
832 /* This function returns the last definition of a variable. In case
833 this variable was last defined in a previous block, Phi nodes are
834 inserted. If the part of the firm graph containing the definition
835 is not yet constructed, a dummy Phi node is returned. */
837 get_r_value_internal (ir_node *block, int pos, ir_mode *mode)
840 /* There are 4 cases to treat.
842 1. The block is not mature and we visit it the first time. We can not
843 create a proper Phi node, therefore a Phi0, i.e., a Phi without
844 predecessors is returned. This node is added to the linked list (field
845 "link") of the containing block to be completed when this block is
846 matured. (Comlpletion will add a new Phi and turn the Phi0 into a Id
849 2. The value is already known in this block, graph_arr[pos] is set and we
850 visit the block the first time. We can return the value without
851 creating any new nodes.
853 3. The block is mature and we visit it the first time. A Phi node needs
854 to be created (phi_merge). If the Phi is not needed, as all it's
855 operands are the same value reaching the block through different
856 paths, it's optimizes away and the value itself is returned.
858 4. The block is mature, and we visit it the second time. Now two
859 subcases are possible:
860 * The value was computed completely the last time we were here.
861 This is the case if there is no loop. We can return the proper value.
862 * The recursion that visited this node and set the flag did not
863 return yet. We are computing a value in a loop and need to
864 break the recursion without knowing the result yet.
865 There is no simple check for the second subcase. Therefore we check
866 for a second visit and treat all such cases as the second subcase.
867 Anyways, the basic situation is the same: we reached a block
868 on two paths without finding a definition of the value: No Phi
869 nodes are needed on both paths.
870 We return this information "Two paths, no Phi needed" by a very tricky
871 implementation that relies on the fact that an obstack is a stack and
872 will return a node with the same address on different allocations.
873 Look also at phi_merge and get_r_phi_in to understand this.
876 /* case 4 -- already visited. */
877 if (get_irn_visited(block) == get_irg_visited(current_ir_graph)) return NULL;
879 /* visited the first time */
880 set_irn_visited(block, get_irg_visited(current_ir_graph));
882 /* Get the local valid value */
883 res = block->attr.block.graph_arr[pos];
885 /* case 2 -- If the value is actually computed, return it. */
886 if (res) { return res;};
888 if (block->attr.block.matured) { /* case 3 */
890 /* The Phi has the same amount of ins as the corresponding block. */
891 int ins = get_irn_arity(block);
893 NEW_ARR_A (ir_node *, nin, ins);
895 /* Phi merge collects the predecessors and then creates a node. */
896 res = phi_merge (block, pos, mode, nin, ins);
898 } else { /* case 1 */
899 /* The block is not mature, we don't know how many in's are needed. A Phi
900 with zero predecessors is created. Such a Phi node is called Phi0
901 node. (There is also an obsolete Phi0 opcode.) The Phi0 is then added
902 to the list of Phi0 nodes in this block to be matured by mature_block
904 The Phi0 has to remember the pos of it's internal value. If the real
905 Phi is computed, pos is used to update the array with the local
908 res = new_r_Phi0 (current_ir_graph, block, mode);
909 res->attr.phi0_pos = pos;
910 res->link = block->link;
914 /* If we get here, the frontend missed a use-before-definition error */
917 printf("Error: no value set\n");
918 assert (mode->code >= irm_f && mode->code <= irm_p);
919 res = new_r_Const (current_ir_graph, block, mode,
920 tarval_mode_null[mode->code]);
923 /* The local valid value is available now. */
924 block->attr.block.graph_arr[pos] = res;
929 /** Finalize a Block node, when all control flows are known. */
930 /** Acceptable parameters are only Block nodes. */
932 mature_block (ir_node *block)
939 assert (get_irn_opcode(block) == iro_Block);
941 if (!get_Block_matured(block)) {
943 /* turn the dynamic in-array into a static one. */
944 ins = ARR_LEN (block->in)-1;
945 NEW_ARR_A (ir_node *, nin, ins);
947 /* Traverse a chain of Phi nodes attached to this block and mature
949 for (n = block->link; n; n=next) {
950 inc_irg_visited(current_ir_graph);
952 exchange (n, phi_merge (block, n->attr.phi0_pos, n->mode, nin, ins));
955 block->attr.block.matured = 1;
957 block = optimize_in_place(block);
964 new_Phi (int arity, ir_node **in, ir_mode *mode)
966 return new_r_Phi (current_ir_graph, current_ir_graph->current_block,
971 new_Const (ir_mode *mode, tarval *con)
973 return new_r_Const (current_ir_graph, current_ir_graph->start_block,
978 new_Id (ir_node *val, ir_mode *mode)
980 return new_r_Id (current_ir_graph, current_ir_graph->current_block,
985 new_Proj (ir_node *arg, ir_mode *mode, long proj)
987 return new_r_Proj (current_ir_graph, current_ir_graph->current_block,
992 new_Conv (ir_node *op, ir_mode *mode)
994 return new_r_Conv (current_ir_graph, current_ir_graph->current_block,
999 new_Tuple (int arity, ir_node **in)
1001 return new_r_Tuple (current_ir_graph, current_ir_graph->current_block,
1006 new_Add (ir_node *op1, ir_node *op2, ir_mode *mode)
1008 return new_r_Add (current_ir_graph, current_ir_graph->current_block,
1013 new_Sub (ir_node *op1, ir_node *op2, ir_mode *mode)
1015 return new_r_Sub (current_ir_graph, current_ir_graph->current_block,
1021 new_Minus (ir_node *op, ir_mode *mode)
1023 return new_r_Minus (current_ir_graph, current_ir_graph->current_block,
1028 new_Mul (ir_node *op1, ir_node *op2, ir_mode *mode)
1030 return new_r_Mul (current_ir_graph, current_ir_graph->current_block,
1035 new_Quot (ir_node *memop, ir_node *op1, ir_node *op2)
1037 return new_r_Quot (current_ir_graph, current_ir_graph->current_block,
1042 new_DivMod (ir_node *memop, ir_node *op1, ir_node *op2)
1044 return new_r_DivMod (current_ir_graph, current_ir_graph->current_block,
1049 new_Div (ir_node *memop, ir_node *op1, ir_node *op2)
1051 return new_r_Div (current_ir_graph, current_ir_graph->current_block,
1056 new_Mod (ir_node *memop, ir_node *op1, ir_node *op2)
1058 return new_r_Mod (current_ir_graph, current_ir_graph->current_block,
1063 new_And (ir_node *op1, ir_node *op2, ir_mode *mode)
1065 return new_r_And (current_ir_graph, current_ir_graph->current_block,
1070 new_Or (ir_node *op1, ir_node *op2, ir_mode *mode)
1072 return new_r_Or (current_ir_graph, current_ir_graph->current_block,
1077 new_Eor (ir_node *op1, ir_node *op2, ir_mode *mode)
1079 return new_r_Eor (current_ir_graph, current_ir_graph->current_block,
1084 new_Not (ir_node *op, ir_mode *mode)
1086 return new_r_Not (current_ir_graph, current_ir_graph->current_block,
1091 new_Shl (ir_node *op, ir_node *k, ir_mode *mode)
1093 return new_r_Shl (current_ir_graph, current_ir_graph->current_block,
1098 new_Shr (ir_node *op, ir_node *k, ir_mode *mode)
1100 return new_r_Shr (current_ir_graph, current_ir_graph->current_block,
1105 new_Shrs (ir_node *op, ir_node *k, ir_mode *mode)
1107 return new_r_Shrs (current_ir_graph, current_ir_graph->current_block,
1112 new_Rotate (ir_node *op, ir_node *k, ir_mode *mode)
1114 return new_r_Rot (current_ir_graph, current_ir_graph->current_block,
1119 new_Abs (ir_node *op, ir_mode *mode)
1121 return new_r_Abs (current_ir_graph, current_ir_graph->current_block,
1126 new_Cmp (ir_node *op1, ir_node *op2)
1128 return new_r_Cmp (current_ir_graph, current_ir_graph->current_block,
1135 return new_r_Jmp (current_ir_graph, current_ir_graph->current_block);
1139 new_Cond (ir_node *c)
1141 return new_r_Cond (current_ir_graph, current_ir_graph->current_block, c);
1145 new_Call (ir_node *store, ir_node *callee, int arity, ir_node **in,
1148 return new_r_Call (current_ir_graph, current_ir_graph->current_block,
1149 store, callee, arity, in, type);
1153 new_Return (ir_node* store, int arity, ir_node **in)
1155 return new_r_Return (current_ir_graph, current_ir_graph->current_block,
1160 new_Raise (ir_node *store, ir_node *obj)
1162 return new_r_Raise (current_ir_graph, current_ir_graph->current_block,
1167 new_Load (ir_node *store, ir_node *addr)
1169 return new_r_Load (current_ir_graph, current_ir_graph->current_block,
1174 new_Store (ir_node *store, ir_node *addr, ir_node *val)
1176 return new_r_Store (current_ir_graph, current_ir_graph->current_block,
1181 new_Alloc (ir_node *store, ir_node *size, type *alloc_type,
1184 return new_r_Alloc (current_ir_graph, current_ir_graph->current_block,
1185 store, size, alloc_type, where);
1189 new_Free (ir_node *store, ir_node *ptr, ir_node *size, type *free_type)
1191 return new_r_Free (current_ir_graph, current_ir_graph->current_block,
1192 store, ptr, size, free_type);
1196 new_simpleSel (ir_node *store, ir_node *objptr, entity *ent)
1197 /* GL: objptr was called frame before. Frame was a bad choice for the name
1198 as the operand could as well be a pointer to a dynamic object. */
1200 return new_r_Sel (current_ir_graph, current_ir_graph->current_block,
1201 store, objptr, 0, NULL, ent);
1205 new_Sel (ir_node *store, ir_node *objptr, int n_index, ir_node **index, entity *sel)
1207 return new_r_Sel (current_ir_graph, current_ir_graph->current_block,
1208 store, objptr, n_index, index, sel);
1212 new_SymConst (type_or_id *value, symconst_kind kind)
1214 return new_r_SymConst (current_ir_graph, current_ir_graph->current_block,
1219 new_Sync (int arity, ir_node** in)
1221 return new_r_Sync (current_ir_graph, current_ir_graph->current_block,
1229 return current_ir_graph->bad;
1232 /*************************************************************************/
1233 /* Comfortable interface with automatic Phi node construction. */
1234 /* (Uses also constructors of ?? interface, except new_Block. */
1235 /* add an adge to a jmp node */
1237 add_in_edge (ir_node *block, ir_node *jmp)
1239 if (block->attr.block.matured) {
1240 printf("Error: Block already matured!\n");
1243 assert (jmp != NULL);
1244 ARR_APP1 (ir_node *, block->in, jmp);
1248 /* changing the current block */
1250 switch_block (ir_node *target)
1252 current_ir_graph->current_block = target;
1255 /****************************/
1256 /* parameter administration */
1258 /* get a value from the parameter array from the current block by its index */
1260 get_value (int pos, ir_mode *mode)
1262 inc_irg_visited(current_ir_graph);
1263 return get_r_value_internal (current_ir_graph->current_block, pos + 1, mode);
1266 /* set a value at position pos in the parameter array from the current block */
1268 set_value (int pos, ir_node *value)
1270 current_ir_graph->current_block->attr.block.graph_arr[pos + 1] = value;
1273 /* get the current store */
1277 /* GL: one could call get_value instead */
1278 inc_irg_visited(current_ir_graph);
1279 return get_r_value_internal (current_ir_graph->current_block, 0, mode_M);
1282 /* set the current store */
1284 set_store (ir_node *store)
1286 /* GL: one could call set_value instead */
1287 current_ir_graph->current_block->attr.block.graph_arr[0] = store;
1290 /*************************************************************************/
1293 /* call once for each run of the library */