[LLVMdev] [Review Request][PATCH] Add the function "vectorizeBasicBlock"
Hal Finkel
hfinkel at anl.gov
Wed Apr 4 09:07:05 PDT 2012
Ether,
Sounds great! Please keep in mind that, eventually, we'll also want to
configure those options from TLI (or something similar). The patch
looks good to me.
-Hal
On Wed, 4 Apr 2012 23:54:18 +0800
Hongbin Zheng <etherzhhb at gmail.com> wrote:
> Hi Hal,
>
> I add a function named "vectorizeBasicBlock" which allow users to
> perform basic block vectoirzation inside their pass. But i am not sure
> whether i missed something as no one use the function right now (But
> it will be used by Polly sometimes later[1]).
>
> In addition, we (tobi and me) also want to make the vectorizer being
> configured command line flags. To achieve this, we are going to patch
> the pass so that it do not read the options like ReqChainDepth,
> SearchLimit, SplatBreaksChain, ... etc. from the command line option
> directly, but read from an instance of the VectorizeConfig class,
> where the VectorizeConfig class is designed to provide the vectorize
> related parameters to to the BBVectorize pas.
>
> After this, people can pass target specific vectorize configuration to
> the BBVectorize pass in tools like LLC. And original
> createBBVectorizePass function can create a VectorizeConfig that read
> the configuration from the commandline options and pass it to the
> BBVectorizePass, hence users can still control the behaviour of the
> pass with command like option.
>
> Any comment or suggestion is appreciated.
>
> best regards
> ether
>
> [1]http://llvm.org/bugs/show_bug.cgi?id=12404
> ---------- Forwarded message ----------
> From: Hongbin Zheng <etherzhhb at gmail.com>
> Date: Wed, Apr 4, 2012 at 9:55 PM
> Subject: [Review Request][PATCH] Add a the function
> "vectorizeBasicBlock" To: llvm-commits at cs.uiuc.edu
> Cc: Tobias Grosser <tobias at grosser.es>
>
>
> 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
--
Hal Finkel
Postdoctoral Appointee
Leadership Computing Facility
Argonne National Laboratory
More information about the llvm-dev
mailing list