- add pass for combo()
[libfirm] / ir / opt / combo.c
index a2f8ee9..081eee9 100644 (file)
@@ -72,6 +72,7 @@
 #include "irgraph_t.h"
 #include "irnode_t.h"
 #include "iropt_t.h"
+#include "irpass_t.h"
 #include "irgwalk.h"
 #include "irop.h"
 #include "irouts.h"
@@ -112,6 +113,7 @@ struct opcode_key_t {
                long      proj;   /**< For Proj nodes, its proj number */
                ir_entity *ent;   /**< For Sel Nodes, its entity */
                int       intVal; /**< For Conv/Div Nodes: strict/remainderless */
+               unsigned  uintVal;/**< for Builtin: the kind */
                ir_node   *block; /**< for Block: itself */
                void      *ptr;   /**< generic pointer for hash/cmp */
        } u;
@@ -287,7 +289,7 @@ static void check_opcode(const partition_t *Z) {
                                key.u.intVal = get_Conv_strict(irn);
                                break;
                        case iro_Div:
-                               key.u.intVal = is_Div_remainderless(irn);
+                               key.u.intVal = get_Div_no_remainder(irn);
                                break;
                        case iro_Block:
                                key.u.block = irn;
@@ -295,6 +297,9 @@ static void check_opcode(const partition_t *Z) {
                        case iro_Load:
                                key.mode = get_Load_mode(irn);
                                break;
+                       case iro_Builtin:
+                               key.u.intVal = get_Builtin_kind(irn);
+                               break;
                        default:
                                break;
                        }
@@ -315,7 +320,7 @@ static void check_opcode(const partition_t *Z) {
                                assert(key.u.intVal == get_Conv_strict(irn));
                                break;
                        case iro_Div:
-                               assert(key.u.intVal == is_Div_remainderless(irn));
+                               assert(key.u.intVal == get_Div_no_remainder(irn));
                                break;
                        case iro_Block:
                                assert(key.u.block == irn);
@@ -323,6 +328,9 @@ static void check_opcode(const partition_t *Z) {
                        case iro_Load:
                                assert(key.mode == get_Load_mode(irn));
                                break;
+                       case iro_Builtin:
+                               assert(key.u.intVal == (int) get_Builtin_kind(irn));
+                               break;
                        default:
                                break;
                        }
@@ -345,6 +353,8 @@ static void check_all_partitions(environment_t *env) {
                        assert(leader != node && leader->part == node->part);
                }
        }
+#else
+       (void) env;
 #endif
 }
 
@@ -352,13 +362,19 @@ static void check_all_partitions(environment_t *env) {
  * Check list.
  */
 static void do_check_list(const node_t *list, int ofs, const partition_t *Z) {
-       const node_t *e;
 
+#ifndef NDEBUG
+       const node_t *e;
 #define NEXT(e)  *((const node_t **)((char *)(e) + (ofs)))
        for (e = list; e != NULL; e = NEXT(e)) {
                assert(e->part == Z);
        }
 #undef NEXT
+#else
+       (void) list;
+       (void) ofs;
+       (void) Z;
+#endif
 }  /* ido_check_list */
 
 /**
@@ -578,7 +594,7 @@ static int cmp_opcode(const void *elt, const void *key, size_t size) {
        return o1->code != o2->code || o1->mode != o2->mode ||
               o1->arity != o2->arity ||
               o1->u.proj != o2->u.proj ||
-              o1->u.intVal != o2->u.intVal ||
+              o1->u.intVal != o2->u.intVal || /* this already checks uIntVal */
               o1->u.ptr != o2->u.ptr;
 }  /* cmp_opcode */
 
