GBE: Remove BBs if it only has a label instruction.
authorZhigang Gong <zhigang.gong@intel.com>
Wed, 26 Mar 2014 10:27:40 +0000 (18:27 +0800)
committerZhigang Gong <zhigang.gong@intel.com>
Tue, 8 Apr 2014 08:21:03 +0000 (16:21 +0800)
v2:
add an extra createCFGSimplificationPass right before the createGenPass.
And don't remove BB at GEN IR layer.

Signed-off-by: Zhigang Gong <zhigang.gong@intel.com>
Reviewed-by: "Yang, Rong R" <rong.r.yang@intel.com>
Reviewed-by: "Song, Ruiling" <ruiling.song@intel.com>
backend/src/ir/context.cpp
backend/src/ir/function.cpp
backend/src/ir/function.hpp
backend/src/llvm/llvm_to_gen.cpp

index 15d3b0a..5497294 100644 (file)
@@ -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();
index a6aecb5..b0df412 100644 (file)
@@ -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<LabelIndex, LabelIndex> labelMap;
+    map<LabelIndex, LabelIndex> 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;
 
index 03aeaeb..7dad1fc 100644 (file)
@@ -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 */
index 4d064a2..50b84ce 100644 (file)
@@ -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