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) {
67 assert(pnc >= 0 && pnc <
68 (int) (sizeof(pnc_name_arr)/sizeof(pnc_name_arr[0])));
69 return pnc_name_arr[pnc];
73 * Calculates the negated (Complement(R)) pnc condition.
75 pn_Cmp get_negated_pnc(long pnc, ir_mode *mode) {
78 /* do NOT add the Uo bit for non-floating point values */
79 if (! mode_is_float(mode))
85 /* Calculates the inversed (R^-1) pnc condition, i.e., "<" --> ">" */
86 pn_Cmp get_inversed_pnc(long pnc) {
87 long code = pnc & ~(pn_Cmp_Lt|pn_Cmp_Gt);
88 long lesser = pnc & pn_Cmp_Lt;
89 long greater = pnc & pn_Cmp_Gt;
91 code |= (lesser ? pn_Cmp_Gt : 0) | (greater ? pn_Cmp_Lt : 0);
97 * Indicates, whether additional data can be registered to ir nodes.
98 * If set to 1, this is not possible anymore.
100 static int forbid_new_data = 0;
103 * The amount of additional space for custom data to be allocated upon
104 * creating a new node.
106 unsigned firm_add_node_size = 0;
109 /* register new space for every node */
110 unsigned firm_register_additional_node_data(unsigned size) {
111 assert(!forbid_new_data && "Too late to register additional node data");
116 return firm_add_node_size += size;
120 void init_irnode(void) {
121 /* Forbid the addition of new data to an ir node. */
126 * irnode constructor.
127 * Create a new irnode in irg, with an op, mode, arity and
128 * some incoming irnodes.
129 * If arity is negative, a node with a dynamic array is created.
132 new_ir_node(dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, ir_mode *mode,
133 int arity, ir_node **in)
136 size_t node_size = offsetof(ir_node, attr) + op->attr_size + firm_add_node_size;
143 p = obstack_alloc(irg->obst, node_size);
144 memset(p, 0, node_size);
145 res = (ir_node *)(p + firm_add_node_size);
147 res->kind = k_ir_node;
151 res->node_idx = irg_register_node_idx(irg, res);
156 res->in = NEW_ARR_F(ir_node *, 1); /* 1: space for block */
158 /* not nice but necessary: End and Sync must always have a flexible array */
159 if (op == op_End || op == op_Sync)
160 res->in = NEW_ARR_F(ir_node *, (arity+1));
162 res->in = NEW_ARR_D(ir_node *, irg->obst, (arity+1));
163 memcpy(&res->in[1], in, sizeof(ir_node *) * arity);
167 set_irn_dbg_info(res, db);
169 res->node_nr = get_irp_new_node_nr();
171 for (i = 0; i < EDGE_KIND_LAST; ++i)
172 INIT_LIST_HEAD(&res->edge_info[i].outs_head);
174 /* don't put this into the for loop, arity is -1 for some nodes! */
175 edges_notify_edge(res, -1, res->in[0], NULL, irg);
176 for (i = 1; i <= arity; ++i)
177 edges_notify_edge(res, i - 1, res->in[i], NULL, irg);
179 hook_new_node(irg, res);
180 if (get_irg_phase_state(irg) == phase_backend) {
181 be_info_new_node(res);
187 /*-- getting some parameters from ir_nodes --*/
189 int (is_ir_node)(const void *thing) {
190 return _is_ir_node(thing);
193 int (get_irn_intra_arity)(const ir_node *node) {
194 return _get_irn_intra_arity(node);
197 int (get_irn_inter_arity)(const ir_node *node) {
198 return _get_irn_inter_arity(node);
201 int (*_get_irn_arity)(const ir_node *node) = _get_irn_intra_arity;
203 int (get_irn_arity)(const ir_node *node) {
204 return _get_irn_arity(node);
207 /* Returns the array with ins. This array is shifted with respect to the
208 array accessed by get_irn_n: The block operand is at position 0 not -1.
209 (@@@ This should be changed.)
210 The order of the predecessors in this array is not guaranteed, except that
211 lists of operands as predecessors of Block or arguments of a Call are
213 ir_node **get_irn_in(const ir_node *node) {
215 #ifdef INTERPROCEDURAL_VIEW
216 if (get_interprocedural_view()) { /* handle Filter and Block specially */
217 if (get_irn_opcode(node) == iro_Filter) {
218 assert(node->attr.filter.in_cg);
219 return node->attr.filter.in_cg;
220 } else if (get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
221 return node->attr.block.in_cg;
223 /* else fall through */
225 #endif /* INTERPROCEDURAL_VIEW */
229 void set_irn_in(ir_node *node, int arity, ir_node **in) {
232 ir_graph *irg = current_ir_graph;
235 #ifdef INTERPROCEDURAL_VIEW
236 if (get_interprocedural_view()) { /* handle Filter and Block specially */
237 ir_opcode code = get_irn_opcode(node);
238 if (code == iro_Filter) {
239 assert(node->attr.filter.in_cg);
240 pOld_in = &node->attr.filter.in_cg;
241 } else if (code == iro_Block && node->attr.block.in_cg) {
242 pOld_in = &node->attr.block.in_cg;
247 #endif /* INTERPROCEDURAL_VIEW */
251 for (i = 0; i < arity; i++) {
252 if (i < ARR_LEN(*pOld_in)-1)
253 edges_notify_edge(node, i, in[i], (*pOld_in)[i+1], irg);
255 edges_notify_edge(node, i, in[i], NULL, irg);
257 for (;i < ARR_LEN(*pOld_in)-1; i++) {
258 edges_notify_edge(node, i, NULL, (*pOld_in)[i+1], irg);
261 if (arity != ARR_LEN(*pOld_in) - 1) {
262 ir_node * block = (*pOld_in)[0];
263 *pOld_in = NEW_ARR_D(ir_node *, irg->obst, arity + 1);
264 (*pOld_in)[0] = block;
266 fix_backedges(irg->obst, node);
268 memcpy((*pOld_in) + 1, in, sizeof(ir_node *) * arity);
271 ir_node *(get_irn_intra_n)(const ir_node *node, int n) {
272 return _get_irn_intra_n(node, n);
275 ir_node *(get_irn_inter_n)(const ir_node *node, int n) {
276 return _get_irn_inter_n(node, n);
279 ir_node *(*_get_irn_n)(const ir_node *node, int n) = _get_irn_intra_n;
281 ir_node *(get_irn_n)(const ir_node *node, int n) {
282 return _get_irn_n(node, n);
285 void set_irn_n(ir_node *node, int n, ir_node *in) {
286 assert(node && node->kind == k_ir_node);
288 assert(n < get_irn_arity(node));
289 assert(in && in->kind == k_ir_node);
291 #ifdef INTERPROCEDURAL_VIEW
292 if ((n == -1) && (get_irn_opcode(node) == iro_Filter)) {
293 /* Change block pred in both views! */
294 node->in[n + 1] = in;
295 assert(node->attr.filter.in_cg);
296 node->attr.filter.in_cg[n + 1] = in;
299 if (get_interprocedural_view()) { /* handle Filter and Block specially */
300 if (get_irn_opcode(node) == iro_Filter) {
301 assert(node->attr.filter.in_cg);
302 node->attr.filter.in_cg[n + 1] = in;
304 } else if (get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) {
305 node->attr.block.in_cg[n + 1] = in;
308 /* else fall through */
310 #endif /* INTERPROCEDURAL_VIEW */
313 hook_set_irn_n(node, n, in, node->in[n + 1]);
315 /* Here, we rely on src and tgt being in the current ir graph */
316 edges_notify_edge(node, n, in, node->in[n + 1], current_ir_graph);
318 node->in[n + 1] = in;
321 int add_irn_n(ir_node *node, ir_node *in) {
323 ir_graph *irg = get_irn_irg(node);
325 assert(node->op->opar == oparity_dynamic);
326 pos = ARR_LEN(node->in) - 1;
327 ARR_APP1(ir_node *, node->in, in);
328 edges_notify_edge(node, pos, node->in[pos + 1], NULL, irg);
331 hook_set_irn_n(node, pos, node->in[pos + 1], NULL);
336 void del_Sync_n(ir_node *n, int i)
338 int arity = get_Sync_n_preds(n);
339 ir_node *last_pred = get_Sync_pred(n, arity - 1);
340 set_Sync_pred(n, i, last_pred);
341 edges_notify_edge(n, arity - 1, NULL, last_pred, get_irn_irg(n));
342 ARR_SHRINKLEN(get_irn_in(n), arity);
345 int (get_irn_deps)(const ir_node *node) {
346 return _get_irn_deps(node);
349 ir_node *(get_irn_dep)(const ir_node *node, int pos) {
350 return _get_irn_dep(node, pos);
353 void (set_irn_dep)(ir_node *node, int pos, ir_node *dep) {
354 _set_irn_dep(node, pos, dep);
357 int add_irn_dep(ir_node *node, ir_node *dep) {
360 /* DEP edges are only allowed in backend phase */
361 assert(get_irg_phase_state(get_irn_irg(node)) == phase_backend);
362 if (node->deps == NULL) {
363 node->deps = NEW_ARR_F(ir_node *, 1);
369 for(i = 0, n = ARR_LEN(node->deps); i < n; ++i) {
370 if(node->deps[i] == NULL)
373 if(node->deps[i] == dep)
377 if (first_zero >= 0) {
378 node->deps[first_zero] = dep;
381 ARR_APP1(ir_node *, node->deps, dep);
386 edges_notify_edge_kind(node, res, dep, NULL, EDGE_KIND_DEP, get_irn_irg(node));
391 void add_irn_deps(ir_node *tgt, ir_node *src) {
394 for (i = 0, n = get_irn_deps(src); i < n; ++i)
395 add_irn_dep(tgt, get_irn_dep(src, i));
399 ir_mode *(get_irn_mode)(const ir_node *node) {
400 return _get_irn_mode(node);
403 void (set_irn_mode)(ir_node *node, ir_mode *mode) {
404 _set_irn_mode(node, mode);
407 /** Gets the string representation of the mode .*/
408 const char *get_irn_modename(const ir_node *node) {
410 return get_mode_name(node->mode);
413 ident *get_irn_modeident(const ir_node *node) {
415 return get_mode_ident(node->mode);
418 ir_op *(get_irn_op)(const ir_node *node) {
419 return _get_irn_op(node);
422 /* should be private to the library: */
423 void (set_irn_op)(ir_node *node, ir_op *op) {
424 _set_irn_op(node, op);
427 unsigned (get_irn_opcode)(const ir_node *node) {
428 return _get_irn_opcode(node);
431 const char *get_irn_opname(const ir_node *node) {
433 if (is_Phi0(node)) return "Phi0";
434 return get_id_str(node->op->name);
437 ident *get_irn_opident(const ir_node *node) {
439 return node->op->name;
442 ir_visited_t (get_irn_visited)(const ir_node *node) {
443 return _get_irn_visited(node);
446 void (set_irn_visited)(ir_node *node, ir_visited_t visited) {
447 _set_irn_visited(node, visited);
450 void (mark_irn_visited)(ir_node *node) {
451 _mark_irn_visited(node);
454 int (irn_visited)(const ir_node *node) {
455 return _irn_visited(node);
458 int (irn_visited_else_mark)(ir_node *node) {
459 return _irn_visited_else_mark(node);
462 void (set_irn_link)(ir_node *node, void *link) {
463 _set_irn_link(node, link);
466 void *(get_irn_link)(const ir_node *node) {
467 return _get_irn_link(node);
470 op_pin_state (get_irn_pinned)(const ir_node *node) {
471 return _get_irn_pinned(node);
474 op_pin_state (is_irn_pinned_in_irg) (const ir_node *node) {
475 return _is_irn_pinned_in_irg(node);
478 void set_irn_pinned(ir_node *node, op_pin_state state) {
479 /* due to optimization an opt may be turned into a Tuple */
483 assert(node && get_op_pinned(get_irn_op(node)) >= op_pin_state_exc_pinned);
484 assert(state == op_pin_state_pinned || state == op_pin_state_floats);
486 node->attr.except.pin_state = state;
489 /* Outputs a unique number for this node */
490 long get_irn_node_nr(const ir_node *node) {
492 return node->node_nr;
495 const_attr *get_irn_const_attr(ir_node *node) {
496 assert(is_Const(node));
497 return &node->attr.con;
500 long get_irn_proj_attr(ir_node *node) {
501 /* BEWARE: check for true Proj node here, no Filter */
502 assert(node->op == op_Proj);
503 return node->attr.proj;
506 alloc_attr *get_irn_alloc_attr(ir_node *node) {
507 assert(is_Alloc(node));
508 return &node->attr.alloc;
511 free_attr *get_irn_free_attr(ir_node *node) {
512 assert(is_Free(node));
513 return &node->attr.free;
516 symconst_attr *get_irn_symconst_attr(ir_node *node) {
517 assert(is_SymConst(node));
518 return &node->attr.symc;
521 call_attr *get_irn_call_attr(ir_node *node) {
522 assert(is_Call(node));
523 node->attr.call.type = skip_tid(node->attr.call.type);
524 return &node->attr.call;
527 sel_attr *get_irn_sel_attr(ir_node *node) {
528 assert(is_Sel(node));
529 return &node->attr.sel;
532 phi_attr *get_irn_phi_attr(ir_node *node) {
533 return &node->attr.phi;
536 block_attr *get_irn_block_attr(ir_node *node) {
537 assert(is_Block(node));
538 return &node->attr.block;
541 load_attr *get_irn_load_attr(ir_node *node) {
542 assert(is_Load(node));
543 return &node->attr.load;
546 store_attr *get_irn_store_attr(ir_node *node) {
547 assert(is_Store(node));
548 return &node->attr.store;
551 except_attr *get_irn_except_attr(ir_node *node) {
552 assert(node->op == op_Div || node->op == op_Quot ||
553 node->op == op_DivMod || node->op == op_Mod || node->op == op_Call || node->op == op_Alloc || node->op == op_Bound);
554 return &node->attr.except;
557 divmod_attr *get_irn_divmod_attr(ir_node *node) {
558 assert(node->op == op_Div || node->op == op_Quot ||
559 node->op == op_DivMod || node->op == op_Mod);
560 return &node->attr.divmod;
563 builtin_attr *get_irn_builtin_attr(ir_node *node) {
564 assert(is_Builtin(node));
565 return &node->attr.builtin;
568 void *(get_irn_generic_attr)(ir_node *node) {
569 assert(is_ir_node(node));
570 return _get_irn_generic_attr(node);
573 const void *(get_irn_generic_attr_const)(const ir_node *node) {
574 assert(is_ir_node(node));
575 return _get_irn_generic_attr_const(node);
578 unsigned (get_irn_idx)(const ir_node *node) {
579 assert(is_ir_node(node));
580 return _get_irn_idx(node);
583 int get_irn_pred_pos(ir_node *node, ir_node *arg) {
585 for (i = get_irn_arity(node) - 1; i >= 0; i--) {
586 if (get_irn_n(node, i) == arg)
592 /** manipulate fields of individual nodes **/
594 /* this works for all except Block */
595 ir_node *get_nodes_block(const ir_node *node) {
596 assert(node->op != op_Block);
597 return get_irn_n(node, -1);
600 void set_nodes_block(ir_node *node, ir_node *block) {
601 assert(node->op != op_Block);
602 set_irn_n(node, -1, block);
605 /* this works for all except Block */
606 ir_node *get_nodes_MacroBlock(const ir_node *node) {
607 assert(node->op != op_Block);
608 return get_Block_MacroBlock(get_irn_n(node, -1));
611 /* Test whether arbitrary node is frame pointer, i.e. Proj(pn_Start_P_frame_base)
612 * from Start. If so returns frame type, else Null. */
613 ir_type *is_frame_pointer(const ir_node *n) {
614 if (is_Proj(n) && (get_Proj_proj(n) == pn_Start_P_frame_base)) {
615 ir_node *start = get_Proj_pred(n);
616 if (is_Start(start)) {
617 return get_irg_frame_type(get_irn_irg(start));
623 /* Test whether arbitrary node is tls pointer, i.e. Proj(pn_Start_P_tls)
624 * from Start. If so returns tls type, else Null. */
625 ir_type *is_tls_pointer(const ir_node *n) {
626 if (is_Proj(n) && (get_Proj_proj(n) == pn_Start_P_tls)) {
627 ir_node *start = get_Proj_pred(n);
628 if (is_Start(start)) {
629 return get_tls_type();
635 ir_node **get_Block_cfgpred_arr(ir_node *node) {
636 assert(is_Block(node));
637 return (ir_node **)&(get_irn_in(node)[1]);
640 int (get_Block_n_cfgpreds)(const ir_node *node) {
641 return _get_Block_n_cfgpreds(node);
644 ir_node *(get_Block_cfgpred)(const ir_node *node, int pos) {
645 return _get_Block_cfgpred(node, pos);
648 void set_Block_cfgpred(ir_node *node, int pos, ir_node *pred) {
649 assert(is_Block(node));
650 set_irn_n(node, pos, pred);
653 int get_Block_cfgpred_pos(const ir_node *block, const ir_node *pred) {
656 for (i = get_Block_n_cfgpreds(block) - 1; i >= 0; --i) {
657 if (get_Block_cfgpred_block(block, i) == pred)
663 ir_node *(get_Block_cfgpred_block)(const ir_node *node, int pos) {
664 return _get_Block_cfgpred_block(node, pos);
667 int get_Block_matured(const ir_node *node) {
668 assert(is_Block(node));
669 return (int)node->attr.block.is_matured;
672 void set_Block_matured(ir_node *node, int matured) {
673 assert(is_Block(node));
674 node->attr.block.is_matured = matured;
677 ir_visited_t (get_Block_block_visited)(const ir_node *node) {
678 return _get_Block_block_visited(node);
681 void (set_Block_block_visited)(ir_node *node, ir_visited_t visit) {
682 _set_Block_block_visited(node, visit);
685 /* For this current_ir_graph must be set. */
686 void (mark_Block_block_visited)(ir_node *node) {
687 _mark_Block_block_visited(node);
690 int (Block_block_visited)(const ir_node *node) {
691 return _Block_block_visited(node);
694 ir_node *get_Block_graph_arr(ir_node *node, int pos) {
695 assert(is_Block(node));
696 return node->attr.block.graph_arr[pos+1];
699 void set_Block_graph_arr(ir_node *node, int pos, ir_node *value) {
700 assert(is_Block(node));
701 node->attr.block.graph_arr[pos+1] = value;
704 #ifdef INTERPROCEDURAL_VIEW
705 void set_Block_cg_cfgpred_arr(ir_node *node, int arity, ir_node *in[]) {
706 assert(is_Block(node));
707 if (node->attr.block.in_cg == NULL || arity != ARR_LEN(node->attr.block.in_cg) - 1) {
708 node->attr.block.in_cg = NEW_ARR_D(ir_node *, current_ir_graph->obst, arity + 1);
709 node->attr.block.in_cg[0] = NULL;
710 node->attr.block.cg_backedge = new_backedge_arr(current_ir_graph->obst, arity);
712 /* Fix backedge array. fix_backedges() operates depending on
713 interprocedural_view. */
714 int ipv = get_interprocedural_view();
715 set_interprocedural_view(1);
716 fix_backedges(current_ir_graph->obst, node);
717 set_interprocedural_view(ipv);
720 memcpy(node->attr.block.in_cg + 1, in, sizeof(ir_node *) * arity);
723 void set_Block_cg_cfgpred(ir_node *node, int pos, ir_node *pred) {
724 assert(is_Block(node) && node->attr.block.in_cg &&
725 0 <= pos && pos < ARR_LEN(node->attr.block.in_cg) - 1);
726 node->attr.block.in_cg[pos + 1] = pred;
729 ir_node **get_Block_cg_cfgpred_arr(ir_node *node) {
730 assert(is_Block(node));
731 return node->attr.block.in_cg == NULL ? NULL : node->attr.block.in_cg + 1;
734 int get_Block_cg_n_cfgpreds(const ir_node *node) {
735 assert(is_Block(node));
736 return node->attr.block.in_cg == NULL ? 0 : ARR_LEN(node->attr.block.in_cg) - 1;
739 ir_node *get_Block_cg_cfgpred(const ir_node *node, int pos) {
740 assert(is_Block(node) && node->attr.block.in_cg);
741 return node->attr.block.in_cg[pos + 1];
744 void remove_Block_cg_cfgpred_arr(ir_node *node) {
745 assert(is_Block(node));
746 node->attr.block.in_cg = NULL;
748 #endif /* INTERPROCEDURAL_VIEW */
750 ir_node *(set_Block_dead)(ir_node *block) {
751 return _set_Block_dead(block);
754 int (is_Block_dead)(const ir_node *block) {
755 return _is_Block_dead(block);
758 ir_extblk *get_Block_extbb(const ir_node *block) {
760 assert(is_Block(block));
761 res = block->attr.block.extblk;
762 assert(res == NULL || is_ir_extbb(res));
766 void set_Block_extbb(ir_node *block, ir_extblk *extblk) {
767 assert(is_Block(block));
768 assert(extblk == NULL || is_ir_extbb(extblk));
769 block->attr.block.extblk = extblk;
772 /* Returns the macro block header of a block.*/
773 ir_node *get_Block_MacroBlock(const ir_node *block) {
775 assert(is_Block(block));
776 mbh = get_irn_n(block, -1);
777 /* once macro block header is respected by all optimizations,
778 this assert can be removed */
783 /* Sets the macro block header of a block. */
784 void set_Block_MacroBlock(ir_node *block, ir_node *mbh) {
785 assert(is_Block(block));
786 assert(is_Block(mbh));
787 set_irn_n(block, -1, mbh);
790 /* returns the macro block header of a node. */
791 ir_node *get_irn_MacroBlock(const ir_node *n) {
793 n = get_nodes_block(n);
794 /* if the Block is Bad, do NOT try to get it's MB, it will fail. */
798 return get_Block_MacroBlock(n);
801 /* returns the graph of a Block. */
802 ir_graph *(get_Block_irg)(const ir_node *block) {
803 return _get_Block_irg(block);
806 ir_entity *create_Block_entity(ir_node *block) {
808 assert(is_Block(block));
810 entity = block->attr.block.entity;
811 if (entity == NULL) {
815 glob = get_glob_type();
816 entity = new_entity(glob, id_unique("block_%u"), get_code_type());
817 nr = get_irp_next_label_nr();
818 set_entity_label(entity, nr);
819 set_entity_compiler_generated(entity, 1);
820 set_entity_allocation(entity, allocation_static);
822 block->attr.block.entity = entity;
827 ir_entity *get_Block_entity(const ir_node *block) {
828 assert(is_Block(block));
829 return block->attr.block.entity;
832 void set_Block_entity(ir_node *block, ir_entity *entity)
834 assert(is_Block(block));
835 assert(get_entity_type(entity) == get_code_type());
836 block->attr.block.entity = entity;
839 int has_Block_entity(const ir_node *block)
841 return block->attr.block.entity != NULL;
844 ir_node *(get_Block_phis)(const ir_node *block) {
845 return _get_Block_phis(block);
848 void (set_Block_phis)(ir_node *block, ir_node *phi) {
849 _set_Block_phis(block, phi);
852 void (add_Block_phi)(ir_node *block, ir_node *phi) {
853 _add_Block_phi(block, phi);
856 /* Get the Block mark (single bit). */
857 unsigned (get_Block_mark)(const ir_node *block) {
858 return _get_Block_mark(block);
861 /* Set the Block mark (single bit). */
862 void (set_Block_mark)(ir_node *block, unsigned mark) {
863 _set_Block_mark(block, mark);
866 int get_End_n_keepalives(const ir_node *end) {
868 return (get_irn_arity(end) - END_KEEPALIVE_OFFSET);
871 ir_node *get_End_keepalive(const ir_node *end, int pos) {
873 return get_irn_n(end, pos + END_KEEPALIVE_OFFSET);
876 void add_End_keepalive(ir_node *end, ir_node *ka) {
881 void set_End_keepalive(ir_node *end, int pos, ir_node *ka) {
883 set_irn_n(end, pos + END_KEEPALIVE_OFFSET, ka);
886 /* Set new keep-alives */
887 void set_End_keepalives(ir_node *end, int n, ir_node *in[]) {
889 ir_graph *irg = get_irn_irg(end);
891 /* notify that edges are deleted */
892 for (i = END_KEEPALIVE_OFFSET; i < ARR_LEN(end->in) - 1; ++i) {
893 edges_notify_edge(end, i, NULL, end->in[i + 1], irg);
895 ARR_RESIZE(ir_node *, end->in, n + 1 + END_KEEPALIVE_OFFSET);
897 for (i = 0; i < n; ++i) {
898 end->in[1 + END_KEEPALIVE_OFFSET + i] = in[i];
899 edges_notify_edge(end, END_KEEPALIVE_OFFSET + i, end->in[1 + END_KEEPALIVE_OFFSET + i], NULL, irg);
903 /* Set new keep-alives from old keep-alives, skipping irn */
904 void remove_End_keepalive(ir_node *end, ir_node *irn) {
905 int n = get_End_n_keepalives(end);
910 for (i = n -1; i >= 0; --i) {
911 ir_node *old_ka = end->in[1 + END_KEEPALIVE_OFFSET + i];
921 irg = get_irn_irg(end);
923 /* remove the edge */
924 edges_notify_edge(end, idx, NULL, irn, irg);
927 /* exchange with the last one */
928 ir_node *old = end->in[1 + END_KEEPALIVE_OFFSET + n - 1];
929 edges_notify_edge(end, n - 1, NULL, old, irg);
930 end->in[1 + END_KEEPALIVE_OFFSET + idx] = old;
931 edges_notify_edge(end, idx, old, NULL, irg);
933 /* now n - 1 keeps, 1 block input */
934 ARR_RESIZE(ir_node *, end->in, (n - 1) + 1 + END_KEEPALIVE_OFFSET);
937 /* remove Bads, NoMems and doublets from the keep-alive set */
938 void remove_End_Bads_and_doublets(ir_node *end) {
940 int idx, n = get_End_n_keepalives(end);
946 irg = get_irn_irg(end);
947 pset_new_init(&keeps);
949 for (idx = n - 1; idx >= 0; --idx) {
950 ir_node *ka = get_End_keepalive(end, idx);
952 if (is_Bad(ka) || is_NoMem(ka) || pset_new_contains(&keeps, ka)) {
953 /* remove the edge */
954 edges_notify_edge(end, idx, NULL, ka, irg);
957 /* exchange with the last one */
958 ir_node *old = end->in[1 + END_KEEPALIVE_OFFSET + n - 1];
959 edges_notify_edge(end, n - 1, NULL, old, irg);
960 end->in[1 + END_KEEPALIVE_OFFSET + idx] = old;
961 edges_notify_edge(end, idx, old, NULL, irg);
965 pset_new_insert(&keeps, ka);
968 /* n keeps, 1 block input */
969 ARR_RESIZE(ir_node *, end->in, n + 1 + END_KEEPALIVE_OFFSET);
971 pset_new_destroy(&keeps);
974 void free_End(ir_node *end) {
978 end->in = NULL; /* @@@ make sure we get an error if we use the
979 in array afterwards ... */
982 /* Return the target address of an IJmp */
983 ir_node *get_IJmp_target(const ir_node *ijmp) {
984 assert(is_IJmp(ijmp));
985 return get_irn_n(ijmp, 0);
988 /** Sets the target address of an IJmp */
989 void set_IJmp_target(ir_node *ijmp, ir_node *tgt) {
990 assert(is_IJmp(ijmp));
991 set_irn_n(ijmp, 0, tgt);
995 > Implementing the case construct (which is where the constant Proj node is
996 > important) involves far more than simply determining the constant values.
997 > We could argue that this is more properly a function of the translator from
998 > Firm to the target machine. That could be done if there was some way of
999 > projecting "default" out of the Cond node.
1000 I know it's complicated.
1001 Basically there are two problems:
1002 - determining the gaps between the Projs
1003 - determining the biggest case constant to know the proj number for
1005 I see several solutions:
1006 1. Introduce a ProjDefault node. Solves both problems.
1007 This means to extend all optimizations executed during construction.
1008 2. Give the Cond node for switch two flavors:
1009 a) there are no gaps in the Projs (existing flavor)
1010 b) gaps may exist, default proj is still the Proj with the largest
1011 projection number. This covers also the gaps.
1012 3. Fix the semantic of the Cond to that of 2b)
1014 Solution 2 seems to be the best:
1015 Computing the gaps in the Firm representation is not too hard, i.e.,
1016 libFIRM can implement a routine that transforms between the two
1017 flavours. This is also possible for 1) but 2) does not require to
1018 change any existing optimization.
1019 Further it should be far simpler to determine the biggest constant than
1020 to compute all gaps.
1021 I don't want to choose 3) as 2a) seems to have advantages for
1022 dataflow analysis and 3) does not allow to convert the representation to
1026 const char *get_cond_kind_name(cond_kind kind)
1028 #define X(a) case a: return #a;
1038 get_Cond_selector(const ir_node *node) {
1039 assert(is_Cond(node));
1040 return get_irn_n(node, 0);
1044 set_Cond_selector(ir_node *node, ir_node *selector) {
1045 assert(is_Cond(node));
1046 set_irn_n(node, 0, selector);
1050 get_Cond_kind(const ir_node *node) {
1051 assert(is_Cond(node));
1052 return node->attr.cond.kind;
1056 set_Cond_kind(ir_node *node, cond_kind kind) {
1057 assert(is_Cond(node));
1058 node->attr.cond.kind = kind;
1062 get_Cond_default_proj(const ir_node *node) {
1063 assert(is_Cond(node));
1064 return node->attr.cond.default_proj;
1067 void set_Cond_default_proj(ir_node *node, long defproj) {
1068 assert(is_Cond(node));
1069 node->attr.cond.default_proj = defproj;
1073 get_Return_mem(const ir_node *node) {
1074 assert(is_Return(node));
1075 return get_irn_n(node, 0);
1079 set_Return_mem(ir_node *node, ir_node *mem) {
1080 assert(is_Return(node));
1081 set_irn_n(node, 0, mem);
1085 get_Return_n_ress(const ir_node *node) {
1086 assert(is_Return(node));
1087 return (get_irn_arity(node) - RETURN_RESULT_OFFSET);
1091 get_Return_res_arr(ir_node *node) {
1092 assert(is_Return(node));
1093 if (get_Return_n_ress(node) > 0)
1094 return (ir_node **)&(get_irn_in(node)[1 + RETURN_RESULT_OFFSET]);
1101 set_Return_n_res(ir_node *node, int results) {
1102 assert(is_Return(node));
1107 get_Return_res(const ir_node *node, int pos) {
1108 assert(is_Return(node));
1109 assert(get_Return_n_ress(node) > pos);
1110 return get_irn_n(node, pos + RETURN_RESULT_OFFSET);
1114 set_Return_res(ir_node *node, int pos, ir_node *res){
1115 assert(is_Return(node));
1116 set_irn_n(node, pos + RETURN_RESULT_OFFSET, res);
1119 tarval *(get_Const_tarval)(const ir_node *node) {
1120 return _get_Const_tarval(node);
1124 set_Const_tarval(ir_node *node, tarval *con) {
1125 assert(is_Const(node));
1126 node->attr.con.tv = con;
1129 int (is_Const_null)(const ir_node *node) {
1130 return _is_Const_null(node);
1133 int (is_Const_one)(const ir_node *node) {
1134 return _is_Const_one(node);
1137 int (is_Const_all_one)(const ir_node *node) {
1138 return _is_Const_all_one(node);
1142 /* The source language type. Must be an atomic type. Mode of type must
1143 be mode of node. For tarvals from entities type must be pointer to
1146 get_Const_type(ir_node *node) {
1147 assert(is_Const(node));
1148 node->attr.con.tp = skip_tid(node->attr.con.tp);
1149 return node->attr.con.tp;
1153 set_Const_type(ir_node *node, ir_type *tp) {
1154 assert(is_Const(node));
1155 if (tp != firm_unknown_type) {
1156 assert(is_atomic_type(tp));
1157 assert(get_type_mode(tp) == get_irn_mode(node));
1159 node->attr.con.tp = tp;
1164 get_SymConst_kind(const ir_node *node) {
1165 assert(is_SymConst(node));
1166 return node->attr.symc.kind;
1170 set_SymConst_kind(ir_node *node, symconst_kind kind) {
1171 assert(is_SymConst(node));
1172 node->attr.symc.kind = kind;
1176 get_SymConst_type(const ir_node *node) {
1177 /* the cast here is annoying, but we have to compensate for
1179 ir_node *irn = (ir_node *)node;
1180 assert(is_SymConst(node) &&
1181 (SYMCONST_HAS_TYPE(get_SymConst_kind(node))));
1182 return irn->attr.symc.sym.type_p = skip_tid(irn->attr.symc.sym.type_p);
1186 set_SymConst_type(ir_node *node, ir_type *tp) {
1187 assert(is_SymConst(node) &&
1188 (SYMCONST_HAS_TYPE(get_SymConst_kind(node))));
1189 node->attr.symc.sym.type_p = tp;
1193 get_SymConst_name(const ir_node *node) {
1194 assert(is_SymConst(node) && SYMCONST_HAS_ID(get_SymConst_kind(node)));
1195 return node->attr.symc.sym.ident_p;
1199 set_SymConst_name(ir_node *node, ident *name) {
1200 assert(is_SymConst(node) && SYMCONST_HAS_ID(get_SymConst_kind(node)));
1201 node->attr.symc.sym.ident_p = name;
1205 /* Only to access SymConst of kind symconst_addr_ent. Else assertion: */
1206 ir_entity *get_SymConst_entity(const ir_node *node) {
1207 assert(is_SymConst(node) && SYMCONST_HAS_ENT(get_SymConst_kind(node)));
1208 return node->attr.symc.sym.entity_p;
1211 void set_SymConst_entity(ir_node *node, ir_entity *ent) {
1212 assert(is_SymConst(node) && SYMCONST_HAS_ENT(get_SymConst_kind(node)));
1213 node->attr.symc.sym.entity_p = ent;
1216 ir_enum_const *get_SymConst_enum(const ir_node *node) {
1217 assert(is_SymConst(node) && SYMCONST_HAS_ENUM(get_SymConst_kind(node)));
1218 return node->attr.symc.sym.enum_p;
1221 void set_SymConst_enum(ir_node *node, ir_enum_const *ec) {
1222 assert(is_SymConst(node) && SYMCONST_HAS_ENUM(get_SymConst_kind(node)));
1223 node->attr.symc.sym.enum_p = ec;
1226 union symconst_symbol
1227 get_SymConst_symbol(const ir_node *node) {
1228 assert(is_SymConst(node));
1229 return node->attr.symc.sym;
1233 set_SymConst_symbol(ir_node *node, union symconst_symbol sym) {
1234 assert(is_SymConst(node));
1235 node->attr.symc.sym = sym;
1239 get_SymConst_value_type(ir_node *node) {
1240 assert(is_SymConst(node));
1241 if (node->attr.symc.tp) node->attr.symc.tp = skip_tid(node->attr.symc.tp);
1242 return node->attr.symc.tp;
1246 set_SymConst_value_type(ir_node *node, ir_type *tp) {
1247 assert(is_SymConst(node));
1248 node->attr.symc.tp = tp;
1252 get_Sel_mem(const ir_node *node) {
1253 assert(is_Sel(node));
1254 return get_irn_n(node, 0);
1258 set_Sel_mem(ir_node *node, ir_node *mem) {
1259 assert(is_Sel(node));
1260 set_irn_n(node, 0, mem);
1264 get_Sel_ptr(const ir_node *node) {
1265 assert(is_Sel(node));
1266 return get_irn_n(node, 1);
1270 set_Sel_ptr(ir_node *node, ir_node *ptr) {
1271 assert(is_Sel(node));
1272 set_irn_n(node, 1, ptr);
1276 get_Sel_n_indexs(const ir_node *node) {
1277 assert(is_Sel(node));
1278 return (get_irn_arity(node) - SEL_INDEX_OFFSET);
1282 get_Sel_index_arr(ir_node *node) {
1283 assert(is_Sel(node));
1284 if (get_Sel_n_indexs(node) > 0)
1285 return (ir_node **)& get_irn_in(node)[SEL_INDEX_OFFSET + 1];
1291 get_Sel_index(const ir_node *node, int pos) {
1292 assert(is_Sel(node));
1293 return get_irn_n(node, pos + SEL_INDEX_OFFSET);
1297 set_Sel_index(ir_node *node, int pos, ir_node *index) {
1298 assert(is_Sel(node));
1299 set_irn_n(node, pos + SEL_INDEX_OFFSET, index);
1303 get_Sel_entity(const ir_node *node) {
1304 assert(is_Sel(node));
1305 return node->attr.sel.entity;
1308 /* need a version without const to prevent warning */
1309 static ir_entity *_get_Sel_entity(ir_node *node) {
1310 return get_Sel_entity(node);
1314 set_Sel_entity(ir_node *node, ir_entity *ent) {
1315 assert(is_Sel(node));
1316 node->attr.sel.entity = ent;
1320 /* For unary and binary arithmetic operations the access to the
1321 operands can be factored out. Left is the first, right the
1322 second arithmetic value as listed in tech report 0999-33.
1323 unops are: Minus, Abs, Not, Conv, Cast
1324 binops are: Add, Sub, Mul, Quot, DivMod, Div, Mod, And, Or, Eor, Shl,
1325 Shr, Shrs, Rotate, Cmp */
1329 get_Call_mem(const ir_node *node) {
1330 assert(is_Call(node));
1331 return get_irn_n(node, 0);
1335 set_Call_mem(ir_node *node, ir_node *mem) {
1336 assert(is_Call(node));
1337 set_irn_n(node, 0, mem);
1341 get_Call_ptr(const ir_node *node) {
1342 assert(is_Call(node));
1343 return get_irn_n(node, 1);
1347 set_Call_ptr(ir_node *node, ir_node *ptr) {
1348 assert(is_Call(node));
1349 set_irn_n(node, 1, ptr);
1353 get_Call_param_arr(ir_node *node) {
1354 assert(is_Call(node));
1355 return &get_irn_in(node)[CALL_PARAM_OFFSET + 1];
1359 get_Call_n_params(const ir_node *node) {
1360 assert(is_Call(node));
1361 return (get_irn_arity(node) - CALL_PARAM_OFFSET);
1365 get_Call_param(const ir_node *node, int pos) {
1366 assert(is_Call(node));
1367 return get_irn_n(node, pos + CALL_PARAM_OFFSET);
1371 set_Call_param(ir_node *node, int pos, ir_node *param) {
1372 assert(is_Call(node));
1373 set_irn_n(node, pos + CALL_PARAM_OFFSET, param);
1377 get_Call_type(ir_node *node) {
1378 assert(is_Call(node));
1379 return node->attr.call.type = skip_tid(node->attr.call.type);
1383 set_Call_type(ir_node *node, ir_type *tp) {
1384 assert(is_Call(node));
1385 assert((get_unknown_type() == tp) || is_Method_type(tp));
1386 node->attr.call.type = tp;
1390 get_Call_tail_call(const ir_node *node) {
1391 assert(is_Call(node));
1392 return node->attr.call.tail_call;
1396 set_Call_tail_call(ir_node *node, unsigned tail_call) {
1397 assert(is_Call(node));
1398 node->attr.call.tail_call = tail_call != 0;
1402 get_Builtin_mem(const ir_node *node) {
1403 assert(is_Builtin(node));
1404 return get_irn_n(node, 0);
1408 set_Builin_mem(ir_node *node, ir_node *mem) {
1409 assert(is_Builtin(node));
1410 set_irn_n(node, 0, mem);
1414 get_Builtin_kind(const ir_node *node) {
1415 assert(is_Builtin(node));
1416 return node->attr.builtin.kind;
1420 set_Builtin_kind(ir_node *node, ir_builtin_kind kind) {
1421 assert(is_Builtin(node));
1422 node->attr.builtin.kind = kind;
1426 get_Builtin_param_arr(ir_node *node) {
1427 assert(is_Builtin(node));
1428 return &get_irn_in(node)[BUILDIN_PARAM_OFFSET + 1];
1432 get_Builtin_n_params(const ir_node *node) {
1433 assert(is_Builtin(node));
1434 return (get_irn_arity(node) - BUILDIN_PARAM_OFFSET);
1438 get_Builtin_param(const ir_node *node, int pos) {
1439 assert(is_Builtin(node));
1440 return get_irn_n(node, pos + BUILDIN_PARAM_OFFSET);
1444 set_Builtin_param(ir_node *node, int pos, ir_node *param) {
1445 assert(is_Builtin(node));
1446 set_irn_n(node, pos + BUILDIN_PARAM_OFFSET, param);
1450 get_Builtin_type(ir_node *node) {
1451 assert(is_Builtin(node));
1452 return node->attr.builtin.type = skip_tid(node->attr.builtin.type);
1456 set_Builtin_type(ir_node *node, ir_type *tp) {
1457 assert(is_Builtin(node));
1458 assert((get_unknown_type() == tp) || is_Method_type(tp));
1459 node->attr.builtin.type = tp;
1462 /* Returns a human readable string for the ir_builtin_kind. */
1463 const char *get_builtin_kind_name(ir_builtin_kind kind) {
1464 #define X(a) case a: return #a;
1467 X(ir_bk_debugbreak);
1468 X(ir_bk_return_address);
1469 X(ir_bk_frame_address);
1479 X(ir_bk_inner_trampoline);
1486 int Call_has_callees(const ir_node *node) {
1487 assert(is_Call(node));
1488 return ((get_irg_callee_info_state(get_irn_irg(node)) != irg_callee_info_none) &&
1489 (node->attr.call.callee_arr != NULL));
1492 int get_Call_n_callees(const ir_node *node) {
1493 assert(is_Call(node) && node->attr.call.callee_arr);
1494 return ARR_LEN(node->attr.call.callee_arr);
1497 ir_entity *get_Call_callee(const ir_node *node, int pos) {
1498 assert(pos >= 0 && pos < get_Call_n_callees(node));
1499 return node->attr.call.callee_arr[pos];
1502 void set_Call_callee_arr(ir_node *node, const int n, ir_entity ** arr) {
1503 assert(is_Call(node));
1504 if (node->attr.call.callee_arr == NULL || get_Call_n_callees(node) != n) {
1505 node->attr.call.callee_arr = NEW_ARR_D(ir_entity *, current_ir_graph->obst, n);
1507 memcpy(node->attr.call.callee_arr, arr, n * sizeof(ir_entity *));
1510 void remove_Call_callee_arr(ir_node *node) {
1511 assert(is_Call(node));
1512 node->attr.call.callee_arr = NULL;
1515 ir_node *get_CallBegin_ptr(const ir_node *node) {
1516 assert(is_CallBegin(node));
1517 return get_irn_n(node, 0);
1520 void set_CallBegin_ptr(ir_node *node, ir_node *ptr) {
1521 assert(is_CallBegin(node));
1522 set_irn_n(node, 0, ptr);
1525 ir_node *get_CallBegin_call(const ir_node *node) {
1526 assert(is_CallBegin(node));
1527 return node->attr.callbegin.call;
1530 void set_CallBegin_call(ir_node *node, ir_node *call) {
1531 assert(is_CallBegin(node));
1532 node->attr.callbegin.call = call;
1536 * Returns non-zero if a Call is surely a self-recursive Call.
1537 * Beware: if this functions returns 0, the call might be self-recursive!
1539 int is_self_recursive_Call(const ir_node *call) {
1540 const ir_node *callee = get_Call_ptr(call);
1542 if (is_SymConst_addr_ent(callee)) {
1543 const ir_entity *ent = get_SymConst_entity(callee);
1544 const ir_graph *irg = get_entity_irg(ent);
1545 if (irg == get_irn_irg(call))
1552 ir_node * get_##OP##_left(const ir_node *node) { \
1553 assert(is_##OP(node)); \
1554 return get_irn_n(node, node->op->op_index); \
1556 void set_##OP##_left(ir_node *node, ir_node *left) { \
1557 assert(is_##OP(node)); \
1558 set_irn_n(node, node->op->op_index, left); \
1560 ir_node *get_##OP##_right(const ir_node *node) { \
1561 assert(is_##OP(node)); \
1562 return get_irn_n(node, node->op->op_index + 1); \
1564 void set_##OP##_right(ir_node *node, ir_node *right) { \
1565 assert(is_##OP(node)); \
1566 set_irn_n(node, node->op->op_index + 1, right); \
1570 ir_node *get_##OP##_op(const ir_node *node) { \
1571 assert(is_##OP(node)); \
1572 return get_irn_n(node, node->op->op_index); \
1574 void set_##OP##_op(ir_node *node, ir_node *op) { \
1575 assert(is_##OP(node)); \
1576 set_irn_n(node, node->op->op_index, op); \
1579 #define BINOP_MEM(OP) \
1583 get_##OP##_mem(const ir_node *node) { \
1584 assert(is_##OP(node)); \
1585 return get_irn_n(node, 0); \
1589 set_##OP##_mem(ir_node *node, ir_node *mem) { \
1590 assert(is_##OP(node)); \
1591 set_irn_n(node, 0, mem); \
1597 ir_mode *get_##OP##_resmode(const ir_node *node) { \
1598 assert(is_##OP(node)); \
1599 return node->attr.divmod.resmode; \
1602 void set_##OP##_resmode(ir_node *node, ir_mode *mode) { \
1603 assert(is_##OP(node)); \
1604 node->attr.divmod.resmode = mode; \
1632 int get_Div_no_remainder(const ir_node *node) {
1633 assert(is_Div(node));
1634 return node->attr.divmod.no_remainder;
1637 void set_Div_no_remainder(ir_node *node, int no_remainder) {
1638 assert(is_Div(node));
1639 node->attr.divmod.no_remainder = no_remainder;
1642 int get_Conv_strict(const ir_node *node) {
1643 assert(is_Conv(node));
1644 return node->attr.conv.strict;
1647 void set_Conv_strict(ir_node *node, int strict_flag) {
1648 assert(is_Conv(node));
1649 node->attr.conv.strict = (char)strict_flag;
1653 get_Cast_type(ir_node *node) {
1654 assert(is_Cast(node));
1655 node->attr.cast.type = skip_tid(node->attr.cast.type);
1656 return node->attr.cast.type;
1660 set_Cast_type(ir_node *node, ir_type *to_tp) {
1661 assert(is_Cast(node));
1662 node->attr.cast.type = to_tp;
1666 /* Checks for upcast.
1668 * Returns true if the Cast node casts a class type to a super type.
1670 int is_Cast_upcast(ir_node *node) {
1671 ir_type *totype = get_Cast_type(node);
1672 ir_type *fromtype = get_irn_typeinfo_type(get_Cast_op(node));
1674 assert(get_irg_typeinfo_state(get_irn_irg(node)) == ir_typeinfo_consistent);
1677 while (is_Pointer_type(totype) && is_Pointer_type(fromtype)) {
1678 totype = get_pointer_points_to_type(totype);
1679 fromtype = get_pointer_points_to_type(fromtype);
1684 if (!is_Class_type(totype)) return 0;
1685 return is_SubClass_of(fromtype, totype);
1688 /* Checks for downcast.
1690 * Returns true if the Cast node casts a class type to a sub type.
1692 int is_Cast_downcast(ir_node *node) {
1693 ir_type *totype = get_Cast_type(node);
1694 ir_type *fromtype = get_irn_typeinfo_type(get_Cast_op(node));
1696 assert(get_irg_typeinfo_state(get_irn_irg(node)) == ir_typeinfo_consistent);
1699 while (is_Pointer_type(totype) && is_Pointer_type(fromtype)) {
1700 totype = get_pointer_points_to_type(totype);
1701 fromtype = get_pointer_points_to_type(fromtype);
1706 if (!is_Class_type(totype)) return 0;
1707 return is_SubClass_of(totype, fromtype);
1711 (is_unop)(const ir_node *node) {
1712 return _is_unop(node);
1716 get_unop_op(const ir_node *node) {
1717 if (node->op->opar == oparity_unary)
1718 return get_irn_n(node, node->op->op_index);
1720 assert(node->op->opar == oparity_unary);
1725 set_unop_op(ir_node *node, ir_node *op) {
1726 if (node->op->opar == oparity_unary)
1727 set_irn_n(node, node->op->op_index, op);
1729 assert(node->op->opar == oparity_unary);
1733 (is_binop)(const ir_node *node) {
1734 return _is_binop(node);
1738 get_binop_left(const ir_node *node) {
1739 assert(node->op->opar == oparity_binary);
1740 return get_irn_n(node, node->op->op_index);
1744 set_binop_left(ir_node *node, ir_node *left) {
1745 assert(node->op->opar == oparity_binary);
1746 set_irn_n(node, node->op->op_index, left);
1750 get_binop_right(const ir_node *node) {
1751 assert(node->op->opar == oparity_binary);
1752 return get_irn_n(node, node->op->op_index + 1);
1756 set_binop_right(ir_node *node, ir_node *right) {
1757 assert(node->op->opar == oparity_binary);
1758 set_irn_n(node, node->op->op_index + 1, right);
1761 int is_Phi0(const ir_node *n) {
1764 return ((get_irn_op(n) == op_Phi) &&
1765 (get_irn_arity(n) == 0) &&
1766 (get_irg_phase_state(get_irn_irg(n)) == phase_building));
1770 get_Phi_preds_arr(ir_node *node) {
1771 assert(node->op == op_Phi);
1772 return (ir_node **)&(get_irn_in(node)[1]);
1776 get_Phi_n_preds(const ir_node *node) {
1777 assert(is_Phi(node) || is_Phi0(node));
1778 return (get_irn_arity(node));
1782 void set_Phi_n_preds(ir_node *node, int n_preds) {
1783 assert(node->op == op_Phi);
1788 get_Phi_pred(const ir_node *node, int pos) {
1789 assert(is_Phi(node) || is_Phi0(node));
1790 return get_irn_n(node, pos);
1794 set_Phi_pred(ir_node *node, int pos, ir_node *pred) {
1795 assert(is_Phi(node) || is_Phi0(node));
1796 set_irn_n(node, pos, pred);
1799 ir_node *(get_Phi_next)(const ir_node *phi) {
1800 return _get_Phi_next(phi);
1803 void (set_Phi_next)(ir_node *phi, ir_node *next) {
1804 _set_Phi_next(phi, next);
1807 int is_memop(const ir_node *node) {
1808 ir_opcode code = get_irn_opcode(node);
1809 return (code == iro_Load || code == iro_Store);
1812 ir_node *get_memop_mem(const ir_node *node) {
1813 assert(is_memop(node));
1814 return get_irn_n(node, 0);
1817 void set_memop_mem(ir_node *node, ir_node *mem) {
1818 assert(is_memop(node));
1819 set_irn_n(node, 0, mem);
1822 ir_node *get_memop_ptr(const ir_node *node) {
1823 assert(is_memop(node));
1824 return get_irn_n(node, 1);
1827 void set_memop_ptr(ir_node *node, ir_node *ptr) {
1828 assert(is_memop(node));
1829 set_irn_n(node, 1, ptr);
1833 get_Load_mem(const ir_node *node) {
1834 assert(is_Load(node));
1835 return get_irn_n(node, 0);
1839 set_Load_mem(ir_node *node, ir_node *mem) {
1840 assert(is_Load(node));
1841 set_irn_n(node, 0, mem);
1845 get_Load_ptr(const ir_node *node) {
1846 assert(is_Load(node));
1847 return get_irn_n(node, 1);
1851 set_Load_ptr(ir_node *node, ir_node *ptr) {
1852 assert(is_Load(node));
1853 set_irn_n(node, 1, ptr);
1857 get_Load_mode(const ir_node *node) {
1858 assert(is_Load(node));
1859 return node->attr.load.mode;
1863 set_Load_mode(ir_node *node, ir_mode *mode) {
1864 assert(is_Load(node));
1865 node->attr.load.mode = mode;
1869 get_Load_volatility(const ir_node *node) {
1870 assert(is_Load(node));
1871 return node->attr.load.volatility;
1875 set_Load_volatility(ir_node *node, ir_volatility volatility) {
1876 assert(is_Load(node));
1877 node->attr.load.volatility = volatility;
1881 get_Load_align(const ir_node *node) {
1882 assert(is_Load(node));
1883 return node->attr.load.aligned;
1887 set_Load_align(ir_node *node, ir_align align) {
1888 assert(is_Load(node));
1889 node->attr.load.aligned = align;
1894 get_Store_mem(const ir_node *node) {
1895 assert(is_Store(node));
1896 return get_irn_n(node, 0);
1900 set_Store_mem(ir_node *node, ir_node *mem) {
1901 assert(is_Store(node));
1902 set_irn_n(node, 0, mem);
1906 get_Store_ptr(const ir_node *node) {
1907 assert(is_Store(node));
1908 return get_irn_n(node, 1);
1912 set_Store_ptr(ir_node *node, ir_node *ptr) {
1913 assert(is_Store(node));
1914 set_irn_n(node, 1, ptr);
1918 get_Store_value(const ir_node *node) {
1919 assert(is_Store(node));
1920 return get_irn_n(node, 2);
1924 set_Store_value(ir_node *node, ir_node *value) {
1925 assert(is_Store(node));
1926 set_irn_n(node, 2, value);
1930 get_Store_volatility(const ir_node *node) {
1931 assert(is_Store(node));
1932 return node->attr.store.volatility;
1936 set_Store_volatility(ir_node *node, ir_volatility volatility) {
1937 assert(is_Store(node));
1938 node->attr.store.volatility = volatility;
1942 get_Store_align(const ir_node *node) {
1943 assert(is_Store(node));
1944 return node->attr.store.aligned;
1948 set_Store_align(ir_node *node, ir_align align) {
1949 assert(is_Store(node));
1950 node->attr.store.aligned = align;
1955 get_Alloc_mem(const ir_node *node) {
1956 assert(is_Alloc(node));
1957 return get_irn_n(node, 0);
1961 set_Alloc_mem(ir_node *node, ir_node *mem) {
1962 assert(is_Alloc(node));
1963 set_irn_n(node, 0, mem);
1967 get_Alloc_size(const ir_node *node) {
1968 assert(is_Alloc(node));
1969 return get_irn_n(node, 1);
1973 set_Alloc_size(ir_node *node, ir_node *size) {
1974 assert(is_Alloc(node));
1975 set_irn_n(node, 1, size);
1979 get_Alloc_type(ir_node *node) {
1980 assert(is_Alloc(node));
1981 return node->attr.alloc.type = skip_tid(node->attr.alloc.type);
1985 set_Alloc_type(ir_node *node, ir_type *tp) {
1986 assert(is_Alloc(node));
1987 node->attr.alloc.type = tp;
1991 get_Alloc_where(const ir_node *node) {
1992 assert(is_Alloc(node));
1993 return node->attr.alloc.where;
1997 set_Alloc_where(ir_node *node, ir_where_alloc where) {
1998 assert(is_Alloc(node));
1999 node->attr.alloc.where = where;
2004 get_Free_mem(const ir_node *node) {
2005 assert(is_Free(node));
2006 return get_irn_n(node, 0);
2010 set_Free_mem(ir_node *node, ir_node *mem) {
2011 assert(is_Free(node));
2012 set_irn_n(node, 0, mem);
2016 get_Free_ptr(const ir_node *node) {
2017 assert(is_Free(node));
2018 return get_irn_n(node, 1);
2022 set_Free_ptr(ir_node *node, ir_node *ptr) {
2023 assert(is_Free(node));
2024 set_irn_n(node, 1, ptr);
2028 get_Free_size(const ir_node *node) {
2029 assert(is_Free(node));
2030 return get_irn_n(node, 2);
2034 set_Free_size(ir_node *node, ir_node *size) {
2035 assert(is_Free(node));
2036 set_irn_n(node, 2, size);
2040 get_Free_type(ir_node *node) {
2041 assert(is_Free(node));
2042 return node->attr.free.type = skip_tid(node->attr.free.type);
2046 set_Free_type(ir_node *node, ir_type *tp) {
2047 assert(is_Free(node));
2048 node->attr.free.type = tp;
2052 get_Free_where(const ir_node *node) {
2053 assert(is_Free(node));
2054 return node->attr.free.where;
2058 set_Free_where(ir_node *node, ir_where_alloc where) {
2059 assert(is_Free(node));
2060 node->attr.free.where = where;
2063 ir_node **get_Sync_preds_arr(ir_node *node) {
2064 assert(is_Sync(node));
2065 return (ir_node **)&(get_irn_in(node)[1]);
2068 int get_Sync_n_preds(const ir_node *node) {
2069 assert(is_Sync(node));
2070 return (get_irn_arity(node));
2074 void set_Sync_n_preds(ir_node *node, int n_preds) {
2075 assert(is_Sync(node));
2079 ir_node *get_Sync_pred(const ir_node *node, int pos) {
2080 assert(is_Sync(node));
2081 return get_irn_n(node, pos);
2084 void set_Sync_pred(ir_node *node, int pos, ir_node *pred) {
2085 assert(is_Sync(node));
2086 set_irn_n(node, pos, pred);
2089 /* Add a new Sync predecessor */
2090 void add_Sync_pred(ir_node *node, ir_node *pred) {
2091 assert(is_Sync(node));
2092 add_irn_n(node, pred);
2095 /* Returns the source language type of a Proj node. */
2096 ir_type *get_Proj_type(ir_node *n) {
2097 ir_type *tp = firm_unknown_type;
2098 ir_node *pred = get_Proj_pred(n);
2100 switch (get_irn_opcode(pred)) {
2103 /* Deal with Start / Call here: we need to know the Proj Nr. */
2104 assert(get_irn_mode(pred) == mode_T);
2105 pred_pred = get_Proj_pred(pred);
2107 if (is_Start(pred_pred)) {
2108 ir_type *mtp = get_entity_type(get_irg_entity(get_irn_irg(pred_pred)));
2109 tp = get_method_param_type(mtp, get_Proj_proj(n));
2110 } else if (is_Call(pred_pred)) {
2111 ir_type *mtp = get_Call_type(pred_pred);
2112 tp = get_method_res_type(mtp, get_Proj_proj(n));
2115 case iro_Start: break;
2116 case iro_Call: break;
2118 ir_node *a = get_Load_ptr(pred);
2120 tp = get_entity_type(get_Sel_entity(a));
2129 get_Proj_pred(const ir_node *node) {
2130 assert(is_Proj(node));
2131 return get_irn_n(node, 0);
2135 set_Proj_pred(ir_node *node, ir_node *pred) {
2136 assert(is_Proj(node));
2137 set_irn_n(node, 0, pred);
2141 get_Proj_proj(const ir_node *node) {
2142 #ifdef INTERPROCEDURAL_VIEW
2143 ir_opcode code = get_irn_opcode(node);
2145 if (code == iro_Proj) {
2146 return node->attr.proj;
2149 assert(code == iro_Filter);
2150 return node->attr.filter.proj;
2153 assert(is_Proj(node));
2154 return node->attr.proj;
2155 #endif /* INTERPROCEDURAL_VIEW */
2159 set_Proj_proj(ir_node *node, long proj) {
2160 #ifdef INTERPROCEDURAL_VIEW
2161 ir_opcode code = get_irn_opcode(node);
2163 if (code == iro_Proj) {
2164 node->attr.proj = proj;
2167 assert(code == iro_Filter);
2168 node->attr.filter.proj = proj;
2171 assert(is_Proj(node));
2172 node->attr.proj = proj;
2173 #endif /* INTERPROCEDURAL_VIEW */
2176 /* Returns non-zero if a node is a routine parameter. */
2177 int (is_arg_Proj)(const ir_node *node) {
2178 return _is_arg_Proj(node);
2182 get_Tuple_preds_arr(ir_node *node) {
2183 assert(is_Tuple(node));
2184 return (ir_node **)&(get_irn_in(node)[1]);
2188 get_Tuple_n_preds(const ir_node *node) {
2189 assert(is_Tuple(node));
2190 return get_irn_arity(node);
2195 set_Tuple_n_preds(ir_node *node, int n_preds) {
2196 assert(is_Tuple(node));
2201 get_Tuple_pred(const ir_node *node, int pos) {
2202 assert(is_Tuple(node));
2203 return get_irn_n(node, pos);
2207 set_Tuple_pred(ir_node *node, int pos, ir_node *pred) {
2208 assert(is_Tuple(node));
2209 set_irn_n(node, pos, pred);
2213 get_Id_pred(const ir_node *node) {
2214 assert(is_Id(node));
2215 return get_irn_n(node, 0);
2219 set_Id_pred(ir_node *node, ir_node *pred) {
2220 assert(is_Id(node));
2221 set_irn_n(node, 0, pred);
2224 ir_node *get_Confirm_value(const ir_node *node) {
2225 assert(is_Confirm(node));
2226 return get_irn_n(node, 0);
2229 void set_Confirm_value(ir_node *node, ir_node *value) {
2230 assert(is_Confirm(node));
2231 set_irn_n(node, 0, value);
2234 ir_node *get_Confirm_bound(const ir_node *node) {
2235 assert(is_Confirm(node));
2236 return get_irn_n(node, 1);
2239 void set_Confirm_bound(ir_node *node, ir_node *bound) {
2240 assert(is_Confirm(node));
2241 set_irn_n(node, 0, bound);
2244 pn_Cmp get_Confirm_cmp(const ir_node *node) {
2245 assert(is_Confirm(node));
2246 return node->attr.confirm.cmp;
2249 void set_Confirm_cmp(ir_node *node, pn_Cmp cmp) {
2250 assert(is_Confirm(node));
2251 node->attr.confirm.cmp = cmp;
2255 get_Filter_pred(ir_node *node) {
2256 assert(is_Filter(node));
2261 set_Filter_pred(ir_node *node, ir_node *pred) {
2262 assert(is_Filter(node));
2267 get_Filter_proj(ir_node *node) {
2268 assert(is_Filter(node));
2269 return node->attr.filter.proj;
2273 set_Filter_proj(ir_node *node, long proj) {
2274 assert(is_Filter(node));
2275 node->attr.filter.proj = proj;
2278 /* Don't use get_irn_arity, get_irn_n in implementation as access
2279 shall work independent of view!!! */
2280 void set_Filter_cg_pred_arr(ir_node *node, int arity, ir_node ** in) {
2281 assert(is_Filter(node));
2282 if (node->attr.filter.in_cg == NULL || arity != ARR_LEN(node->attr.filter.in_cg) - 1) {
2283 ir_graph *irg = get_irn_irg(node);
2284 node->attr.filter.in_cg = NEW_ARR_D(ir_node *, current_ir_graph->obst, arity + 1);
2285 node->attr.filter.backedge = new_backedge_arr(irg->obst, arity);
2286 node->attr.filter.in_cg[0] = node->in[0];
2288 memcpy(node->attr.filter.in_cg + 1, in, sizeof(ir_node *) * arity);
2291 void set_Filter_cg_pred(ir_node * node, int pos, ir_node * pred) {
2292 assert(is_Filter(node) && node->attr.filter.in_cg &&
2293 0 <= pos && pos < ARR_LEN(node->attr.filter.in_cg) - 1);
2294 node->attr.filter.in_cg[pos + 1] = pred;
2297 int get_Filter_n_cg_preds(ir_node *node) {
2298 assert(is_Filter(node) && node->attr.filter.in_cg);
2299 return (ARR_LEN(node->attr.filter.in_cg) - 1);
2302 ir_node *get_Filter_cg_pred(ir_node *node, int pos) {
2304 assert(is_Filter(node) && node->attr.filter.in_cg &&
2306 arity = ARR_LEN(node->attr.filter.in_cg);
2307 assert(pos < arity - 1);
2308 return node->attr.filter.in_cg[pos + 1];
2312 ir_node *get_Mux_sel(const ir_node *node) {
2313 assert(is_Mux(node));
2317 void set_Mux_sel(ir_node *node, ir_node *sel) {
2318 assert(is_Mux(node));
2322 ir_node *get_Mux_false(const ir_node *node) {
2323 assert(is_Mux(node));
2327 void set_Mux_false(ir_node *node, ir_node *ir_false) {
2328 assert(is_Mux(node));
2329 node->in[2] = ir_false;
2332 ir_node *get_Mux_true(const ir_node *node) {
2333 assert(is_Mux(node));
2337 void set_Mux_true(ir_node *node, ir_node *ir_true) {
2338 assert(is_Mux(node));
2339 node->in[3] = ir_true;
2343 ir_node *get_CopyB_mem(const ir_node *node) {
2344 assert(is_CopyB(node));
2345 return get_irn_n(node, 0);
2348 void set_CopyB_mem(ir_node *node, ir_node *mem) {
2349 assert(node->op == op_CopyB);
2350 set_irn_n(node, 0, mem);
2353 ir_node *get_CopyB_dst(const ir_node *node) {
2354 assert(is_CopyB(node));
2355 return get_irn_n(node, 1);
2358 void set_CopyB_dst(ir_node *node, ir_node *dst) {
2359 assert(is_CopyB(node));
2360 set_irn_n(node, 1, dst);
2363 ir_node *get_CopyB_src(const ir_node *node) {
2364 assert(is_CopyB(node));
2365 return get_irn_n(node, 2);
2368 void set_CopyB_src(ir_node *node, ir_node *src) {
2369 assert(is_CopyB(node));
2370 set_irn_n(node, 2, src);
2373 ir_type *get_CopyB_type(ir_node *node) {
2374 assert(is_CopyB(node));
2375 return node->attr.copyb.type = skip_tid(node->attr.copyb.type);
2378 void set_CopyB_type(ir_node *node, ir_type *data_type) {
2379 assert(is_CopyB(node) && data_type);
2380 node->attr.copyb.type = data_type;
2385 get_InstOf_type(ir_node *node) {
2386 assert(node->op == op_InstOf);
2387 return node->attr.instof.type = skip_tid(node->attr.instof.type);
2391 set_InstOf_type(ir_node *node, ir_type *type) {
2392 assert(node->op == op_InstOf);
2393 node->attr.instof.type = type;
2397 get_InstOf_store(const ir_node *node) {
2398 assert(node->op == op_InstOf);
2399 return get_irn_n(node, 0);
2403 set_InstOf_store(ir_node *node, ir_node *obj) {
2404 assert(node->op == op_InstOf);
2405 set_irn_n(node, 0, obj);
2409 get_InstOf_obj(const ir_node *node) {
2410 assert(node->op == op_InstOf);
2411 return get_irn_n(node, 1);
2415 set_InstOf_obj(ir_node *node, ir_node *obj) {
2416 assert(node->op == op_InstOf);
2417 set_irn_n(node, 1, obj);
2420 /* Returns the memory input of a Raise operation. */
2422 get_Raise_mem(const ir_node *node) {
2423 assert(is_Raise(node));
2424 return get_irn_n(node, 0);
2428 set_Raise_mem(ir_node *node, ir_node *mem) {
2429 assert(is_Raise(node));
2430 set_irn_n(node, 0, mem);
2434 get_Raise_exo_ptr(const ir_node *node) {
2435 assert(is_Raise(node));
2436 return get_irn_n(node, 1);
2440 set_Raise_exo_ptr(ir_node *node, ir_node *exo_ptr) {
2441 assert(is_Raise(node));
2442 set_irn_n(node, 1, exo_ptr);
2447 /* Returns the memory input of a Bound operation. */
2448 ir_node *get_Bound_mem(const ir_node *bound) {
2449 assert(is_Bound(bound));
2450 return get_irn_n(bound, 0);
2453 void set_Bound_mem(ir_node *bound, ir_node *mem) {
2454 assert(is_Bound(bound));
2455 set_irn_n(bound, 0, mem);
2458 /* Returns the index input of a Bound operation. */
2459 ir_node *get_Bound_index(const ir_node *bound) {
2460 assert(is_Bound(bound));
2461 return get_irn_n(bound, 1);
2464 void set_Bound_index(ir_node *bound, ir_node *idx) {
2465 assert(is_Bound(bound));
2466 set_irn_n(bound, 1, idx);
2469 /* Returns the lower bound input of a Bound operation. */
2470 ir_node *get_Bound_lower(const ir_node *bound) {
2471 assert(is_Bound(bound));
2472 return get_irn_n(bound, 2);
2475 void set_Bound_lower(ir_node *bound, ir_node *lower) {
2476 assert(is_Bound(bound));
2477 set_irn_n(bound, 2, lower);
2480 /* Returns the upper bound input of a Bound operation. */
2481 ir_node *get_Bound_upper(const ir_node *bound) {
2482 assert(is_Bound(bound));
2483 return get_irn_n(bound, 3);
2486 void set_Bound_upper(ir_node *bound, ir_node *upper) {
2487 assert(is_Bound(bound));
2488 set_irn_n(bound, 3, upper);
2491 /* Return the operand of a Pin node. */
2492 ir_node *get_Pin_op(const ir_node *pin) {
2493 assert(is_Pin(pin));
2494 return get_irn_n(pin, 0);
2497 void set_Pin_op(ir_node *pin, ir_node *node) {
2498 assert(is_Pin(pin));
2499 set_irn_n(pin, 0, node);
2502 /* Return the assembler text of an ASM pseudo node. */
2503 ident *get_ASM_text(const ir_node *node) {
2504 assert(is_ASM(node));
2505 return node->attr.assem.asm_text;
2508 /* Return the number of input constraints for an ASM node. */
2509 int get_ASM_n_input_constraints(const ir_node *node) {
2510 assert(is_ASM(node));
2511 return ARR_LEN(node->attr.assem.inputs);
2514 /* Return the input constraints for an ASM node. This is a flexible array. */
2515 const ir_asm_constraint *get_ASM_input_constraints(const ir_node *node) {
2516 assert(is_ASM(node));
2517 return node->attr.assem.inputs;
2520 /* Return the number of output constraints for an ASM node. */
2521 int get_ASM_n_output_constraints(const ir_node *node) {
2522 assert(is_ASM(node));
2523 return ARR_LEN(node->attr.assem.outputs);
2526 /* Return the output constraints for an ASM node. */
2527 const ir_asm_constraint *get_ASM_output_constraints(const ir_node *node) {
2528 assert(is_ASM(node));
2529 return node->attr.assem.outputs;
2532 /* Return the number of clobbered registers for an ASM node. */
2533 int get_ASM_n_clobbers(const ir_node *node) {
2534 assert(is_ASM(node));
2535 return ARR_LEN(node->attr.assem.clobber);
2538 /* Return the list of clobbered registers for an ASM node. */
2539 ident **get_ASM_clobbers(const ir_node *node) {
2540 assert(is_ASM(node));
2541 return node->attr.assem.clobber;
2544 /* returns the graph of a node */
2546 get_irn_irg(const ir_node *node) {
2548 * Do not use get_nodes_Block() here, because this
2549 * will check the pinned state.
2550 * However even a 'wrong' block is always in the proper
2553 if (! is_Block(node))
2554 node = get_irn_n(node, -1);
2555 /* note that get_Block_irg() can handle Bad nodes */
2556 return get_Block_irg(node);
2560 /*----------------------------------------------------------------*/
2561 /* Auxiliary routines */
2562 /*----------------------------------------------------------------*/
2565 skip_Proj(ir_node *node) {
2566 /* don't assert node !!! */
2571 node = get_Proj_pred(node);
2577 skip_Proj_const(const ir_node *node) {
2578 /* don't assert node !!! */
2583 node = get_Proj_pred(node);
2589 skip_Tuple(ir_node *node) {
2594 if (is_Proj(node)) {
2595 pred = get_Proj_pred(node);
2596 op = get_irn_op(pred);
2599 * Looks strange but calls get_irn_op() only once
2600 * in most often cases.
2602 if (op == op_Proj) { /* nested Tuple ? */
2603 pred = skip_Tuple(pred);
2605 if (is_Tuple(pred)) {
2606 node = get_Tuple_pred(pred, get_Proj_proj(node));
2609 } else if (op == op_Tuple) {
2610 node = get_Tuple_pred(pred, get_Proj_proj(node));
2617 /* returns operand of node if node is a Cast */
2618 ir_node *skip_Cast(ir_node *node) {
2620 return get_Cast_op(node);
2624 /* returns operand of node if node is a Cast */
2625 const ir_node *skip_Cast_const(const ir_node *node) {
2627 return get_Cast_op(node);
2631 /* returns operand of node if node is a Pin */
2632 ir_node *skip_Pin(ir_node *node) {
2634 return get_Pin_op(node);
2638 /* returns operand of node if node is a Confirm */
2639 ir_node *skip_Confirm(ir_node *node) {
2640 if (is_Confirm(node))
2641 return get_Confirm_value(node);
2645 /* skip all high-level ops */
2646 ir_node *skip_HighLevel_ops(ir_node *node) {
2647 while (is_op_highlevel(get_irn_op(node))) {
2648 node = get_irn_n(node, 0);
2654 /* This should compact Id-cycles to self-cycles. It has the same (or less?) complexity
2655 * than any other approach, as Id chains are resolved and all point to the real node, or
2656 * all id's are self loops.
2658 * Note: This function takes 10% of mostly ANY the compiler run, so it's
2659 * a little bit "hand optimized".
2661 * Moreover, it CANNOT be switched off using get_opt_normalize() ...
2664 skip_Id(ir_node *node) {
2666 /* don't assert node !!! */
2668 if (!node || (node->op != op_Id)) return node;
2670 /* Don't use get_Id_pred(): We get into an endless loop for
2671 self-referencing Ids. */
2672 pred = node->in[0+1];
2674 if (pred->op != op_Id) return pred;
2676 if (node != pred) { /* not a self referencing Id. Resolve Id chain. */
2677 ir_node *rem_pred, *res;
2679 if (pred->op != op_Id) return pred; /* shortcut */
2682 assert(get_irn_arity (node) > 0);
2684 node->in[0+1] = node; /* turn us into a self referencing Id: shorten Id cycles. */
2685 res = skip_Id(rem_pred);
2686 if (res->op == op_Id) /* self-loop */ return node;
2688 node->in[0+1] = res; /* Turn Id chain into Ids all referencing the chain end. */
2695 void skip_Id_and_store(ir_node **node) {
2698 if (!n || (n->op != op_Id)) return;
2700 /* Don't use get_Id_pred(): We get into an endless loop for
2701 self-referencing Ids. */
2706 (is_strictConv)(const ir_node *node) {
2707 return _is_strictConv(node);
2711 (is_no_Block)(const ir_node *node) {
2712 return _is_no_Block(node);
2715 /* Returns true if node is a SymConst node with kind symconst_addr_ent. */
2717 (is_SymConst_addr_ent)(const ir_node *node) {
2718 return _is_SymConst_addr_ent(node);
2721 /* Returns true if the operation manipulates control flow. */
2722 int is_cfop(const ir_node *node) {
2723 return is_op_cfopcode(get_irn_op(node));
2726 /* Returns true if the operation manipulates interprocedural control flow:
2727 CallBegin, EndReg, EndExcept */
2728 int is_ip_cfop(const ir_node *node) {
2729 return is_ip_cfopcode(get_irn_op(node));
2732 /* Returns true if the operation can change the control flow because
2735 is_fragile_op(const ir_node *node) {
2736 return is_op_fragile(get_irn_op(node));
2739 /* Returns the memory operand of fragile operations. */
2740 ir_node *get_fragile_op_mem(ir_node *node) {
2741 assert(node && is_fragile_op(node));
2743 switch (get_irn_opcode(node)) {
2754 return get_irn_n(node, pn_Generic_M_regular);
2759 assert(0 && "should not be reached");
2764 /* Returns the result mode of a Div operation. */
2765 ir_mode *get_divop_resmod(const ir_node *node) {
2766 switch (get_irn_opcode(node)) {
2767 case iro_Quot : return get_Quot_resmode(node);
2768 case iro_DivMod: return get_DivMod_resmode(node);
2769 case iro_Div : return get_Div_resmode(node);
2770 case iro_Mod : return get_Mod_resmode(node);
2772 assert(0 && "should not be reached");
2777 /* Returns true if the operation is a forking control flow operation. */
2778 int (is_irn_forking)(const ir_node *node) {
2779 return _is_irn_forking(node);
2782 void (copy_node_attr)(const ir_node *old_node, ir_node *new_node) {
2783 _copy_node_attr(old_node, new_node);
2786 /* Return the type associated with the value produced by n
2787 * if the node remarks this type as it is the case for
2788 * Cast, Const, SymConst and some Proj nodes. */
2789 ir_type *(get_irn_type)(ir_node *node) {
2790 return _get_irn_type(node);
2793 /* Return the type attribute of a node n (SymConst, Call, Alloc, Free,
2795 ir_type *(get_irn_type_attr)(ir_node *node) {
2796 return _get_irn_type_attr(node);
2799 /* Return the entity attribute of a node n (SymConst, Sel) or NULL. */
2800 ir_entity *(get_irn_entity_attr)(ir_node *node) {
2801 return _get_irn_entity_attr(node);
2804 /* Returns non-zero for constant-like nodes. */
2805 int (is_irn_constlike)(const ir_node *node) {
2806 return _is_irn_constlike(node);
2810 * Returns non-zero for nodes that are allowed to have keep-alives and
2811 * are neither Block nor PhiM.
2813 int (is_irn_keep)(const ir_node *node) {
2814 return _is_irn_keep(node);
2818 * Returns non-zero for nodes that are always placed in the start block.
2820 int (is_irn_start_block_placed)(const ir_node *node) {
2821 return _is_irn_start_block_placed(node);
2824 /* Returns non-zero for nodes that are machine operations. */
2825 int (is_irn_machine_op)(const ir_node *node) {
2826 return _is_irn_machine_op(node);
2829 /* Returns non-zero for nodes that are machine operands. */
2830 int (is_irn_machine_operand)(const ir_node *node) {
2831 return _is_irn_machine_operand(node);
2834 /* Returns non-zero for nodes that have the n'th user machine flag set. */
2835 int (is_irn_machine_user)(const ir_node *node, unsigned n) {
2836 return _is_irn_machine_user(node, n);
2840 /* Gets the string representation of the jump prediction .*/
2841 const char *get_cond_jmp_predicate_name(cond_jmp_predicate pred) {
2842 #define X(a) case a: return #a;
2844 X(COND_JMP_PRED_NONE);
2845 X(COND_JMP_PRED_TRUE);
2846 X(COND_JMP_PRED_FALSE);
2852 /* Returns the conditional jump prediction of a Cond node. */
2853 cond_jmp_predicate (get_Cond_jmp_pred)(const ir_node *cond) {
2854 return _get_Cond_jmp_pred(cond);
2857 /* Sets a new conditional jump prediction. */
2858 void (set_Cond_jmp_pred)(ir_node *cond, cond_jmp_predicate pred) {
2859 _set_Cond_jmp_pred(cond, pred);
2862 /** the get_type operation must be always implemented and return a firm type */
2863 static ir_type *get_Default_type(ir_node *n) {
2865 return get_unknown_type();
2868 /* Sets the get_type operation for an ir_op_ops. */
2869 ir_op_ops *firm_set_default_get_type(ir_opcode code, ir_op_ops *ops) {
2871 case iro_Const: ops->get_type = get_Const_type; break;
2872 case iro_SymConst: ops->get_type = get_SymConst_value_type; break;
2873 case iro_Cast: ops->get_type = get_Cast_type; break;
2874 case iro_Proj: ops->get_type = get_Proj_type; break;
2876 /* not allowed to be NULL */
2877 if (! ops->get_type)
2878 ops->get_type = get_Default_type;
2884 /** Return the attribute type of a SymConst node if exists */
2885 static ir_type *get_SymConst_attr_type(ir_node *self) {
2886 symconst_kind kind = get_SymConst_kind(self);
2887 if (SYMCONST_HAS_TYPE(kind))
2888 return get_SymConst_type(self);
2892 /** Return the attribute entity of a SymConst node if exists */
2893 static ir_entity *get_SymConst_attr_entity(ir_node *self) {
2894 symconst_kind kind = get_SymConst_kind(self);
2895 if (SYMCONST_HAS_ENT(kind))
2896 return get_SymConst_entity(self);
2900 /** the get_type_attr operation must be always implemented */
2901 static ir_type *get_Null_type(ir_node *n) {
2903 return firm_unknown_type;
2906 /* Sets the get_type operation for an ir_op_ops. */
2907 ir_op_ops *firm_set_default_get_type_attr(ir_opcode code, ir_op_ops *ops) {
2909 case iro_SymConst: ops->get_type_attr = get_SymConst_attr_type; break;
2910 case iro_Call: ops->get_type_attr = get_Call_type; break;
2911 case iro_Alloc: ops->get_type_attr = get_Alloc_type; break;
2912 case iro_Free: ops->get_type_attr = get_Free_type; break;
2913 case iro_Cast: ops->get_type_attr = get_Cast_type; break;
2915 /* not allowed to be NULL */
2916 if (! ops->get_type_attr)
2917 ops->get_type_attr = get_Null_type;
2923 /** the get_entity_attr operation must be always implemented */
2924 static ir_entity *get_Null_ent(ir_node *n) {
2929 /* Sets the get_type operation for an ir_op_ops. */
2930 ir_op_ops *firm_set_default_get_entity_attr(ir_opcode code, ir_op_ops *ops) {
2932 case iro_SymConst: ops->get_entity_attr = get_SymConst_attr_entity; break;
2933 case iro_Sel: ops->get_entity_attr = _get_Sel_entity; break;
2935 /* not allowed to be NULL */
2936 if (! ops->get_entity_attr)
2937 ops->get_entity_attr = get_Null_ent;
2943 /* Sets the debug information of a node. */
2944 void (set_irn_dbg_info)(ir_node *n, dbg_info *db) {
2945 _set_irn_dbg_info(n, db);
2949 * Returns the debug information of an node.
2951 * @param n The node.
2953 dbg_info *(get_irn_dbg_info)(const ir_node *n) {
2954 return _get_irn_dbg_info(n);
2957 /* checks whether a node represents a global address */
2958 int is_Global(const ir_node *node) {
2959 return is_SymConst_addr_ent(node);
2962 /* returns the entity of a global address */
2963 ir_entity *get_Global_entity(const ir_node *node) {
2964 return get_SymConst_entity(node);
2968 * Calculate a hash value of a node.
2970 unsigned firm_default_hash(const ir_node *node) {
2974 /* hash table value = 9*(9*(9*(9*(9*arity+in[0])+in[1])+ ...)+mode)+code */
2975 h = irn_arity = get_irn_intra_arity(node);
2977 /* consider all in nodes... except the block if not a control flow. */
2978 for (i = is_cfop(node) ? -1 : 0; i < irn_arity; ++i) {
2979 h = 9*h + HASH_PTR(get_irn_intra_n(node, i));
2983 h = 9*h + HASH_PTR(get_irn_mode(node));
2985 h = 9*h + HASH_PTR(get_irn_op(node));
2988 } /* firm_default_hash */
2990 /* include generated code */
2991 #include "gen_irnode.c.inl"