Add an irg attribute the Bad nodes: so get_Block_irg() can operate on
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Thu, 25 Jun 2009 22:48:39 +0000 (22:48 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Thu, 25 Jun 2009 22:48:39 +0000 (22:48 +0000)
Bad nodes just like on Block nodes.
This simplifies get_irn_irg() and implements the idea the the irg can
be retrieved from "the block" of a node.

[r26188]

ir/common/irtools.c
ir/ir/ircons.c
ir/ir/irgraph.c
ir/ir/irnode.c
ir/ir/irnode_t.h
ir/ir/irtypes.h
ir/opt/opt_inline.c
scripts/ir_spec.py

index 7696d44..d7dd346 100644 (file)
@@ -116,7 +116,7 @@ copy_irn_to_irg(ir_node *n, ir_graph *irg) {
 
        /* fix the irg for blocks */
        if (is_Block(nn)) {
-               nn->attr.block.irg = irg;
+               nn->attr.block.irg.irg = irg;
 
                /* we cannot allow blocks WITHOUT macroblock input */
                set_Block_MacroBlock(nn, get_Block_MacroBlock(n));
index a0206f9..9d4064d 100644 (file)
@@ -1284,7 +1284,7 @@ new_d_immBlock(dbg_info *db) {
        res->attr.block.is_matured  = 0;
        res->attr.block.is_dead     = 0;
        res->attr.block.is_mb_head  = 1;
-       res->attr.block.irg         = current_ir_graph;
+       res->attr.block.irg.irg     = current_ir_graph;
        res->attr.block.backedge    = NULL;
        res->attr.block.in_cg       = NULL;
        res->attr.block.cg_backedge = NULL;
index feb0844..98a95ef 100644 (file)
@@ -178,7 +178,7 @@ void irg_set_nloc(ir_graph *res, int n_loc) {
 ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc) {
        ir_graph *res;
        ir_node  *first_block;
-       ir_node  *end, *start, *start_block, *initial_mem, *projX;
+       ir_node  *end, *start, *start_block, *initial_mem, *projX, *bad;
 
        res = alloc_graph();
 
@@ -205,8 +205,8 @@ ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc) {
 
        res->last_node_idx = 0;
 
-       res->value_table = new_identities (); /* value table for global value
-                                                numbering for optimizing use in iropt.c */
+       res->value_table = new_identities(); /* value table for global value
+                                               numbering for optimizing use in iropt.c */
        res->outs = NULL;
 
        res->inline_property       = irg_inline_any;
@@ -248,7 +248,9 @@ ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc) {
        start_block = new_immBlock();
        set_cur_block(start_block);
        set_irg_start_block(res, start_block);
-       set_irg_bad        (res, new_ir_node(NULL, res, start_block, op_Bad, mode_T, 0, NULL));
+       bad = new_ir_node(NULL, res, start_block, op_Bad, mode_T, 0, NULL);
+       bad->attr.irg.irg = res;
+       set_irg_bad        (res, bad);
        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);
@@ -343,6 +345,7 @@ ir_graph *new_const_code_irg(void)
        set_cur_block(start_block);
        set_irg_start_block(res, start_block);
        bad = new_ir_node(NULL, res, start_block, op_Bad, mode_T, 0, NULL);
+       bad->attr.irg.irg = res;
        set_irg_bad(res, bad);
        no_mem = new_ir_node(NULL, res, start_block, op_NoMem, mode_M, 0, NULL);
        set_irg_no_mem(res, no_mem);
@@ -400,9 +403,10 @@ static void copy_all_nodes(ir_node *n, void *env) {
        new_backedge_info(nn);
        set_irn_link(n, nn);
 
-       /* fix the irg for blocks */
+       /* fix the irg for Blocks: as Bad nodes are NOT copied, no
+          need t fix them */
        if (is_Block(nn))
-               nn->attr.block.irg = irg;
+               nn->attr.block.irg.irg = irg;
 
        /* fix access to entities on the stack frame */
        if (is_Sel(nn)) {
index a42a144..31dbcf4 100644 (file)
@@ -2539,10 +2539,8 @@ get_irn_irg(const ir_node *node) {
         */
        if (! is_Block(node))
                node = get_irn_n(node, -1);
-       if (is_Bad(node))  /* sometimes bad is predecessor of nodes instead of block: in case of optimization */
-               node = get_irn_n(node, -1);
-       assert(is_Block(node));
-       return node->attr.block.irg;
+       /* note that get_Block_irg() can handle Bad nodes */
+       return get_Block_irg(node);
 }
 
 
index 90def07..231ff6e 100644 (file)
@@ -537,8 +537,8 @@ _is_Block_dead(const ir_node *block) {
 
 static ir_graph *
 _get_Block_irg(const ir_node *block) {
-       assert(is_Block(block));
-       return block->attr.block.irg;
+       assert(is_Block(block) || is_Bad(block));
+       return block->attr.irg.irg;
 }
 
 static inline tarval *_get_Const_tarval(const ir_node *node) {
index 3015366..06d3206 100644 (file)
@@ -115,12 +115,17 @@ struct ir_mode {
        const void        *tv_priv;     /**< tarval module will save private data here */
 };
 
-/** ir node attributes **/
+/* ir node attributes */
+
+/** first attribute of Bad and Block nodes */
+typedef struct {
+       ir_graph *irg;              /**< The graph this block like node belongs to. */
+} irg_attr;
 
 /** Block attributes */
 typedef struct {
        /* General attributes */
-       ir_graph *irg;              /**< The graph this block belongs to. */
+       irg_attr     irg;           /**< The graph this block belongs to. */
        ir_visited_t block_visited; /**< For the walker that walks over all blocks. */
        /* Attributes private to construction: */
        unsigned is_matured:1;      /**< If set, all in-nodes of the block are fixed. */
@@ -304,6 +309,7 @@ typedef struct {
 /** Some IR-nodes just have one attribute, these are stored here,
    some have more. Their name is 'irnodename_attr' */
 typedef union {
+       irg_attr       irg;           /**< For Blocks and Bad: its belonging irg */
        block_attr     block;         /**< For Block: Fields needed to construct it */
        cond_attr      cond;          /**< For Cond. */
        const_attr     con;           /**< For Const: contains the value of the constant and a type */
index f1843c7..419163e 100644 (file)
@@ -726,14 +726,15 @@ static void copy_node_inline(ir_node *n, void *env) {
 
        copy_node(n, NULL);
        if (is_Sel(n)) {
-               nn = get_new_node (n);
+               nn = get_new_node(n);
                assert(is_Sel(nn));
+               /* use copied entities from the new frame */
                if (get_entity_owner(get_Sel_entity(n)) == frame_tp) {
                        set_Sel_entity(nn, get_entity_link(get_Sel_entity(n)));
                }
        } else if (is_Block(n)) {
-               nn = get_new_node (n);
-               nn->attr.block.irg = current_ir_graph;
+               nn = get_new_node(n);
+               nn->attr.block.irg.irg = current_ir_graph;
        }
 }
 
index ac7e0bd..0d568a5 100755 (executable)
@@ -104,11 +104,15 @@ ASM = dict(
 ),
 
 Bad = dict(
-       mode       = "mode_Bad",
-       flags      = "cfopcode, fragile, start_block, dump_noblock",
-       pinned     = "yes",
-       knownBlock = True,
-       singleton  = True,
+       mode        = "mode_Bad",
+       flags       = "cfopcode, fragile, start_block, dump_noblock",
+       pinned      = "yes",
+       attr_struct = "irg_attr",
+       knownBlock  = True,
+       singleton   = True,
+       init = '''
+       res->attr.irg.irg = irg;
+       ''',
 ),
 
 Block = dict(
@@ -128,7 +132,7 @@ Block = dict(
 
        res->attr.block.is_dead     = 0;
        res->attr.block.is_mb_head  = 1;
-       res->attr.block.irg         = irg;
+       res->attr.block.irg.irg     = irg;
        res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
        res->attr.block.in_cg       = NULL;
        res->attr.block.cg_backedge = NULL;