#include "irnode_t.h"
#include "irgraph_t.h"
-#include "xp_help.h"
#include "irmode_t.h"
#include "typegmod_t.h"
#include "array.h"
#define END_KEEPALIVE_OFFSET 0
/* Declarations for inlineing */
-INLINE ir_node ** get_irn_in (ir_node *node);
-INLINE ir_mode *get_irn_mode (ir_node *node);
-INLINE ir_op *get_irn_op (ir_node *node);
-INLINE opcode get_irn_opcode (ir_node *node);
-INLINE ident *get_irn_opident (ir_node *node);
+INLINE ir_node ** get_irn_in (const ir_node *node);
+INLINE ir_mode *get_irn_mode (const ir_node *node);
+INLINE ir_op *get_irn_op (const ir_node *node);
+INLINE opcode get_irn_opcode (const ir_node *node);
+INLINE ident *get_irn_opident (const ir_node *node);
INLINE type *get_SymConst_type (ir_node *node);
INLINE ir_node *skip_nop (ir_node *node);
-INLINE int is_Proj (ir_node *node);
+INLINE int is_Proj (const ir_node *node);
-static char *pnc_name_arr [] = {"False", "Eq", "Lt", "Le",
- "Gt", "Ge", "Lg", "Leg", "Uo",
- "Ue", "Ul", "Ule", "Ug", "Uge",
- "Ne", "True" };
+static const char *pnc_name_arr [] = {
+ "False", "Eq", "Lt", "Le",
+ "Gt", "Ge", "Lg", "Leg", "Uo",
+ "Ue", "Ul", "Ule", "Ug", "Uge",
+ "Ne", "True"
+};
-INLINE char *get_pnc_string(int pnc) {
+INLINE const char *get_pnc_string(int pnc) {
return pnc_name_arr[pnc];
}
return 99; /* to shut up gcc */
}
-static char *pns_name_arr [] = {"initial_exec", "global_store",
- "frame_base", "globals", "args"};
+const char *pns_name_arr [] = {
+ "initial_exec", "global_store",
+ "frame_base", "globals", "args"
+};
-static char *symconst_name_arr [] = {"type_tag", "size", "linkage_ptr_info"};
+const char *symconst_name_arr [] = {
+ "type_tag", "size", "linkage_ptr_info"
+};
void
init_irnode (void)
memcpy (&new->attr, &old->attr, get_op_attr_size(get_irn_op(old)));
}
-/* IR-Nodes with attributes */
-int
-ir_node_print (XP_PAR1, const xprintf_info *info ATTRIBUTE((unused)), XP_PARN)
-{
- int printed = 0;
- ir_node *np = XP_GETARG (ir_node *, 0);
-
- if (!np) {
- XPS ("<null ir_node>");
- return printed;
- }
-
- XPF1 ("%I", get_irn_opident(np));
-
- switch (get_irn_opcode (np)) { /* node label */
- case iro_Const:
- XPF1 ("%I", get_irn_mode(np)->name);
- XPS (" : ");
- XPF1 ("%v", get_irn_const_attr);
- break;
- case iro_Proj:
- if (get_irn_mode (np) == mode_b) {
- XPC (" ");
- XP (pnc_name_arr[get_irn_proj_attr(np)]);
- } else if (get_irn_opcode (get_irn_in (np)[1]) == iro_Start) {
- XPC (" ");
- XP (pns_name_arr[get_irn_proj_attr(np)]);
- } else {
- XPF1 ("%I", get_irn_mode(np)->name);
- XPC (" ");
- XPF1 ("%d", get_irn_proj_attr(np));
- }
- break;
- case iro_SymConst:
- XPF1 ("%I", get_irn_mode(np)->name);
- XPC (" ");
- XP (symconst_name_arr[get_irn_symconst_attr(np).num]);
- XPF1 (" %#N", get_type_ident(get_SymConst_type(np)));
- break;
- case iro_Start: /* don't dump mode of these */
- case iro_Cond:
- case iro_Block:
- case iro_Call:
- case iro_Jmp:
- case iro_Return:
- case iro_End:
- case iro_Break:
- case iro_EndReg:
- case iro_EndExcept:
- case iro_CallBegin:
- break;
- default:
- XPF1 ("%I", get_irn_mode(np)->name);
- }
+/** getting some parameters from ir_nodes **/
- return printed;
+int
+is_ir_node (void *thing) {
+ assert(thing);
+ if (get_kind(thing) == k_ir_node)
+ return 1;
+ else
+ return 0;
}
-/** getting some parameters from ir_nodes **/
-
/* returns the number of predecessors without the block predecessor. */
INLINE int
-get_irn_arity (ir_node *node) {
+get_irn_arity (const ir_node *node) {
assert(node);
if (interprocedural_view) { /* handle Filter and Block specially */
if (get_irn_opcode(node) == iro_Filter) {
lists of operands as predecessors of Block or arguments of a Call are
consecutive. */
INLINE ir_node **
-get_irn_in (ir_node *node) {
+get_irn_in (const ir_node *node) {
assert(node);
if (interprocedural_view) { /* handle Filter and Block specially */
if (get_irn_opcode(node) == iro_Filter) {
}
INLINE ir_mode *
-get_irn_mode (ir_node *node)
+get_irn_mode (const ir_node *node)
{
assert (node);
return node->mode;
}
+INLINE void
+set_irn_mode (ir_node *node, ir_mode *mode)
+{
+ assert (node);
+ node->mode=mode;
+ return;
+}
+
INLINE modecode
-get_irn_modecode (ir_node *node)
+get_irn_modecode (const ir_node *node)
{
assert (node);
return node->mode->code;
INLINE ident *
-get_irn_modeident (ir_node *node)
+get_irn_modeident (const ir_node *node)
{
assert(node);
- return node->mode->name;
+ return get_mode_ident(node->mode);
}
INLINE ir_op *
-get_irn_op (ir_node *node)
+get_irn_op (const ir_node *node)
{
assert (node);
return node->op;
}
INLINE opcode
-get_irn_opcode (ir_node *node)
+get_irn_opcode (const ir_node *node)
{
assert (node);
assert (k_ir_node == get_kind(node));
}
INLINE const char *
-get_irn_opname (ir_node *node)
+get_irn_opname (const ir_node *node)
{
assert(node);
return id_to_str(node->op->name);
}
INLINE ident *
-get_irn_opident (ir_node *node)
+get_irn_opident (const ir_node *node)
{
assert(node);
return node->op->name;
}
INLINE unsigned long
-get_irn_visited (ir_node *node)
+get_irn_visited (const ir_node *node)
{
assert (node);
return node->visited;
}
INLINE int
-irn_not_visited (ir_node *node) {
+irn_not_visited (const ir_node *node) {
assert (node);
return (node->visited < current_ir_graph->visited);
}
INLINE int
-irn_visited (ir_node *node) {
+irn_visited (const ir_node *node) {
assert (node);
return (node->visited >= current_ir_graph->visited);
}
}
INLINE void *
-get_irn_link (ir_node *node) {
+get_irn_link (const ir_node *node) {
assert (node);
return node->link;
}
/* Outputs a unique number for this node */
INLINE long
-get_irn_node_nr(ir_node *node) {
+get_irn_node_nr(const ir_node *node) {
assert(node);
#ifdef DEBUG_libfirm
return node->node_nr;
in array afterwards ... */
}
-ir_graph *get_EndReg_irg (ir_node *end) {
+ir_graph *get_EndReg_irg (const ir_node *end) {
assert (end->op == op_EndReg);
return end->attr.end.irg;
}
-ir_graph *get_EndExcept_irg (ir_node *end) {
+ir_graph *get_EndExcept_irg (const ir_node *end) {
assert (end->op == op_EndReg);
return end->attr.end.irg;
}
INLINE ir_node *
get_Raise_mem (ir_node *node) {
- assert (node->op == op_Return);
+ assert (node->op == op_Raise);
return get_irn_n(node, 0);
}
}
INLINE symconst_kind
-get_SymConst_kind (ir_node *node) {
+get_SymConst_kind (const ir_node *node) {
assert (node->op == op_SymConst);
return node->attr.i.num;
}
/* 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
+ unops are: Minus, Abs, Not, Conv, Cast
binops are: Add, Sub, Mul, Quot, DivMod, Div, Mod, And, Or, Eor, Shl,
Shr, Shrs, Rotate, Cmp */
set_irn_n(node, 0, op);
}
+INLINE ir_node *
+get_Cast_op (ir_node *node) {
+ assert (node->op == op_Cast);
+ return get_irn_n(node, 0);
+}
+
+INLINE void
+set_Cast_op (ir_node *node, ir_node *op) {
+ assert (node->op == op_Cast);
+ set_irn_n(node, 0, op);
+}
+INLINE type *
+get_Cast_type (ir_node *node) {
+ assert (node->op == op_Cast);
+ return node->attr.cast.totype;
+}
-int
+INLINE void
+set_Cast_type (ir_node *node, type *to_tp) {
+ assert (node->op == op_Cast);
+ node->attr.cast.totype = to_tp;
+}
+
+INLINE int
is_unop (ir_node *node) {
return ( node->op == op_Minus ||
node->op == op_Abs ||
node->op == op_Not ||
- node->op == op_Conv );
+ node->op == op_Conv ||
+ node->op == op_Cast );
}
INLINE ir_node *
get_unop_op (ir_node *node) {
- assert ( node->op == op_Minus ||
- node->op == op_Abs ||
- node->op == op_Not ||
- node->op == op_Conv );
+ assert (is_unop(node));
switch (get_irn_opcode (node)) {
case iro_Minus: return get_Minus_op(node); break;
case iro_Abs: return get_Abs_op(node); break;
case iro_Not: return get_Not_op(node); break;
case iro_Conv: return get_Conv_op(node); break;
+ case iro_Cast: return get_Cast_op(node); break;
default: return NULL;
}
}
INLINE void
set_unop_op (ir_node *node, ir_node *op) {
- assert (node->op == op_Minus ||
- node->op == op_Abs ||
- node->op == op_Not ||
- node->op == op_Conv );
- switch (get_irn_opcode (node)) {
+ assert (is_unop(node));
+ switch (get_irn_opcode (node)) {
case iro_Minus: set_Minus_op(node, op); break;
case iro_Abs: set_Abs_op(node, op); break;
case iro_Not: set_Not_op(node, op); break;
case iro_Conv: set_Conv_op(node, op); break;
+ case iro_Cast: set_Cast_op(node, op); break;
default: ;
- }
+ }
}
return node->attr.end.irg;
} else {
assert(0 && "no irg attr");
+ return NULL;
}
}
return node;
}
+/* This should compact Id-cycles to self-cycles. It has the same (or less?) complexity
+ than any other approach, as Id chains are resolved and all point to the real node, or
+ all id's are self loops. */
INLINE ir_node *
skip_nop (ir_node *node) {
/* don't assert node !!! */
/* Don't use get_Id_pred: We get into an endless loop for
self-referencing Ids. */
if (node && (node->op == op_Id) && (node != node->in[0+1])) {
+ ir_node *rem_pred = node->in[0+1];
+ ir_node *res;
+
assert (get_irn_arity (node) > 0);
- return node->in[0+1];
+
+ node->in[0+1] = node;
+ res = skip_nop(rem_pred);
+ if (res->op == op_Id) /* self-loop */ return node;
+
+ node->in[0+1] = res;
+ return res;
} else {
return node;
}
}
INLINE int
-is_Proj (ir_node *node) {
+is_Proj (const ir_node *node) {
assert(node);
return node->op == op_Proj
|| (!interprocedural_view && node->op == op_Filter);