3 * File name: ir/ir/irnode.c
4 * Purpose: Representation of an intermediate operation.
5 * Author: Martin Trapp, Christian Schaefer
6 * Modified by: Goetz Lindenmaier
9 * Copyright: (c) 1998-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
20 #include "irgraph_t.h"
24 #include "irbackedge_t.h"
31 /* some constants fixing the positions of nodes predecessors
33 #define CALL_PARAM_OFFSET 2
34 #define SEL_INDEX_OFFSET 2
35 #define RETURN_RESULT_OFFSET 1 /* mem is not a result */
36 #define END_KEEPALIVE_OFFSET 0
38 /* Declarations for inlineing */
39 INLINE ir_node ** get_irn_in (const ir_node *node);
40 INLINE ir_mode *get_irn_mode (const ir_node *node);
41 INLINE ir_op *get_irn_op (const ir_node *node);
42 INLINE opcode get_irn_opcode (const ir_node *node);
43 INLINE ident *get_irn_opident (const ir_node *node);
44 INLINE type *get_SymConst_type (ir_node *node);
45 INLINE ir_node *skip_nop (ir_node *node);
46 INLINE int is_Proj (const ir_node *node);
49 static const char *pnc_name_arr [] = {
50 "False", "Eq", "Lt", "Le",
51 "Gt", "Ge", "Lg", "Leg", "Uo",
52 "Ue", "Ul", "Ule", "Ug", "Uge",
56 INLINE const char *get_pnc_string(int pnc) {
57 return pnc_name_arr[pnc];
62 get_negated_pnc(int pnc) {
64 case False: return True; break;
65 case Eq: return Ne; break;
66 case Lt: return Uge; break;
67 case Le: return Ug; break;
68 case Gt: return Ule; break;
69 case Ge: return Ul; break;
70 case Lg: return Ue; break;
71 case Leg: return Uo; break;
72 case Uo: return Leg; break;
73 case Ue: return Lg; break;
74 case Ul: return Ge; break;
75 case Ule: return Gt; break;
76 case Ug: return Le; break;
77 case Uge: return Lt; break;
78 case Ne: return Eq; break;
79 case True: return False; break;
81 return 99; /* to shut up gcc */
84 const char *pns_name_arr [] = {
85 "initial_exec", "global_store",
86 "frame_base", "globals", "args"
89 const char *symconst_name_arr [] = {
90 "type_tag", "size", "linkage_ptr_info"
98 /* irnode constructor */
99 /* create a new irnode in irg, with an op, mode, arity and */
100 /* some incoming irnodes */
101 /* this constructor is used in every specified irnode constructor */
103 new_ir_node (dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, ir_mode *mode,
104 int arity, ir_node **in)
107 int node_size = offsetof (ir_node, attr) + op->attr_size;
109 res = (ir_node *) obstack_alloc (irg->obst, node_size);
111 res->kind = k_ir_node;
117 res->in = NEW_ARR_F (ir_node *, 1); /* 1: space for block */
119 res->in = NEW_ARR_D (ir_node *, irg->obst, (arity+1));
120 memcpy (&res->in[1], in, sizeof (ir_node *) * arity);
123 set_irn_dbg_info(res, db);
127 res->node_nr = get_irp_new_node_nr();
133 /* Copies all attributes stored in the old node to the new node.
134 Assumes both have the same opcode and sufficient size. */
136 copy_attrs (ir_node *old, ir_node *new) {
137 assert (get_irn_op(old) == get_irn_op(new));
138 memcpy (&new->attr, &old->attr, get_op_attr_size(get_irn_op(old)));
141 /** getting some parameters from ir_nodes **/
144 is_ir_node (void *thing) {
146 if (get_kind(thing) == k_ir_node)
152 /* returns the number of predecessors without the block predecessor. */
154 get_irn_intra_arity (const ir_node *node) {
156 return ARR_LEN(node->in) - 1;
159 /* returns the number of predecessors without the block predecessor. */
161 get_irn_inter_arity (const ir_node *node) {
163 if (get_irn_opcode(node) == iro_Filter) {
164 assert(node->attr.filter.in_cg);
165 return ARR_LEN(node->attr.filter.in_cg) - 1;
166 } else if (get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
167 return ARR_LEN(node->attr.block.in_cg) - 1;
169 return get_irn_intra_arity(node);
172 /* returns the number of predecessors without the block predecessor. */
174 get_irn_arity (const ir_node *node) {
176 if (interprocedural_view) return get_irn_inter_arity(node);
177 return get_irn_intra_arity(node);
180 /* Returns the array with ins. This array is shifted with respect to the
181 array accessed by get_irn_n: The block operand is at position 0 not -1.
182 (@@@ This should be changed.)
183 The order of the predecessors in this array is not guaranteed, except that
184 lists of operands as predecessors of Block or arguments of a Call are
187 get_irn_in (const ir_node *node) {
189 if (interprocedural_view) { /* handle Filter and Block specially */
190 if (get_irn_opcode(node) == iro_Filter) {
191 assert(node->attr.filter.in_cg);
192 return node->attr.filter.in_cg;
193 } else if (get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
194 return node->attr.block.in_cg;
196 /* else fall through */
202 set_irn_in (ir_node *node, int arity, ir_node **in) {
205 if (interprocedural_view) { /* handle Filter and Block specially */
206 if (get_irn_opcode(node) == iro_Filter) {
207 assert(node->attr.filter.in_cg);
208 arr = &node->attr.filter.in_cg;
209 } else if (get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
210 arr = &node->attr.block.in_cg;
217 if (arity != ARR_LEN(*arr) - 1) {
218 ir_node * block = (*arr)[0];
219 *arr = NEW_ARR_D(ir_node *, current_ir_graph->obst, arity + 1);
222 fix_backedges(current_ir_graph->obst, node);
223 memcpy((*arr) + 1, in, sizeof(ir_node *) * arity);
227 get_irn_intra_n (ir_node *node, int n) {
228 return (node->in[n + 1] = skip_nop(node->in[n + 1]));
232 get_irn_inter_n (ir_node *node, int n) {
233 /* handle Filter and Block specially */
234 if (get_irn_opcode(node) == iro_Filter) {
235 assert(node->attr.filter.in_cg);
236 return (node->attr.filter.in_cg[n + 1] = skip_nop(node->attr.filter.in_cg[n + 1]));
237 } else if (get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
238 return (node->attr.block.in_cg[n + 1] = skip_nop(node->attr.block.in_cg[n + 1]));
241 return get_irn_intra_n (node, n);
244 /* to iterate through the predecessors without touching the array */
245 /* To iterate over the operands iterate from 0 to i < get_irn_arity(),
246 to iterate includind the Block predecessor iterate from i = -1 to
248 If it is a block, the entry -1 is NULL. */
250 get_irn_n (ir_node *node, int n) {
251 assert(node); assert(-1 <= n && n < get_irn_arity(node));
252 if (interprocedural_view) return get_irn_inter_n (node, n);
253 return get_irn_intra_n (node, n);
258 set_irn_n (ir_node *node, int n, ir_node *in) {
259 assert(node && -1 <= n && n < get_irn_arity(node));
260 if ((n == -1) && (get_irn_opcode(node) == iro_Filter)) {
261 /* Change block pred in both views! */
262 node->in[n + 1] = in;
263 assert(node->attr.filter.in_cg);
264 node->attr.filter.in_cg[n + 1] = in;
267 if (interprocedural_view) { /* handle Filter and Block specially */
268 if (get_irn_opcode(node) == iro_Filter) {
269 assert(node->attr.filter.in_cg);
270 node->attr.filter.in_cg[n + 1] = in;
272 } else if (get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
273 node->attr.block.in_cg[n + 1] = in;
276 /* else fall through */
278 node->in[n + 1] = in;
282 get_irn_mode (const ir_node *node)
289 set_irn_mode (ir_node *node, ir_mode *mode)
297 get_irn_modecode (const ir_node *node)
300 return node->mode->code;
303 /** Gets the string representation of the mode .*/
305 get_irn_modename (const ir_node *node)
308 return get_mode_name(node->mode);
312 get_irn_modeident (const ir_node *node)
315 return get_mode_ident(node->mode);
319 get_irn_op (const ir_node *node)
325 /* should be private to the library: */
327 set_irn_op (ir_node *node, ir_op *op)
334 get_irn_opcode (const ir_node *node)
337 assert (k_ir_node == get_kind(node));
339 return node->op->code;
343 get_irn_opname (const ir_node *node)
346 return get_id_str(node->op->name);
350 get_irn_opident (const ir_node *node)
353 return node->op->name;
357 get_irn_visited (const ir_node *node)
360 return node->visited;
364 set_irn_visited (ir_node *node, unsigned long visited)
367 node->visited = visited;
371 mark_irn_visited (ir_node *node) {
373 node->visited = current_ir_graph->visited;
377 irn_not_visited (const ir_node *node) {
379 return (node->visited < current_ir_graph->visited);
383 irn_visited (const ir_node *node) {
385 return (node->visited >= current_ir_graph->visited);
389 set_irn_link (ir_node *node, void *link) {
391 /* Link field is used for Phi construction and various optimizations
393 assert(get_irg_phase_state(current_ir_graph) != phase_building);
399 get_irn_link (const ir_node *node) {
404 /* Outputs a unique number for this node */
406 get_irn_node_nr(const ir_node *node) {
409 return node->node_nr;
416 get_irn_const_attr (ir_node *node)
418 assert (node->op == op_Const);
419 return node->attr.con;
423 get_irn_proj_attr (ir_node *node)
425 assert (node->op == op_Proj);
426 return node->attr.proj;
430 get_irn_alloc_attr (ir_node *node)
432 assert (node->op == op_Alloc);
437 get_irn_free_attr (ir_node *node)
439 assert (node->op == op_Free);
440 return node->attr.f = skip_tid(node->attr.f);
444 get_irn_symconst_attr (ir_node *node)
446 assert (node->op == op_SymConst);
451 get_irn_call_attr (ir_node *node)
453 assert (node->op == op_Call);
454 return node->attr.call.cld_tp = skip_tid(node->attr.call.cld_tp);
458 get_irn_sel_attr (ir_node *node)
460 assert (node->op == op_Sel);
465 get_irn_phi_attr (ir_node *node)
467 assert (node->op == op_Phi);
468 return node->attr.phi0_pos;
472 get_irn_block_attr (ir_node *node)
474 assert (node->op == op_Block);
475 return node->attr.block;
478 /** manipulate fields of individual nodes **/
480 /* this works for all except Block */
482 get_nodes_Block (ir_node *node) {
483 assert (!(node->op == op_Block));
484 return get_irn_n(node, -1);
488 set_nodes_Block (ir_node *node, ir_node *block) {
489 assert (!(node->op == op_Block));
490 set_irn_n(node, -1, block);
493 /* Test whether arbitrary node is frame pointer, i.e. Proj(pn_Start_P_frame_base)
494 * from Start. If so returns frame type, else Null. */
495 type *is_frame_pointer(ir_node *n) {
496 if ((get_irn_op(n) == op_Proj) &&
497 (get_Proj_proj(n) == pn_Start_P_frame_base)) {
498 ir_node *start = get_Proj_pred(n);
499 if (get_irn_op(start) == op_Start) {
500 return get_irg_frame_type(get_irn_irg(start));
506 /* Test whether arbitrary node is globals pointer, i.e. Proj(pn_Start_P_globals)
507 * from Start. If so returns global type, else Null. */
508 type *is_globals_pointer(ir_node *n) {
509 if ((get_irn_op(n) == op_Proj) &&
510 (get_Proj_proj(n) == pn_Start_P_globals)) {
511 ir_node *start = get_Proj_pred(n);
512 if (get_irn_op(start) == op_Start) {
513 return get_glob_type();
519 /* Test whether arbitrary node is value arg base, i.e. Proj(pn_Start_P_value_arg_base)
520 * from Start. If so returns 1, else 0. */
521 int is_value_arg_pointer(ir_node *n) {
522 if ((get_irn_op(n) == op_Proj) &&
523 (get_Proj_proj(n) == pn_Start_P_value_arg_base) &&
524 (get_irn_op(get_Proj_pred(n)) == op_Start))
529 /* Returns an array with the predecessors of the Block. Depending on
530 the implementation of the graph datastructure this can be a copy of
531 the internal representation of predecessors as well as the internal
532 array itself. Therefore writing to this array might obstruct the ir. */
534 get_Block_cfgpred_arr (ir_node *node)
536 assert ((node->op == op_Block));
537 return (ir_node **)&(get_irn_in(node)[1]);
542 get_Block_n_cfgpreds (ir_node *node) {
543 assert ((node->op == op_Block));
544 return (get_irn_arity(node));
548 get_Block_cfgpred (ir_node *node, int pos) {
549 assert (node->op == op_Block);
551 if (-1 > pos || get_irn_arity(node) <= pos) {
552 dump_ir_block_graph(current_ir_graph);
553 printf("pos: %d, arity: %d ", pos, get_irn_arity(node));
556 assert(node); assert(-1 <= pos && pos < get_irn_arity(node));
557 return get_irn_n(node, pos);
561 set_Block_cfgpred (ir_node *node, int pos, ir_node *pred) {
562 assert (node->op == op_Block);
563 set_irn_n(node, pos, pred);
567 get_Block_matured (ir_node *node) {
568 assert (node->op == op_Block);
569 return node->attr.block.matured;
573 set_Block_matured (ir_node *node, bool matured) {
574 assert (node->op == op_Block);
575 node->attr.block.matured = matured;
578 get_Block_block_visited (ir_node *node) {
579 assert (node->op == op_Block);
580 return node->attr.block.block_visited;
584 set_Block_block_visited (ir_node *node, unsigned long visit) {
585 assert (node->op == op_Block);
586 node->attr.block.block_visited = visit;
589 /* For this current_ir_graph must be set. */
591 mark_Block_block_visited (ir_node *node) {
592 assert (node->op == op_Block);
593 node->attr.block.block_visited = get_irg_block_visited(current_ir_graph);
597 Block_not_block_visited(ir_node *node) {
598 assert (node->op == op_Block);
599 return (node->attr.block.block_visited < get_irg_block_visited(current_ir_graph));
603 get_Block_graph_arr (ir_node *node, int pos) {
604 assert (node->op == op_Block);
605 return node->attr.block.graph_arr[pos+1];
609 set_Block_graph_arr (ir_node *node, int pos, ir_node *value) {
610 assert (node->op == op_Block);
611 node->attr.block.graph_arr[pos+1] = value;
614 /* handler handling for Blocks * /
616 set_Block_handler (ir_node *block, ir_node *handler) {
617 assert ((block->op == op_Block));
618 assert ((handler->op == op_Block));
619 block->attr.block.handler_entry = handler;
623 get_Block_handler (ir_node *block) {
624 assert ((block->op == op_Block));
625 return (block->attr.block.handler_entry);
628 / * handler handling for Nodes * /
630 set_Node_handler (ir_node *node, ir_node *handler) {
631 set_Block_handler (get_nodes_Block (node), handler);
635 get_Node_handler (ir_node *node) {
636 return (get_Block_handler (get_nodes_Block (node)));
639 / * exc_t handling for Blocks * /
640 void set_Block_exc (ir_node *block, exc_t exc) {
641 assert ((block->op == op_Block));
642 block->attr.block.exc = exc;
645 exc_t get_Block_exc (ir_node *block) {
646 assert ((block->op == op_Block));
647 return (block->attr.block.exc);
650 / * exc_t handling for Nodes * /
651 void set_Node_exc (ir_node *node, exc_t exc) {
652 set_Block_exc (get_nodes_Block (node), exc);
655 exc_t get_Node_exc (ir_node *node) {
656 return (get_Block_exc (get_nodes_Block (node)));
660 void set_Block_cg_cfgpred_arr(ir_node * node, int arity, ir_node ** in) {
661 assert(node->op == op_Block);
662 if (node->attr.block.in_cg == NULL || arity != ARR_LEN(node->attr.block.in_cg) - 1) {
663 node->attr.block.in_cg = NEW_ARR_D(ir_node *, current_ir_graph->obst, arity + 1);
664 node->attr.block.in_cg[0] = NULL;
665 node->attr.block.cg_backedge = new_backedge_arr(current_ir_graph->obst, arity);
667 /* Fix backedge array. fix_backedges operates depending on
668 interprocedural_view. */
669 bool ipv = interprocedural_view;
670 interprocedural_view = true;
671 fix_backedges(current_ir_graph->obst, node);
672 interprocedural_view = ipv;
675 memcpy(node->attr.block.in_cg + 1, in, sizeof(ir_node *) * arity);
678 void set_Block_cg_cfgpred(ir_node * node, int pos, ir_node * pred) {
679 assert(node->op == op_Block &&
680 node->attr.block.in_cg &&
681 0 <= pos && pos < ARR_LEN(node->attr.block.in_cg) - 1);
682 node->attr.block.in_cg[pos + 1] = pred;
685 ir_node ** get_Block_cg_cfgpred_arr(ir_node * node) {
686 assert(node->op == op_Block);
687 return node->attr.block.in_cg == NULL ? NULL : node->attr.block.in_cg + 1;
690 int get_Block_cg_n_cfgpreds(ir_node * node) {
691 assert(node->op == op_Block);
692 return node->attr.block.in_cg == NULL ? 0 : ARR_LEN(node->attr.block.in_cg) - 1;
695 ir_node * get_Block_cg_cfgpred(ir_node * node, int pos) {
696 assert(node->op == op_Block && node->attr.block.in_cg);
697 return node->attr.block.in_cg[pos + 1];
700 void remove_Block_cg_cfgpred_arr(ir_node * node) {
701 assert(node->op == op_Block);
702 node->attr.block.in_cg = NULL;
705 /* Start references the irg it is in. */
707 get_Start_irg(ir_node *node) {
708 return get_irn_irg(node);
712 set_Start_irg(ir_node *node, ir_graph *irg) {
713 assert(node->op == op_Start);
714 assert(is_ir_graph(irg));
715 assert(0 && " Why set irg? ");
716 //node->attr.start.irg = irg;
720 get_End_n_keepalives(ir_node *end) {
721 assert (end->op == op_End);
722 return (get_irn_arity(end) - END_KEEPALIVE_OFFSET);
726 get_End_keepalive(ir_node *end, int pos) {
727 assert (end->op == op_End);
728 return get_irn_n(end, pos + END_KEEPALIVE_OFFSET);
732 add_End_keepalive (ir_node *end, ir_node *ka) {
733 assert (end->op == op_End);
734 ARR_APP1 (ir_node *, end->in, ka);
738 set_End_keepalive(ir_node *end, int pos, ir_node *ka) {
739 assert (end->op == op_End);
740 set_irn_n(end, pos + END_KEEPALIVE_OFFSET, ka);
744 free_End (ir_node *end) {
745 assert (end->op == op_End);
747 DEL_ARR_F(end->in); /* GL @@@ tut nicht ! */
748 end->in = NULL; /* @@@ make sure we get an error if we use the
749 in array afterwards ... */
752 ir_graph *get_EndReg_irg (ir_node *end) {
753 return get_irn_irg(end);
756 ir_graph *get_EndExcept_irg (ir_node *end) {
757 return get_irn_irg(end);
761 > Implementing the case construct (which is where the constant Proj node is
762 > important) involves far more than simply determining the constant values.
763 > We could argue that this is more properly a function of the translator from
764 > Firm to the target machine. That could be done if there was some way of
765 > projecting "default" out of the Cond node.
766 I know it's complicated.
767 Basically there are two proglems:
768 - determining the gaps between the projs
769 - determining the biggest case constant to konw the proj number for
771 I see several solutions:
772 1. Introduce a ProjDefault node. Solves both problems.
773 This means to extend all optimizations executed during construction.
774 2. Give the Cond node for switch two flavors:
775 a) there are no gaps in the projs (existing flavor)
776 b) gaps may exist, default proj is still the Proj with the largest
777 projection number. This covers also the gaps.
778 3. Fix the semantic of the Cond to that of 2b)
780 Solution 2 seems to be the best:
781 Computing the gaps in the Firm representation is not too hard, i.e.,
782 libfirm can implement a routine that transforms betweeen the two
783 flavours. This is also possible for 1) but 2) does not require to
784 change any existing optimization.
785 Further it should be far simpler to determine the biggest constant than
787 I don't want to choose 3) as 2a) seems to have advantages for
788 dataflow analysis and 3) does not allow to convert the representation to
792 get_Cond_selector (ir_node *node) {
793 assert (node->op == op_Cond);
794 return get_irn_n(node, 0);
798 set_Cond_selector (ir_node *node, ir_node *selector) {
799 assert (node->op == op_Cond);
800 set_irn_n(node, 0, selector);
804 get_Cond_kind (ir_node *node) {
805 assert (node->op == op_Cond);
806 return node->attr.c.kind;
810 set_Cond_kind (ir_node *node, cond_kind kind) {
811 assert (node->op == op_Cond);
812 node->attr.c.kind = kind;
816 get_Return_mem (ir_node *node) {
817 assert (node->op == op_Return);
818 return get_irn_n(node, 0);
822 set_Return_mem (ir_node *node, ir_node *mem) {
823 assert (node->op == op_Return);
824 set_irn_n(node, 0, mem);
828 get_Return_n_ress (ir_node *node) {
829 assert (node->op == op_Return);
830 return (get_irn_arity(node) - RETURN_RESULT_OFFSET);
834 get_Return_res_arr (ir_node *node)
836 assert ((node->op == op_Return));
837 if (get_Return_n_ress(node) > 0)
838 return (ir_node **)&(get_irn_in(node)[1 + RETURN_RESULT_OFFSET]);
845 set_Return_n_res (ir_node *node, int results) {
846 assert (node->op == op_Return);
851 get_Return_res (ir_node *node, int pos) {
852 assert (node->op == op_Return);
853 assert (get_Return_n_ress(node) > pos);
854 return get_irn_n(node, pos + RETURN_RESULT_OFFSET);
858 set_Return_res (ir_node *node, int pos, ir_node *res){
859 assert (node->op == op_Return);
860 set_irn_n(node, pos + RETURN_RESULT_OFFSET, res);
864 get_Raise_mem (ir_node *node) {
865 assert (node->op == op_Raise);
866 return get_irn_n(node, 0);
870 set_Raise_mem (ir_node *node, ir_node *mem) {
871 assert (node->op == op_Raise);
872 set_irn_n(node, 0, mem);
876 get_Raise_exo_ptr (ir_node *node) {
877 assert (node->op == op_Raise);
878 return get_irn_n(node, 1);
882 set_Raise_exo_ptr (ir_node *node, ir_node *exo_ptr) {
883 assert (node->op == op_Raise);
884 set_irn_n(node, 1, exo_ptr);
887 INLINE tarval *get_Const_tarval (ir_node *node) {
888 assert (node->op == op_Const);
889 return node->attr.con.tv;
893 set_Const_tarval (ir_node *node, tarval *con) {
894 assert (node->op == op_Const);
895 node->attr.con.tv = con;
899 /* The source language type. Must be an atomic type. Mode of type must
900 be mode of node. For tarvals from entities type must be pointer to
903 get_Const_type (ir_node *node) {
904 assert (node->op == op_Const);
905 return node->attr.con.tp;
909 set_Const_type (ir_node *node, type *tp) {
910 assert (node->op == op_Const);
911 if (tp != unknown_type) {
912 assert (is_atomic_type(tp));
913 assert (get_type_mode(tp) == get_irn_mode(node));
914 assert (!tarval_is_entity(get_Const_tarval(node)) ||
915 (is_pointer_type(tp) &&
916 (get_pointer_points_to_type(tp) ==
917 get_entity_type(get_tarval_entity(get_Const_tarval(node))))));
920 node->attr.con.tp = tp;
925 get_SymConst_kind (const ir_node *node) {
926 assert (node->op == op_SymConst);
927 return node->attr.i.num;
931 set_SymConst_kind (ir_node *node, symconst_kind num) {
932 assert (node->op == op_SymConst);
933 node->attr.i.num = num;
937 get_SymConst_type (ir_node *node) {
938 assert ( (node->op == op_SymConst)
939 && ( get_SymConst_kind(node) == type_tag
940 || get_SymConst_kind(node) == size));
941 return node->attr.i.tori.typ = skip_tid(node->attr.i.tori.typ);
945 set_SymConst_type (ir_node *node, type *tp) {
946 assert ( (node->op == op_SymConst)
947 && ( get_SymConst_kind(node) == type_tag
948 || get_SymConst_kind(node) == size));
949 node->attr.i.tori.typ = tp;
953 get_SymConst_ptrinfo (ir_node *node) {
954 assert ( (node->op == op_SymConst)
955 && (get_SymConst_kind(node) == linkage_ptr_info));
956 return node->attr.i.tori.ptrinfo;
960 set_SymConst_ptrinfo (ir_node *node, ident *ptrinfo) {
961 assert ( (node->op == op_SymConst)
962 && (get_SymConst_kind(node) == linkage_ptr_info));
963 node->attr.i.tori.ptrinfo = ptrinfo;
967 get_SymConst_type_or_id (ir_node *node) {
968 assert (node->op == op_SymConst);
969 return &(node->attr.i.tori);
973 set_SymConst_type_or_id (ir_node *node, type_or_id_p tori) {
974 assert (node->op == op_SymConst);
975 memcpy (&(node->attr.i.tori), tori, sizeof(type_or_id));
979 get_Sel_mem (ir_node *node) {
980 assert (node->op == op_Sel);
981 return get_irn_n(node, 0);
985 set_Sel_mem (ir_node *node, ir_node *mem) {
986 assert (node->op == op_Sel);
987 set_irn_n(node, 0, mem);
991 get_Sel_ptr (ir_node *node) {
992 assert (node->op == op_Sel);
993 return get_irn_n(node, 1);
997 set_Sel_ptr (ir_node *node, ir_node *ptr) {
998 assert (node->op == op_Sel);
999 set_irn_n(node, 1, ptr);
1003 get_Sel_n_indexs (ir_node *node) {
1004 assert (node->op == op_Sel);
1005 return (get_irn_arity(node) - SEL_INDEX_OFFSET);
1009 get_Sel_index_arr (ir_node *node)
1011 assert ((node->op == op_Sel));
1012 if (get_Sel_n_indexs(node) > 0)
1013 return (ir_node **)& get_irn_in(node)[SEL_INDEX_OFFSET + 1];
1019 get_Sel_index (ir_node *node, int pos) {
1020 assert (node->op == op_Sel);
1021 return get_irn_n(node, pos + SEL_INDEX_OFFSET);
1025 set_Sel_index (ir_node *node, int pos, ir_node *index) {
1026 assert (node->op == op_Sel);
1027 set_irn_n(node, pos + SEL_INDEX_OFFSET, index);
1031 get_Sel_entity (ir_node *node) {
1032 assert (node->op == op_Sel);
1033 return node->attr.s.ent;
1037 set_Sel_entity (ir_node *node, entity *ent) {
1038 assert (node->op == op_Sel);
1039 node->attr.s.ent = ent;
1043 get_InstOf_ent (ir_node *node) {
1044 assert (node->op = op_InstOf);
1045 return (node->attr.io.ent);
1049 set_InstOf_ent (ir_node *node, type *ent) {
1050 assert (node->op = op_InstOf);
1051 node->attr.io.ent = ent;
1055 get_InstOf_store (ir_node *node) {
1056 assert (node->op = op_InstOf);
1057 return (get_irn_n (node, 0));
1061 set_InstOf_store (ir_node *node, ir_node *obj) {
1062 assert (node->op = op_InstOf);
1063 set_irn_n (node, 0, obj);
1067 get_InstOf_obj (ir_node *node) {
1068 assert (node->op = op_InstOf);
1069 return (get_irn_n (node, 1));
1073 set_InstOf_obj (ir_node *node, ir_node *obj) {
1074 assert (node->op = op_InstOf);
1075 set_irn_n (node, 1, obj);
1079 /* For unary and binary arithmetic operations the access to the
1080 operands can be factored out. Left is the first, right the
1081 second arithmetic value as listed in tech report 0999-33.
1082 unops are: Minus, Abs, Not, Conv, Cast
1083 binops are: Add, Sub, Mul, Quot, DivMod, Div, Mod, And, Or, Eor, Shl,
1084 Shr, Shrs, Rotate, Cmp */
1088 get_Call_mem (ir_node *node) {
1089 assert (node->op == op_Call);
1090 return get_irn_n(node, 0);
1094 set_Call_mem (ir_node *node, ir_node *mem) {
1095 assert (node->op == op_Call);
1096 set_irn_n(node, 0, mem);
1100 get_Call_ptr (ir_node *node) {
1101 assert (node->op == op_Call);
1102 return get_irn_n(node, 1);
1106 set_Call_ptr (ir_node *node, ir_node *ptr) {
1107 assert (node->op == op_Call);
1108 set_irn_n(node, 1, ptr);
1112 get_Call_param_arr (ir_node *node) {
1113 assert (node->op == op_Call);
1114 return (ir_node **)&get_irn_in(node)[CALL_PARAM_OFFSET + 1];
1118 get_Call_n_params (ir_node *node) {
1119 assert (node->op == op_Call);
1120 return (get_irn_arity(node) - CALL_PARAM_OFFSET);
1124 get_Call_arity (ir_node *node) {
1125 assert (node->op == op_Call);
1126 return get_Call_n_params(node);
1130 set_Call_arity (ir_node *node, ir_node *arity) {
1131 assert (node->op == op_Call);
1136 get_Call_param (ir_node *node, int pos) {
1137 assert (node->op == op_Call);
1138 return get_irn_n(node, pos + CALL_PARAM_OFFSET);
1142 set_Call_param (ir_node *node, int pos, ir_node *param) {
1143 assert (node->op == op_Call);
1144 set_irn_n(node, pos + CALL_PARAM_OFFSET, param);
1148 get_Call_type (ir_node *node) {
1149 assert (node->op == op_Call);
1150 return node->attr.call.cld_tp = skip_tid(node->attr.call.cld_tp);
1154 set_Call_type (ir_node *node, type *tp) {
1155 assert (node->op == op_Call);
1156 assert (is_method_type(tp));
1157 node->attr.call.cld_tp = tp;
1160 int Call_has_callees(ir_node *node) {
1161 return (node->attr.call.callee_arr != NULL);
1164 int get_Call_n_callees(ir_node * node) {
1165 assert(node->op == op_Call && node->attr.call.callee_arr);
1166 return ARR_LEN(node->attr.call.callee_arr);
1169 entity * get_Call_callee(ir_node * node, int pos) {
1170 assert(node->op == op_Call && node->attr.call.callee_arr);
1171 return node->attr.call.callee_arr[pos];
1174 void set_Call_callee_arr(ir_node * node, int n, entity ** arr) {
1175 assert(node->op == op_Call);
1176 if (node->attr.call.callee_arr == NULL || get_Call_n_callees(node) != n) {
1177 node->attr.call.callee_arr = NEW_ARR_D(entity *, current_ir_graph->obst, n);
1179 memcpy(node->attr.call.callee_arr, arr, n * sizeof(entity *));
1182 void remove_Call_callee_arr(ir_node * node) {
1183 assert(node->op == op_Call);
1184 node->attr.call.callee_arr = NULL;
1187 ir_node * get_CallBegin_ptr (ir_node *node) {
1188 assert(node->op == op_CallBegin);
1189 return get_irn_n(node, 0);
1191 void set_CallBegin_ptr (ir_node *node, ir_node *ptr) {
1192 assert(node->op == op_CallBegin);
1193 set_irn_n(node, 0, ptr);
1195 ir_graph * get_CallBegin_irg (ir_node *node) {
1196 return get_irn_irg(node);
1198 ir_node * get_CallBegin_call (ir_node *node) {
1199 assert(node->op == op_CallBegin);
1200 return node->attr.callbegin.call;
1202 void set_CallBegin_call (ir_node *node, ir_node *call) {
1203 assert(node->op == op_CallBegin);
1204 node->attr.callbegin.call = call;
1208 get_Add_left (ir_node *node) {
1209 assert (node->op == op_Add);
1210 return get_irn_n(node, 0);
1214 set_Add_left (ir_node *node, ir_node *left) {
1215 assert (node->op == op_Add);
1216 set_irn_n(node, 0, left);
1220 get_Add_right (ir_node *node) {
1221 assert (node->op == op_Add);
1222 return get_irn_n(node, 1);
1226 set_Add_right (ir_node *node, ir_node *right) {
1227 assert (node->op == op_Add);
1228 set_irn_n(node, 1, right);
1232 get_Sub_left (ir_node *node) {
1233 assert (node->op == op_Sub);
1234 return get_irn_n(node, 0);
1238 set_Sub_left (ir_node *node, ir_node *left) {
1239 assert (node->op == op_Sub);
1240 set_irn_n(node, 0, left);
1244 get_Sub_right (ir_node *node) {
1245 assert (node->op == op_Sub);
1246 return get_irn_n(node, 1);
1250 set_Sub_right (ir_node *node, ir_node *right) {
1251 assert (node->op == op_Sub);
1252 set_irn_n(node, 1, right);
1257 get_Minus_op (ir_node *node) {
1258 assert (node->op == op_Minus);
1259 return get_irn_n(node, 0);
1263 set_Minus_op (ir_node *node, ir_node *op) {
1264 assert (node->op == op_Minus);
1265 set_irn_n(node, 0, op);
1270 get_Mul_left (ir_node *node) {
1271 assert (node->op == op_Mul);
1272 return get_irn_n(node, 0);
1276 set_Mul_left (ir_node *node, ir_node *left) {
1277 assert (node->op == op_Mul);
1278 set_irn_n(node, 0, left);
1282 get_Mul_right (ir_node *node) {
1283 assert (node->op == op_Mul);
1284 return get_irn_n(node, 1);
1288 set_Mul_right (ir_node *node, ir_node *right) {
1289 assert (node->op == op_Mul);
1290 set_irn_n(node, 1, right);
1294 get_Quot_left (ir_node *node) {
1295 assert (node->op == op_Quot);
1296 return get_irn_n(node, 1);
1300 set_Quot_left (ir_node *node, ir_node *left) {
1301 assert (node->op == op_Quot);
1302 set_irn_n(node, 1, left);
1306 get_Quot_right (ir_node *node) {
1307 assert (node->op == op_Quot);
1308 return get_irn_n(node, 2);
1312 set_Quot_right (ir_node *node, ir_node *right) {
1313 assert (node->op == op_Quot);
1314 set_irn_n(node, 2, right);
1318 get_Quot_mem (ir_node *node) {
1319 assert (node->op == op_Quot);
1320 return get_irn_n(node, 0);
1324 set_Quot_mem (ir_node *node, ir_node *mem) {
1325 assert (node->op == op_Quot);
1326 set_irn_n(node, 0, mem);
1330 get_DivMod_left (ir_node *node) {
1331 assert (node->op == op_DivMod);
1332 return get_irn_n(node, 1);
1336 set_DivMod_left (ir_node *node, ir_node *left) {
1337 assert (node->op == op_DivMod);
1338 set_irn_n(node, 1, left);
1342 get_DivMod_right (ir_node *node) {
1343 assert (node->op == op_DivMod);
1344 return get_irn_n(node, 2);
1348 set_DivMod_right (ir_node *node, ir_node *right) {
1349 assert (node->op == op_DivMod);
1350 set_irn_n(node, 2, right);
1354 get_DivMod_mem (ir_node *node) {
1355 assert (node->op == op_DivMod);
1356 return get_irn_n(node, 0);
1360 set_DivMod_mem (ir_node *node, ir_node *mem) {
1361 assert (node->op == op_DivMod);
1362 set_irn_n(node, 0, mem);
1366 get_Div_left (ir_node *node) {
1367 assert (node->op == op_Div);
1368 return get_irn_n(node, 1);
1372 set_Div_left (ir_node *node, ir_node *left) {
1373 assert (node->op == op_Div);
1374 set_irn_n(node, 1, left);
1378 get_Div_right (ir_node *node) {
1379 assert (node->op == op_Div);
1380 return get_irn_n(node, 2);
1384 set_Div_right (ir_node *node, ir_node *right) {
1385 assert (node->op == op_Div);
1386 set_irn_n(node, 2, right);
1390 get_Div_mem (ir_node *node) {
1391 assert (node->op == op_Div);
1392 return get_irn_n(node, 0);
1396 set_Div_mem (ir_node *node, ir_node *mem) {
1397 assert (node->op == op_Div);
1398 set_irn_n(node, 0, mem);
1402 get_Mod_left (ir_node *node) {
1403 assert (node->op == op_Mod);
1404 return get_irn_n(node, 1);
1408 set_Mod_left (ir_node *node, ir_node *left) {
1409 assert (node->op == op_Mod);
1410 set_irn_n(node, 1, left);
1414 get_Mod_right (ir_node *node) {
1415 assert (node->op == op_Mod);
1416 return get_irn_n(node, 2);
1420 set_Mod_right (ir_node *node, ir_node *right) {
1421 assert (node->op == op_Mod);
1422 set_irn_n(node, 2, right);
1426 get_Mod_mem (ir_node *node) {
1427 assert (node->op == op_Mod);
1428 return get_irn_n(node, 0);
1432 set_Mod_mem (ir_node *node, ir_node *mem) {
1433 assert (node->op == op_Mod);
1434 set_irn_n(node, 0, mem);
1438 get_Abs_op (ir_node *node) {
1439 assert (node->op == op_Abs);
1440 return get_irn_n(node, 0);
1444 set_Abs_op (ir_node *node, ir_node *op) {
1445 assert (node->op == op_Abs);
1446 set_irn_n(node, 0, op);
1450 get_And_left (ir_node *node) {
1451 assert (node->op == op_And);
1452 return get_irn_n(node, 0);
1456 set_And_left (ir_node *node, ir_node *left) {
1457 assert (node->op == op_And);
1458 set_irn_n(node, 0, left);
1462 get_And_right (ir_node *node) {
1463 assert (node->op == op_And);
1464 return get_irn_n(node, 1);
1468 set_And_right (ir_node *node, ir_node *right) {
1469 assert (node->op == op_And);
1470 set_irn_n(node, 1, right);
1474 get_Or_left (ir_node *node) {
1475 assert (node->op == op_Or);
1476 return get_irn_n(node, 0);
1480 set_Or_left (ir_node *node, ir_node *left) {
1481 assert (node->op == op_Or);
1482 set_irn_n(node, 0, left);
1486 get_Or_right (ir_node *node) {
1487 assert (node->op == op_Or);
1488 return get_irn_n(node, 1);
1492 set_Or_right (ir_node *node, ir_node *right) {
1493 assert (node->op == op_Or);
1494 set_irn_n(node, 1, right);
1498 get_Eor_left (ir_node *node) {
1499 assert (node->op == op_Eor);
1500 return get_irn_n(node, 0);
1504 set_Eor_left (ir_node *node, ir_node *left) {
1505 assert (node->op == op_Eor);
1506 set_irn_n(node, 0, left);
1510 get_Eor_right (ir_node *node) {
1511 assert (node->op == op_Eor);
1512 return get_irn_n(node, 1);
1516 set_Eor_right (ir_node *node, ir_node *right) {
1517 assert (node->op == op_Eor);
1518 set_irn_n(node, 1, right);
1523 get_Not_op (ir_node *node) {
1524 assert (node->op == op_Not);
1525 return get_irn_n(node, 0);
1529 set_Not_op (ir_node *node, ir_node *op) {
1530 assert (node->op == op_Not);
1531 set_irn_n(node, 0, op);
1536 get_Shl_left (ir_node *node) {
1537 assert (node->op == op_Shl);
1538 return get_irn_n(node, 0);
1542 set_Shl_left (ir_node *node, ir_node *left) {
1543 assert (node->op == op_Shl);
1544 set_irn_n(node, 0, left);
1548 get_Shl_right (ir_node *node) {
1549 assert (node->op == op_Shl);
1550 return get_irn_n(node, 1);
1554 set_Shl_right (ir_node *node, ir_node *right) {
1555 assert (node->op == op_Shl);
1556 set_irn_n(node, 1, right);
1560 get_Shr_left (ir_node *node) {
1561 assert (node->op == op_Shr);
1562 return get_irn_n(node, 0);
1566 set_Shr_left (ir_node *node, ir_node *left) {
1567 assert (node->op == op_Shr);
1568 set_irn_n(node, 0, left);
1572 get_Shr_right (ir_node *node) {
1573 assert (node->op == op_Shr);
1574 return get_irn_n(node, 1);
1578 set_Shr_right (ir_node *node, ir_node *right) {
1579 assert (node->op == op_Shr);
1580 set_irn_n(node, 1, right);
1584 get_Shrs_left (ir_node *node) {
1585 assert (node->op == op_Shrs);
1586 return get_irn_n(node, 0);
1590 set_Shrs_left (ir_node *node, ir_node *left) {
1591 assert (node->op == op_Shrs);
1592 set_irn_n(node, 0, left);
1596 get_Shrs_right (ir_node *node) {
1597 assert (node->op == op_Shrs);
1598 return get_irn_n(node, 1);
1602 set_Shrs_right (ir_node *node, ir_node *right) {
1603 assert (node->op == op_Shrs);
1604 set_irn_n(node, 1, right);
1608 get_Rot_left (ir_node *node) {
1609 assert (node->op == op_Rot);
1610 return get_irn_n(node, 0);
1614 set_Rot_left (ir_node *node, ir_node *left) {
1615 assert (node->op == op_Rot);
1616 set_irn_n(node, 0, left);
1620 get_Rot_right (ir_node *node) {
1621 assert (node->op == op_Rot);
1622 return get_irn_n(node, 1);
1626 set_Rot_right (ir_node *node, ir_node *right) {
1627 assert (node->op == op_Rot);
1628 set_irn_n(node, 1, right);
1632 get_Cmp_left (ir_node *node) {
1633 assert (node->op == op_Cmp);
1634 return get_irn_n(node, 0);
1638 set_Cmp_left (ir_node *node, ir_node *left) {
1639 assert (node->op == op_Cmp);
1640 set_irn_n(node, 0, left);
1644 get_Cmp_right (ir_node *node) {
1645 assert (node->op == op_Cmp);
1646 return get_irn_n(node, 1);
1650 set_Cmp_right (ir_node *node, ir_node *right) {
1651 assert (node->op == op_Cmp);
1652 set_irn_n(node, 1, right);
1656 get_Conv_op (ir_node *node) {
1657 assert (node->op == op_Conv);
1658 return get_irn_n(node, 0);
1662 set_Conv_op (ir_node *node, ir_node *op) {
1663 assert (node->op == op_Conv);
1664 set_irn_n(node, 0, op);
1668 get_Cast_op (ir_node *node) {
1669 assert (node->op == op_Cast);
1670 return get_irn_n(node, 0);
1674 set_Cast_op (ir_node *node, ir_node *op) {
1675 assert (node->op == op_Cast);
1676 set_irn_n(node, 0, op);
1680 get_Cast_type (ir_node *node) {
1681 assert (node->op == op_Cast);
1682 return node->attr.cast.totype;
1686 set_Cast_type (ir_node *node, type *to_tp) {
1687 assert (node->op == op_Cast);
1688 node->attr.cast.totype = to_tp;
1692 is_unop (ir_node *node) {
1693 return (node->op->opar == oparity_unary);
1697 get_unop_op (ir_node *node) {
1698 assert (is_unop(node));
1699 switch (get_irn_opcode (node)) {
1700 case iro_Minus: return get_Minus_op(node); break;
1701 case iro_Abs: return get_Abs_op(node); break;
1702 case iro_Not: return get_Not_op(node); break;
1703 case iro_Conv: return get_Conv_op(node); break;
1704 case iro_Cast: return get_Cast_op(node); break;
1705 default: return NULL;
1710 set_unop_op (ir_node *node, ir_node *op) {
1711 assert (is_unop(node));
1712 switch (get_irn_opcode (node)) {
1713 case iro_Minus: set_Minus_op(node, op); break;
1714 case iro_Abs: set_Abs_op(node, op); break;
1715 case iro_Not: set_Not_op(node, op); break;
1716 case iro_Conv: set_Conv_op(node, op); break;
1717 case iro_Cast: set_Cast_op(node, op); break;
1724 is_binop (ir_node *node) {
1725 return (node->op->opar == oparity_binary);
1726 /* return (node->op == op_Add ||
1727 node->op == op_Cmp ||
1728 node->op == op_Sub ||
1729 node->op == op_Mul ||
1730 node->op == op_Quot ||
1731 node->op == op_DivMod ||
1732 node->op == op_Div ||
1733 node->op == op_Mod ||
1734 node->op == op_And ||
1735 node->op == op_Or ||
1736 node->op == op_Eor ||
1737 node->op == op_Shl ||
1738 node->op == op_Shr ||
1739 node->op == op_Shrs ||
1740 node->op == op_Rot );
1745 get_binop_left (ir_node *node) {
1746 assert (node->op->opar == oparity_binary);
1748 switch (get_irn_opcode (node)) {
1749 case iro_Add : return get_Add_left(node); break;
1750 case iro_Sub : return get_Sub_left(node); break;
1751 case iro_Mul : return get_Mul_left(node); break;
1752 case iro_Quot : return get_Quot_left(node); break;
1753 case iro_DivMod: return get_DivMod_left(node); break;
1754 case iro_Div : return get_Div_left(node); break;
1755 case iro_Mod : return get_Mod_left(node); break;
1756 case iro_And : return get_And_left(node); break;
1757 case iro_Or : return get_Or_left(node); break;
1758 case iro_Eor : return get_Eor_left(node); break;
1759 case iro_Shl : return get_Shl_left(node); break;
1760 case iro_Shr : return get_Shr_left(node); break;
1761 case iro_Shrs : return get_Shrs_left(node); break;
1762 case iro_Rot : return get_Rot_left(node); break;
1763 case iro_Cmp : return get_Cmp_left(node); break;
1764 default: return NULL;
1769 set_binop_left (ir_node *node, ir_node *left) {
1770 assert (node->op->opar == oparity_binary);
1772 switch (get_irn_opcode (node)) {
1773 case iro_Add : set_Add_left(node, left); break;
1774 case iro_Sub : set_Sub_left(node, left); break;
1775 case iro_Mul : set_Mul_left(node, left); break;
1776 case iro_Quot : set_Quot_left(node, left); break;
1777 case iro_DivMod: set_DivMod_left(node, left); break;
1778 case iro_Div : set_Div_left(node, left); break;
1779 case iro_Mod : set_Mod_left(node, left); break;
1780 case iro_And : set_And_left(node, left); break;
1781 case iro_Or : set_Or_left(node, left); break;
1782 case iro_Eor : set_Eor_left(node, left); break;
1783 case iro_Shl : set_Shl_left(node, left); break;
1784 case iro_Shr : set_Shr_left(node, left); break;
1785 case iro_Shrs : set_Shrs_left(node, left); break;
1786 case iro_Rot : set_Rot_left(node, left); break;
1787 case iro_Cmp : set_Cmp_left(node, left); break;
1793 get_binop_right (ir_node *node) {
1794 assert (node->op->opar == oparity_binary);
1796 switch (get_irn_opcode (node)) {
1797 case iro_Add : return get_Add_right(node); break;
1798 case iro_Sub : return get_Sub_right(node); break;
1799 case iro_Mul : return get_Mul_right(node); break;
1800 case iro_Quot : return get_Quot_right(node); break;
1801 case iro_DivMod: return get_DivMod_right(node); break;
1802 case iro_Div : return get_Div_right(node); break;
1803 case iro_Mod : return get_Mod_right(node); break;
1804 case iro_And : return get_And_right(node); break;
1805 case iro_Or : return get_Or_right(node); break;
1806 case iro_Eor : return get_Eor_right(node); break;
1807 case iro_Shl : return get_Shl_right(node); break;
1808 case iro_Shr : return get_Shr_right(node); break;
1809 case iro_Shrs : return get_Shrs_right(node); break;
1810 case iro_Rot : return get_Rot_right(node); break;
1811 case iro_Cmp : return get_Cmp_right(node); break;
1812 default: return NULL;
1817 set_binop_right (ir_node *node, ir_node *right) {
1818 assert (node->op->opar == oparity_binary);
1820 switch (get_irn_opcode (node)) {
1821 case iro_Add : set_Add_right(node, right); break;
1822 case iro_Sub : set_Sub_right(node, right); break;
1823 case iro_Mul : set_Mul_right(node, right); break;
1824 case iro_Quot : set_Quot_right(node, right); break;
1825 case iro_DivMod: set_DivMod_right(node, right); break;
1826 case iro_Div : set_Div_right(node, right); break;
1827 case iro_Mod : set_Mod_right(node, right); break;
1828 case iro_And : set_And_right(node, right); break;
1829 case iro_Or : set_Or_right(node, right); break;
1830 case iro_Eor : set_Eor_right(node, right); break;
1831 case iro_Shl : set_Shl_right(node, right); break;
1832 case iro_Shr : set_Shr_right(node, right); break;
1833 case iro_Shrs : set_Shrs_right(node, right); break;
1834 case iro_Rot : set_Rot_right(node, right); break;
1835 case iro_Cmp : set_Cmp_right(node, right); break;
1840 INLINE int is_Phi (ir_node *n) {
1842 return ((get_irn_op(n) == op_Phi) ||
1843 (get_irn_op(n) == op_Filter && interprocedural_view));
1847 get_Phi_preds_arr (ir_node *node) {
1848 assert (node->op == op_Phi);
1849 return (ir_node **)&(get_irn_in(node)[1]);
1853 get_Phi_n_preds (ir_node *node) {
1854 assert (is_Phi(node));
1855 return (get_irn_arity(node));
1859 INLINE void set_Phi_n_preds (ir_node *node, int n_preds) {
1860 assert (node->op == op_Phi);
1865 get_Phi_pred (ir_node *node, int pos) {
1866 assert (is_Phi(node));
1867 return get_irn_n(node, pos);
1871 set_Phi_pred (ir_node *node, int pos, ir_node *pred) {
1872 assert (is_Phi(node));
1873 set_irn_n(node, pos, pred);
1877 get_Load_mem (ir_node *node) {
1878 assert (node->op == op_Load);
1879 return get_irn_n(node, 0);
1883 set_Load_mem (ir_node *node, ir_node *mem) {
1884 assert (node->op == op_Load);
1885 set_irn_n(node, 0, mem);
1889 get_Load_ptr (ir_node *node) {
1890 assert (node->op == op_Load);
1891 return get_irn_n(node, 1);
1895 set_Load_ptr (ir_node *node, ir_node *ptr) {
1896 assert (node->op == op_Load);
1897 set_irn_n(node, 1, ptr);
1902 get_Store_mem (ir_node *node) {
1903 assert (node->op == op_Store);
1904 return get_irn_n(node, 0);
1908 set_Store_mem (ir_node *node, ir_node *mem) {
1909 assert (node->op == op_Store);
1910 set_irn_n(node, 0, mem);
1914 get_Store_ptr (ir_node *node) {
1915 assert (node->op == op_Store);
1916 return get_irn_n(node, 1);
1920 set_Store_ptr (ir_node *node, ir_node *ptr) {
1921 assert (node->op == op_Store);
1922 set_irn_n(node, 1, ptr);
1926 get_Store_value (ir_node *node) {
1927 assert (node->op == op_Store);
1928 return get_irn_n(node, 2);
1932 set_Store_value (ir_node *node, ir_node *value) {
1933 assert (node->op == op_Store);
1934 set_irn_n(node, 2, value);
1938 get_Alloc_mem (ir_node *node) {
1939 assert (node->op == op_Alloc);
1940 return get_irn_n(node, 0);
1944 set_Alloc_mem (ir_node *node, ir_node *mem) {
1945 assert (node->op == op_Alloc);
1946 set_irn_n(node, 0, mem);
1950 get_Alloc_size (ir_node *node) {
1951 assert (node->op == op_Alloc);
1952 return get_irn_n(node, 1);
1956 set_Alloc_size (ir_node *node, ir_node *size) {
1957 assert (node->op == op_Alloc);
1958 set_irn_n(node, 1, size);
1962 get_Alloc_type (ir_node *node) {
1963 assert (node->op == op_Alloc);
1964 return node->attr.a.type = skip_tid(node->attr.a.type);
1968 set_Alloc_type (ir_node *node, type *tp) {
1969 assert (node->op == op_Alloc);
1970 node->attr.a.type = tp;
1974 get_Alloc_where (ir_node *node) {
1975 assert (node->op == op_Alloc);
1976 return node->attr.a.where;
1980 set_Alloc_where (ir_node *node, where_alloc where) {
1981 assert (node->op == op_Alloc);
1982 node->attr.a.where = where;
1987 get_Free_mem (ir_node *node) {
1988 assert (node->op == op_Free);
1989 return get_irn_n(node, 0);
1993 set_Free_mem (ir_node *node, ir_node *mem) {
1994 assert (node->op == op_Free);
1995 set_irn_n(node, 0, mem);
1999 get_Free_ptr (ir_node *node) {
2000 assert (node->op == op_Free);
2001 return get_irn_n(node, 1);
2005 set_Free_ptr (ir_node *node, ir_node *ptr) {
2006 assert (node->op == op_Free);
2007 set_irn_n(node, 1, ptr);
2011 get_Free_size (ir_node *node) {
2012 assert (node->op == op_Free);
2013 return get_irn_n(node, 2);
2017 set_Free_size (ir_node *node, ir_node *size) {
2018 assert (node->op == op_Free);
2019 set_irn_n(node, 2, size);
2023 get_Free_type (ir_node *node) {
2024 assert (node->op == op_Free);
2025 return node->attr.f = skip_tid(node->attr.f);
2029 set_Free_type (ir_node *node, type *tp) {
2030 assert (node->op == op_Free);
2035 get_Sync_preds_arr (ir_node *node) {
2036 assert (node->op == op_Sync);
2037 return (ir_node **)&(get_irn_in(node)[1]);
2041 get_Sync_n_preds (ir_node *node) {
2042 assert (node->op == op_Sync);
2043 return (get_irn_arity(node));
2048 set_Sync_n_preds (ir_node *node, int n_preds) {
2049 assert (node->op == op_Sync);
2054 get_Sync_pred (ir_node *node, int pos) {
2055 assert (node->op == op_Sync);
2056 return get_irn_n(node, pos);
2060 set_Sync_pred (ir_node *node, int pos, ir_node *pred) {
2061 assert (node->op == op_Sync);
2062 set_irn_n(node, pos, pred);
2066 get_Proj_pred (ir_node *node) {
2067 assert (is_Proj(node));
2068 return get_irn_n(node, 0);
2072 set_Proj_pred (ir_node *node, ir_node *pred) {
2073 assert (is_Proj(node));
2074 set_irn_n(node, 0, pred);
2078 get_Proj_proj (ir_node *node) {
2079 assert (is_Proj(node));
2080 if (get_irn_opcode(node) == iro_Proj) {
2081 return node->attr.proj;
2083 assert(get_irn_opcode(node) == iro_Filter);
2084 return node->attr.filter.proj;
2089 set_Proj_proj (ir_node *node, long proj) {
2090 assert (node->op == op_Proj);
2091 node->attr.proj = proj;
2095 get_Tuple_preds_arr (ir_node *node) {
2096 assert (node->op == op_Tuple);
2097 return (ir_node **)&(get_irn_in(node)[1]);
2101 get_Tuple_n_preds (ir_node *node) {
2102 assert (node->op == op_Tuple);
2103 return (get_irn_arity(node));
2108 set_Tuple_n_preds (ir_node *node, int n_preds) {
2109 assert (node->op == op_Tuple);
2114 get_Tuple_pred (ir_node *node, int pos) {
2115 assert (node->op == op_Tuple);
2116 return get_irn_n(node, pos);
2120 set_Tuple_pred (ir_node *node, int pos, ir_node *pred) {
2121 assert (node->op == op_Tuple);
2122 set_irn_n(node, pos, pred);
2126 get_Id_pred (ir_node *node) {
2127 assert (node->op == op_Id);
2128 return get_irn_n(node, 0);
2132 set_Id_pred (ir_node *node, ir_node *pred) {
2133 assert (node->op == op_Id);
2134 set_irn_n(node, 0, pred);
2137 INLINE ir_node *get_Confirm_value (ir_node *node) {
2138 assert (node->op == op_Confirm);
2139 return get_irn_n(node, 0);
2141 INLINE void set_Confirm_value (ir_node *node, ir_node *value) {
2142 assert (node->op == op_Confirm);
2143 set_irn_n(node, 0, value);
2145 INLINE ir_node *get_Confirm_bound (ir_node *node) {
2146 assert (node->op == op_Confirm);
2147 return get_irn_n(node, 1);
2149 INLINE void set_Confirm_bound (ir_node *node, ir_node *bound) {
2150 assert (node->op == op_Confirm);
2151 set_irn_n(node, 0, bound);
2153 INLINE pn_Cmp get_Confirm_cmp (ir_node *node) {
2154 assert (node->op == op_Confirm);
2155 return node->attr.confirm_cmp;
2157 INLINE void set_Confirm_cmp (ir_node *node, pn_Cmp cmp) {
2158 assert (node->op == op_Confirm);
2159 node->attr.confirm_cmp = cmp;
2164 get_Filter_pred (ir_node *node) {
2165 assert(node->op == op_Filter);
2169 set_Filter_pred (ir_node *node, ir_node *pred) {
2170 assert(node->op == op_Filter);
2174 get_Filter_proj(ir_node *node) {
2175 assert(node->op == op_Filter);
2176 return node->attr.filter.proj;
2179 set_Filter_proj (ir_node *node, long proj) {
2180 assert(node->op == op_Filter);
2181 node->attr.filter.proj = proj;
2184 /* Don't use get_irn_arity, get_irn_n in implementation as access
2185 shall work independent of view!!! */
2186 void set_Filter_cg_pred_arr(ir_node * node, int arity, ir_node ** in) {
2187 assert(node->op == op_Filter);
2188 if (node->attr.filter.in_cg == NULL || arity != ARR_LEN(node->attr.filter.in_cg) - 1) {
2189 node->attr.filter.in_cg = NEW_ARR_D(ir_node *, current_ir_graph->obst, arity + 1);
2190 node->attr.filter.backedge = NEW_ARR_D (int, current_ir_graph->obst, arity);
2191 memset(node->attr.filter.backedge, 0, sizeof(int) * arity);
2192 node->attr.filter.in_cg[0] = node->in[0];
2194 memcpy(node->attr.filter.in_cg + 1, in, sizeof(ir_node *) * arity);
2197 void set_Filter_cg_pred(ir_node * node, int pos, ir_node * pred) {
2198 assert(node->op == op_Filter && node->attr.filter.in_cg &&
2199 0 <= pos && pos < ARR_LEN(node->attr.filter.in_cg) - 1);
2200 node->attr.filter.in_cg[pos + 1] = pred;
2202 int get_Filter_n_cg_preds(ir_node *node) {
2203 assert(node->op == op_Filter && node->attr.filter.in_cg);
2204 return (ARR_LEN(node->attr.filter.in_cg) - 1);
2206 ir_node *get_Filter_cg_pred(ir_node *node, int pos) {
2208 assert(node->op == op_Filter && node->attr.filter.in_cg &&
2210 arity = ARR_LEN(node->attr.filter.in_cg);
2211 assert(pos < arity - 1);
2212 return node->attr.filter.in_cg[pos + 1];
2217 get_irn_irg(ir_node *node) {
2218 if (get_irn_op(node) != op_Block)
2219 node = get_nodes_block(node);
2220 assert(get_irn_op(node) == op_Block);
2221 return node->attr.block.irg;
2225 /******************************************************************/
2226 /* Auxiliary routines */
2227 /******************************************************************/
2230 skip_Proj (ir_node *node) {
2231 /* don't assert node !!! */
2232 if (node && is_Proj(node)) {
2233 return get_Proj_pred(node);
2240 skip_Tuple (ir_node *node) {
2243 if (!get_opt_normalize()) return node;
2245 node = skip_nop(node);
2246 if (get_irn_op(node) == op_Proj) {
2247 pred = skip_nop(get_Proj_pred(node));
2248 if (get_irn_op(pred) == op_Proj) /* nested Tuple ? */
2249 pred = skip_nop(skip_Tuple(pred));
2250 if (get_irn_op(pred) == op_Tuple)
2251 return get_Tuple_pred(pred, get_Proj_proj(node));
2257 /* This should compact Id-cycles to self-cycles. It has the same (or less?) complexity
2258 than any other approach, as Id chains are resolved and all point to the real node, or
2259 all id's are self loops. */
2261 skip_nop (ir_node *node) {
2262 /* don't assert node !!! */
2264 if (!get_opt_normalize()) return node;
2266 /* Don't use get_Id_pred: We get into an endless loop for
2267 self-referencing Ids. */
2268 if (node && (node->op == op_Id) && (node != node->in[0+1])) {
2269 ir_node *rem_pred = node->in[0+1];
2272 assert (get_irn_arity (node) > 0);
2274 node->in[0+1] = node;
2275 res = skip_nop(rem_pred);
2276 if (res->op == op_Id) /* self-loop */ return node;
2278 node->in[0+1] = res;
2285 /* This should compact Id-cycles to self-cycles. It has the same (or less?) complexity
2286 than any other approach, as Id chains are resolved and all point to the real node, or
2287 all id's are self loops. */
2288 extern int opt_normalize;
2290 skip_nop (ir_node *node) {
2292 /* don't assert node !!! */
2294 if (!opt_normalize) return node;
2296 /* Don't use get_Id_pred: We get into an endless loop for
2297 self-referencing Ids. */
2298 if (node && (node->op == op_Id) && (node != (pred = node->in[0+1]))) {
2299 ir_node *rem_pred, *res;
2301 if (pred->op != op_Id) return pred; /* shortcut */
2304 assert (get_irn_arity (node) > 0);
2306 node->in[0+1] = node;
2307 res = skip_nop(rem_pred);
2308 if (res->op == op_Id) /* self-loop */ return node;
2310 node->in[0+1] = res;
2321 skip_Id (ir_node *node) {
2322 return skip_nop(node);
2326 is_Bad (ir_node *node) {
2328 if ((node) && get_irn_opcode(node) == iro_Bad)
2334 is_no_Block (ir_node *node) {
2336 return (get_irn_opcode(node) != iro_Block);
2340 is_Block (ir_node *node) {
2342 return (get_irn_opcode(node) == iro_Block);
2345 /* returns true if node is a Unknown node. */
2347 is_Unknown (ir_node *node) {
2349 return (get_irn_opcode(node) == iro_Unknown);
2353 is_Proj (const ir_node *node) {
2355 return node->op == op_Proj
2356 || (!interprocedural_view && node->op == op_Filter);
2359 /* Returns true if the operation manipulates control flow. */
2361 is_cfop(ir_node *node) {
2362 return is_cfopcode(get_irn_op(node));
2365 /* Returns true if the operation manipulates interprocedural control flow:
2366 CallBegin, EndReg, EndExcept */
2367 INLINE int is_ip_cfop(ir_node *node) {
2368 return is_ip_cfopcode(get_irn_op(node));
2371 ir_graph *get_ip_cfop_irg(ir_node *n) {
2372 return get_irn_irg(n);
2375 /* Returns true if the operation can change the control flow because
2378 is_fragile_op(ir_node *node) {
2379 return ( (get_irn_opcode(node) == iro_Call)
2380 || (get_irn_opcode(node) == iro_Quot)
2381 || (get_irn_opcode(node) == iro_DivMod)
2382 || (get_irn_opcode(node) == iro_Div)
2383 || (get_irn_opcode(node) == iro_Mod)
2384 || (get_irn_opcode(node) == iro_Load)
2385 || (get_irn_opcode(node) == iro_Store)
2386 || (get_irn_opcode(node) == iro_Alloc)
2387 || (get_irn_opcode(node) == iro_Bad)
2388 || (get_irn_opcode(node) == iro_Unknown));
2392 /* Returns the memory operand of fragile operations. */
2393 ir_node *get_fragile_op_mem(ir_node *node) {
2394 assert(node && is_fragile_op(node));
2396 switch (get_irn_opcode (node)) {
2405 return get_irn_n(node, 0);
2410 assert(0 && "not reached");