diff --git a/CMakeLists.txt b/CMakeLists.txt index 334206e8..83ccab03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -239,7 +239,7 @@ set(RELIB_SOURCES src/jit/ir/ir_write.c src/jit/passes/constant_propagation_pass.c src/jit/passes/control_flow_analysis_pass.c - src/jit/passes/conversion_elimination_pass.c + #src/jit/passes/conversion_elimination_pass.c src/jit/passes/dead_code_elimination_pass.c src/jit/passes/expression_simplification_pass.c src/jit/passes/load_store_elimination_pass.c diff --git a/src/jit/ir/ir.c b/src/jit/ir/ir.c index 960ab3d5..1fbaf4bc 100644 --- a/src/jit/ir/ir.c +++ b/src/jit/ir/ir.c @@ -134,8 +134,6 @@ void ir_remove_block(struct ir *ir, struct ir_block *block) { } void ir_add_edge(struct ir *ir, struct ir_block *src, struct ir_block *dst) { - CHECK_NE(src, dst); - /* linked list data is intrusive, need to allocate two edge objects */ { struct ir_edge *edge = ir_calloc(ir, sizeof(struct ir_edge)); diff --git a/src/jit/ir/ir_write.c b/src/jit/ir/ir_write.c index debc4817..51030803 100644 --- a/src/jit/ir/ir_write.c +++ b/src/jit/ir/ir_write.c @@ -193,6 +193,20 @@ static void ir_write_instr(struct ir_writer *w, const struct ir_instr *instr, static void ir_write_block(struct ir_writer *w, const struct ir_block *block, FILE *output) { + /* write out control flow information */ + fprintf(output, "# predecessors "); + list_for_each_entry(edge, &block->incoming, struct ir_edge, it) { + fprintf(output, "%%%d ", ir_get_block_label(w, edge->src)); + } + fprintf(output, "\n"); + + fprintf(output, "# successors "); + list_for_each_entry(edge, &block->outgoing, struct ir_edge, it) { + fprintf(output, "%%%d ", ir_get_block_label(w, edge->dst)); + } + fprintf(output, "\n"); + + /* write out actual block */ fprintf(output, "%%%d:", ir_get_block_label(w, block)); ir_write_meta(w, block, output); fprintf(output, "\n"); diff --git a/src/jit/jit.c b/src/jit/jit.c index 89444853..15a44fd9 100644 --- a/src/jit/jit.c +++ b/src/jit/jit.c @@ -9,6 +9,7 @@ #include "jit/jit_backend.h" #include "jit/jit_frontend.h" #include "jit/passes/constant_propagation_pass.h" +#include "jit/passes/control_flow_analysis_pass.h" #include "jit/passes/dead_code_elimination_pass.h" #include "jit/passes/expression_simplification_pass.h" #include "jit/passes/load_store_elimination_pass.h" @@ -373,6 +374,7 @@ void jit_compile_code(struct jit *jit, uint32_t guest_addr) { /* run optimization passes */ jit_promote_fastmem(jit, block, &ir); + cfa_run(jit->cfa, &ir); lse_run(jit->lse, &ir); cprop_run(jit->cprop, &ir); esimp_run(jit->esimp, &ir); @@ -477,6 +479,10 @@ void jit_destroy(struct jit *jit) { lse_destroy(jit->lse); } + if (jit->cfa) { + cfa_destroy(jit->cfa); + } + if (jit->exc_handler) { exception_handler_remove(jit->exc_handler); } @@ -493,6 +499,7 @@ struct jit *jit_create(const char *tag, struct jit_frontend *frontend, jit->backend = backend; /* create optimization passes */ + jit->cfa = cfa_create(); jit->lse = lse_create(); jit->cprop = cprop_create(); jit->esimp = esimp_create(); diff --git a/src/jit/passes/control_flow_analysis_pass.c b/src/jit/passes/control_flow_analysis_pass.c index f852c291..4911b8ad 100644 --- a/src/jit/passes/control_flow_analysis_pass.c +++ b/src/jit/passes/control_flow_analysis_pass.c @@ -8,7 +8,7 @@ void cfa_run(struct cfa *cfa, struct ir *ir) { /* add edges between blocks for easy traversing */ if (instr->op == OP_BRANCH || instr->op == OP_BRANCH_FALSE || instr->op == OP_BRANCH_TRUE) { - if (instr->arg[0]->blk) { + if (instr->arg[0]->type == VALUE_BLOCK) { ir_add_edge(ir, block, instr->arg[0]->blk); } }