[llvm-commits] [Review Request][PATCH] Add a the function "vectorizeBasicBlock"

Hongbin Zheng etherzhhb at gmail.com
Wed Apr 4 06:55:55 PDT 2012


hi,

This patch add a the function "vectorizeBasicBlock" which allow users
vectorize a  BasicBlock in other passes, e.g. we can call
vectorizeBasicBlock in the  loop unroll pass right after the loop is
unrolled.

The function is currently declared in
"include/llvm/Transforms/Vectorize.h",  I have no idea in which header
the function should be declared though.

best regards
ether

---
 include/llvm/Transforms/Vectorize.h      |   13 ++++++++++++-
 lib/Transforms/Vectorize/BBVectorize.cpp |   25 ++++++++++++++++++++-----
 2 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/include/llvm/Transforms/Vectorize.h
b/include/llvm/Transforms/Vectorize.h
index dfc099d..373d501 100644
--- a/include/llvm/Transforms/Vectorize.h
+++ b/include/llvm/Transforms/Vectorize.h
@@ -16,7 +16,7 @@
 #define LLVM_TRANSFORMS_VECTORIZE_H

 namespace llvm {
-
+class BasicBlock;
 class BasicBlockPass;

 //===----------------------------------------------------------------------===//
@@ -25,6 +25,17 @@ 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.
+///
+/// @returns True if the BB is changed, false otherwise.
+bool vectorizeBasicBlock(Pass *P, BasicBlock &BB);
+
 } // End llvm namespace

 #endif
diff --git a/lib/Transforms/Vectorize/BBVectorize.cpp
b/lib/Transforms/Vectorize/BBVectorize.cpp
index 28eb634..d65cdd8 100644
--- a/lib/Transforms/Vectorize/BBVectorize.cpp
+++ b/lib/Transforms/Vectorize/BBVectorize.cpp
@@ -143,6 +143,12 @@ namespace {
     BBVectorize() : BasicBlockPass(ID) {
       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;
@@ -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
@@ -303,6 +305,14 @@ namespace {
       DEBUG(dbgs() << "BBV: done!\n");
       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);
@@ -1861,3 +1871,8 @@ BasicBlockPass *llvm::createBBVectorizePass() {
   return new BBVectorize();
 }

+bool llvm::vectorizeBasicBlock(Pass *P, BasicBlock &BB) {
+  BBVectorize BBVectorizer(P);
+  return BBVectorizer.vectorizeBB(BB);
+}
+
-- 
1.7.5.4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-a-the-function-vectorizeBasicBlock-which-allow-u.patch
Type: text/x-diff
Size: 3525 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120404/75b2c4f0/attachment.patch>


More information about the llvm-commits mailing list