LLVM  5.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"
30 #include "llvm/IR/Function.h"
31 #include "llvm/IR/PassManager.h"
32 
33 namespace llvm {
34 
35 /// A private "module" namespace for types and utilities used by this pass.
36 /// These are implementation details and should not be used by clients.
37 namespace slpvectorizer {
38 class BoUpSLP;
39 }
40 
41 struct SLPVectorizerPass : public PassInfoMixin<SLPVectorizerPass> {
46 
47  ScalarEvolution *SE = nullptr;
49  TargetLibraryInfo *TLI = nullptr;
50  AliasAnalysis *AA = nullptr;
51  LoopInfo *LI = nullptr;
52  DominatorTree *DT = nullptr;
53  AssumptionCache *AC = nullptr;
54  DemandedBits *DB = nullptr;
55  const DataLayout *DL = nullptr;
56 
57 public:
59 
60  // Glue for old PM.
62  TargetLibraryInfo *TLI_, AliasAnalysis *AA_, LoopInfo *LI_,
65 
66 private:
67  /// \brief Collect store and getelementptr instructions and organize them
68  /// according to the underlying object of their pointer operands. We sort the
69  /// instructions by their underlying objects to reduce the cost of
70  /// consecutive access queries.
71  ///
72  /// TODO: We can further reduce this cost if we flush the chain creation
73  /// every time we run into a memory barrier.
74  void collectSeedInstructions(BasicBlock *BB);
75 
76  /// \brief Try to vectorize a chain that starts at two arithmetic instrs.
77  bool tryToVectorizePair(Value *A, Value *B, slpvectorizer::BoUpSLP &R);
78 
79  /// \brief Try to vectorize a list of operands.
80  /// \@param BuildVector A list of users to ignore for the purpose of
81  /// scheduling and that don't need extracting.
82  /// \returns true if a value was vectorized.
83  bool tryToVectorizeList(ArrayRef<Value *> VL, slpvectorizer::BoUpSLP &R,
84  ArrayRef<Value *> BuildVector = None,
85  bool AllowReorder = false);
86 
87  /// \brief Try to vectorize a chain that may start at the operands of \p V.
88  bool tryToVectorize(BinaryOperator *V, slpvectorizer::BoUpSLP &R);
89 
90  /// \brief Vectorize the store instructions collected in Stores.
91  bool vectorizeStoreChains(slpvectorizer::BoUpSLP &R);
92 
93  /// \brief Vectorize the index computations of the getelementptr instructions
94  /// collected in GEPs.
95  bool vectorizeGEPIndices(BasicBlock *BB, slpvectorizer::BoUpSLP &R);
96 
97  /// Try to find horizontal reduction or otherwise vectorize a chain of binary
98  /// operators.
99  bool vectorizeRootInstruction(PHINode *P, Value *V, BasicBlock *BB,
102 
103  /// \brief Scan the basic block and look for patterns that are likely to start
104  /// a vectorization chain.
105  bool vectorizeChainsInBlock(BasicBlock *BB, slpvectorizer::BoUpSLP &R);
106 
107  bool vectorizeStoreChain(ArrayRef<Value *> Chain, slpvectorizer::BoUpSLP &R,
108  unsigned VecRegSize);
109 
110  bool vectorizeStores(ArrayRef<StoreInst *> Stores, slpvectorizer::BoUpSLP &R);
111 
112  /// The store instructions in a basic block organized by base pointer.
113  StoreListMap Stores;
114 
115  /// The getelementptr instructions in a basic block organized by base pointer.
117 };
118 }
119 
120 #endif // LLVM_TRANSFORMS_VECTORIZE_SLPVECTORIZER_H
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:109
MapVector< Value *, WeakTrackingVHList > WeakTrackingVHListMap
Definition: SLPVectorizer.h:45
The main scalar evolution driver.
A cache of .assume calls within a function.
ScalarEvolution * SE
Definition: SLPVectorizer.h:47
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
AssumptionCache * AC
Definition: SLPVectorizer.h:53
#define F(x, y, z)
Definition: MD5.cpp:55
SmallVector< WeakTrackingVH, 8 > WeakTrackingVHList
Definition: SLPVectorizer.h:44
MapVector< Value *, StoreList > StoreListMap
Definition: SLPVectorizer.h:43
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:365
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:134
#define P(N)
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
SmallVector< StoreInst *, 8 > StoreList
Definition: SLPVectorizer.h:42
#define A
Definition: LargeTest.cpp:12
DominatorTree * DT
Definition: SLPVectorizer.h:52
AliasAnalysis * AA
Definition: SLPVectorizer.h:50
const DataLayout * DL
Definition: SLPVectorizer.h:55
#define B
Definition: LargeTest.cpp:24
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:861
Provides information about what library functions are available for the current target.
TargetTransformInfo * TTI
Definition: SLPVectorizer.h:48
bool runImpl(Function &F, ScalarEvolution *SE_, TargetTransformInfo *TTI_, TargetLibraryInfo *TLI_, AliasAnalysis *AA_, LoopInfo *LI_, DominatorTree *DT_, AssumptionCache *AC_, DemandedBits *DB_, OptimizationRemarkEmitter *ORE_)
TargetLibraryInfo * TLI
Definition: SLPVectorizer.h:49
LLVM Value Representation.
Definition: Value.h:73
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.
The optimization diagnostic interface.