2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Representation of an intermediate operation.
23 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
33 #include "irgraph_t.h"
35 #include "irbackedge_t.h"
39 #include "iredgekinds.h"
40 #include "iredges_t.h"
48 /* some constants fixing the positions of nodes predecessors
50 #define CALL_PARAM_OFFSET 2
51 #define BUILDIN_PARAM_OFFSET 1
52 #define SEL_INDEX_OFFSET 2
53 #define RETURN_RESULT_OFFSET 1 /* mem is not a result */
54 #define END_KEEPALIVE_OFFSET 0
56 static const char *pnc_name_arr [] = {
57 "pn_Cmp_False", "pn_Cmp_Eq", "pn_Cmp_Lt", "pn_Cmp_Le",
58 "pn_Cmp_Gt", "pn_Cmp_Ge", "pn_Cmp_Lg", "pn_Cmp_Leg",
59 "pn_Cmp_Uo", "pn_Cmp_Ue", "pn_Cmp_Ul", "pn_Cmp_Ule",
60 "pn_Cmp_Ug", "pn_Cmp_Uge", "pn_Cmp_Ne", "pn_Cmp_True"
64 * returns the pnc name from an pnc constant
66 const char *get_pnc_string(int pnc)
68 assert(pnc >= 0 && pnc <
69 (int) (sizeof(pnc_name_arr)/sizeof(pnc_name_arr[0])));
70 return pnc_name_arr[pnc];
74 * Calculates the negated (Complement(R)) pnc condition.
76 pn_Cmp get_negated_pnc(long pnc, ir_mode *mode)
80 /* do NOT add the Uo bit for non-floating point values */
81 if (! mode_is_float(mode))
87 /* Calculates the inversed (R^-1) pnc condition, i.e., "<" --> ">" */
88 pn_Cmp get_inversed_pnc(long pnc)
90 long code = pnc & ~(pn_Cmp_Lt|pn_Cmp_Gt);
91 long lesser = pnc & pn_Cmp_Lt;
92 long greater = pnc & pn_Cmp_Gt;
94 code |= (lesser ? pn_Cmp_Gt : 0) | (greater ? pn_Cmp_Lt : 0);
100 * Indicates, whether additional data can be registered to ir nodes.
101 * If set to 1, this is not possible anymore.
103 static int forbid_new_data = 0;
106 * The amount of additional space for custom data to be allocated upon
107 * creating a new node.
109 unsigned firm_add_node_size = 0;
112 /* register new space for every node */
113 unsigned firm_register_additional_node_data(unsigned size)
115 assert(!forbid_new_data && "Too late to register additional node data");
120 return firm_add_node_size += size;
124 void init_irnode(void)
126 /* Forbid the addition of new data to an ir node. */
130 struct struct_align {
140 * irnode constructor.
141 * Create a new irnode in irg, with an op, mode, arity and
142 * some incoming irnodes.
143 * If arity is negative, a node with a dynamic array is created.
145 ir_node *new_ir_node(dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op,
146 ir_mode *mode, int arity, ir_node **in)
149 unsigned align = offsetof(struct struct_align, s) - 1;
150 unsigned add_node_size = (firm_add_node_size + align) & ~align;
151 size_t node_size = offsetof(ir_node, attr) + op->attr_size + add_node_size;
158 p = obstack_alloc(irg->obst, node_size);
159 memset(p, 0, node_size);
160 res = (ir_node *)(p + add_node_size);
162 res->kind = k_ir_node;
166 res->node_idx = irg_register_node_idx(irg, res);
171 res->in = NEW_ARR_F(ir_node *, 1); /* 1: space for block */
173 /* not nice but necessary: End and Sync must always have a flexible array */
174 if (op == op_End || op == op_Sync)
175 res->in = NEW_ARR_F(ir_node *, (arity+1));
177 res->in = NEW_ARR_D(ir_node *, irg->obst, (arity+1));
178 memcpy(&res->in[1], in, sizeof(ir_node *) * arity);
182 set_irn_dbg_info(res, db);
184 res->node_nr = get_irp_new_node_nr();
186 for (i = 0; i < EDGE_KIND_LAST; ++i) {
187 INIT_LIST_HEAD(&res->edge_info[i].outs_head);
188 /* edges will be build immediately */
189 res->edge_info[i].edges_built = 1;
190 res->edge_info[i].out_count = 0;
193 /* don't put this into the for loop, arity is -1 for some nodes! */
194 edges_notify_edge(res, -1, res->in[0], NULL, irg);
195 for (i = 1; i <= arity; ++i)
196 edges_notify_edge(res, i - 1, res->in[i], NULL, irg);
198 hook_new_node(irg, res);
199 if (get_irg_phase_state(irg) == phase_backend) {
200 be_info_new_node(res);
206 /*-- getting some parameters from ir_nodes --*/
208 int (is_ir_node)(const void *thing)
210 return _is_ir_node(thing);
213 int (get_irn_intra_arity)(const ir_node *node)
215 return _get_irn_intra_arity(node);
218 int (get_irn_inter_arity)(const ir_node *node)
220 return _get_irn_inter_arity(node);
223 int (*_get_irn_arity)(const ir_node *node) = _get_irn_intra_arity;
225 int (get_irn_arity)(const ir_node *node)
227 return _get_irn_arity(node);
230 /* Returns the array with ins. This array is shifted with respect to the
231 array accessed by get_irn_n: The block operand is at position 0 not -1.
232 (@@@ This should be changed.)
233 The order of the predecessors in this array is not guaranteed, except that
234 lists of operands as predecessors of Block or arguments of a Call are
236 ir_node **get_irn_in(const ir_node *node)
239 #ifdef INTERPROCEDURAL_VIEW
240 if (get_interprocedural_view()) { /* handle Filter and Block specially */
241 if (get_irn_opcode(node) == iro_Filter) {
242 assert(node->attr.filter.in_cg);
243 return node->attr.filter.in_cg;
244 } else if (get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
245 return node->attr.block.in_cg;
247 /* else fall through */
249 #endif /* INTERPROCEDURAL_VIEW */
253 void set_irn_in(ir_node *node, int arity, ir_node **in)
257 ir_graph *irg = get_irn_irg(node);
260 #ifdef INTERPROCEDURAL_VIEW
261 if (get_interprocedural_view()) { /* handle Filter and Block specially */
262 ir_opcode code = get_irn_opcode(node);
263 if (code == iro_Filter) {
264 assert(node->attr.filter.in_cg);
265 pOld_in = &node->attr.filter.in_cg;
266 } else if (code == iro_Block && node->attr.block.in_cg) {
267 pOld_in = &node->attr.block.in_cg;
272 #endif /* INTERPROCEDURAL_VIEW */
276 for (i = 0; i < arity; i++) {
277 if (i < ARR_LEN(*pOld_in)-1)
278 edges_notify_edge(node, i, in[i], (*pOld_in)[i+1], irg);
280 edges_notify_edge(node, i, in[i], NULL, irg);
282 for (;i < ARR_LEN(*pOld_in)-1; i++) {
283 edges_notify_edge(node, i, NULL, (*pOld_in)[i+1], irg);
286 if (arity != ARR_LEN(*pOld_in) - 1) {
287 ir_node * block = (*pOld_in)[0];
288 *pOld_in = NEW_ARR_D(ir_node *, irg->obst, arity + 1);
289 (*pOld_in)[0] = block;
291 fix_backedges(irg->obst, node);
293 memcpy((*pOld_in) + 1, in, sizeof(ir_node *) * arity);
296 ir_node *(get_irn_intra_n)(const ir_node *node, int n)
298 return _get_irn_intra_n(node, n);
301 ir_node *(get_irn_inter_n)(const ir_node *node, int n)
303 return _get_irn_inter_n(node, n);
306 ir_node *(*_get_irn_n)(const ir_node *node, int n) = _get_irn_intra_n;
308 ir_node *(get_irn_n)(const ir_node *node, int n)
310 return _get_irn_n(node, n);
313 void set_irn_n(ir_node *node, int n, ir_node *in)
315 assert(node && node->kind == k_ir_node);
317 assert(n < get_irn_arity(node));
318 assert(in && in->kind == k_ir_node);
320 #ifdef INTERPROCEDURAL_VIEW
321 if ((n == -1) && (get_irn_opcode(node) == iro_Filter)) {
322 /* Change block pred in both views! */
323 node->in[n + 1] = in;
324 assert(node->attr.filter.in_cg);
325 node->attr.filter.in_cg[n + 1] = in;
328 if (get_interprocedural_view()) { /* handle Filter and Block specially */
329 if (get_irn_opcode(node) == iro_Filter) {
330 assert(node->attr.filter.in_cg);
331 node->attr.filter.in_cg[n + 1] = in;
333 } else if (get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
334 node->attr.block.in_cg[n + 1] = in;
337 /* else fall through */
339 #endif /* INTERPROCEDURAL_VIEW */
342 hook_set_irn_n(node, n, in, node->in[n + 1]);
344 /* Here, we rely on src and tgt being in the current ir graph */
345 edges_notify_edge(node, n, in, node->in[n + 1], current_ir_graph);
347 node->in[n + 1] = in;
350 int add_irn_n(ir_node *node, ir_node *in)
353 ir_graph *irg = get_irn_irg(node);
355 assert(node->op->opar == oparity_dynamic);
356 pos = ARR_LEN(node->in) - 1;
357 ARR_APP1(ir_node *, node->in, in);
358 edges_notify_edge(node, pos, node->in[pos + 1], NULL, irg);
361 hook_set_irn_n(node, pos, node->in[pos + 1], NULL);
366 void del_Sync_n(ir_node *n, int i)
368 int arity = get_Sync_n_preds(n);
369 ir_node *last_pred = get_Sync_pred(n, arity - 1);
370 set_Sync_pred(n, i, last_pred);
371 edges_notify_edge(n, arity - 1, NULL, last_pred, get_irn_irg(n));
372 ARR_SHRINKLEN(get_irn_in(n), arity);
375 int (get_irn_deps)(const ir_node *node)
377 return _get_irn_deps(node);
380 ir_node *(get_irn_dep)(const ir_node *node, int pos)
382 return _get_irn_dep(node, pos);
385 void (set_irn_dep)(ir_node *node, int pos, ir_node *dep)
387 _set_irn_dep(node, pos, dep);
390 int add_irn_dep(ir_node *node, ir_node *dep)
394 /* DEP edges are only allowed in backend phase */
395 assert(get_irg_phase_state(get_irn_irg(node)) == phase_backend);
396 if (node->deps == NULL) {
397 node->deps = NEW_ARR_F(ir_node *, 1);
403 for (i = 0, n = ARR_LEN(node->deps); i < n; ++i) {
404 if (node->deps[i] == NULL)
407 if (node->deps[i] == dep)
411 if (first_zero >= 0) {
412 node->deps[first_zero] = dep;
415 ARR_APP1(ir_node *, node->deps, dep);
420 edges_notify_edge_kind(node, res, dep, NULL, EDGE_KIND_DEP, get_irn_irg(node));
425 void add_irn_deps(ir_node *tgt, ir_node *src)
429 for (i = 0, n = get_irn_deps(src); i < n; ++i)
430 add_irn_dep(tgt, get_irn_dep(src, i));
434 ir_mode *(get_irn_mode)(const ir_node *node)
436 return _get_irn_mode(node);
439 void (set_irn_mode)(ir_node *node, ir_mode *mode)
441 _set_irn_mode(node, mode);
444 /** Gets the string representation of the mode .*/
445 const char *get_irn_modename(const ir_node *node)
448 return get_mode_name(node->mode);
451 ident *get_irn_modeident(const ir_node *node)
454 return get_mode_ident(node->mode);
457 ir_op *(get_irn_op)(const ir_node *node)
459 return _get_irn_op(node);
462 /* should be private to the library: */
463 void (set_irn_op)(ir_node *node, ir_op *op)
465 _set_irn_op(node, op);
468 unsigned (get_irn_opcode)(const ir_node *node)
470 return _get_irn_opcode(node);
473 const char *get_irn_opname(const ir_node *node)
476 if (is_Phi0(node)) return "Phi0";
477 return get_id_str(node->op->name);
480 ident *get_irn_opident(const ir_node *node)
483 return node->op->name;
486 ir_visited_t (get_irn_visited)(const ir_node *node)
488 return _get_irn_visited(node);
491 void (set_irn_visited)(ir_node *node, ir_visited_t visited)
493 _set_irn_visited(node, visited);
496 void (mark_irn_visited)(ir_node *node)
498 _mark_irn_visited(node);
501 int (irn_visited)(const ir_node *node)
503 return _irn_visited(node);
506 int (irn_visited_else_mark)(ir_node *node)
508 return _irn_visited_else_mark(node);
511 void (set_irn_link)(ir_node *node, void *link)
513 _set_irn_link(node, link);
516 void *(get_irn_link)(const ir_node *node)
518 return _get_irn_link(node);
521 op_pin_state (get_irn_pinned)(const ir_node *node)
523 return _get_irn_pinned(node);
526 op_pin_state (is_irn_pinned_in_irg) (const ir_node *node)
528 return _is_irn_pinned_in_irg(node);
531 void set_irn_pinned(ir_node *node, op_pin_state state)
533 /* due to optimization an opt may be turned into a Tuple */
537 assert(node && get_op_pinned(get_irn_op(node)) >= op_pin_state_exc_pinned);
538 assert(state == op_pin_state_pinned || state == op_pin_state_floats);
540 node->attr.except.pin_state = state;
543 /* Outputs a unique number for this node */
544 long get_irn_node_nr(const ir_node *node)
547 return node->node_nr;
550 const_attr *get_irn_const_attr(ir_node *node)
552 assert(is_Const(node));
553 return &node->attr.con;
556 long get_irn_proj_attr(ir_node *node)
558 /* BEWARE: check for true Proj node here, no Filter */
559 assert(node->op == op_Proj);
560 return node->attr.proj;
563 alloc_attr *get_irn_alloc_attr(ir_node *node)
565 assert(is_Alloc(node));
566 return &node->attr.alloc;
569 free_attr *get_irn_free_attr(ir_node *node)
571 assert(is_Free(node));
572 return &node->attr.free;
575 symconst_attr *get_irn_symconst_attr(ir_node *node)
577 assert(is_SymConst(node));
578 return &node->attr.symc;
581 call_attr *get_irn_call_attr(ir_node *node)
583 assert(is_Call(node));
584 return &node->attr.call;
587 sel_attr *get_irn_sel_attr(ir_node *node)
589 assert(is_Sel(node));
590 return &node->attr.sel;
593 phi_attr *get_irn_phi_attr(ir_node *node)
595 return &node->attr.phi;
598 block_attr *get_irn_block_attr(ir_node *node)
600 assert(is_Block(node));
601 return &node->attr.block;
604 load_attr *get_irn_load_attr(ir_node *node)
606 assert(is_Load(node));
607 return &node->attr.load;
610 store_attr *get_irn_store_attr(ir_node *node)
612 assert(is_Store(node));
613 return &node->attr.store;
616 except_attr *get_irn_except_attr(ir_node *node)
618 assert(node->op == op_Div || node->op == op_Quot ||
619 node->op == op_DivMod || node->op == op_Mod || node->op == op_Call || node->op == op_Alloc || node->op == op_Bound);
620 return &node->attr.except;
623 divmod_attr *get_irn_divmod_attr(ir_node *node)
625 assert(node->op == op_Div || node->op == op_Quot ||
626 node->op == op_DivMod || node->op == op_Mod);
627 return &node->attr.divmod;
630 builtin_attr *get_irn_builtin_attr(ir_node *node)
632 assert(is_Builtin(node));
633 return &node->attr.builtin;
636 void *(get_irn_generic_attr)(ir_node *node)
638 assert(is_ir_node(node));
639 return _get_irn_generic_attr(node);
642 const void *(get_irn_generic_attr_const)(const ir_node *node)
644 assert(is_ir_node(node));
645 return _get_irn_generic_attr_const(node);
648 unsigned (get_irn_idx)(const ir_node *node)
650 assert(is_ir_node(node));
651 return _get_irn_idx(node);
654 int get_irn_pred_pos(ir_node *node, ir_node *arg)
657 for (i = get_irn_arity(node) - 1; i >= 0; i--) {
658 if (get_irn_n(node, i) == arg)
664 /** manipulate fields of individual nodes **/
666 /* this works for all except Block */
667 ir_node *get_nodes_block(const ir_node *node)
669 assert(node->op != op_Block);
670 return get_irn_n(node, -1);
673 void set_nodes_block(ir_node *node, ir_node *block)
675 assert(node->op != op_Block);
676 set_irn_n(node, -1, block);
679 /* this works for all except Block */
680 ir_node *get_nodes_MacroBlock(const ir_node *node)
682 assert(node->op != op_Block);
683 return get_Block_MacroBlock(get_irn_n(node, -1));
686 /* Test whether arbitrary node is frame pointer, i.e. Proj(pn_Start_P_frame_base)
687 * from Start. If so returns frame type, else Null. */
688 ir_type *is_frame_pointer(const ir_node *n)
690 if (is_Proj(n) && (get_Proj_proj(n) == pn_Start_P_frame_base)) {
691 ir_node *start = get_Proj_pred(n);
692 if (is_Start(start)) {
693 return get_irg_frame_type(get_irn_irg(start));
699 /* Test whether arbitrary node is tls pointer, i.e. Proj(pn_Start_P_tls)
700 * from Start. If so returns tls type, else Null. */
701 ir_type *is_tls_pointer(const ir_node *n)
703 if (is_Proj(n) && (get_Proj_proj(n) == pn_Start_P_tls)) {
704 ir_node *start = get_Proj_pred(n);
705 if (is_Start(start)) {
706 return get_tls_type();
712 ir_node **get_Block_cfgpred_arr(ir_node *node)
714 assert(is_Block(node));
715 return (ir_node **)&(get_irn_in(node)[1]);
718 int (get_Block_n_cfgpreds)(const ir_node *node)
720 return _get_Block_n_cfgpreds(node);
723 ir_node *(get_Block_cfgpred)(const ir_node *node, int pos)
725 return _get_Block_cfgpred(node, pos);
728 void set_Block_cfgpred(ir_node *node, int pos, ir_node *pred)
730 assert(is_Block(node));
731 set_irn_n(node, pos, pred);
734 int get_Block_cfgpred_pos(const ir_node *block, const ir_node *pred)
738 for (i = get_Block_n_cfgpreds(block) - 1; i >= 0; --i) {
739 if (get_Block_cfgpred_block(block, i) == pred)
745 ir_node *(get_Block_cfgpred_block)(const ir_node *node, int pos)
747 return _get_Block_cfgpred_block(node, pos);
750 int get_Block_matured(const ir_node *node)
752 assert(is_Block(node));
753 return (int)node->attr.block.is_matured;
756 void set_Block_matured(ir_node *node, int matured)
758 assert(is_Block(node));
759 node->attr.block.is_matured = matured;
762 ir_visited_t (get_Block_block_visited)(const ir_node *node)
764 return _get_Block_block_visited(node);
767 void (set_Block_block_visited)(ir_node *node, ir_visited_t visit)
769 _set_Block_block_visited(node, visit);
772 /* For this current_ir_graph must be set. */
773 void (mark_Block_block_visited)(ir_node *node)
775 _mark_Block_block_visited(node);
778 int (Block_block_visited)(const ir_node *node)
780 return _Block_block_visited(node);
783 #ifdef INTERPROCEDURAL_VIEW
784 void set_Block_cg_cfgpred_arr(ir_node *node, int arity, ir_node *in[])
786 assert(is_Block(node));
787 if (node->attr.block.in_cg == NULL || arity != ARR_LEN(node->attr.block.in_cg) - 1) {
788 node->attr.block.in_cg = NEW_ARR_D(ir_node *, current_ir_graph->obst, arity + 1);
789 node->attr.block.in_cg[0] = NULL;
790 node->attr.block.cg_backedge = new_backedge_arr(current_ir_graph->obst, arity);
792 /* Fix backedge array. fix_backedges() operates depending on
793 interprocedural_view. */
794 int ipv = get_interprocedural_view();
795 set_interprocedural_view(1);
796 fix_backedges(current_ir_graph->obst, node);
797 set_interprocedural_view(ipv);
800 memcpy(node->attr.block.in_cg + 1, in, sizeof(ir_node *) * arity);
803 void set_Block_cg_cfgpred(ir_node *node, int pos, ir_node *pred)
805 assert(is_Block(node) && node->attr.block.in_cg &&
806 0 <= pos && pos < ARR_LEN(node->attr.block.in_cg) - 1);
807 node->attr.block.in_cg[pos + 1] = pred;
810 ir_node **get_Block_cg_cfgpred_arr(ir_node *node)
812 assert(is_Block(node));
813 return node->attr.block.in_cg == NULL ? NULL : node->attr.block.in_cg + 1;
816 int get_Block_cg_n_cfgpreds(const ir_node *node)
818 assert(is_Block(node));
819 return node->attr.block.in_cg == NULL ? 0 : ARR_LEN(node->attr.block.in_cg) - 1;
822 ir_node *get_Block_cg_cfgpred(const ir_node *node, int pos)
824 assert(is_Block(node) && node->attr.block.in_cg);
825 return node->attr.block.in_cg[pos + 1];
828 void remove_Block_cg_cfgpred_arr(ir_node *node)
830 assert(is_Block(node));
831 node->attr.block.in_cg = NULL;
833 #endif /* INTERPROCEDURAL_VIEW */
835 ir_node *(set_Block_dead)(ir_node *block)
837 return _set_Block_dead(block);
840 int (is_Block_dead)(const ir_node *block)
842 return _is_Block_dead(block);
845 ir_extblk *get_Block_extbb(const ir_node *block)
848 assert(is_Block(block));
849 res = block->attr.block.extblk;
850 assert(res == NULL || is_ir_extbb(res));
854 void set_Block_extbb(ir_node *block, ir_extblk *extblk)
856 assert(is_Block(block));
857 assert(extblk == NULL || is_ir_extbb(extblk));
858 block->attr.block.extblk = extblk;
861 /* Returns the macro block header of a block.*/
862 ir_node *get_Block_MacroBlock(const ir_node *block)
865 assert(is_Block(block));
866 mbh = get_irn_n(block, -1);
867 /* once macro block header is respected by all optimizations,
868 this assert can be removed */
873 /* Sets the macro block header of a block. */
874 void set_Block_MacroBlock(ir_node *block, ir_node *mbh)
876 assert(is_Block(block));
878 assert(is_Block(mbh));
879 set_irn_n(block, -1, mbh);
882 /* returns the macro block header of a node. */
883 ir_node *get_irn_MacroBlock(const ir_node *n)
886 n = get_nodes_block(n);
887 /* if the Block is Bad, do NOT try to get it's MB, it will fail. */
891 return get_Block_MacroBlock(n);
894 /* returns the graph of a Block. */
895 ir_graph *(get_Block_irg)(const ir_node *block)
897 return _get_Block_irg(block);
900 ir_entity *create_Block_entity(ir_node *block)
903 assert(is_Block(block));
905 entity = block->attr.block.entity;
906 if (entity == NULL) {
910 glob = get_glob_type();
911 entity = new_entity(glob, id_unique("block_%u"), get_code_type());
912 set_entity_visibility(entity, ir_visibility_local);
913 set_entity_linkage(entity, IR_LINKAGE_CONSTANT);
914 nr = get_irp_next_label_nr();
915 set_entity_label(entity, nr);
916 set_entity_compiler_generated(entity, 1);
918 block->attr.block.entity = entity;
923 ir_entity *get_Block_entity(const ir_node *block)
925 assert(is_Block(block));
926 return block->attr.block.entity;
929 void set_Block_entity(ir_node *block, ir_entity *entity)
931 assert(is_Block(block));
932 assert(get_entity_type(entity) == get_code_type());
933 block->attr.block.entity = entity;
936 int has_Block_entity(const ir_node *block)
938 return block->attr.block.entity != NULL;
941 ir_node *(get_Block_phis)(const ir_node *block)
943 return _get_Block_phis(block);
946 void (set_Block_phis)(ir_node *block, ir_node *phi)
948 _set_Block_phis(block, phi);
951 void (add_Block_phi)(ir_node *block, ir_node *phi)
953 _add_Block_phi(block, phi);
956 /* Get the Block mark (single bit). */
957 unsigned (get_Block_mark)(const ir_node *block)
959 return _get_Block_mark(block);
962 /* Set the Block mark (single bit). */
963 void (set_Block_mark)(ir_node *block, unsigned mark)
965 _set_Block_mark(block, mark);
968 int get_End_n_keepalives(const ir_node *end)
971 return (get_irn_arity(end) - END_KEEPALIVE_OFFSET);
974 ir_node *get_End_keepalive(const ir_node *end, int pos)
977 return get_irn_n(end, pos + END_KEEPALIVE_OFFSET);
980 void add_End_keepalive(ir_node *end, ir_node *ka)
986 void set_End_keepalive(ir_node *end, int pos, ir_node *ka)
989 set_irn_n(end, pos + END_KEEPALIVE_OFFSET, ka);
992 /* Set new keep-alives */
993 void set_End_keepalives(ir_node *end, int n, ir_node *in[])
996 ir_graph *irg = get_irn_irg(end);
998 /* notify that edges are deleted */
999 for (i = END_KEEPALIVE_OFFSET; i < ARR_LEN(end->in) - 1; ++i) {
1000 edges_notify_edge(end, i, NULL, end->in[i + 1], irg);
1002 ARR_RESIZE(ir_node *, end->in, n + 1 + END_KEEPALIVE_OFFSET);
1004 for (i = 0; i < n; ++i) {
1005 end->in[1 + END_KEEPALIVE_OFFSET + i] = in[i];
1006 edges_notify_edge(end, END_KEEPALIVE_OFFSET + i, end->in[1 + END_KEEPALIVE_OFFSET + i], NULL, irg);
1010 /* Set new keep-alives from old keep-alives, skipping irn */
1011 void remove_End_keepalive(ir_node *end, ir_node *irn)
1013 int n = get_End_n_keepalives(end);
1018 for (i = n -1; i >= 0; --i) {
1019 ir_node *old_ka = end->in[1 + END_KEEPALIVE_OFFSET + i];
1022 if (old_ka == irn) {
1029 irg = get_irn_irg(end);
1031 /* remove the edge */
1032 edges_notify_edge(end, idx, NULL, irn, irg);
1035 /* exchange with the last one */
1036 ir_node *old = end->in[1 + END_KEEPALIVE_OFFSET + n - 1];
1037 edges_notify_edge(end, n - 1, NULL, old, irg);
1038 end->in[1 + END_KEEPALIVE_OFFSET + idx] = old;
1039 edges_notify_edge(end, idx, old, NULL, irg);
1041 /* now n - 1 keeps, 1 block input */
1042 ARR_RESIZE(ir_node *, end->in, (n - 1) + 1 + END_KEEPALIVE_OFFSET);
1045 /* remove Bads, NoMems and doublets from the keep-alive set */
1046 void remove_End_Bads_and_doublets(ir_node *end)
1049 int idx, n = get_End_n_keepalives(end);
1055 irg = get_irn_irg(end);
1056 pset_new_init(&keeps);
1058 for (idx = n - 1; idx >= 0; --idx) {
1059 ir_node *ka = get_End_keepalive(end, idx);
1061 if (is_Bad(ka) || is_NoMem(ka) || pset_new_contains(&keeps, ka)) {
1062 /* remove the edge */
1063 edges_notify_edge(end, idx, NULL, ka, irg);
1066 /* exchange with the last one */
1067 ir_node *old = end->in[1 + END_KEEPALIVE_OFFSET + n - 1];
1068 edges_notify_edge(end, n - 1, NULL, old, irg);
1069 end->in[1 + END_KEEPALIVE_OFFSET + idx] = old;
1070 edges_notify_edge(end, idx, old, NULL, irg);
1074 pset_new_insert(&keeps, ka);
1077 /* n keeps, 1 block input */
1078 ARR_RESIZE(ir_node *, end->in, n + 1 + END_KEEPALIVE_OFFSET);
1080 pset_new_destroy(&keeps);
1083 void free_End(ir_node *end)
1085 assert(is_End(end));
1088 end->in = NULL; /* @@@ make sure we get an error if we use the
1089 in array afterwards ... */
1092 /* Return the target address of an IJmp */
1093 ir_node *get_IJmp_target(const ir_node *ijmp)
1095 assert(is_IJmp(ijmp));
1096 return get_irn_n(ijmp, 0);
1099 /** Sets the target address of an IJmp */
1100 void set_IJmp_target(ir_node *ijmp, ir_node *tgt)
1102 assert(is_IJmp(ijmp));
1103 set_irn_n(ijmp, 0, tgt);
1106 ir_node *get_Cond_selector(const ir_node *node)
1108 assert(is_Cond(node));
1109 return get_irn_n(node, 0);
1112 void set_Cond_selector(ir_node *node, ir_node *selector)
1114 assert(is_Cond(node));
1115 set_irn_n(node, 0, selector);
1118 long get_Cond_default_proj(const ir_node *node)
1120 assert(is_Cond(node));
1121 return node->attr.cond.default_proj;
1124 void set_Cond_default_proj(ir_node *node, long defproj)
1126 assert(is_Cond(node));
1127 node->attr.cond.default_proj = defproj;
1130 ir_node *get_Return_mem(const ir_node *node)
1132 assert(is_Return(node));
1133 return get_irn_n(node, 0);
1136 void set_Return_mem(ir_node *node, ir_node *mem)
1138 assert(is_Return(node));
1139 set_irn_n(node, 0, mem);
1142 int get_Return_n_ress(const ir_node *node)
1144 assert(is_Return(node));
1145 return (get_irn_arity(node) - RETURN_RESULT_OFFSET);
1148 ir_node **get_Return_res_arr(ir_node *node)
1150 assert(is_Return(node));
1151 if (get_Return_n_ress(node) > 0)
1152 return (ir_node **)&(get_irn_in(node)[1 + RETURN_RESULT_OFFSET]);
1158 void set_Return_n_res(ir_node *node, int results)
1160 assert(is_Return(node));
1164 ir_node *get_Return_res(const ir_node *node, int pos)
1166 assert(is_Return(node));
1167 assert(get_Return_n_ress(node) > pos);
1168 return get_irn_n(node, pos + RETURN_RESULT_OFFSET);
1171 void set_Return_res(ir_node *node, int pos, ir_node *res)
1173 assert(is_Return(node));
1174 set_irn_n(node, pos + RETURN_RESULT_OFFSET, res);
1177 tarval *(get_Const_tarval)(const ir_node *node)
1179 return _get_Const_tarval(node);
1182 void set_Const_tarval(ir_node *node, tarval *con)
1184 assert(is_Const(node));
1185 node->attr.con.tv = con;
1188 int (is_Const_null)(const ir_node *node)
1190 return _is_Const_null(node);
1193 int (is_Const_one)(const ir_node *node)
1195 return _is_Const_one(node);
1198 int (is_Const_all_one)(const ir_node *node)
1200 return _is_Const_all_one(node);
1204 /* The source language type. Must be an atomic type. Mode of type must
1205 be mode of node. For tarvals from entities type must be pointer to
1207 ir_type *get_Const_type(ir_node *node)
1209 assert(is_Const(node));
1210 return node->attr.con.tp;
1213 void set_Const_type(ir_node *node, ir_type *tp)
1215 assert(is_Const(node));
1216 if (tp != firm_unknown_type) {
1217 assert(is_atomic_type(tp));
1218 assert(get_type_mode(tp) == get_irn_mode(node));
1220 node->attr.con.tp = tp;
1224 symconst_kind get_SymConst_kind(const ir_node *node)
1226 assert(is_SymConst(node));
1227 return node->attr.symc.kind;
1230 void set_SymConst_kind(ir_node *node, symconst_kind kind)
1232 assert(is_SymConst(node));
1233 node->attr.symc.kind = kind;
1236 ir_type *get_SymConst_type(const ir_node *node)
1238 /* the cast here is annoying, but we have to compensate for
1240 ir_node *irn = (ir_node *)node;
1241 assert(is_SymConst(node) &&
1242 (SYMCONST_HAS_TYPE(get_SymConst_kind(node))));
1243 return irn->attr.symc.sym.type_p;
1246 void set_SymConst_type(ir_node *node, ir_type *tp)
1248 assert(is_SymConst(node) &&
1249 (SYMCONST_HAS_TYPE(get_SymConst_kind(node))));
1250 node->attr.symc.sym.type_p = tp;
1254 /* Only to access SymConst of kind symconst_addr_ent. Else assertion: */
1255 ir_entity *get_SymConst_entity(const ir_node *node)
1257 assert(is_SymConst(node) && SYMCONST_HAS_ENT(get_SymConst_kind(node)));
1258 return node->attr.symc.sym.entity_p;
1261 void set_SymConst_entity(ir_node *node, ir_entity *ent)
1263 assert(is_SymConst(node) && SYMCONST_HAS_ENT(get_SymConst_kind(node)));
1264 node->attr.symc.sym.entity_p = ent;
1267 ir_enum_const *get_SymConst_enum(const ir_node *node)
1269 assert(is_SymConst(node) && SYMCONST_HAS_ENUM(get_SymConst_kind(node)));
1270 return node->attr.symc.sym.enum_p;
1273 void set_SymConst_enum(ir_node *node, ir_enum_const *ec)
1275 assert(is_SymConst(node) && SYMCONST_HAS_ENUM(get_SymConst_kind(node)));
1276 node->attr.symc.sym.enum_p = ec;
1279 union symconst_symbol
1280 get_SymConst_symbol(const ir_node *node)
1282 assert(is_SymConst(node));
1283 return node->attr.symc.sym;
1286 void set_SymConst_symbol(ir_node *node, union symconst_symbol sym)
1288 assert(is_SymConst(node));
1289 node->attr.symc.sym = sym;
1292 ir_type *get_SymConst_value_type(ir_node *node)
1294 assert(is_SymConst(node));
1295 return node->attr.symc.tp;
1298 void set_SymConst_value_type(ir_node *node, ir_type *tp)
1300 assert(is_SymConst(node));
1301 node->attr.symc.tp = tp;
1304 ir_node *get_Sel_mem(const ir_node *node)
1306 assert(is_Sel(node));
1307 return get_irn_n(node, 0);
1310 void set_Sel_mem(ir_node *node, ir_node *mem)
1312 assert(is_Sel(node));
1313 set_irn_n(node, 0, mem);
1316 ir_node *get_Sel_ptr(const ir_node *node)
1318 assert(is_Sel(node));
1319 return get_irn_n(node, 1);
1322 void set_Sel_ptr(ir_node *node, ir_node *ptr)
1324 assert(is_Sel(node));
1325 set_irn_n(node, 1, ptr);
1328 int get_Sel_n_indexs(const ir_node *node)
1330 assert(is_Sel(node));
1331 return (get_irn_arity(node) - SEL_INDEX_OFFSET);
1334 ir_node **get_Sel_index_arr(ir_node *node)
1336 assert(is_Sel(node));
1337 if (get_Sel_n_indexs(node) > 0)
1338 return (ir_node **)& get_irn_in(node)[SEL_INDEX_OFFSET + 1];
1343 ir_node *get_Sel_index(const ir_node *node, int pos)
1345 assert(is_Sel(node));
1346 return get_irn_n(node, pos + SEL_INDEX_OFFSET);
1349 void set_Sel_index(ir_node *node, int pos, ir_node *index)
1351 assert(is_Sel(node));
1352 set_irn_n(node, pos + SEL_INDEX_OFFSET, index);
1355 ir_entity *get_Sel_entity(const ir_node *node)
1357 assert(is_Sel(node));
1358 return node->attr.sel.entity;
1361 /* need a version without const to prevent warning */
1362 static ir_entity *_get_Sel_entity(ir_node *node)
1364 return get_Sel_entity(node);
1367 void set_Sel_entity(ir_node *node, ir_entity *ent)
1369 assert(is_Sel(node));
1370 node->attr.sel.entity = ent;
1374 /* For unary and binary arithmetic operations the access to the
1375 operands can be factored out. Left is the first, right the
1376 second arithmetic value as listed in tech report 0999-33.
1377 unops are: Minus, Abs, Not, Conv, Cast
1378 binops are: Add, Sub, Mul, Quot, DivMod, Div, Mod, And, Or, Eor, Shl,
1379 Shr, Shrs, Rotate, Cmp */
1382 ir_node *get_Call_mem(const ir_node *node)
1384 assert(is_Call(node));
1385 return get_irn_n(node, 0);
1388 void set_Call_mem(ir_node *node, ir_node *mem)
1390 assert(is_Call(node));
1391 set_irn_n(node, 0, mem);
1394 ir_node *get_Call_ptr(const ir_node *node)
1396 assert(is_Call(node));
1397 return get_irn_n(node, 1);
1400 void set_Call_ptr(ir_node *node, ir_node *ptr)
1402 assert(is_Call(node));
1403 set_irn_n(node, 1, ptr);
1406 ir_node **get_Call_param_arr(ir_node *node)
1408 assert(is_Call(node));
1409 return &get_irn_in(node)[CALL_PARAM_OFFSET + 1];
1412 int get_Call_n_params(const ir_node *node)
1414 assert(is_Call(node));
1415 return (get_irn_arity(node) - CALL_PARAM_OFFSET);
1418 ir_node *get_Call_param(const ir_node *node, int pos)
1420 assert(is_Call(node));
1421 return get_irn_n(node, pos + CALL_PARAM_OFFSET);
1424 void set_Call_param(ir_node *node, int pos, ir_node *param)
1426 assert(is_Call(node));
1427 set_irn_n(node, pos + CALL_PARAM_OFFSET, param);
1430 ir_type *get_Call_type(ir_node *node)
1432 assert(is_Call(node));
1433 return node->attr.call.type;
1436 void set_Call_type(ir_node *node, ir_type *tp)
1438 assert(is_Call(node));
1439 assert((get_unknown_type() == tp) || is_Method_type(tp));
1440 node->attr.call.type = tp;
1443 unsigned get_Call_tail_call(const ir_node *node)
1445 assert(is_Call(node));
1446 return node->attr.call.tail_call;
1449 void set_Call_tail_call(ir_node *node, unsigned tail_call)
1451 assert(is_Call(node));
1452 node->attr.call.tail_call = tail_call != 0;
1455 ir_node *get_Builtin_mem(const ir_node *node)
1457 assert(is_Builtin(node));
1458 return get_irn_n(node, 0);
1461 void set_Builtin_mem(ir_node *node, ir_node *mem)
1463 assert(is_Builtin(node));
1464 set_irn_n(node, 0, mem);
1467 ir_builtin_kind get_Builtin_kind(const ir_node *node)
1469 assert(is_Builtin(node));
1470 return node->attr.builtin.kind;
1473 void set_Builtin_kind(ir_node *node, ir_builtin_kind kind)
1475 assert(is_Builtin(node));
1476 node->attr.builtin.kind = kind;
1479 ir_node **get_Builtin_param_arr(ir_node *node)
1481 assert(is_Builtin(node));
1482 return &get_irn_in(node)[BUILDIN_PARAM_OFFSET + 1];
1485 int get_Builtin_n_params(const ir_node *node)
1487 assert(is_Builtin(node));
1488 return (get_irn_arity(node) - BUILDIN_PARAM_OFFSET);
1491 ir_node *get_Builtin_param(const ir_node *node, int pos)
1493 assert(is_Builtin(node));
1494 return get_irn_n(node, pos + BUILDIN_PARAM_OFFSET);
1497 void set_Builtin_param(ir_node *node, int pos, ir_node *param)
1499 assert(is_Builtin(node));
1500 set_irn_n(node, pos + BUILDIN_PARAM_OFFSET, param);
1503 ir_type *get_Builtin_type(ir_node *node)
1505 assert(is_Builtin(node));
1506 return node->attr.builtin.type;
1509 void set_Builtin_type(ir_node *node, ir_type *tp)
1511 assert(is_Builtin(node));
1512 assert((get_unknown_type() == tp) || is_Method_type(tp));
1513 node->attr.builtin.type = tp;
1516 /* Returns a human readable string for the ir_builtin_kind. */
1517 const char *get_builtin_kind_name(ir_builtin_kind kind)
1519 #define X(a) case a: return #a;
1522 X(ir_bk_debugbreak);
1523 X(ir_bk_return_address);
1524 X(ir_bk_frame_address);
1534 X(ir_bk_inner_trampoline);
1541 int Call_has_callees(const ir_node *node)
1543 assert(is_Call(node));
1544 return ((get_irg_callee_info_state(get_irn_irg(node)) != irg_callee_info_none) &&
1545 (node->attr.call.callee_arr != NULL));
1548 int get_Call_n_callees(const ir_node *node)
1550 assert(is_Call(node) && node->attr.call.callee_arr);
1551 return ARR_LEN(node->attr.call.callee_arr);
1554 ir_entity *get_Call_callee(const ir_node *node, int pos)
1556 assert(pos >= 0 && pos < get_Call_n_callees(node));
1557 return node->attr.call.callee_arr[pos];
1560 void set_Call_callee_arr(ir_node *node, const int n, ir_entity ** arr)
1562 assert(is_Call(node));
1563 if (node->attr.call.callee_arr == NULL || get_Call_n_callees(node) != n) {
1564 node->attr.call.callee_arr = NEW_ARR_D(ir_entity *, current_ir_graph->obst, n);
1566 memcpy(node->attr.call.callee_arr, arr, n * sizeof(ir_entity *));
1569 void remove_Call_callee_arr(ir_node *node)
1571 assert(is_Call(node));
1572 node->attr.call.callee_arr = NULL;
1575 ir_node *get_CallBegin_ptr(const ir_node *node)
1577 assert(is_CallBegin(node));
1578 return get_irn_n(node, 0);
1581 void set_CallBegin_ptr(ir_node *node, ir_node *ptr)
1583 assert(is_CallBegin(node));
1584 set_irn_n(node, 0, ptr);
1587 ir_node *get_CallBegin_call(const ir_node *node)
1589 assert(is_CallBegin(node));
1590 return node->attr.callbegin.call;
1593 void set_CallBegin_call(ir_node *node, ir_node *call)
1595 assert(is_CallBegin(node));
1596 node->attr.callbegin.call = call;
1600 * Returns non-zero if a Call is surely a self-recursive Call.
1601 * Beware: if this functions returns 0, the call might be self-recursive!
1603 int is_self_recursive_Call(const ir_node *call)
1605 const ir_node *callee = get_Call_ptr(call);
1607 if (is_SymConst_addr_ent(callee)) {
1608 const ir_entity *ent = get_SymConst_entity(callee);
1609 const ir_graph *irg = get_entity_irg(ent);
1610 if (irg == get_irn_irg(call))
1617 ir_node * get_##OP##_left(const ir_node *node) { \
1618 assert(is_##OP(node)); \
1619 return get_irn_n(node, node->op->op_index); \
1621 void set_##OP##_left(ir_node *node, ir_node *left) { \
1622 assert(is_##OP(node)); \
1623 set_irn_n(node, node->op->op_index, left); \
1625 ir_node *get_##OP##_right(const ir_node *node) { \
1626 assert(is_##OP(node)); \
1627 return get_irn_n(node, node->op->op_index + 1); \
1629 void set_##OP##_right(ir_node *node, ir_node *right) { \
1630 assert(is_##OP(node)); \
1631 set_irn_n(node, node->op->op_index + 1, right); \
1635 ir_node *get_##OP##_op(const ir_node *node) { \
1636 assert(is_##OP(node)); \
1637 return get_irn_n(node, node->op->op_index); \
1639 void set_##OP##_op(ir_node *node, ir_node *op) { \
1640 assert(is_##OP(node)); \
1641 set_irn_n(node, node->op->op_index, op); \
1644 #define BINOP_MEM(OP) \
1648 get_##OP##_mem(const ir_node *node) { \
1649 assert(is_##OP(node)); \
1650 return get_irn_n(node, 0); \
1654 set_##OP##_mem(ir_node *node, ir_node *mem) { \
1655 assert(is_##OP(node)); \
1656 set_irn_n(node, 0, mem); \
1662 ir_mode *get_##OP##_resmode(const ir_node *node) { \
1663 assert(is_##OP(node)); \
1664 return node->attr.divmod.resmode; \
1667 void set_##OP##_resmode(ir_node *node, ir_mode *mode) { \
1668 assert(is_##OP(node)); \
1669 node->attr.divmod.resmode = mode; \
1697 int get_Div_no_remainder(const ir_node *node)
1699 assert(is_Div(node));
1700 return node->attr.divmod.no_remainder;
1703 void set_Div_no_remainder(ir_node *node, int no_remainder)
1705 assert(is_Div(node));
1706 node->attr.divmod.no_remainder = no_remainder;
1709 int get_Conv_strict(const ir_node *node)
1711 assert(is_Conv(node));
1712 return node->attr.conv.strict;
1715 void set_Conv_strict(ir_node *node, int strict_flag)
1717 assert(is_Conv(node));
1718 node->attr.conv.strict = (char)strict_flag;
1721 ir_type *get_Cast_type(ir_node *node)
1723 assert(is_Cast(node));
1724 return node->attr.cast.type;
1727 void set_Cast_type(ir_node *node, ir_type *to_tp)
1729 assert(is_Cast(node));
1730 node->attr.cast.type = to_tp;
1734 /* Checks for upcast.
1736 * Returns true if the Cast node casts a class type to a super type.
1738 int is_Cast_upcast(ir_node *node)
1740 ir_type *totype = get_Cast_type(node);
1741 ir_type *fromtype = get_irn_typeinfo_type(get_Cast_op(node));
1743 assert(get_irg_typeinfo_state(get_irn_irg(node)) == ir_typeinfo_consistent);
1746 while (is_Pointer_type(totype) && is_Pointer_type(fromtype)) {
1747 totype = get_pointer_points_to_type(totype);
1748 fromtype = get_pointer_points_to_type(fromtype);
1753 if (!is_Class_type(totype)) return 0;
1754 return is_SubClass_of(fromtype, totype);
1757 /* Checks for downcast.
1759 * Returns true if the Cast node casts a class type to a sub type.
1761 int is_Cast_downcast(ir_node *node)
1763 ir_type *totype = get_Cast_type(node);
1764 ir_type *fromtype = get_irn_typeinfo_type(get_Cast_op(node));
1766 assert(get_irg_typeinfo_state(get_irn_irg(node)) == ir_typeinfo_consistent);
1769 while (is_Pointer_type(totype) && is_Pointer_type(fromtype)) {
1770 totype = get_pointer_points_to_type(totype);
1771 fromtype = get_pointer_points_to_type(fromtype);
1776 if (!is_Class_type(totype)) return 0;
1777 return is_SubClass_of(totype, fromtype);
1780 int (is_unop)(const ir_node *node)
1782 return _is_unop(node);
1785 ir_node *get_unop_op(const ir_node *node)
1787 if (node->op->opar == oparity_unary)
1788 return get_irn_n(node, node->op->op_index);
1790 assert(node->op->opar == oparity_unary);
1794 void set_unop_op(ir_node *node, ir_node *op)
1796 if (node->op->opar == oparity_unary)
1797 set_irn_n(node, node->op->op_index, op);
1799 assert(node->op->opar == oparity_unary);
1802 int (is_binop)(const ir_node *node)
1804 return _is_binop(node);
1807 ir_node *get_binop_left(const ir_node *node)
1809 assert(node->op->opar == oparity_binary);
1810 return get_irn_n(node, node->op->op_index);
1813 void set_binop_left(ir_node *node, ir_node *left)
1815 assert(node->op->opar == oparity_binary);
1816 set_irn_n(node, node->op->op_index, left);
1819 ir_node *get_binop_right(const ir_node *node)
1821 assert(node->op->opar == oparity_binary);
1822 return get_irn_n(node, node->op->op_index + 1);
1825 void set_binop_right(ir_node *node, ir_node *right)
1827 assert(node->op->opar == oparity_binary);
1828 set_irn_n(node, node->op->op_index + 1, right);
1831 int is_Phi0(const ir_node *n)
1835 return ((get_irn_op(n) == op_Phi) &&
1836 (get_irn_arity(n) == 0) &&
1837 (get_irg_phase_state(get_irn_irg(n)) == phase_building));
1840 ir_node **get_Phi_preds_arr(ir_node *node)
1842 assert(node->op == op_Phi);
1843 return (ir_node **)&(get_irn_in(node)[1]);
1846 int get_Phi_n_preds(const ir_node *node)
1848 assert(is_Phi(node) || is_Phi0(node));
1849 return (get_irn_arity(node));
1853 void set_Phi_n_preds(ir_node *node, int n_preds)
1855 assert(node->op == op_Phi);
1859 ir_node *get_Phi_pred(const ir_node *node, int pos)
1861 assert(is_Phi(node) || is_Phi0(node));
1862 return get_irn_n(node, pos);
1865 void set_Phi_pred(ir_node *node, int pos, ir_node *pred)
1867 assert(is_Phi(node) || is_Phi0(node));
1868 set_irn_n(node, pos, pred);
1871 ir_node *(get_Phi_next)(const ir_node *phi)
1873 return _get_Phi_next(phi);
1876 void (set_Phi_next)(ir_node *phi, ir_node *next)
1878 _set_Phi_next(phi, next);
1881 int is_memop(const ir_node *node)
1883 ir_opcode code = get_irn_opcode(node);
1884 return (code == iro_Load || code == iro_Store);
1887 ir_node *get_memop_mem(const ir_node *node)
1889 assert(is_memop(node));
1890 return get_irn_n(node, 0);
1893 void set_memop_mem(ir_node *node, ir_node *mem)
1895 assert(is_memop(node));
1896 set_irn_n(node, 0, mem);
1899 ir_node *get_memop_ptr(const ir_node *node)
1901 assert(is_memop(node));
1902 return get_irn_n(node, 1);
1905 void set_memop_ptr(ir_node *node, ir_node *ptr)
1907 assert(is_memop(node));
1908 set_irn_n(node, 1, ptr);
1911 ir_node *get_Load_mem(const ir_node *node)
1913 assert(is_Load(node));
1914 return get_irn_n(node, 0);
1917 void set_Load_mem(ir_node *node, ir_node *mem)
1919 assert(is_Load(node));
1920 set_irn_n(node, 0, mem);
1923 ir_node *get_Load_ptr(const ir_node *node)
1925 assert(is_Load(node));
1926 return get_irn_n(node, 1);
1929 void set_Load_ptr(ir_node *node, ir_node *ptr)
1931 assert(is_Load(node));
1932 set_irn_n(node, 1, ptr);
1935 ir_mode *get_Load_mode(const ir_node *node)
1937 assert(is_Load(node));
1938 return node->attr.load.mode;
1941 void set_Load_mode(ir_node *node, ir_mode *mode)
1943 assert(is_Load(node));
1944 node->attr.load.mode = mode;
1947 ir_volatility get_Load_volatility(const ir_node *node)
1949 assert(is_Load(node));
1950 return node->attr.load.volatility;
1953 void set_Load_volatility(ir_node *node, ir_volatility volatility)
1955 assert(is_Load(node));
1956 node->attr.load.volatility = volatility;
1959 ir_align get_Load_align(const ir_node *node)
1961 assert(is_Load(node));
1962 return node->attr.load.aligned;
1965 void set_Load_align(ir_node *node, ir_align align)
1967 assert(is_Load(node));
1968 node->attr.load.aligned = align;
1972 ir_node *get_Store_mem(const ir_node *node)
1974 assert(is_Store(node));
1975 return get_irn_n(node, 0);
1978 void set_Store_mem(ir_node *node, ir_node *mem)
1980 assert(is_Store(node));
1981 set_irn_n(node, 0, mem);
1984 ir_node *get_Store_ptr(const ir_node *node)
1986 assert(is_Store(node));
1987 return get_irn_n(node, 1);
1990 void set_Store_ptr(ir_node *node, ir_node *ptr)
1992 assert(is_Store(node));
1993 set_irn_n(node, 1, ptr);
1996 ir_node *get_Store_value(const ir_node *node)
1998 assert(is_Store(node));
1999 return get_irn_n(node, 2);
2002 void set_Store_value(ir_node *node, ir_node *value)
2004 assert(is_Store(node));
2005 set_irn_n(node, 2, value);
2008 ir_volatility get_Store_volatility(const ir_node *node)
2010 assert(is_Store(node));
2011 return node->attr.store.volatility;
2014 void set_Store_volatility(ir_node *node, ir_volatility volatility)
2016 assert(is_Store(node));
2017 node->attr.store.volatility = volatility;
2020 ir_align get_Store_align(const ir_node *node)
2022 assert(is_Store(node));
2023 return node->attr.store.aligned;
2026 void set_Store_align(ir_node *node, ir_align align)
2028 assert(is_Store(node));
2029 node->attr.store.aligned = align;
2033 ir_node *get_Alloc_mem(const ir_node *node)
2035 assert(is_Alloc(node));
2036 return get_irn_n(node, 0);
2039 void set_Alloc_mem(ir_node *node, ir_node *mem)
2041 assert(is_Alloc(node));
2042 set_irn_n(node, 0, mem);
2045 ir_node *get_Alloc_count(const ir_node *node)
2047 assert(is_Alloc(node));
2048 return get_irn_n(node, 1);
2051 void set_Alloc_count(ir_node *node, ir_node *count)
2053 assert(is_Alloc(node));
2054 set_irn_n(node, 1, count);
2057 ir_type *get_Alloc_type(ir_node *node)
2059 assert(is_Alloc(node));
2060 return node->attr.alloc.type;
2063 void set_Alloc_type(ir_node *node, ir_type *tp)
2065 assert(is_Alloc(node));
2066 node->attr.alloc.type = tp;
2069 ir_where_alloc get_Alloc_where(const ir_node *node)
2071 assert(is_Alloc(node));
2072 return node->attr.alloc.where;
2075 void set_Alloc_where(ir_node *node, ir_where_alloc where)
2077 assert(is_Alloc(node));
2078 node->attr.alloc.where = where;
2082 ir_node *get_Free_mem(const ir_node *node)
2084 assert(is_Free(node));
2085 return get_irn_n(node, 0);
2088 void set_Free_mem(ir_node *node, ir_node *mem)
2090 assert(is_Free(node));
2091 set_irn_n(node, 0, mem);
2094 ir_node *get_Free_ptr(const ir_node *node)
2096 assert(is_Free(node));
2097 return get_irn_n(node, 1);
2100 void set_Free_ptr(ir_node *node, ir_node *ptr)
2102 assert(is_Free(node));
2103 set_irn_n(node, 1, ptr);
2106 ir_node *get_Free_size(const ir_node *node)
2108 assert(is_Free(node));
2109 return get_irn_n(node, 2);
2112 void set_Free_size(ir_node *node, ir_node *size)
2114 assert(is_Free(node));
2115 set_irn_n(node, 2, size);
2118 ir_type *get_Free_type(ir_node *node)
2120 assert(is_Free(node));
2121 return node->attr.free.type;
2124 void set_Free_type(ir_node *node, ir_type *tp)
2126 assert(is_Free(node));
2127 node->attr.free.type = tp;
2130 ir_where_alloc get_Free_where(const ir_node *node)
2132 assert(is_Free(node));
2133 return node->attr.free.where;
2136 void set_Free_where(ir_node *node, ir_where_alloc where)
2138 assert(is_Free(node));
2139 node->attr.free.where = where;
2142 ir_node **get_Sync_preds_arr(ir_node *node)
2144 assert(is_Sync(node));
2145 return (ir_node **)&(get_irn_in(node)[1]);
2148 int get_Sync_n_preds(const ir_node *node)
2150 assert(is_Sync(node));
2151 return (get_irn_arity(node));
2155 void set_Sync_n_preds(ir_node *node, int n_preds)
2157 assert(is_Sync(node));
2161 ir_node *get_Sync_pred(const ir_node *node, int pos)
2163 assert(is_Sync(node));
2164 return get_irn_n(node, pos);
2167 void set_Sync_pred(ir_node *node, int pos, ir_node *pred)
2169 assert(is_Sync(node));
2170 set_irn_n(node, pos, pred);
2173 /* Add a new Sync predecessor */
2174 void add_Sync_pred(ir_node *node, ir_node *pred)
2176 assert(is_Sync(node));
2177 add_irn_n(node, pred);
2180 /* Returns the source language type of a Proj node. */
2181 ir_type *get_Proj_type(ir_node *n)
2183 ir_type *tp = firm_unknown_type;
2184 ir_node *pred = get_Proj_pred(n);
2186 switch (get_irn_opcode(pred)) {
2189 /* Deal with Start / Call here: we need to know the Proj Nr. */
2190 assert(get_irn_mode(pred) == mode_T);
2191 pred_pred = get_Proj_pred(pred);
2193 if (is_Start(pred_pred)) {
2194 ir_type *mtp = get_entity_type(get_irg_entity(get_irn_irg(pred_pred)));
2195 tp = get_method_param_type(mtp, get_Proj_proj(n));
2196 } else if (is_Call(pred_pred)) {
2197 ir_type *mtp = get_Call_type(pred_pred);
2198 tp = get_method_res_type(mtp, get_Proj_proj(n));
2201 case iro_Start: break;
2202 case iro_Call: break;
2204 ir_node *a = get_Load_ptr(pred);
2206 tp = get_entity_type(get_Sel_entity(a));
2214 ir_node *get_Proj_pred(const ir_node *node)
2216 assert(is_Proj(node));
2217 return get_irn_n(node, 0);
2220 void set_Proj_pred(ir_node *node, ir_node *pred)
2222 assert(is_Proj(node));
2223 set_irn_n(node, 0, pred);
2226 long get_Proj_proj(const ir_node *node)
2228 #ifdef INTERPROCEDURAL_VIEW
2229 ir_opcode code = get_irn_opcode(node);
2231 if (code == iro_Proj) {
2232 return node->attr.proj;
2235 assert(code == iro_Filter);
2236 return node->attr.filter.proj;
2239 assert(is_Proj(node));
2240 return node->attr.proj;
2241 #endif /* INTERPROCEDURAL_VIEW */
2244 void set_Proj_proj(ir_node *node, long proj)
2246 #ifdef INTERPROCEDURAL_VIEW
2247 ir_opcode code = get_irn_opcode(node);
2249 if (code == iro_Proj) {
2250 node->attr.proj = proj;
2253 assert(code == iro_Filter);
2254 node->attr.filter.proj = proj;
2257 assert(is_Proj(node));
2258 node->attr.proj = proj;
2259 #endif /* INTERPROCEDURAL_VIEW */
2262 /* Returns non-zero if a node is a routine parameter. */
2263 int (is_arg_Proj)(const ir_node *node)
2265 return _is_arg_Proj(node);
2268 ir_node **get_Tuple_preds_arr(ir_node *node)
2270 assert(is_Tuple(node));
2271 return (ir_node **)&(get_irn_in(node)[1]);
2274 int get_Tuple_n_preds(const ir_node *node)
2276 assert(is_Tuple(node));
2277 return get_irn_arity(node);
2281 void set_Tuple_n_preds(ir_node *node, int n_preds)
2283 assert(is_Tuple(node));
2287 ir_node *get_Tuple_pred(const ir_node *node, int pos)
2289 assert(is_Tuple(node));
2290 return get_irn_n(node, pos);
2293 void set_Tuple_pred(ir_node *node, int pos, ir_node *pred)
2295 assert(is_Tuple(node));
2296 set_irn_n(node, pos, pred);
2299 ir_node *get_Id_pred(const ir_node *node)
2301 assert(is_Id(node));
2302 return get_irn_n(node, 0);
2305 void set_Id_pred(ir_node *node, ir_node *pred)
2307 assert(is_Id(node));
2308 set_irn_n(node, 0, pred);
2311 ir_node *get_Confirm_value(const ir_node *node)
2313 assert(is_Confirm(node));
2314 return get_irn_n(node, 0);
2317 void set_Confirm_value(ir_node *node, ir_node *value)
2319 assert(is_Confirm(node));
2320 set_irn_n(node, 0, value);
2323 ir_node *get_Confirm_bound(const ir_node *node)
2325 assert(is_Confirm(node));
2326 return get_irn_n(node, 1);
2329 void set_Confirm_bound(ir_node *node, ir_node *bound)
2331 assert(is_Confirm(node));
2332 set_irn_n(node, 0, bound);
2335 pn_Cmp get_Confirm_cmp(const ir_node *node)
2337 assert(is_Confirm(node));
2338 return node->attr.confirm.cmp;
2341 void set_Confirm_cmp(ir_node *node, pn_Cmp cmp)
2343 assert(is_Confirm(node));
2344 node->attr.confirm.cmp = cmp;
2347 ir_node *get_Filter_pred(ir_node *node)
2349 assert(is_Filter(node));
2353 void set_Filter_pred(ir_node *node, ir_node *pred)
2355 assert(is_Filter(node));
2359 long get_Filter_proj(ir_node *node)
2361 assert(is_Filter(node));
2362 return node->attr.filter.proj;
2365 void set_Filter_proj(ir_node *node, long proj)
2367 assert(is_Filter(node));
2368 node->attr.filter.proj = proj;
2371 /* Don't use get_irn_arity, get_irn_n in implementation as access
2372 shall work independent of view!!! */
2373 void set_Filter_cg_pred_arr(ir_node *node, int arity, ir_node ** in)
2375 assert(is_Filter(node));
2376 if (node->attr.filter.in_cg == NULL || arity != ARR_LEN(node->attr.filter.in_cg) - 1) {
2377 ir_graph *irg = get_irn_irg(node);
2378 node->attr.filter.in_cg = NEW_ARR_D(ir_node *, current_ir_graph->obst, arity + 1);
2379 node->attr.filter.backedge = new_backedge_arr(irg->obst, arity);
2380 node->attr.filter.in_cg[0] = node->in[0];
2382 memcpy(node->attr.filter.in_cg + 1, in, sizeof(ir_node *) * arity);
2385 void set_Filter_cg_pred(ir_node * node, int pos, ir_node * pred)
2387 assert(is_Filter(node) && node->attr.filter.in_cg &&
2388 0 <= pos && pos < ARR_LEN(node->attr.filter.in_cg) - 1);
2389 node->attr.filter.in_cg[pos + 1] = pred;
2392 int get_Filter_n_cg_preds(ir_node *node)
2394 assert(is_Filter(node) && node->attr.filter.in_cg);
2395 return (ARR_LEN(node->attr.filter.in_cg) - 1);
2398 ir_node *get_Filter_cg_pred(ir_node *node, int pos)
2401 assert(is_Filter(node) && node->attr.filter.in_cg &&
2403 arity = ARR_LEN(node->attr.filter.in_cg);
2404 assert(pos < arity - 1);
2405 return node->attr.filter.in_cg[pos + 1];
2409 ir_node *get_Mux_sel(const ir_node *node)
2411 assert(is_Mux(node));
2415 void set_Mux_sel(ir_node *node, ir_node *sel)
2417 assert(is_Mux(node));
2421 ir_node *get_Mux_false(const ir_node *node)
2423 assert(is_Mux(node));
2427 void set_Mux_false(ir_node *node, ir_node *ir_false)
2429 assert(is_Mux(node));
2430 node->in[2] = ir_false;
2433 ir_node *get_Mux_true(const ir_node *node)
2435 assert(is_Mux(node));
2439 void set_Mux_true(ir_node *node, ir_node *ir_true)
2441 assert(is_Mux(node));
2442 node->in[3] = ir_true;
2446 ir_node *get_CopyB_mem(const ir_node *node)
2448 assert(is_CopyB(node));
2449 return get_irn_n(node, 0);
2452 void set_CopyB_mem(ir_node *node, ir_node *mem)
2454 assert(node->op == op_CopyB);
2455 set_irn_n(node, 0, mem);
2458 ir_node *get_CopyB_dst(const ir_node *node)
2460 assert(is_CopyB(node));
2461 return get_irn_n(node, 1);
2464 void set_CopyB_dst(ir_node *node, ir_node *dst)
2466 assert(is_CopyB(node));
2467 set_irn_n(node, 1, dst);
2470 ir_node *get_CopyB_src(const ir_node *node)
2472 assert(is_CopyB(node));
2473 return get_irn_n(node, 2);
2476 void set_CopyB_src(ir_node *node, ir_node *src)
2478 assert(is_CopyB(node));
2479 set_irn_n(node, 2, src);
2482 ir_type *get_CopyB_type(ir_node *node)
2484 assert(is_CopyB(node));
2485 return node->attr.copyb.type;
2488 void set_CopyB_type(ir_node *node, ir_type *data_type)
2490 assert(is_CopyB(node) && data_type);
2491 node->attr.copyb.type = data_type;
2495 ir_type *get_InstOf_type(ir_node *node)
2497 assert(node->op == op_InstOf);
2498 return node->attr.instof.type;
2501 void set_InstOf_type(ir_node *node, ir_type *type)
2503 assert(node->op == op_InstOf);
2504 node->attr.instof.type = type;
2507 ir_node *get_InstOf_store(const ir_node *node)
2509 assert(node->op == op_InstOf);
2510 return get_irn_n(node, 0);
2513 void set_InstOf_store(ir_node *node, ir_node *obj)
2515 assert(node->op == op_InstOf);
2516 set_irn_n(node, 0, obj);
2519 ir_node *get_InstOf_obj(const ir_node *node)
2521 assert(node->op == op_InstOf);
2522 return get_irn_n(node, 1);
2525 void set_InstOf_obj(ir_node *node, ir_node *obj)
2527 assert(node->op == op_InstOf);
2528 set_irn_n(node, 1, obj);
2531 /* Returns the memory input of a Raise operation. */
2532 ir_node *get_Raise_mem(const ir_node *node)
2534 assert(is_Raise(node));
2535 return get_irn_n(node, 0);
2538 void set_Raise_mem(ir_node *node, ir_node *mem)
2540 assert(is_Raise(node));
2541 set_irn_n(node, 0, mem);
2544 ir_node *get_Raise_exo_ptr(const ir_node *node)
2546 assert(is_Raise(node));
2547 return get_irn_n(node, 1);
2550 void set_Raise_exo_ptr(ir_node *node, ir_node *exo_ptr)
2552 assert(is_Raise(node));
2553 set_irn_n(node, 1, exo_ptr);
2558 /* Returns the memory input of a Bound operation. */
2559 ir_node *get_Bound_mem(const ir_node *bound)
2561 assert(is_Bound(bound));
2562 return get_irn_n(bound, 0);
2565 void set_Bound_mem(ir_node *bound, ir_node *mem)
2567 assert(is_Bound(bound));
2568 set_irn_n(bound, 0, mem);
2571 /* Returns the index input of a Bound operation. */
2572 ir_node *get_Bound_index(const ir_node *bound)
2574 assert(is_Bound(bound));
2575 return get_irn_n(bound, 1);
2578 void set_Bound_index(ir_node *bound, ir_node *idx)
2580 assert(is_Bound(bound));
2581 set_irn_n(bound, 1, idx);
2584 /* Returns the lower bound input of a Bound operation. */
2585 ir_node *get_Bound_lower(const ir_node *bound)
2587 assert(is_Bound(bound));
2588 return get_irn_n(bound, 2);
2591 void set_Bound_lower(ir_node *bound, ir_node *lower)
2593 assert(is_Bound(bound));
2594 set_irn_n(bound, 2, lower);
2597 /* Returns the upper bound input of a Bound operation. */
2598 ir_node *get_Bound_upper(const ir_node *bound)
2600 assert(is_Bound(bound));
2601 return get_irn_n(bound, 3);
2604 void set_Bound_upper(ir_node *bound, ir_node *upper)
2606 assert(is_Bound(bound));
2607 set_irn_n(bound, 3, upper);
2610 /* Return the operand of a Pin node. */
2611 ir_node *get_Pin_op(const ir_node *pin)
2613 assert(is_Pin(pin));
2614 return get_irn_n(pin, 0);
2617 void set_Pin_op(ir_node *pin, ir_node *node)
2619 assert(is_Pin(pin));
2620 set_irn_n(pin, 0, node);
2623 /* Return the assembler text of an ASM pseudo node. */
2624 ident *get_ASM_text(const ir_node *node)
2626 assert(is_ASM(node));
2627 return node->attr.assem.asm_text;
2630 /* Return the number of input constraints for an ASM node. */
2631 int get_ASM_n_input_constraints(const ir_node *node)
2633 assert(is_ASM(node));
2634 return ARR_LEN(node->attr.assem.inputs);
2637 /* Return the input constraints for an ASM node. This is a flexible array. */
2638 const ir_asm_constraint *get_ASM_input_constraints(const ir_node *node)
2640 assert(is_ASM(node));
2641 return node->attr.assem.inputs;
2644 /* Return the number of output constraints for an ASM node. */
2645 int get_ASM_n_output_constraints(const ir_node *node)
2647 assert(is_ASM(node));
2648 return ARR_LEN(node->attr.assem.outputs);
2651 /* Return the output constraints for an ASM node. */
2652 const ir_asm_constraint *get_ASM_output_constraints(const ir_node *node)
2654 assert(is_ASM(node));
2655 return node->attr.assem.outputs;
2658 /* Return the number of clobbered registers for an ASM node. */
2659 int get_ASM_n_clobbers(const ir_node *node)
2661 assert(is_ASM(node));
2662 return ARR_LEN(node->attr.assem.clobber);
2665 /* Return the list of clobbered registers for an ASM node. */
2666 ident **get_ASM_clobbers(const ir_node *node)
2668 assert(is_ASM(node));
2669 return node->attr.assem.clobber;
2672 /* returns the graph of a node */
2673 ir_graph *(get_irn_irg)(const ir_node *node)
2675 return _get_irn_irg(node);
2679 /*----------------------------------------------------------------*/
2680 /* Auxiliary routines */
2681 /*----------------------------------------------------------------*/
2683 ir_node *skip_Proj(ir_node *node)
2685 /* don't assert node !!! */
2690 node = get_Proj_pred(node);
2696 skip_Proj_const(const ir_node *node)
2698 /* don't assert node !!! */
2703 node = get_Proj_pred(node);
2708 ir_node *skip_Tuple(ir_node *node)
2714 if (is_Proj(node)) {
2715 pred = get_Proj_pred(node);
2716 op = get_irn_op(pred);
2719 * Looks strange but calls get_irn_op() only once
2720 * in most often cases.
2722 if (op == op_Proj) { /* nested Tuple ? */
2723 pred = skip_Tuple(pred);
2725 if (is_Tuple(pred)) {
2726 node = get_Tuple_pred(pred, get_Proj_proj(node));
2729 } else if (op == op_Tuple) {
2730 node = get_Tuple_pred(pred, get_Proj_proj(node));
2737 /* returns operand of node if node is a Cast */
2738 ir_node *skip_Cast(ir_node *node)
2741 return get_Cast_op(node);
2745 /* returns operand of node if node is a Cast */
2746 const ir_node *skip_Cast_const(const ir_node *node)
2749 return get_Cast_op(node);
2753 /* returns operand of node if node is a Pin */
2754 ir_node *skip_Pin(ir_node *node)
2757 return get_Pin_op(node);
2761 /* returns operand of node if node is a Confirm */
2762 ir_node *skip_Confirm(ir_node *node)
2764 if (is_Confirm(node))
2765 return get_Confirm_value(node);
2769 /* skip all high-level ops */
2770 ir_node *skip_HighLevel_ops(ir_node *node)
2772 while (is_op_highlevel(get_irn_op(node))) {
2773 node = get_irn_n(node, 0);
2779 /* This should compact Id-cycles to self-cycles. It has the same (or less?) complexity
2780 * than any other approach, as Id chains are resolved and all point to the real node, or
2781 * all id's are self loops.
2783 * Note: This function takes 10% of mostly ANY the compiler run, so it's
2784 * a little bit "hand optimized".
2786 * Moreover, it CANNOT be switched off using get_opt_normalize() ...
2788 ir_node *skip_Id(ir_node *node)
2791 /* don't assert node !!! */
2793 if (!node || (node->op != op_Id)) return node;
2795 /* Don't use get_Id_pred(): We get into an endless loop for
2796 self-referencing Ids. */
2797 pred = node->in[0+1];
2799 if (pred->op != op_Id) return pred;
2801 if (node != pred) { /* not a self referencing Id. Resolve Id chain. */
2802 ir_node *rem_pred, *res;
2804 if (pred->op != op_Id) return pred; /* shortcut */
2807 assert(get_irn_arity (node) > 0);
2809 node->in[0+1] = node; /* turn us into a self referencing Id: shorten Id cycles. */
2810 res = skip_Id(rem_pred);
2811 if (res->op == op_Id) /* self-loop */ return node;
2813 node->in[0+1] = res; /* Turn Id chain into Ids all referencing the chain end. */
2820 int (is_strictConv)(const ir_node *node)
2822 return _is_strictConv(node);
2825 int (is_no_Block)(const ir_node *node)
2827 return _is_no_Block(node);
2830 /* Returns true if node is a SymConst node with kind symconst_addr_ent. */
2831 int (is_SymConst_addr_ent)(const ir_node *node)
2833 return _is_SymConst_addr_ent(node);
2836 /* Returns true if the operation manipulates control flow. */
2837 int is_cfop(const ir_node *node)
2839 return is_op_cfopcode(get_irn_op(node));
2842 /* Returns true if the operation manipulates interprocedural control flow:
2843 CallBegin, EndReg, EndExcept */
2844 int is_ip_cfop(const ir_node *node)
2846 return is_ip_cfopcode(get_irn_op(node));
2849 /* Returns true if the operation can change the control flow because
2851 int is_fragile_op(const ir_node *node)
2853 return is_op_fragile(get_irn_op(node));
2856 /* Returns the memory operand of fragile operations. */
2857 ir_node *get_fragile_op_mem(ir_node *node)
2859 assert(node && is_fragile_op(node));
2861 switch (get_irn_opcode(node)) {
2872 return get_irn_n(node, pn_Generic_M);
2877 assert(0 && "should not be reached");
2882 /* Returns the result mode of a Div operation. */
2883 ir_mode *get_divop_resmod(const ir_node *node)
2885 switch (get_irn_opcode(node)) {
2886 case iro_Quot : return get_Quot_resmode(node);
2887 case iro_DivMod: return get_DivMod_resmode(node);
2888 case iro_Div : return get_Div_resmode(node);
2889 case iro_Mod : return get_Mod_resmode(node);
2891 assert(0 && "should not be reached");
2896 /* Returns true if the operation is a forking control flow operation. */
2897 int (is_irn_forking)(const ir_node *node)
2899 return _is_irn_forking(node);
2902 void (copy_node_attr)(ir_graph *irg, const ir_node *old_node, ir_node *new_node)
2904 _copy_node_attr(irg, old_node, new_node);
2907 /* Return the type associated with the value produced by n
2908 * if the node remarks this type as it is the case for
2909 * Cast, Const, SymConst and some Proj nodes. */
2910 ir_type *(get_irn_type)(ir_node *node)
2912 return _get_irn_type(node);
2915 /* Return the type attribute of a node n (SymConst, Call, Alloc, Free,
2917 ir_type *(get_irn_type_attr)(ir_node *node)
2919 return _get_irn_type_attr(node);
2922 /* Return the entity attribute of a node n (SymConst, Sel) or NULL. */
2923 ir_entity *(get_irn_entity_attr)(ir_node *node)
2925 return _get_irn_entity_attr(node);
2928 /* Returns non-zero for constant-like nodes. */
2929 int (is_irn_constlike)(const ir_node *node)
2931 return _is_irn_constlike(node);
2935 * Returns non-zero for nodes that are allowed to have keep-alives and
2936 * are neither Block nor PhiM.
2938 int (is_irn_keep)(const ir_node *node)
2940 return _is_irn_keep(node);
2944 * Returns non-zero for nodes that are always placed in the start block.
2946 int (is_irn_start_block_placed)(const ir_node *node)
2948 return _is_irn_start_block_placed(node);
2951 /* Returns non-zero for nodes that are machine operations. */
2952 int (is_irn_machine_op)(const ir_node *node)
2954 return _is_irn_machine_op(node);
2957 /* Returns non-zero for nodes that are machine operands. */
2958 int (is_irn_machine_operand)(const ir_node *node)
2960 return _is_irn_machine_operand(node);
2963 /* Returns non-zero for nodes that have the n'th user machine flag set. */
2964 int (is_irn_machine_user)(const ir_node *node, unsigned n)
2966 return _is_irn_machine_user(node, n);
2969 /* Returns non-zero for nodes that are CSE neutral to its users. */
2970 int (is_irn_cse_neutral)(const ir_node *node)
2972 return _is_irn_cse_neutral(node);
2975 /* Gets the string representation of the jump prediction .*/
2976 const char *get_cond_jmp_predicate_name(cond_jmp_predicate pred)
2978 #define X(a) case a: return #a;
2980 X(COND_JMP_PRED_NONE);
2981 X(COND_JMP_PRED_TRUE);
2982 X(COND_JMP_PRED_FALSE);
2988 /* Returns the conditional jump prediction of a Cond node. */
2989 cond_jmp_predicate (get_Cond_jmp_pred)(const ir_node *cond)
2991 return _get_Cond_jmp_pred(cond);
2994 /* Sets a new conditional jump prediction. */
2995 void (set_Cond_jmp_pred)(ir_node *cond, cond_jmp_predicate pred)
2997 _set_Cond_jmp_pred(cond, pred);
3000 /** the get_type operation must be always implemented and return a firm type */
3001 static ir_type *get_Default_type(ir_node *n)
3004 return get_unknown_type();
3007 /* Sets the get_type operation for an ir_op_ops. */
3008 ir_op_ops *firm_set_default_get_type(ir_opcode code, ir_op_ops *ops)
3011 case iro_Const: ops->get_type = get_Const_type; break;
3012 case iro_SymConst: ops->get_type = get_SymConst_value_type; break;
3013 case iro_Cast: ops->get_type = get_Cast_type; break;
3014 case iro_Proj: ops->get_type = get_Proj_type; break;
3016 /* not allowed to be NULL */
3017 if (! ops->get_type)
3018 ops->get_type = get_Default_type;
3024 /** Return the attribute type of a SymConst node if exists */
3025 static ir_type *get_SymConst_attr_type(ir_node *self)
3027 symconst_kind kind = get_SymConst_kind(self);
3028 if (SYMCONST_HAS_TYPE(kind))
3029 return get_SymConst_type(self);
3033 /** Return the attribute entity of a SymConst node if exists */
3034 static ir_entity *get_SymConst_attr_entity(ir_node *self)
3036 symconst_kind kind = get_SymConst_kind(self);
3037 if (SYMCONST_HAS_ENT(kind))
3038 return get_SymConst_entity(self);
3042 /** the get_type_attr operation must be always implemented */
3043 static ir_type *get_Null_type(ir_node *n)
3046 return firm_unknown_type;
3049 /* Sets the get_type operation for an ir_op_ops. */
3050 ir_op_ops *firm_set_default_get_type_attr(ir_opcode code, ir_op_ops *ops)
3053 case iro_SymConst: ops->get_type_attr = get_SymConst_attr_type; break;
3054 case iro_Call: ops->get_type_attr = get_Call_type; break;
3055 case iro_Alloc: ops->get_type_attr = get_Alloc_type; break;
3056 case iro_Free: ops->get_type_attr = get_Free_type; break;
3057 case iro_Cast: ops->get_type_attr = get_Cast_type; break;
3059 /* not allowed to be NULL */
3060 if (! ops->get_type_attr)
3061 ops->get_type_attr = get_Null_type;
3067 /** the get_entity_attr operation must be always implemented */
3068 static ir_entity *get_Null_ent(ir_node *n)
3074 /* Sets the get_type operation for an ir_op_ops. */
3075 ir_op_ops *firm_set_default_get_entity_attr(ir_opcode code, ir_op_ops *ops)
3078 case iro_SymConst: ops->get_entity_attr = get_SymConst_attr_entity; break;
3079 case iro_Sel: ops->get_entity_attr = _get_Sel_entity; break;
3081 /* not allowed to be NULL */
3082 if (! ops->get_entity_attr)
3083 ops->get_entity_attr = get_Null_ent;
3089 /* Sets the debug information of a node. */
3090 void (set_irn_dbg_info)(ir_node *n, dbg_info *db)
3092 _set_irn_dbg_info(n, db);
3096 * Returns the debug information of an node.
3098 * @param n The node.
3100 dbg_info *(get_irn_dbg_info)(const ir_node *n)
3102 return _get_irn_dbg_info(n);
3105 /* checks whether a node represents a global address */
3106 int is_Global(const ir_node *node)
3108 return is_SymConst_addr_ent(node);
3111 /* returns the entity of a global address */
3112 ir_entity *get_Global_entity(const ir_node *node)
3114 return get_SymConst_entity(node);
3118 * Calculate a hash value of a node.
3120 unsigned firm_default_hash(const ir_node *node)
3125 /* hash table value = 9*(9*(9*(9*(9*arity+in[0])+in[1])+ ...)+mode)+code */
3126 h = irn_arity = get_irn_intra_arity(node);
3128 /* consider all in nodes... except the block if not a control flow. */
3129 for (i = is_cfop(node) ? -1 : 0; i < irn_arity; ++i) {
3130 ir_node *pred = get_irn_intra_n(node, i);
3131 if (is_irn_cse_neutral(pred))
3134 h = 9*h + HASH_PTR(pred);
3138 h = 9*h + HASH_PTR(get_irn_mode(node));
3140 h = 9*h + HASH_PTR(get_irn_op(node));
3143 } /* firm_default_hash */
3145 /* include generated code */
3146 #include "gen_irnode.c.inl"