@@ -1666,7 +1682,7 @@ static void *lambda_opcode(const node_t *node, environment_t *env) {
                key.u.intVal = get_Conv_strict(irn);
                break;
        case iro_Div:
-               key.u.intVal = is_Div_remainderless(irn);
+               key.u.intVal = get_Div_no_remainder(irn);
                break;
        case iro_Block:
                /*
@@ -1680,6 +1696,9 @@ static void *lambda_opcode(const node_t *node, environment_t *env) {
        case iro_Load:
                key.mode = get_Load_mode(irn);
                break;
+       case iro_Builtin:
+               key.u.intVal = get_Builtin_kind(irn);
+               break;
        default:
                break;
        }
@@ -1904,7 +1923,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_label(block)) {
+       if (block == get_irg_start_block(current_ir_graph) || has_Block_entity(block)) {
                /* start block and labelled blocks are always reachable */
                node->type.tv = tarval_reachable;
                return;
@@ -1946,7 +1965,7 @@ static void compute_Unknown(node_t *node) {
         * It would be safe to compute Top IF it can be assured, that only Cmp
         * nodes are inputs to Conds. We check that first.
         * This is the way Frontends typically build Firm, but some optimizations
-        * (cond_eval for instance) might replace them by Phib's...
+        * (jump threading for instance) might replace them by Phib's...
         */
        node->type.tv = tarval_UNKNOWN;
 }  /* compute_Unknown */
@@ -2366,7 +2385,7 @@ static void compute_Proj_Cond(node_t *node, ir_node *cond) {
                        node->type.tv = tarval_reachable;
                } else if (selector->type.tv == tarval_top) {
                        if (tarval_UNKNOWN == tarval_top &&
-                           pnc == get_Cond_defaultProj(cond)) {
+                           pnc == get_Cond_default_proj(cond)) {
                                /* a switch based of Top is always "default" */
                                node->type.tv = tarval_reachable;
                        } else {
@@ -2374,7 +2393,7 @@ static void compute_Proj_Cond(node_t *node, ir_node *cond) {
                        }
                } else {
                        long value = get_tarval_long(selector->type.tv);
-                       if (pnc == get_Cond_defaultProj(cond)) {
+                       if (pnc == get_Cond_default_proj(cond)) {
                                /* default switch, have to check ALL other cases */
                                int i;
 
@@ -2944,7 +2963,7 @@ static int only_one_reachable_proj(ir_node *n) {
  * @param block  the destination block
  */
 static int can_exchange(ir_node *pred, ir_node *block) {
-       if (is_Start(pred) || has_Block_label(block))
+       if (is_Start(pred) || has_Block_entity(block))
                return 0;
        else if (is_Jmp(pred))
                return 1;
@@ -3130,7 +3149,7 @@ static void exchange_leader(ir_node *irn, ir_node *leader) {
                ir_node  *block = get_nodes_block(leader);
                dbg_info *dbg   = get_irn_dbg_info(irn);
 
-               leader = new_rd_Conv(dbg, current_ir_graph, block, leader, mode);
+               leader = new_rd_Conv(dbg, block, leader, mode);
        }
        exchange(irn, leader);
 }  /* exchange_leader */
@@ -3253,7 +3272,7 @@ static void apply_result(ir_node *irn, void *ctx) {
 
                                if (is_Cond(cond)) {
                                        if (only_one_reachable_proj(cond)) {
-                                               ir_node *jmp = new_r_Jmp(current_ir_graph, block->node);
+                                               ir_node *jmp = new_r_Jmp(block->node);
                                                set_irn_node(jmp, node);
                                                node->node = jmp;
                                                DB((dbg, LEVEL_1, "%+F is replaced by %+F\n", irn, jmp));
@@ -3295,7 +3314,7 @@ static void apply_result(ir_node *irn, void *ctx) {
                        } else if (is_entity(node->type.sym.entity_p)) {
                                if (! is_SymConst(irn)) {
                                        /* can be replaced by a SymConst */
-                                       ir_node *symc = new_r_SymConst(current_ir_graph, block->node, get_irn_mode(irn), node->type.sym, symconst_addr_ent);
+                                       ir_node *symc = new_r_SymConst(current_ir_graph, get_irn_mode(irn), node->type.sym, symconst_addr_ent);
                                        set_irn_node(symc, node);
                                        node->node = symc;
 
@@ -3532,6 +3551,7 @@ void combo(ir_graph *irg) {
                set_irg_extblk_inconsistent(irg);
                set_irg_doms_inconsistent(irg);
                set_irg_loopinfo_inconsistent(irg);
+               set_irg_entity_usage_state(irg, ir_entity_usage_not_computed);
        }
 
        ir_free_resources(irg, IR_RESOURCE_IRN_LINK | IR_RESOURCE_PHI_LIST);
@@ -3548,3 +3568,29 @@ void combo(ir_graph *irg) {
        set_value_of_func(NULL);
        current_ir_graph = rem;
 }  /* combo */
+
+/**
+ * Wrapper for running combo() as an ir_graph pass.
+ */
+static int pass_wrapper(ir_graph *irg, void *context) {
+       (void)context;
+       combo(irg);
+       /* combo is a fix-point iteration */
+       return 0;
+}  /* pass_wrapper */
+
+/* Creates an ir_graph pass for combo. */
+ir_graph_pass_t *combo_pass(const char *name, int verify, int dump) {
+       struct ir_graph_pass_t *pass = XMALLOCZ(ir_graph_pass_t);
+
+       pass->kind       = k_ir_prog_pass;
+       pass->run_on_irg = pass_wrapper;
+       pass->context    = pass;
+       pass->name       = name ? name : "combo";
+       pass->verify     = verify != 0;
+       pass->dump       = dump != 0;
+
+       INIT_LIST_HEAD(&pass->list);
+
+       return pass;
+}  /* combo_pass */