From 66e761064fcfd00f9f403f9f9aa6c9fc0a916117 Mon Sep 17 00:00:00 2001 From: Zhigang Gong Date: Wed, 26 Mar 2014 18:27:40 +0800 Subject: [PATCH] GBE: Remove BBs if it only has a label instruction. v2: add an extra createCFGSimplificationPass right before the createGenPass. And don't remove BB at GEN IR layer. Signed-off-by: Zhigang Gong Reviewed-by: "Yang, Rong R" Reviewed-by: "Song, Ruiling" --- backend/src/ir/context.cpp | 3 ++- backend/src/ir/function.cpp | 12 ++++++++++++ backend/src/ir/function.hpp | 2 ++ backend/src/llvm/llvm_to_gen.cpp | 2 ++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/backend/src/ir/context.cpp b/backend/src/ir/context.cpp index 15d3b0a..5497294 100644 --- a/backend/src/ir/context.cpp +++ b/backend/src/ir/context.cpp @@ -75,7 +75,8 @@ namespace ir { // Remove all returns and insert one unique return block at the end of the // function lowerReturn(unit, fn->getName()); - + // check if there is empty labels at first + fn->checkEmptyLabels(); // Properly order labels and compute the CFG, it's needed by FunctionArgumentLower fn->sortLabels(); fn->computeCFG(); diff --git a/backend/src/ir/function.cpp b/backend/src/ir/function.cpp index a6aecb5..b0df412 100644 --- a/backend/src/ir/function.cpp +++ b/backend/src/ir/function.cpp @@ -64,6 +64,18 @@ namespace ir { loops.push_back(GBE_NEW(Loop, bbs, exits)); } + void Function::checkEmptyLabels(void) { + // Empty label map, we map the removed label to the next label. + map labelMap; + map revLabelMap; + foreachBlock([&](BasicBlock &BB) { + Instruction * insn = BB.getLastInstruction(); + if (insn->getOpcode() == OP_LABEL) { + GBE_ASSERTM(0, "Found empty block. "); + } + }); + } + void Function::sortLabels(void) { uint32_t last = 0; diff --git a/backend/src/ir/function.hpp b/backend/src/ir/function.hpp index 03aeaeb..7dad1fc 100644 --- a/backend/src/ir/function.hpp +++ b/backend/src/ir/function.hpp @@ -281,6 +281,8 @@ namespace ir { void computeCFG(void); /*! Sort labels in increasing orders (top block has the smallest label) */ void sortLabels(void); + /*! check empty Label. */ + void checkEmptyLabels(void); /*! Get the pointer family */ RegisterFamily getPointerFamily(void) const; /*! Number of registers in the register file */ diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp index 4d064a2..50b84ce 100644 --- a/backend/src/llvm/llvm_to_gen.cpp +++ b/backend/src/llvm/llvm_to_gen.cpp @@ -202,6 +202,8 @@ namespace gbe passes.add(createGVNPass()); // Remove redundancies passes.add(createScalarizePass()); // Expand all vector ops passes.add(createDeadInstEliminationPass()); // Remove simplified instructions + passes.add(createCFGSimplificationPass()); // Merge & remove BBs + passes.add(createScalarizePass()); // Expand all vector ops passes.add(createGenPass(unit)); // Print the code extra optimization passes -- 2.7.4