LLVM  4.0.0
SLPVectorizer.h
Go to the documentation of this file.
1 //===---- SLPVectorizer.h ---------------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // This pass implements the Bottom Up SLP vectorizer. It detects consecutive
10 // stores that can be put together into vector-stores. Next, it attempts to
11 // construct vectorizable tree using the use-def chains. If a profitable tree
12 // was found, the SLP vectorizer performs vectorization on the tree.
13 //
14 // The pass is inspired by the work described in the paper:
15 // "Loop-Aware SLP in GCC" by Ira Rosen, Dorit Nuzman, Ayal Zaks.
16 //
17 //===----------------------------------------------------------------------===//
18 
19 #ifndef LLVM_TRANSFORMS_VECTORIZE_SLPVECTORIZER_H
20 #define LLVM_TRANSFORMS_VECTORIZE_SLPVECTORIZER_H
21 
22 #include "llvm/ADT/MapVector.h"
26 #include "llvm/Analysis/LoopInfo.h"
29 #include "llvm/IR/Function.h"
30 #include "llvm/IR/PassManager.h"
31 
32 namespace llvm {
33 
34 /// A private "module" namespace for types and utilities used by this pass.
35 /// These are implementation details and should not be used by clients.
36 namespace slpvectorizer {
37 class BoUpSLP;
38 }
39 
40 struct SLPVectorizerPass : public PassInfoMixin<SLPVectorizerPass> {
45 
46  ScalarEvolution *SE = nullptr;
48  TargetLibraryInfo *TLI = nullptr;
49  AliasAnalysis *AA = nullptr;
50  LoopInfo *LI = nullptr;
51  DominatorTree *DT = nullptr;
52  AssumptionCache *AC = nullptr;
53  DemandedBits *DB = nullptr;
54  const DataLayout *DL = nullptr;
55 
56 public:
58 
59  // Glue for old PM.
61  TargetLibraryInfo *TLI_, AliasAnalysis *AA_, LoopInfo *LI_,
62  DominatorTree *DT_, AssumptionCache *AC_, DemandedBits *DB_);
63 
64 private:
65  /// \brief Collect store and getelementptr instructions and organize them
66  /// according to the underlying object of their pointer operands. We sort the
67  /// instructions by their underlying objects to reduce the cost of
68  /// consecutive access queries.
69  ///
70  /// TODO: We can further reduce this cost if we flush the chain creation
71  /// every time we run into a memory barrier.
72  void collectSeedInstructions(BasicBlock *BB);
73 
74  /// \brief Try to vectorize a chain that starts at two arithmetic instrs.
75  bool tryToVectorizePair(Value *A, Value *B, slpvectorizer::BoUpSLP &R);
76 
77  /// \brief Try to vectorize a list of operands.
78  /// \@param BuildVector A list of users to ignore for the purpose of
79  /// scheduling and that don't need extracting.
80  /// \returns true if a value was vectorized.
81  bool tryToVectorizeList(ArrayRef<Value *> VL, slpvectorizer::BoUpSLP &R,
82  ArrayRef<Value *> BuildVector = None,
83  bool AllowReorder = false);
84 
85  /// \brief Try to vectorize a chain that may start at the operands of \V;
86  bool tryToVectorize(BinaryOperator *V, slpvectorizer::BoUpSLP &R);
87 
88  /// \brief Vectorize the store instructions collected in Stores.
89  bool vectorizeStoreChains(slpvectorizer::BoUpSLP &R);
90 
91  /// \brief Vectorize the index computations of the getelementptr instructions
92  /// collected in GEPs.
93  bool vectorizeGEPIndices(BasicBlock *BB, slpvectorizer::BoUpSLP &R);
94 
95  /// \brief Scan the basic block and look for patterns that are likely to start
96  /// a vectorization chain.
97  bool vectorizeChainsInBlock(BasicBlock *BB, slpvectorizer::BoUpSLP &R);
98 
99  bool vectorizeStoreChain(ArrayRef<Value *> Chain, slpvectorizer::BoUpSLP &R,
100  unsigned VecRegSize);
101 
102  bool vectorizeStores(ArrayRef<StoreInst *> Stores, slpvectorizer::BoUpSLP &R);
103 
104  /// The store instructions in a basic block organized by base pointer.
105  StoreListMap Stores;
106 
107  /// The getelementptr instructions in a basic block organized by base pointer.
108  WeakVHListMap GEPs;
109 };
110 }
111 
112 #endif // LLVM_TRANSFORMS_VECTORIZE_SLPVECTORIZER_H
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:102
The main scalar evolution driver.
A cache of .assume calls within a function.
SmallVector< WeakVH, 8 > WeakVHList
Definition: SLPVectorizer.h:43
ScalarEvolution * SE
Definition: SLPVectorizer.h:46
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
AssumptionCache * AC
Definition: SLPVectorizer.h:52
#define F(x, y, z)
Definition: MD5.cpp:51
MapVector< Value *, StoreList > StoreListMap
Definition: SLPVectorizer.h:42
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:311
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
bool runImpl(Function &F, ScalarEvolution *SE_, TargetTransformInfo *TTI_, TargetLibraryInfo *TLI_, AliasAnalysis *AA_, LoopInfo *LI_, DominatorTree *DT_, AssumptionCache *AC_, DemandedBits *DB_)
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
MapVector< Value *, WeakVHList > WeakVHListMap
Definition: SLPVectorizer.h:44
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:96
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:107
LLVM Basic Block Representation.
Definition: BasicBlock.h:51
SmallVector< StoreInst *, 8 > StoreList
Definition: SLPVectorizer.h:41
DominatorTree * DT
Definition: SLPVectorizer.h:51
AliasAnalysis * AA
Definition: SLPVectorizer.h:49
const DataLayout * DL
Definition: SLPVectorizer.h:54
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
Provides information about what library functions are available for the current target.
TargetTransformInfo * TTI
Definition: SLPVectorizer.h:47
TargetLibraryInfo * TLI
Definition: SLPVectorizer.h:48
LLVM Value Representation.
Definition: Value.h:71
A container for analyses that lazily runs them and caches their results.
This pass exposes codegen information to IR-level passes.
This header defines various interfaces for pass management in LLVM.
Bottom Up SLP Vectorizer.
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")