* @file
* @brief Representation of an intermediate operation.
* @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
- * @version $Id$
*/
#include "config.h"
#include "irhooks.h"
#include "irtools.h"
+#include "util.h"
#include "beinfo.h"
/* some constants fixing the positions of nodes predecessors
in the in array */
-#define CALL_PARAM_OFFSET 2
-#define BUILDIN_PARAM_OFFSET 1
-#define SEL_INDEX_OFFSET 2
-#define RETURN_RESULT_OFFSET 1 /* mem is not a result */
+#define CALL_PARAM_OFFSET (n_Call_max+1)
+#define BUILTIN_PARAM_OFFSET (n_Builtin_max+1)
+#define SEL_INDEX_OFFSET (n_Sel_max+1)
+#define RETURN_RESULT_OFFSET (n_Return_max+1)
#define END_KEEPALIVE_OFFSET 0
-static const char *pnc_name_arr [] = {
- "pn_Cmp_False", "pn_Cmp_Eq", "pn_Cmp_Lt", "pn_Cmp_Le",
- "pn_Cmp_Gt", "pn_Cmp_Ge", "pn_Cmp_Lg", "pn_Cmp_Leg",
- "pn_Cmp_Uo", "pn_Cmp_Ue", "pn_Cmp_Ul", "pn_Cmp_Ule",
- "pn_Cmp_Ug", "pn_Cmp_Uge", "pn_Cmp_Ne", "pn_Cmp_True"
+static const char *relation_names [] = {
+ "false",
+ "equal",
+ "less",
+ "less_equal",
+ "greater",
+ "greater_equal",
+ "less_greater",
+ "less_equal_greater",
+ "unordered",
+ "unordered_equal",
+ "unordered_less",
+ "unordered_less_equal",
+ "unordered_greater",
+ "unordered_greater_equal",
+ "not_equal",
+ "true"
};
-/**
- * returns the pnc name from an pnc constant
- */
-const char *get_pnc_string(int pnc)
+const char *get_relation_string(ir_relation relation)
{
- assert(pnc >= 0 && pnc <
- (int) (sizeof(pnc_name_arr)/sizeof(pnc_name_arr[0])));
- return pnc_name_arr[pnc];
+ assert(relation < (ir_relation)ARRAY_SIZE(relation_names));
+ return relation_names[relation];
}
-/*
- * Calculates the negated (Complement(R)) pnc condition.
- */
-pn_Cmp get_negated_pnc(long pnc, ir_mode *mode)
+ir_relation get_negated_relation(ir_relation relation)
{
- pnc ^= pn_Cmp_True;
-
- /* do NOT add the Uo bit for non-floating point values */
- if (! mode_is_float(mode))
- pnc &= ~pn_Cmp_Uo;
-
- return (pn_Cmp) pnc;
+ return relation ^ ir_relation_true;
}
-/* Calculates the inversed (R^-1) pnc condition, i.e., "<" --> ">" */
-pn_Cmp get_inversed_pnc(long pnc)
+ir_relation get_inversed_relation(ir_relation relation)
{
- long code = pnc & ~(pn_Cmp_Lt|pn_Cmp_Gt);
- long lesser = pnc & pn_Cmp_Lt;
- long greater = pnc & pn_Cmp_Gt;
-
- code |= (lesser ? pn_Cmp_Gt : 0) | (greater ? pn_Cmp_Lt : 0);
-
- return (pn_Cmp) code;
+ ir_relation code = relation & ~(ir_relation_less|ir_relation_greater);
+ bool less = relation & ir_relation_less;
+ bool greater = relation & ir_relation_greater;
+ code |= (less ? ir_relation_greater : 0) | (greater ? ir_relation_less : 0);
+ return code;
}
/**
* If arity is negative, a node with a dynamic array is created.
*/
ir_node *new_ir_node(dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op,
- ir_mode *mode, int arity, ir_node **in)
+ ir_mode *mode, int arity, ir_node *const *in)
{
ir_node *res;
unsigned align = offsetof(struct struct_align, s) - 1;
assert(irg);
assert(op);
assert(mode);
- p = obstack_alloc(irg->obst, node_size);
+ p = (char*)obstack_alloc(irg->obst, node_size);
memset(p, 0, node_size);
res = (ir_node *)(p + add_node_size);
int (is_ir_node)(const void *thing)
{
- return _is_ir_node(thing);
+ return is_ir_node_(thing);
}
int (get_irn_arity)(const ir_node *node)
{
- return _get_irn_arity(node);
+ return get_irn_arity_(node);
}
/* Returns the array with ins. This array is shifted with respect to the
pOld_in = &node->in;
+#ifndef NDEBUG
+ assert(node != NULL && node->kind == k_ir_node);
+ assert(arity >= 0);
+ for (i = 0; i < arity; ++i) {
+ assert(in[i] != NULL && in[0]->kind == k_ir_node);
+ }
+#endif
for (i = 0; i < arity; i++) {
- if (i < ARR_LEN(*pOld_in)-1)
+ if (i < (int)ARR_LEN(*pOld_in)-1)
edges_notify_edge(node, i, in[i], (*pOld_in)[i+1], irg);
else
edges_notify_edge(node, i, in[i], NULL, irg);
}
- for (;i < ARR_LEN(*pOld_in)-1; i++) {
+ for (;i < (int)ARR_LEN(*pOld_in)-1; i++) {
edges_notify_edge(node, i, NULL, (*pOld_in)[i+1], irg);
}
- if (arity != ARR_LEN(*pOld_in) - 1) {
+ if (arity != (int)ARR_LEN(*pOld_in) - 1) {
ir_node * block = (*pOld_in)[0];
*pOld_in = NEW_ARR_D(ir_node *, irg->obst, arity + 1);
(*pOld_in)[0] = block;
fix_backedges(irg->obst, node);
memcpy((*pOld_in) + 1, in, sizeof(ir_node *) * arity);
+
+ /* update irg flags */
+ clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_OUTS | IR_GRAPH_STATE_CONSISTENT_LOOPINFO);
}
ir_node *(get_irn_n)(const ir_node *node, int n)
{
- return _get_irn_n(node, n);
+ return get_irn_n_(node, n);
}
void set_irn_n(ir_node *node, int n, ir_node *in)
{
+ ir_graph *irg = get_irn_irg(node);
assert(node && node->kind == k_ir_node);
assert(-1 <= n);
assert(n < get_irn_arity(node));
hook_set_irn_n(node, n, in, node->in[n + 1]);
/* Here, we rely on src and tgt being in the current ir graph */
- edges_notify_edge(node, n, in, node->in[n + 1], current_ir_graph);
+ edges_notify_edge(node, n, in, node->in[n + 1], irg);
node->in[n + 1] = in;
+
+ /* update irg flags */
+ clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_OUTS | IR_GRAPH_STATE_CONSISTENT_LOOPINFO);
}
int add_irn_n(ir_node *node, ir_node *in)
int (get_irn_deps)(const ir_node *node)
{
- return _get_irn_deps(node);
+ return get_irn_deps_(node);
}
ir_node *(get_irn_dep)(const ir_node *node, int pos)
{
- return _get_irn_dep(node, pos);
+ return get_irn_dep_(node, pos);
}
void (set_irn_dep)(ir_node *node, int pos, ir_node *dep)
{
- _set_irn_dep(node, pos, dep);
+ set_irn_dep_(node, pos, dep);
}
int add_irn_dep(ir_node *node, ir_node *dep)
ir_mode *(get_irn_mode)(const ir_node *node)
{
- return _get_irn_mode(node);
+ return get_irn_mode_(node);
}
void (set_irn_mode)(ir_node *node, ir_mode *mode)
{
- _set_irn_mode(node, mode);
-}
-
-/** Gets the string representation of the mode .*/
-const char *get_irn_modename(const ir_node *node)
-{
- assert(node);
- return get_mode_name(node->mode);
-}
-
-ident *get_irn_modeident(const ir_node *node)
-{
- assert(node);
- return get_mode_ident(node->mode);
+ set_irn_mode_(node, mode);
}
ir_op *(get_irn_op)(const ir_node *node)
{
- return _get_irn_op(node);
+ return get_irn_op_(node);
}
/* should be private to the library: */
void (set_irn_op)(ir_node *node, ir_op *op)
{
- _set_irn_op(node, op);
+ set_irn_op_(node, op);
}
unsigned (get_irn_opcode)(const ir_node *node)
{
- return _get_irn_opcode(node);
+ return get_irn_opcode_(node);
}
const char *get_irn_opname(const ir_node *node)
ir_visited_t (get_irn_visited)(const ir_node *node)
{
- return _get_irn_visited(node);
+ return get_irn_visited_(node);
}
void (set_irn_visited)(ir_node *node, ir_visited_t visited)
{
- _set_irn_visited(node, visited);
+ set_irn_visited_(node, visited);
}
void (mark_irn_visited)(ir_node *node)
{
- _mark_irn_visited(node);
+ mark_irn_visited_(node);
}
int (irn_visited)(const ir_node *node)
{
- return _irn_visited(node);
+ return irn_visited_(node);
}
int (irn_visited_else_mark)(ir_node *node)
{
- return _irn_visited_else_mark(node);
+ return irn_visited_else_mark_(node);
}
void (set_irn_link)(ir_node *node, void *link)
{
- _set_irn_link(node, link);
+ set_irn_link_(node, link);
}
void *(get_irn_link)(const ir_node *node)
{
- return _get_irn_link(node);
+ return get_irn_link_(node);
}
op_pin_state (get_irn_pinned)(const ir_node *node)
{
- return _get_irn_pinned(node);
+ return get_irn_pinned_(node);
}
op_pin_state (is_irn_pinned_in_irg) (const ir_node *node)
{
- return _is_irn_pinned_in_irg(node);
+ return is_irn_pinned_in_irg_(node);
}
void set_irn_pinned(ir_node *node, op_pin_state state)
void *(get_irn_generic_attr)(ir_node *node)
{
assert(is_ir_node(node));
- return _get_irn_generic_attr(node);
+ return get_irn_generic_attr_(node);
}
const void *(get_irn_generic_attr_const)(const ir_node *node)
{
assert(is_ir_node(node));
- return _get_irn_generic_attr_const(node);
+ return get_irn_generic_attr_const_(node);
}
unsigned (get_irn_idx)(const ir_node *node)
{
assert(is_ir_node(node));
- return _get_irn_idx(node);
+ return get_irn_idx_(node);
}
int get_irn_pred_pos(ir_node *node, ir_node *arg)
/** manipulate fields of individual nodes **/
-/* this works for all except Block */
-ir_node *get_nodes_block(const ir_node *node)
+ir_node *(get_nodes_block)(const ir_node *node)
{
- assert(node->op != op_Block);
- return get_irn_n(node, -1);
+ return get_nodes_block_(node);
}
void set_nodes_block(ir_node *node, ir_node *block)
set_irn_n(node, -1, block);
}
-/* this works for all except Block */
-ir_node *get_nodes_MacroBlock(const ir_node *node)
-{
- assert(node->op != op_Block);
- return get_Block_MacroBlock(get_irn_n(node, -1));
-}
-
/* Test whether arbitrary node is frame pointer, i.e. Proj(pn_Start_P_frame_base)
* from Start. If so returns frame type, else Null. */
ir_type *is_frame_pointer(const ir_node *n)
return NULL;
}
-/* Test whether arbitrary node is tls pointer, i.e. Proj(pn_Start_P_tls)
- * from Start. If so returns tls type, else Null. */
-ir_type *is_tls_pointer(const ir_node *n)
-{
- if (is_Proj(n) && (get_Proj_proj(n) == pn_Start_P_tls)) {
- ir_node *start = get_Proj_pred(n);
- if (is_Start(start)) {
- return get_tls_type();
- }
- }
- return NULL;
-}
-
ir_node **get_Block_cfgpred_arr(ir_node *node)
{
assert(is_Block(node));
int (get_Block_n_cfgpreds)(const ir_node *node)
{
- return _get_Block_n_cfgpreds(node);
+ return get_Block_n_cfgpreds_(node);
}
ir_node *(get_Block_cfgpred)(const ir_node *node, int pos)
{
- return _get_Block_cfgpred(node, pos);
+ return get_Block_cfgpred_(node, pos);
}
void set_Block_cfgpred(ir_node *node, int pos, ir_node *pred)
ir_node *(get_Block_cfgpred_block)(const ir_node *node, int pos)
{
- return _get_Block_cfgpred_block(node, pos);
+ return get_Block_cfgpred_block_(node, pos);
}
int get_Block_matured(const ir_node *node)
ir_visited_t (get_Block_block_visited)(const ir_node *node)
{
- return _get_Block_block_visited(node);
+ return get_Block_block_visited_(node);
}
void (set_Block_block_visited)(ir_node *node, ir_visited_t visit)
{
- _set_Block_block_visited(node, visit);
+ set_Block_block_visited_(node, visit);
}
-/* For this current_ir_graph must be set. */
void (mark_Block_block_visited)(ir_node *node)
{
- _mark_Block_block_visited(node);
+ mark_Block_block_visited_(node);
}
int (Block_block_visited)(const ir_node *node)
{
- return _Block_block_visited(node);
-}
-
-ir_node *(set_Block_dead)(ir_node *block)
-{
- return _set_Block_dead(block);
-}
-
-int (is_Block_dead)(const ir_node *block)
-{
- return _is_Block_dead(block);
+ return Block_block_visited_(node);
}
ir_extblk *get_Block_extbb(const ir_node *block)
block->attr.block.extblk = extblk;
}
-/* Returns the macro block header of a block.*/
-ir_node *get_Block_MacroBlock(const ir_node *block)
-{
- ir_node *mbh;
- assert(is_Block(block));
- mbh = get_irn_n(block, -1);
- /* once macro block header is respected by all optimizations,
- this assert can be removed */
- assert(mbh != NULL);
- return mbh;
-}
-
-/* Sets the macro block header of a block. */
-void set_Block_MacroBlock(ir_node *block, ir_node *mbh)
-{
- assert(is_Block(block));
- mbh = skip_Id(mbh);
- assert(is_Block(mbh));
- set_irn_n(block, -1, mbh);
-}
-
-/* returns the macro block header of a node. */
-ir_node *get_irn_MacroBlock(const ir_node *n)
-{
- if (! is_Block(n)) {
- n = get_nodes_block(n);
- /* if the Block is Bad, do NOT try to get it's MB, it will fail. */
- if (is_Bad(n))
- return (ir_node *)n;
- }
- return get_Block_MacroBlock(n);
-}
-
/* returns the graph of a Block. */
ir_graph *(get_Block_irg)(const ir_node *block)
{
- return _get_Block_irg(block);
+ return get_Block_irg_(block);
}
ir_entity *create_Block_entity(ir_node *block)
return entity;
}
-ir_entity *get_Block_entity(const ir_node *block)
-{
- assert(is_Block(block));
- return block->attr.block.entity;
-}
-
-void set_Block_entity(ir_node *block, ir_entity *entity)
-{
- assert(is_Block(block));
- assert(get_entity_type(entity) == get_code_type());
- block->attr.block.entity = entity;
-}
-
-int has_Block_entity(const ir_node *block)
-{
- return block->attr.block.entity != NULL;
-}
-
ir_node *(get_Block_phis)(const ir_node *block)
{
- return _get_Block_phis(block);
+ return get_Block_phis_(block);
}
void (set_Block_phis)(ir_node *block, ir_node *phi)
{
- _set_Block_phis(block, phi);
+ set_Block_phis_(block, phi);
}
void (add_Block_phi)(ir_node *block, ir_node *phi)
{
- _add_Block_phi(block, phi);
+ add_Block_phi_(block, phi);
}
/* Get the Block mark (single bit). */
unsigned (get_Block_mark)(const ir_node *block)
{
- return _get_Block_mark(block);
+ return get_Block_mark_(block);
}
/* Set the Block mark (single bit). */
void (set_Block_mark)(ir_node *block, unsigned mark)
{
- _set_Block_mark(block, mark);
+ set_Block_mark_(block, mark);
}
int get_End_n_keepalives(const ir_node *end)
/* Set new keep-alives */
void set_End_keepalives(ir_node *end, int n, ir_node *in[])
{
- int i;
+ size_t e;
+ int i;
ir_graph *irg = get_irn_irg(end);
/* notify that edges are deleted */
- for (i = END_KEEPALIVE_OFFSET; i < ARR_LEN(end->in) - 1; ++i) {
- edges_notify_edge(end, i, NULL, end->in[i + 1], irg);
+ for (e = END_KEEPALIVE_OFFSET; e < ARR_LEN(end->in) - 1; ++e) {
+ edges_notify_edge(end, e, NULL, end->in[e + 1], irg);
}
ARR_RESIZE(ir_node *, end->in, n + 1 + END_KEEPALIVE_OFFSET);
end->in[1 + END_KEEPALIVE_OFFSET + i] = in[i];
edges_notify_edge(end, END_KEEPALIVE_OFFSET + i, end->in[1 + END_KEEPALIVE_OFFSET + i], NULL, irg);
}
+
+ /* update irg flags */
+ clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_OUTS);
}
/* Set new keep-alives from old keep-alives, skipping irn */
}
/* now n - 1 keeps, 1 block input */
ARR_RESIZE(ir_node *, end->in, (n - 1) + 1 + END_KEEPALIVE_OFFSET);
+
+ /* update irg flags */
+ clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_OUTS);
}
/* remove Bads, NoMems and doublets from the keep-alive set */
pset_new_t keeps;
int idx, n = get_End_n_keepalives(end);
ir_graph *irg;
+ bool changed = false;
if (n <= 0)
return;
ir_node *ka = get_End_keepalive(end, idx);
if (is_Bad(ka) || is_NoMem(ka) || pset_new_contains(&keeps, ka)) {
+ changed = true;
/* remove the edge */
edges_notify_edge(end, idx, NULL, ka, irg);
ARR_RESIZE(ir_node *, end->in, n + 1 + END_KEEPALIVE_OFFSET);
pset_new_destroy(&keeps);
+
+ if (changed) {
+ clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_OUTS);
+ }
}
void free_End(ir_node *end)
in array afterwards ... */
}
-int get_Return_n_ress(const ir_node *node)
+size_t get_Return_n_ress(const ir_node *node)
{
assert(is_Return(node));
- return (get_irn_arity(node) - RETURN_RESULT_OFFSET);
+ return (size_t)(get_irn_arity(node) - RETURN_RESULT_OFFSET);
}
ir_node **get_Return_res_arr(ir_node *node)
return NULL;
}
-/*
-void set_Return_n_res(ir_node *node, int results)
-{
- assert(is_Return(node));
-}
-*/
-
ir_node *get_Return_res(const ir_node *node, int pos)
{
assert(is_Return(node));
- assert(get_Return_n_ress(node) > pos);
+ assert(pos >= 0);
+ assert(get_Return_n_ress(node) > (size_t)pos);
return get_irn_n(node, pos + RETURN_RESULT_OFFSET);
}
int (is_Const_null)(const ir_node *node)
{
- return _is_Const_null(node);
+ return is_Const_null_(node);
}
int (is_Const_one)(const ir_node *node)
{
- return _is_Const_one(node);
+ return is_Const_one_(node);
}
int (is_Const_all_one)(const ir_node *node)
{
- return _is_Const_all_one(node);
-}
-
-
-/* The source language type. Must be an atomic type. Mode of type must
- be mode of node. For tarvals from entities type must be pointer to
- entity type. */
-ir_type *get_Const_type(const ir_node *node)
-{
- assert(is_Const(node));
- return node->attr.con.tp;
+ return is_Const_all_one_(node);
}
-void set_Const_type(ir_node *node, ir_type *tp)
-{
- assert(is_Const(node));
- if (tp != firm_unknown_type) {
- assert(is_atomic_type(tp));
- assert(get_type_mode(tp) == get_irn_mode(node));
- }
- node->attr.con.tp = tp;
-}
symconst_kind get_SymConst_kind(const ir_node *node)
node->attr.symc.sym = sym;
}
-ir_type *get_SymConst_value_type(const ir_node *node)
-{
- assert(is_SymConst(node));
- return node->attr.symc.tp;
-}
-
-void set_SymConst_value_type(ir_node *node, ir_type *tp)
-{
- assert(is_SymConst(node));
- node->attr.symc.tp = tp;
-}
-
int get_Sel_n_indexs(const ir_node *node)
{
assert(is_Sel(node));
set_irn_n(node, pos + SEL_INDEX_OFFSET, index);
}
-
-/* For unary and binary arithmetic operations the access to the
- operands can be factored out. Left is the first, right the
- second arithmetic value as listed in tech report 0999-33.
- unops are: Minus, Abs, Not, Conv, Cast
- binops are: Add, Sub, Mul, Quot, DivMod, Div, Mod, And, Or, Eor, Shl,
- Shr, Shrs, Rotate, Cmp */
-
-
ir_node **get_Call_param_arr(ir_node *node)
{
assert(is_Call(node));
return &get_irn_in(node)[CALL_PARAM_OFFSET + 1];
}
-int get_Call_n_params(const ir_node *node)
+size_t get_Call_n_params(const ir_node *node)
{
assert(is_Call(node));
- return (get_irn_arity(node) - CALL_PARAM_OFFSET);
+ return (size_t) (get_irn_arity(node) - CALL_PARAM_OFFSET);
}
ir_node *get_Call_param(const ir_node *node, int pos)
ir_node **get_Builtin_param_arr(ir_node *node)
{
assert(is_Builtin(node));
- return &get_irn_in(node)[BUILDIN_PARAM_OFFSET + 1];
+ return &get_irn_in(node)[BUILTIN_PARAM_OFFSET + 1];
}
int get_Builtin_n_params(const ir_node *node)
{
assert(is_Builtin(node));
- return (get_irn_arity(node) - BUILDIN_PARAM_OFFSET);
+ return (get_irn_arity(node) - BUILTIN_PARAM_OFFSET);
}
ir_node *get_Builtin_param(const ir_node *node, int pos)
{
assert(is_Builtin(node));
- return get_irn_n(node, pos + BUILDIN_PARAM_OFFSET);
+ return get_irn_n(node, pos + BUILTIN_PARAM_OFFSET);
}
void set_Builtin_param(ir_node *node, int pos, ir_node *param)
{
assert(is_Builtin(node));
- set_irn_n(node, pos + BUILDIN_PARAM_OFFSET, param);
+ set_irn_n(node, pos + BUILTIN_PARAM_OFFSET, param);
}
/* Returns a human readable string for the ir_builtin_kind. */
(node->attr.call.callee_arr != NULL));
}
-int get_Call_n_callees(const ir_node *node)
+size_t get_Call_n_callees(const ir_node *node)
{
assert(is_Call(node) && node->attr.call.callee_arr);
return ARR_LEN(node->attr.call.callee_arr);
}
-ir_entity *get_Call_callee(const ir_node *node, int pos)
+ir_entity *get_Call_callee(const ir_node *node, size_t pos)
{
- assert(pos >= 0 && pos < get_Call_n_callees(node));
+ assert(pos < get_Call_n_callees(node));
return node->attr.call.callee_arr[pos];
}
-void set_Call_callee_arr(ir_node *node, const int n, ir_entity ** arr)
+void set_Call_callee_arr(ir_node *node, size_t n, ir_entity ** arr)
{
+ ir_graph *irg = get_irn_irg(node);
+
assert(is_Call(node));
if (node->attr.call.callee_arr == NULL || get_Call_n_callees(node) != n) {
- node->attr.call.callee_arr = NEW_ARR_D(ir_entity *, current_ir_graph->obst, n);
+ node->attr.call.callee_arr = NEW_ARR_D(ir_entity *, irg->obst, n);
}
memcpy(node->attr.call.callee_arr, arr, n * sizeof(ir_entity *));
}
node->attr.call.callee_arr = NULL;
}
-/*
- * Returns non-zero if a Call is surely a self-recursive Call.
- * Beware: if this functions returns 0, the call might be self-recursive!
- */
-int is_self_recursive_Call(const ir_node *call)
-{
- const ir_node *callee = get_Call_ptr(call);
-
- if (is_SymConst_addr_ent(callee)) {
- const ir_entity *ent = get_SymConst_entity(callee);
- const ir_graph *irg = get_entity_irg(ent);
- if (irg == get_irn_irg(call))
- return 1;
- }
- return 0;
-}
-
/* Checks for upcast.
*
* Returns true if the Cast node casts a class type to a super type.
int (is_unop)(const ir_node *node)
{
- return _is_unop(node);
+ return is_unop_(node);
}
ir_node *get_unop_op(const ir_node *node)
int (is_binop)(const ir_node *node)
{
- return _is_binop(node);
+ return is_binop_(node);
}
ir_node *get_binop_left(const ir_node *node)
ir_node **get_Phi_preds_arr(ir_node *node)
{
- assert(node->op == op_Phi);
+ assert(is_Phi(node));
return (ir_node **)&(get_irn_in(node)[1]);
}
return (get_irn_arity(node));
}
-/*
-void set_Phi_n_preds(ir_node *node, int n_preds)
-{
- assert(node->op == op_Phi);
-}
-*/
-
ir_node *get_Phi_pred(const ir_node *node, int pos)
{
assert(is_Phi(node) || is_Phi0(node));
ir_node *(get_Phi_next)(const ir_node *phi)
{
- return _get_Phi_next(phi);
+ return get_Phi_next_(phi);
}
void (set_Phi_next)(ir_node *phi, ir_node *next)
{
- _set_Phi_next(phi, next);
+ set_Phi_next_(phi, next);
}
int is_memop(const ir_node *node)
{
- ir_opcode code = get_irn_opcode(node);
+ unsigned code = get_irn_opcode(node);
return (code == iro_Load || code == iro_Store);
}
ir_node *get_memop_mem(const ir_node *node)
{
assert(is_memop(node));
+ assert(n_Load_mem == 0 && n_Store_mem == 0);
return get_irn_n(node, 0);
}
void set_memop_mem(ir_node *node, ir_node *mem)
{
assert(is_memop(node));
+ assert(n_Load_mem == 0 && n_Store_mem == 0);
set_irn_n(node, 0, mem);
}
ir_node *get_memop_ptr(const ir_node *node)
{
assert(is_memop(node));
+ assert(n_Load_mem == 1 && n_Store_mem == 1);
return get_irn_n(node, 1);
}
void set_memop_ptr(ir_node *node, ir_node *ptr)
{
assert(is_memop(node));
+ assert(n_Load_mem == 1 && n_Store_mem == 1);
set_irn_n(node, 1, ptr);
}
-ir_volatility get_Load_volatility(const ir_node *node)
-{
- assert(is_Load(node));
- return node->attr.load.volatility;
-}
-
-void set_Load_volatility(ir_node *node, ir_volatility volatility)
-{
- assert(is_Load(node));
- node->attr.load.volatility = volatility;
-}
-
-ir_align get_Load_align(const ir_node *node)
-{
- assert(is_Load(node));
- return node->attr.load.aligned;
-}
-
-void set_Load_align(ir_node *node, ir_align align)
-{
- assert(is_Load(node));
- node->attr.load.aligned = align;
-}
-
-
-ir_volatility get_Store_volatility(const ir_node *node)
-{
- assert(is_Store(node));
- return node->attr.store.volatility;
-}
-
-void set_Store_volatility(ir_node *node, ir_volatility volatility)
-{
- assert(is_Store(node));
- node->attr.store.volatility = volatility;
-}
-
-ir_align get_Store_align(const ir_node *node)
-{
- assert(is_Store(node));
- return node->attr.store.aligned;
-}
-
-void set_Store_align(ir_node *node, ir_align align)
-{
- assert(is_Store(node));
- node->attr.store.aligned = align;
-}
-
ir_node **get_Sync_preds_arr(ir_node *node)
{
add_irn_n(node, pred);
}
-/* Returns the source language type of a Proj node. */
-ir_type *get_Proj_type(const ir_node *n)
+int (is_arg_Proj)(const ir_node *node)
{
- ir_type *tp = firm_unknown_type;
- ir_node *pred = get_Proj_pred(n);
-
- switch (get_irn_opcode(pred)) {
- case iro_Proj: {
- ir_node *pred_pred;
- /* Deal with Start / Call here: we need to know the Proj Nr. */
- assert(get_irn_mode(pred) == mode_T);
- pred_pred = get_Proj_pred(pred);
+ return is_arg_Proj_(node);
+}
- if (is_Start(pred_pred)) {
- ir_type *mtp = get_entity_type(get_irg_entity(get_irn_irg(pred_pred)));
- tp = get_method_param_type(mtp, get_Proj_proj(n));
- } else if (is_Call(pred_pred)) {
- ir_type *mtp = get_Call_type(pred_pred);
- tp = get_method_res_type(mtp, get_Proj_proj(n));
- }
- } break;
- case iro_Start: break;
- case iro_Call: break;
- case iro_Load: {
- ir_node *a = get_Load_ptr(pred);
- if (is_Sel(a))
- tp = get_entity_type(get_Sel_entity(a));
- } break;
- default:
- break;
- }
- return tp;
+int is_x_except_Proj(const ir_node *node)
+{
+ ir_node *pred;
+ if (!is_Proj(node))
+ return false;
+ pred = get_Proj_pred(node);
+ if (!is_fragile_op(pred))
+ return false;
+ return get_Proj_proj(node) == pred->op->pn_x_except;
}
-long get_Proj_proj(const ir_node *node)
+int is_x_regular_Proj(const ir_node *node)
{
- assert(is_Proj(node));
- return node->attr.proj;
+ ir_node *pred;
+ if (!is_Proj(node))
+ return false;
+ pred = get_Proj_pred(node);
+ if (!is_fragile_op(pred))
+ return false;
+ return get_Proj_proj(node) == pred->op->pn_x_regular;
}
-void set_Proj_proj(ir_node *node, long proj)
+void ir_set_throws_exception(ir_node *node, int throws_exception)
{
- assert(is_Proj(node));
- node->attr.proj = proj;
+ except_attr *attr = &node->attr.except;
+ assert(is_fragile_op(node));
+ attr->throws_exception = throws_exception;
}
-int (is_arg_Proj)(const ir_node *node)
+int ir_throws_exception(const ir_node *node)
{
- return _is_arg_Proj(node);
+ const except_attr *attr = &node->attr.except;
+ assert(is_fragile_op(node));
+ return attr->throws_exception;
}
ir_node **get_Tuple_preds_arr(ir_node *node)
/* returns the graph of a node */
ir_graph *(get_irn_irg)(const ir_node *node)
{
- return _get_irn_irg(node);
+ return get_irn_irg_(node);
}
ir_node *skip_Tuple(ir_node *node)
{
ir_node *pred;
- ir_op *op;
restart:
if (is_Proj(node)) {
pred = get_Proj_pred(node);
- op = get_irn_op(pred);
- /*
- * Looks strange but calls get_irn_op() only once
- * in most often cases.
- */
- if (op == op_Proj) { /* nested Tuple ? */
+ if (is_Proj(pred)) { /* nested Tuple ? */
pred = skip_Tuple(pred);
if (is_Tuple(pred)) {
node = get_Tuple_pred(pred, get_Proj_proj(node));
goto restart;
}
- } else if (op == op_Tuple) {
+ } else if (is_Tuple(pred)) {
node = get_Tuple_pred(pred, get_Proj_proj(node));
goto restart;
}
*
* Note: This function takes 10% of mostly ANY the compiler run, so it's
* a little bit "hand optimized".
- *
- * Moreover, it CANNOT be switched off using get_opt_normalize() ...
*/
ir_node *skip_Id(ir_node *node)
{
node->in[0+1] = node; /* turn us into a self referencing Id: shorten Id cycles. */
res = skip_Id(rem_pred);
- if (res->op == op_Id) /* self-loop */ return node;
+ if (is_Id(res)) /* self-loop */ return node;
node->in[0+1] = res; /* Turn Id chain into Ids all referencing the chain end. */
return res;
int (is_strictConv)(const ir_node *node)
{
- return _is_strictConv(node);
+ return is_strictConv_(node);
}
/* Returns true if node is a SymConst node with kind symconst_addr_ent. */
int (is_SymConst_addr_ent)(const ir_node *node)
{
- return _is_SymConst_addr_ent(node);
+ return is_SymConst_addr_ent_(node);
}
/* Returns true if the operation manipulates control flow. */
int is_cfop(const ir_node *node)
{
+ if (is_fragile_op(node) && ir_throws_exception(node))
+ return true;
+
return is_op_cfopcode(get_irn_op(node));
}
+int is_unknown_jump(const ir_node *node)
+{
+ return is_op_unknown_jump(get_irn_op(node));
+}
+
/* Returns true if the operation can change the control flow because
of an exception. */
int is_fragile_op(const ir_node *node)
ir_node *get_fragile_op_mem(ir_node *node)
{
assert(node && is_fragile_op(node));
-
- switch (get_irn_opcode(node)) {
- case iro_Call :
- case iro_Quot :
- case iro_DivMod:
- case iro_Div :
- case iro_Mod :
- case iro_Load :
- case iro_Store :
- case iro_Alloc :
- case iro_Bound :
- case iro_CopyB :
- return get_irn_n(node, pn_Generic_M);
- case iro_Bad :
- case iro_Unknown:
- return node;
- default:
- panic("should not be reached");
- }
-}
-
-/* Returns the result mode of a Div operation. */
-ir_mode *get_divop_resmod(const ir_node *node)
-{
- switch (get_irn_opcode(node)) {
- case iro_Quot : return get_Quot_resmode(node);
- case iro_DivMod: return get_DivMod_resmode(node);
- case iro_Div : return get_Div_resmode(node);
- case iro_Mod : return get_Mod_resmode(node);
- default:
- panic("should not be reached");
- }
+ return get_irn_n(node, node->op->fragile_mem_index);
}
/* Returns true if the operation is a forking control flow operation. */
int (is_irn_forking)(const ir_node *node)
{
- return _is_irn_forking(node);
+ return is_irn_forking_(node);
}
void (copy_node_attr)(ir_graph *irg, const ir_node *old_node, ir_node *new_node)
{
- _copy_node_attr(irg, old_node, new_node);
-}
-
-/* Return the type associated with the value produced by n
- * if the node remarks this type as it is the case for
- * Cast, Const, SymConst and some Proj nodes. */
-ir_type *(get_irn_type)(ir_node *node)
-{
- return _get_irn_type(node);
+ copy_node_attr_(irg, old_node, new_node);
}
/* Return the type attribute of a node n (SymConst, Call, Alloc, Free,
Cast) or NULL.*/
ir_type *(get_irn_type_attr)(ir_node *node)
{
- return _get_irn_type_attr(node);
+ return get_irn_type_attr_(node);
}
/* Return the entity attribute of a node n (SymConst, Sel) or NULL. */
ir_entity *(get_irn_entity_attr)(ir_node *node)
{
- return _get_irn_entity_attr(node);
+ return get_irn_entity_attr_(node);
}
/* Returns non-zero for constant-like nodes. */
int (is_irn_constlike)(const ir_node *node)
{
- return _is_irn_constlike(node);
+ return is_irn_constlike_(node);
}
/*
*/
int (is_irn_keep)(const ir_node *node)
{
- return _is_irn_keep(node);
+ return is_irn_keep_(node);
}
/*
*/
int (is_irn_start_block_placed)(const ir_node *node)
{
- return _is_irn_start_block_placed(node);
-}
-
-/* Returns non-zero for nodes that are machine operations. */
-int (is_irn_machine_op)(const ir_node *node)
-{
- return _is_irn_machine_op(node);
-}
-
-/* Returns non-zero for nodes that are machine operands. */
-int (is_irn_machine_operand)(const ir_node *node)
-{
- return _is_irn_machine_operand(node);
-}
-
-/* Returns non-zero for nodes that have the n'th user machine flag set. */
-int (is_irn_machine_user)(const ir_node *node, unsigned n)
-{
- return _is_irn_machine_user(node, n);
+ return is_irn_start_block_placed_(node);
}
/* Returns non-zero for nodes that are CSE neutral to its users. */
int (is_irn_cse_neutral)(const ir_node *node)
{
- return _is_irn_cse_neutral(node);
+ return is_irn_cse_neutral_(node);
}
/* Gets the string representation of the jump prediction .*/
#undef X
}
-/** the get_type operation must be always implemented and return a firm type */
-static ir_type *get_Default_type(const ir_node *n)
-{
- (void) n;
- return get_unknown_type();
-}
-
-/* Sets the get_type operation for an ir_op_ops. */
-ir_op_ops *firm_set_default_get_type(ir_opcode code, ir_op_ops *ops)
-{
- switch (code) {
- case iro_Const: ops->get_type = get_Const_type; break;
- case iro_SymConst: ops->get_type = get_SymConst_value_type; break;
- case iro_Cast: ops->get_type = get_Cast_type; break;
- case iro_Proj: ops->get_type = get_Proj_type; break;
- default:
- /* not allowed to be NULL */
- if (! ops->get_type)
- ops->get_type = get_Default_type;
- break;
- }
- return ops;
-}
-
/** Return the attribute type of a SymConst node if exists */
static ir_type *get_SymConst_attr_type(const ir_node *self)
{
}
/* Sets the get_type operation for an ir_op_ops. */
-ir_op_ops *firm_set_default_get_type_attr(ir_opcode code, ir_op_ops *ops)
+void firm_set_default_get_type_attr(unsigned code, ir_op_ops *ops)
{
switch (code) {
+ case iro_Alloc: ops->get_type_attr = get_Alloc_type; break;
+ case iro_Builtin: ops->get_type_attr = get_Builtin_type; break;
+ case iro_Call: ops->get_type_attr = get_Call_type; break;
+ case iro_Cast: ops->get_type_attr = get_Cast_type; break;
+ case iro_CopyB: ops->get_type_attr = get_CopyB_type; break;
+ case iro_Free: ops->get_type_attr = get_Free_type; break;
+ case iro_InstOf: ops->get_type_attr = get_InstOf_type; break;
case iro_SymConst: ops->get_type_attr = get_SymConst_attr_type; break;
- case iro_Call: ops->get_type_attr = get_Call_type; break;
- case iro_Alloc: ops->get_type_attr = get_Alloc_type; break;
- case iro_Free: ops->get_type_attr = get_Free_type; break;
- case iro_Cast: ops->get_type_attr = get_Cast_type; break;
default:
/* not allowed to be NULL */
if (! ops->get_type_attr)
ops->get_type_attr = get_Null_type;
break;
}
- return ops;
}
/** the get_entity_attr operation must be always implemented */
}
/* Sets the get_type operation for an ir_op_ops. */
-ir_op_ops *firm_set_default_get_entity_attr(ir_opcode code, ir_op_ops *ops)
+void firm_set_default_get_entity_attr(unsigned code, ir_op_ops *ops)
{
switch (code) {
case iro_SymConst: ops->get_entity_attr = get_SymConst_attr_entity; break;
case iro_Sel: ops->get_entity_attr = get_Sel_entity; break;
+ case iro_Block: ops->get_entity_attr = get_Block_entity; break;
default:
/* not allowed to be NULL */
if (! ops->get_entity_attr)
ops->get_entity_attr = get_Null_ent;
break;
}
- return ops;
}
/* Sets the debug information of a node. */
void (set_irn_dbg_info)(ir_node *n, dbg_info *db)
{
- _set_irn_dbg_info(n, db);
+ set_irn_dbg_info_(n, db);
}
/**
*/
dbg_info *(get_irn_dbg_info)(const ir_node *n)
{
- return _get_irn_dbg_info(n);
+ return get_irn_dbg_info_(n);
+}
+
+ir_switch_table *ir_new_switch_table(ir_graph *irg, size_t n_entries)
+{
+ struct obstack *obst = get_irg_obstack(irg);
+ ir_switch_table *res = OALLOCFZ(obst, ir_switch_table, entries, n_entries);
+ res->n_entries = n_entries;
+ return res;
+}
+
+void ir_switch_table_set(ir_switch_table *table, size_t n,
+ ir_tarval *min, ir_tarval *max, long pn)
+{
+ ir_switch_table_entry *entry = ir_switch_table_get_entry(table, n);
+ entry->min = min;
+ entry->max = max;
+ entry->pn = pn;
}
-/* checks whether a node represents a global address */
-int is_Global(const ir_node *node)
+size_t (ir_switch_table_get_n_entries)(const ir_switch_table *table)
{
- return is_SymConst_addr_ent(node);
+ return ir_switch_table_get_n_entries_(table);
}
-/* returns the entity of a global address */
-ir_entity *get_Global_entity(const ir_node *node)
+ir_tarval *ir_switch_table_get_max(const ir_switch_table *table, size_t e)
{
- return get_SymConst_entity(node);
+ return ir_switch_table_get_entry_const(table, e)->max;
+}
+
+ir_tarval *ir_switch_table_get_min(const ir_switch_table *table, size_t e)
+{
+ return ir_switch_table_get_entry_const(table, e)->min;
+}
+
+long ir_switch_table_get_pn(const ir_switch_table *table, size_t e)
+{
+ return ir_switch_table_get_entry_const(table, e)->pn;
+}
+
+ir_switch_table *ir_switch_table_duplicate(ir_graph *irg,
+ const ir_switch_table *table)
+{
+ size_t n_entries = ir_switch_table_get_n_entries(table);
+ size_t e;
+ ir_switch_table *res = ir_new_switch_table(irg, n_entries);
+ for (e = 0; e < n_entries; ++e) {
+ const ir_switch_table_entry *entry
+ = ir_switch_table_get_entry_const(table, e);
+ ir_switch_table_entry *new_entry = ir_switch_table_get_entry(res, e);
+ *new_entry = *entry;
+ }
+ return res;
}
/*
h = 9*h + HASH_PTR(get_irn_op(node));
return h;
-} /* firm_default_hash */
+}
/* include generated code */
#include "gen_irnode.c.inl"