handle Block_entity like other node attributes
authorMatthias Braun <matze@braunis.de>
Wed, 16 Nov 2011 23:05:18 +0000 (00:05 +0100)
committerMatthias Braun <matze@braunis.de>
Thu, 17 Nov 2011 15:37:13 +0000 (16:37 +0100)
include/libfirm/irnode.h
ir/be/begnuas.c
ir/be/beirgmod.c
ir/be/ia32/ia32_emitter.c
ir/be/sparc/sparc_emitter.c
ir/ir/irdumptxt.c
ir/ir/irnode.c
ir/opt/cfopt.c
ir/opt/combo.c
ir/opt/return.c
scripts/ir_spec.py

index a70794e..1cff2db 100644 (file)
@@ -306,14 +306,8 @@ FIRM_API ir_extblk *get_Block_extbb(const ir_node *block);
 FIRM_API void set_Block_extbb(ir_node *block, ir_extblk *extblk);
 /** Returns the ir_graph this Block belongs to. */
 FIRM_API ir_graph *get_Block_irg(const ir_node *block);
-/** Returns non-zero if the block has an entity assigned */
-FIRM_API int has_Block_entity(const ir_node *block);
-/** Returns the entity for a Block */
-FIRM_API ir_entity *get_Block_entity(const ir_node *block);
 /** Returns the entity for a Block (creating it if necessary) */
 FIRM_API ir_entity *create_Block_entity(ir_node *block);
-/** Set a new entity for a block */
-FIRM_API void set_Block_entity(ir_node *block, ir_entity *entity);
 /** Gets the head of the Phi list for this block. */
 FIRM_API ir_node *get_Block_phis(const ir_node *block);
 /** Sets the head of the Phi list for this block. */
index 16899b2..a3a2608 100644 (file)
@@ -1561,7 +1561,7 @@ void be_gas_emit_entity(const ir_entity *entity)
 
 void be_gas_emit_block_name(const ir_node *block)
 {
-       if (has_Block_entity(block)) {
+       if (get_Block_entity(block) != NULL) {
                ir_entity *entity = get_Block_entity(block);
                be_gas_emit_entity(entity);
        } else {
index ef85c0c..0cfb3f4 100644 (file)
@@ -180,7 +180,8 @@ static void remove_empty_block(ir_node *block)
 
                assert(succ_block == NULL);
                succ_block = get_edge_src_irn(edge);
-               if (has_Block_entity(succ_block) && has_Block_entity(block)) {
+               if (get_Block_entity(succ_block) != NULL
+                   && get_Block_entity(block) != NULL) {
                        /*
                         * Currently we can add only one label for a block.
                         * Therefore we cannot combine them if  both block already have one.
@@ -191,7 +192,7 @@ static void remove_empty_block(ir_node *block)
                set_irn_n(succ_block, pos, pred);
        }
 
-       if (has_Block_entity(block)) {
+       if (get_Block_entity(block) != NULL) {
                /* move the label to the successor block */
                ir_entity *entity = get_Block_entity(block);
                set_Block_entity(succ_block, entity);
index bf06b9c..c7f6b38 100644 (file)
@@ -118,7 +118,7 @@ static int block_needs_label(const ir_node *block)
        int need_label = 1;
        int  n_cfgpreds = get_Block_n_cfgpreds(block);
 
-       if (has_Block_entity(block))
+       if (get_Block_entity(block) != NULL)
                return 1;
 
        if (n_cfgpreds == 0) {
index 39384bf..108547c 100644 (file)
@@ -1270,7 +1270,7 @@ static bool block_needs_label(const ir_node *block, const ir_node *sched_prev)
 {
        int n_cfgpreds;
 
-       if (has_Block_entity(block))
+       if (get_Block_entity(block) != NULL)
                return true;
 
        n_cfgpreds = get_Block_n_cfgpreds(block);
index 0902740..90236a9 100644 (file)
@@ -152,7 +152,7 @@ void dump_irnode_to_file(FILE *F, ir_node *n)
        /* Source types */
        switch (get_irn_opcode(n)) {
        case iro_Block: {
-               if (has_Block_entity(n))
+               if (get_Block_entity(n) != NULL)
                        fprintf(F, "  Label: %lu\n", get_entity_label(get_Block_entity(n)));
                fprintf(F, "  block visited: %lu\n", get_Block_block_visited(n));
                fprintf(F, "  block marked: %u\n", get_Block_mark(n));
index 771374e..63816e6 100644 (file)
@@ -643,24 +643,6 @@ 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);
@@ -1674,6 +1656,7 @@ 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)
index 7ed73c2..49aa772 100644 (file)
@@ -114,7 +114,7 @@ static void collect_nodes(ir_node *n, void *ctx)
                ir_node *block = get_nodes_block(n);
                add_Block_phi(block, n);
        } else if (is_Block(n)) {
-               if (has_Block_entity(n)) {
+               if (get_Block_entity(n) != NULL) {
                        /* block with a jump label attached cannot be removed. */
                        set_Block_removable(n, false);
                }
index ba7deb5..ad88f5a 100644 (file)
@@ -1929,7 +1929,7 @@ static void compute_Block(node_t *node)
        int     i;
        ir_node *block = node->node;
 
-       if (block == get_irg_start_block(current_ir_graph) || has_Block_entity(block)) {
+       if (block == get_irg_start_block(current_ir_graph) || get_Block_entity(block) != NULL) {
                /* start block and labelled blocks are always reachable */
                node->type.tv = tarval_reachable;
                return;
@@ -2990,7 +2990,7 @@ static int only_one_reachable_proj(ir_node *n)
  */
 static int can_exchange(ir_node *pred, ir_node *block)
 {
-       if (is_Start(pred) || has_Block_entity(block))
+       if (is_Start(pred) || get_Block_entity(block) != NULL)
                return 0;
        else if (is_Jmp(pred))
                return 1;
index 76b1bdb..ce012ee 100644 (file)
@@ -187,7 +187,7 @@ static bool can_move_ret(ir_node *ret)
        /* check, that predecessors are Jmps */
        n = get_Block_n_cfgpreds(retbl);
        /* we cannot move above a labeled block, as this might kill the block */
-       if (n <= 1 || has_Block_entity(retbl))
+       if (n <= 1 || get_Block_entity(retbl) != NULL)
                return false;
        for (i = 0; i < n; ++i) {
                ir_node *pred = get_Block_cfgpred(retbl, i);
index 3e97a83..bfe1a74 100755 (executable)
@@ -175,6 +175,14 @@ class Block(Op):
        arity            = "variable"
        flags            = [ "labeled" ]
        attr_struct      = "block_attr"
+       attrs            = [
+               dict(
+                       name    = "entity",
+                       type    = "ir_entity*",
+                       comment = "entity representing this block",
+                       init    = "NULL",
+               ),
+       ]
        customSerializer = True
 
        init = '''