new_r_ir_graph (entity *ent, int n_loc)
{
ir_graph *res;
- ir_node *first_block;
- ir_node *projX;
+ ir_node *first_block;
+ ir_node *end, *start, *start_block, *initial_mem, *projX;
res = alloc_graph();
res->kind = k_ir_graph;
res->frame_type = new_type_frame(mangle(get_entity_ident(ent), frame_type_suffix));
/*-- Nodes needed in every graph --*/
- res->end_block = new_immBlock();
- res->end = new_End();
- res->end_reg = res->end;
- res->end_except = res->end;
-
- res->start_block = new_immBlock();
- res->start = new_Start();
- res->bad = new_ir_node(NULL, res, res->start_block, op_Bad, mode_T, 0, NULL);
- res->no_mem = new_ir_node(NULL, res, res->start_block, op_NoMem, mode_M, 0, NULL);
+ set_irg_end_block (res, new_immBlock());
+ end = new_End();
+ set_irg_end (res, end);
+ set_irg_end_reg (res, end);
+ set_irg_end_except(res, end);
+
+ start_block = new_immBlock();
+ set_irg_start_block(res, start_block);
+ set_irg_bad (res, new_ir_node(NULL, res, start_block, op_Bad, mode_T, 0, NULL));
+ set_irg_no_mem (res, new_ir_node(NULL, res, start_block, op_NoMem, mode_M, 0, NULL));
+ start = new_Start();
+ set_irg_start (res, start);
/* Proj results of start node */
- projX = new_Proj (res->start, mode_X, pn_Start_X_initial_exec);
- res->frame = new_Proj (res->start, mode_P_data, pn_Start_P_frame_base);
- res->globals = new_Proj (res->start, mode_P_data, pn_Start_P_globals);
- res->initial_mem = new_Proj (res->start, mode_M, pn_Start_M);
- res->args = new_Proj (res->start, mode_T, pn_Start_T_args);
+ projX = new_Proj(start, mode_X, pn_Start_X_initial_exec);
+ set_irg_frame (res, new_Proj(start, mode_P_data, pn_Start_P_frame_base));
+ set_irg_globals (res, new_Proj(start, mode_P_data, pn_Start_P_globals));
+ set_irg_args (res, new_Proj(start, mode_T, pn_Start_T_args));
+ initial_mem = new_Proj(start, mode_M, pn_Start_M);
+ set_irg_initial_mem(res, initial_mem);
+
+ add_immBlock_pred(start_block, projX);
+ set_store(initial_mem);
+
#ifdef DEBUG_libfirm
res->graph_nr = get_irp_new_node_nr();
#endif
res->proj_args = NULL;
- set_store(res->initial_mem);
-
- add_immBlock_pred(res->start_block, projX);
/*
* The code generation needs it. leave it in now.
* Use of this edge is matter of discussion, unresolved. Also possible:
Must look like a correct irg, spare everything else. */
ir_graph *new_const_code_irg(void) {
ir_graph *res;
- ir_node *projX;
+ ir_node *end, *start_block, *start, *projX;
res = alloc_graph();
hook_new_graph(res, NULL);
current_ir_graph = res;
- res->n_loc = 1; /* Only the memory. */
- res->visited = 0; /* visited flag, for the ir walker */
- res->block_visited=0; /* visited flag, for the 'block'-walker */
+ res->n_loc = 1; /* Only the memory. */
+ res->visited = 0; /* visited flag, for the ir walker */
+ res->block_visited = 0; /* visited flag, for the 'block'-walker */
#if USE_EXPLICIT_PHI_IN_STACK
res->Phi_in_stack = NULL;
#endif
res->frame_type = NULL;
/* -- The end block -- */
- res->end_block = new_immBlock ();
- res->end = new_End ();
- res->end_reg = res->end;
- res->end_except = res->end;
+ set_irg_end_block (res, new_immBlock());
+ end = new_End();
+ set_irg_end (res, end);
+ set_irg_end_reg (res, end);
+ set_irg_end_except(res, end);
mature_immBlock(get_cur_block()); /* mature the end block */
/* -- The start block -- */
- res->start_block = new_immBlock ();
- res->bad = new_ir_node (NULL, res, res->start_block, op_Bad, mode_T, 0, NULL);
- res->no_mem = new_ir_node (NULL, res, res->start_block, op_NoMem, mode_M, 0, NULL);
- res->start = new_Start ();
+ start_block = new_immBlock();
+ set_irg_start_block(res, start_block);
+ set_irg_bad (res, new_ir_node (NULL, res, start_block, op_Bad, mode_T, 0, NULL));
+ set_irg_no_mem (res, new_ir_node (NULL, res, start_block, op_NoMem, mode_M, 0, NULL));
+ start = new_Start();
+ set_irg_start (res, start);
+
/* Proj results of start node */
- res->initial_mem = new_Proj (res->start, mode_M, pn_Start_M);
- projX = new_Proj (res->start, mode_X, pn_Start_X_initial_exec);
- add_immBlock_pred (res->start_block, projX);
- mature_immBlock (res->start_block); /* mature the start block */
+ set_irg_initial_mem(res, new_Proj(start, mode_M, pn_Start_M));
+ projX = new_Proj(start, mode_X, pn_Start_X_initial_exec);
+ add_immBlock_pred(start_block, projX);
+ mature_immBlock (start_block); /* mature the start block */
- add_immBlock_pred (new_immBlock (), projX);
- mature_immBlock (get_cur_block()); /* mature the 'body' block for expressions */
+ add_immBlock_pred(new_immBlock(), projX);
+ mature_immBlock (get_cur_block()); /* mature the 'body' block for expressions */
/* Set the visited flag high enough that the blocks will never be visited. */
set_irn_visited(get_cur_block(), -1);
set_Block_block_visited(get_cur_block(), -1);
- set_Block_block_visited(res->start_block, -1);
- set_irn_visited(res->start_block, -1);
- set_irn_visited(res->bad, -1);
- set_irn_visited(res->no_mem, -1);
+ set_Block_block_visited(start_block, -1);
+ set_irn_visited(start_block, -1);
+ set_irn_visited(get_irg_bad(res), -1);
+ set_irn_visited(get_irg_no_mem(res), -1);
res->phase_state = phase_high;
set_entity_peculiarity (irg->ent, pec);
}
- free_End(irg->end);
+ free_End(get_irg_end(irg));
obstack_free(irg->obst,NULL);
free(irg->obst);
#if USE_EXPLICIT_PHI_IN_STACK
void set_irg_end_reg (ir_graph *irg, ir_node *node) {
assert(get_irn_op(node) == op_EndReg || get_irn_op(node) == op_End);
- irg->end_reg = node;
+ irg->anchors[anchor_end_reg] = node;
}
ir_node *
void set_irg_end_except (ir_graph *irg, ir_node *node) {
assert(get_irn_op(node) == op_EndExcept || get_irn_op(node) == op_End);
- irg->end_except = node;
+ irg->anchors[anchor_end_except] = node;
}
ir_node *
}
void
-(set_irg_phase_low)(ir_graph *irg) {
- _set_irg_phase_low(irg);
+(set_irg_phase_state)(ir_graph *irg, irg_phase_state state) {
+ _set_irg_phase_state(irg, state);
}
op_pin_state
unsigned activated : 1;
} irg_edge_info_t;
+/**
+ * Index constants for nodes that can be accessed through the graph itself.
+ */
+enum irg_anchors {
+ anchor_start_block = 0, /**< block the start node will belong to */
+ anchor_start, /**< start node of this ir_graph */
+ anchor_end_block, /**< block the end node will belong to */
+ anchor_end, /**< end node of this ir_graph */
+ anchor_end_reg, /**< end node of this ir_graph */
+ anchor_end_except, /**< end node of this ir_graph */
+ anchor_cstore, /**< constant store -- no more needed!! */
+ anchor_frame, /**< method's frame */
+ anchor_globals, /**< pointer to the data segment containing all
+ globals as well as global procedures. */
+ anchor_initial_mem, /**< initial memory of this graph */
+ anchor_args, /**< methods arguments */
+ anchor_bad, /**< bad node of this ir_graph, the one and
+ only in this graph */
+ anchor_no_mem, /**< NoMem node of this ir_graph, the one and only in this graph */
+ anchor_max
+};
/** ir_graph holds all information for a procedure */
struct ir_graph {
entity *ent; /**< The entity of this procedure, i.e.,
the type of the procedure and the
class it belongs to. */
- ir_type *frame_type; /**< A class type representing the stack frame.
- Can include "inner" methods. */
- ir_node *start_block; /**< block the start node will belong to */
- ir_node *start; /**< start node of this ir_graph */
- ir_node *end_block; /**< block the end node will belong to */
- ir_node *end; /**< end node of this ir_graph */
- ir_node *end_reg; /**< end node of this ir_graph */
- ir_node *end_except; /**< end node of this ir_graph */
- ir_node *cstore; /**< constant store -- no more needed!! */
- ir_node *frame; /**< method's frame */
- ir_node *globals; /**< pointer to the data segment containing all
- globals as well as global procedures. */
- ir_node *initial_mem; /**< initial memory of this graph */
- ir_node *args; /**< methods arguments */
- ir_node **proj_args; /**< projs of the methods arguments */
- ir_node *bad; /**< bad node of this ir_graph, the one and
- only in this graph */
- ir_node *no_mem; /**< NoMem node of this ir_graph, the one and
- only in this graph */
- /* GL removed: we need unknown with mode for analyses. */
- /* struct ir_node *unknown;*/ /**< unknown node of this ir_graph */
+ ir_type *frame_type; /**< A class type representing the stack frame.
+ Can include "inner" methods. */
+ ir_node *anchors[anchor_max]; /**< anchor nodes */
+ ir_node **proj_args; /**< projs of the methods arguments */
struct obstack *obst; /**< obstack where all of the ir_nodes live */
ir_node *current_block; /**< block for newly gen_*()-erated ir_nodes */
struct obstack *extbb_obst; /**< obstack for extended basic block info */
/** Returns the start block of a graph. */
static INLINE ir_node *
_get_irg_start_block(const ir_graph *irg) {
- return irg->start_block;
+ return irg->anchors[anchor_start_block];
}
static INLINE void
_set_irg_start_block(ir_graph *irg, ir_node *node) {
- irg->start_block = node;
+ irg->anchors[anchor_start_block] = node;
}
static INLINE ir_node *
_get_irg_start(const ir_graph *irg) {
- return irg->start;
+ return irg->anchors[anchor_start];
}
static INLINE void
_set_irg_start(ir_graph *irg, ir_node *node) {
- irg->start = node;
+ irg->anchors[anchor_start] = node;
}
static INLINE ir_node *
_get_irg_end_block(const ir_graph *irg) {
- return irg->end_block;
+ return irg->anchors[anchor_end_block];
}
static INLINE void
_set_irg_end_block(ir_graph *irg, ir_node *node) {
- irg->end_block = node;
+ irg->anchors[anchor_end_block] = node;
}
static INLINE ir_node *
_get_irg_end(const ir_graph *irg) {
- return irg->end;
+ return irg->anchors[anchor_end];
}
static INLINE void
_set_irg_end(ir_graph *irg, ir_node *node) {
- irg->end = node;
+ irg->anchors[anchor_end] = node;
}
static INLINE ir_node *
_get_irg_end_reg(const ir_graph *irg) {
- return irg->end_reg;
+ return irg->anchors[anchor_end_reg];
}
static INLINE ir_node *
_get_irg_end_except (const ir_graph *irg) {
- return irg->end_except;
+ return irg->anchors[anchor_end_except];
}
static INLINE ir_node *
_get_irg_cstore(const ir_graph *irg) {
- return irg->cstore;
+ return irg->anchors[anchor_cstore];
}
static INLINE void
_set_irg_cstore(ir_graph *irg, ir_node *node) {
- irg->cstore = node;
+ irg->anchors[anchor_cstore] = node;
}
static INLINE ir_node *
_get_irg_frame(const ir_graph *irg) {
- return irg->frame;
+ return irg->anchors[anchor_frame];
}
static INLINE void
_set_irg_frame(ir_graph *irg, ir_node *node) {
- irg->frame = node;
+ irg->anchors[anchor_frame] = node;
}
static INLINE ir_node *
_get_irg_globals(const ir_graph *irg) {
- return irg->globals;
+ return irg->anchors[anchor_globals];
}
static INLINE void
_set_irg_globals(ir_graph *irg, ir_node *node) {
- irg->globals = node;
+ irg->anchors[anchor_globals] = node;
}
static INLINE ir_node *
_get_irg_initial_mem(const ir_graph *irg) {
- return irg->initial_mem;
+ return irg->anchors[anchor_initial_mem];
}
static INLINE void
_set_irg_initial_mem(ir_graph *irg, ir_node *node) {
- irg->initial_mem = node;
+ irg->anchors[anchor_initial_mem] = node;
}
static INLINE ir_node *
_get_irg_args(const ir_graph *irg) {
- return irg->args;
+ return irg->anchors[anchor_args];
}
static INLINE void
_set_irg_args(ir_graph *irg, ir_node *node) {
- irg->args = node;
+ irg->anchors[anchor_args] = node;
}
static INLINE ir_node **
static INLINE ir_node *
_get_irg_bad(const ir_graph *irg) {
- return irg->bad;
+ return irg->anchors[anchor_bad];
}
static INLINE void
_set_irg_bad(ir_graph *irg, ir_node *node) {
- irg->bad = node;
+ irg->anchors[anchor_bad] = node;
}
static INLINE ir_node *
_get_irg_no_mem(const ir_graph *irg) {
- return irg->no_mem;
+ return irg->anchors[anchor_no_mem];
}
static INLINE void
_set_irg_no_mem(ir_graph *irg, ir_node *node) {
- irg->no_mem = node;
+ irg->anchors[anchor_no_mem] = node;
}
static INLINE ir_node *
_get_irg_current_block(const ir_graph *irg) {
static INLINE void
_set_irg_frame_type(ir_graph *irg, ir_type *ftp) {
- assert(is_Class_type(ftp));
+ assert(is_frame_type(ftp));
irg->frame_type = ftp;
}
}
static INLINE void
-_set_irg_phase_low(ir_graph *irg) {
- irg->phase_state = phase_low;
+_set_irg_phase_state(ir_graph *irg, irg_phase_state state) {
+ irg->phase_state = state;
}
static INLINE op_pin_state
#define set_irg_frame_type(irg, ftp) _set_irg_frame_type(irg, ftp)
#define get_irg_obstack(irg) _get_irg_obstack(irg)
#define get_irg_phase_state(irg) _get_irg_phase_state(irg)
-#define set_irg_phase_low(irg) _set_irg_phase_low(irg)
+#define set_irg_phase_state(irg, state) _set_irg_phase_state(irg, state)
#define get_irg_pinned(irg) _get_irg_pinned(irg)
#define get_irg_outs_state(irg) _get_irg_outs_state(irg)
#define set_irg_outs_inconsistent(irg) _set_irg_outs_inconsistent(irg)
-#define get_irg_extblk_state(irg) _get_irg_extblk_state(irg)
-#define set_irg_extblk_inconsistent(irg) _set_irg_extblk_inconsistent(irg)
+#define get_irg_extblk_state(irg) _get_irg_extblk_state(irg)
+#define set_irg_extblk_inconsistent(irg) _set_irg_extblk_inconsistent(irg)
#define get_irg_dom_state(irg) _get_irg_dom_state(irg)
#define get_irg_postdom_state(irg) _get_irg_postdom_state(irg)
#define set_irg_doms_inconsistent(irg) _set_irg_doms_inconsistent(irg)