Add the function "vectorizeBasicBlock" which allow users vectorize a
authorHongbin Zheng <etherzhhb@gmail.com>
Thu, 5 Apr 2012 08:05:16 +0000 (08:05 +0000)
committerHongbin Zheng <etherzhhb@gmail.com>
Thu, 5 Apr 2012 08:05:16 +0000 (08:05 +0000)
 BasicBlock in other passes, e.g. we can call vectorizeBasicBlock in the
 loop unroll pass right after the loop is unrolled.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154089 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Transforms/Vectorize.h
lib/Transforms/Vectorize/BBVectorize.cpp

index dfc099ddb9b4f7f597e9cd24a3e74fd5c384d13a..ad06937caa7c818d228d8ec09eeb82caa040daa0 100644 (file)
@@ -16,7 +16,7 @@
 #define LLVM_TRANSFORMS_VECTORIZE_H
 
 namespace llvm {
-
+class BasicBlock;
 class BasicBlockPass;
 
 //===----------------------------------------------------------------------===//
@@ -25,6 +25,18 @@ class BasicBlockPass;
 //
 BasicBlockPass *createBBVectorizePass();
 
+//===----------------------------------------------------------------------===//
+/// @brief Vectorize the BasicBlock.
+///
+/// @param BB The BasicBlock to be vectorized
+/// @param P  The current running pass, should require AliasAnalysis and
+///           ScalarEvolution. After the vectorization, AliasAnalysis,
+///           ScalarEvolution and CFG are preserved.
+///
+/// @return True if the BB is changed, false otherwise.
+///
+bool vectorizeBasicBlock(Pass *P, BasicBlock &BB);
+
 } // End llvm namespace
 
 #endif
index 28eb6345071f3060f845acd450f1875619633b72..5abb242428a24359e3924e7b54ae9dc505fc8ed4 100644 (file)
@@ -144,6 +144,12 @@ namespace {
       initializeBBVectorizePass(*PassRegistry::getPassRegistry());
     }
 
+    BBVectorize(Pass *P) : BasicBlockPass(ID) {
+      AA = &P->getAnalysis<AliasAnalysis>();
+      SE = &P->getAnalysis<ScalarEvolution>();
+      TD = P->getAnalysisIfAvailable<TargetData>();
+    }
+
     typedef std::pair<Value *, Value *> ValuePair;
     typedef std::pair<ValuePair, size_t> ValuePairWithDepth;
     typedef std::pair<ValuePair, ValuePair> VPPair; // A ValuePair pair
@@ -280,11 +286,7 @@ namespace {
                      Instruction *&InsertionPt,
                      Instruction *I, Instruction *J);
 
-    virtual bool runOnBasicBlock(BasicBlock &BB) {
-      AA = &getAnalysis<AliasAnalysis>();
-      SE = &getAnalysis<ScalarEvolution>();
-      TD = getAnalysisIfAvailable<TargetData>();
-
+    bool vectorizeBB(BasicBlock &BB) {
       bool changed = false;
       // Iterate a sufficient number of times to merge types of size 1 bit,
       // then 2 bits, then 4, etc. up to half of the target vector width of the
@@ -304,6 +306,14 @@ namespace {
       return changed;
     }
 
+    virtual bool runOnBasicBlock(BasicBlock &BB) {
+      AA = &getAnalysis<AliasAnalysis>();
+      SE = &getAnalysis<ScalarEvolution>();
+      TD = getAnalysisIfAvailable<TargetData>();
+
+      return vectorizeBB(BB);
+    }
+
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
       BasicBlockPass::getAnalysisUsage(AU);
       AU.addRequired<AliasAnalysis>();
@@ -1861,3 +1871,7 @@ BasicBlockPass *llvm::createBBVectorizePass() {
   return new BBVectorize();
 }
 
+bool llvm::vectorizeBasicBlock(Pass *P, BasicBlock &BB) {
+  BBVectorize BBVectorizer(P);
+  return BBVectorizer.vectorizeBB(BB);
+}