Fixed initialization of option tables
[libfirm] / ir / be / beverify.c
index f0accc4..74df99f 100644 (file)
  * PURPOSE.
  */
 
-/*
- * Author:    Matthias Braun
- * Date:      05.05.2006
- * Copyright: (c) Universitaet Karlsruhe
- * License:   This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
- * CVS-Id:    $Id$
+/**
+ * @file
+ * @brief       Various verify routines that check a scheduled graph for correctness.
+ * @author      Matthias Braun
+ * @date        05.05.2006
+ * @version     $Id$
  */
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -46,7 +46,7 @@
 #include "besched_t.h"
 #include "benode_t.h"
 #include "beirg_t.h"
-#include "bera.h"
+#include "beintlive_t.h"
 
 static int my_values_interfere(const ir_node *a, const ir_node *b);
 
@@ -125,6 +125,7 @@ int be_verify_register_pressure(const be_irg_t *birg,
        env.registers_available = env.cls->n_regs - be_put_ignore_regs(birg, env.cls, NULL);
        env.problem_found       = 0;
 
+       be_liveness_assure_sets(env.lv);
        irg_block_walk_graph(irg, verify_liveness_walker, NULL, &env);
        be_liveness_free(env.lv);
 
@@ -161,6 +162,8 @@ static void verify_schedule_walker(ir_node *block, void *data) {
         *   1. Make sure that all phi nodes are scheduled at the beginning of the block
         *   2. There is 1 or no control flow changing node scheduled and exactly delay_branches operations after it.
         *   3. No value is defined after it has been used
+        *   4. mode_T nodes have all projs scheduled behind them followed by Keeps
+        *       (except mode_X projs)
         */
        sched_foreach(block, node) {
                int i, arity;
@@ -245,6 +248,54 @@ static void verify_schedule_walker(ir_node *block, void *data) {
                                   node, block, get_irg_dump_name(env->irg));
                        env->problem_found = 1;
                }
+
+               // check that all projs/keeps are behind their nodes
+               if(is_Proj(node)) {
+                       ir_node *prev = sched_prev(node);
+                       while(is_Proj(prev))
+                               prev = sched_prev(prev);
+                       if(get_Proj_pred(node) != prev) {
+                               ir_fprintf(stderr, "%+F not scheduled after its pred node in block %+F (%s)\n",
+                                          node, block, get_irg_dump_name(env->irg));
+                               env->problem_found = 1;
+                       }
+               }
+               if(be_is_Keep(node)) {
+                       int arity   = get_irn_arity(node);
+                       int problem = 0;
+                       for(i = 0; i < arity; ++i) {
+                               ir_node *in = get_irn_n(node, i);
+                               ir_node *succ = sched_next(in);
+                               while(succ != node && !sched_is_end(succ)) {
+                                       /* the node in between has to be another input of the
+                                        * keep or a Proj */
+                                       int i2;
+                                       int found = 0;
+
+                                       if(is_Proj(succ)) {
+                                               succ = sched_next(succ);
+                                               continue;
+                                       }
+
+                                       for(i2 = 0; i2 < arity; ++i2) {
+                                               ir_node *in2 = get_irn_n(node, i2);
+                                               if(in2 == succ) {
+                                                       found = 1;
+                                                       break;
+                                               }
+                                       }
+                                       if(!found)
+                                               problem = 1;
+
+                                       succ = sched_next(succ);
+                               }
+                       }
+                       if(problem) {
+                               ir_fprintf(stderr, "%+F not scheduled after its pred node in block %+F (%s)\n",
+                                          node, block, get_irg_dump_name(env->irg));
+                               env->problem_found = 1;
+                       }
+               }
        }
 
        /* check that all delay branches are filled (at least with NOPs) */
@@ -261,12 +312,15 @@ static int should_be_scheduled(be_verify_schedule_env_t *env, ir_node *node) {
 
        if(get_irn_mode(node) == mode_M) {
                if(is_Proj(node))
-                       return -1;
+                       return 0;
                if(is_Phi(node) || is_Sync(node) || is_Pin(node))
                        return 0;
        }
-       if(is_Proj(node) && get_irn_mode(node) == mode_X)
-               return 0;
+       if(is_Proj(node)) {
+               if(get_irn_mode(node) == mode_X)
+                       return 0;
+               return should_be_scheduled(env, get_Proj_pred(node));
+       }
        if(be_is_Keep(node) && get_irn_opcode(get_nodes_block(node)) == iro_Bad)
                return 0;
 
@@ -345,6 +399,8 @@ typedef struct {
 static int cmp_spill(const void* d1, const void* d2, size_t size) {
        const spill_t* s1 = d1;
        const spill_t* s2 = d2;
+       (void) size;
+
        return s1->spill != s2->spill;
 }
 
@@ -386,18 +442,21 @@ static ir_node *get_memory_edge(const ir_node *node) {
        return result;
 }
 
-static void collect(be_verify_spillslots_env_t *env, ir_node *node, ir_node *reload, ir_entity* ent);
+static
+void collect(be_verify_spillslots_env_t *env, ir_node *node, ir_node *reload, ir_entity* ent);
 
-static void check_entity(be_verify_spillslots_env_t *env, ir_node *node, ir_entity *ent) {
+static
+void be_check_entity(be_verify_spillslots_env_t *env, ir_node *node, ir_entity *ent) {
        if(ent == NULL) {
                ir_fprintf(stderr, "Verify warning: Node %+F in block %+F(%s) should have an entity assigned\n",
                           node, get_nodes_block(node), get_irg_dump_name(env->irg));
        }
 }
 
-static void collect_spill(be_verify_spillslots_env_t *env, ir_node *node, ir_node *reload, ir_entity* ent) {
+static
+void collect_spill(be_verify_spillslots_env_t *env, ir_node *node, ir_node *reload, ir_entity* ent) {
        ir_entity *spillent = arch_get_frame_entity(env->arch_env, node);
-       check_entity(env, node, spillent);
+       be_check_entity(env, node, spillent);
        get_spill(env, node, ent);
 
        if(spillent != ent) {
@@ -421,7 +480,7 @@ static void collect_memperm(be_verify_spillslots_env_t *env, ir_node *node, ir_n
        out = get_Proj_proj(node);
 
        spillent = be_get_MemPerm_out_entity(memperm, out);
-       check_entity(env, memperm, spillent);
+       be_check_entity(env, memperm, spillent);
        if(spillent != ent) {
                ir_fprintf(stderr, "Verify warning: MemPerm %+F has different entity than reload %+F in block %+F(%s)\n",
                        node, reload, get_nodes_block(node), get_irg_dump_name(env->irg));
@@ -508,7 +567,7 @@ static void collect_spills_walker(ir_node *node, void *data) {
                        return;
                }
                ent = arch_get_frame_entity(env->arch_env, node);
-               check_entity(env, node, ent);
+               be_check_entity(env, node, ent);
 
                collect(env, spill, node, ent);
                ARR_APP1(ir_node*, env->reloads, node);
@@ -553,7 +612,7 @@ static void check_lonely_spills(ir_node *node, void *data) {
                spill_t *spill = find_spill(env, node);
                if(be_is_Spill(node)) {
                        ir_entity *ent = arch_get_frame_entity(env->arch_env, node);
-                       check_entity(env, node, ent);
+                       be_check_entity(env, node, ent);
                }
 
                if(spill == NULL) {
@@ -793,6 +852,7 @@ int be_verify_register_allocation(const arch_env_t *arch_env, ir_graph *irg) {
        env.lv = be_liveness(irg);
        env.problem_found = 0;
 
+       be_liveness_assure_sets(env.lv);
        irg_block_walk_graph(irg, verify_block_register_allocation, NULL, &env);
 
        be_liveness_free(env.lv);