LLVM  14.0.0git
SLPVectorizer.h
Go to the documentation of this file.
1 //===- SLPVectorizer.h ------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 // This pass implements the Bottom Up SLP vectorizer. It detects consecutive
9 // stores that can be put together into vector-stores. Next, it attempts to
10 // construct vectorizable tree using the use-def chains. If a profitable tree
11 // was found, the SLP vectorizer performs vectorization on the tree.
12 //
13 // The pass is inspired by the work described in the paper:
14 // "Loop-Aware SLP in GCC" by Ira Rosen, Dorit Nuzman, Ayal Zaks.
15 //
16 //===----------------------------------------------------------------------===//
17 
18 #ifndef LLVM_TRANSFORMS_VECTORIZE_SLPVECTORIZER_H
19 #define LLVM_TRANSFORMS_VECTORIZE_SLPVECTORIZER_H
20 
21 #include "llvm/ADT/ArrayRef.h"
22 #include "llvm/ADT/MapVector.h"
23 #include "llvm/ADT/None.h"
24 #include "llvm/ADT/SmallVector.h"
25 #include "llvm/IR/PassManager.h"
26 
27 namespace llvm {
28 
29 class AAResults;
30 class AssumptionCache;
31 class BasicBlock;
32 class CmpInst;
33 class DataLayout;
34 class DemandedBits;
35 class DominatorTree;
36 class Function;
37 class GetElementPtrInst;
38 class InsertElementInst;
39 class InsertValueInst;
40 class Instruction;
41 class LoopInfo;
42 class OptimizationRemarkEmitter;
43 class PHINode;
44 class ScalarEvolution;
45 class StoreInst;
46 class TargetLibraryInfo;
47 class TargetTransformInfo;
48 class Value;
49 
50 /// A private "module" namespace for types and utilities used by this pass.
51 /// These are implementation details and should not be used by clients.
52 namespace slpvectorizer {
53 
54 class BoUpSLP;
55 
56 } // end namespace slpvectorizer
57 
58 struct SLPVectorizerPass : public PassInfoMixin<SLPVectorizerPass> {
63 
64  ScalarEvolution *SE = nullptr;
66  TargetLibraryInfo *TLI = nullptr;
67  AAResults *AA = nullptr;
68  LoopInfo *LI = nullptr;
69  DominatorTree *DT = nullptr;
70  AssumptionCache *AC = nullptr;
71  DemandedBits *DB = nullptr;
72  const DataLayout *DL = nullptr;
73 
74 public:
76 
77  // Glue for old PM.
79  TargetLibraryInfo *TLI_, AAResults *AA_, LoopInfo *LI_,
82 
83 private:
84  /// Collect store and getelementptr instructions and organize them
85  /// according to the underlying object of their pointer operands. We sort the
86  /// instructions by their underlying objects to reduce the cost of
87  /// consecutive access queries.
88  ///
89  /// TODO: We can further reduce this cost if we flush the chain creation
90  /// every time we run into a memory barrier.
91  void collectSeedInstructions(BasicBlock *BB);
92 
93  /// Try to vectorize a chain that starts at two arithmetic instrs.
94  bool tryToVectorizePair(Value *A, Value *B, slpvectorizer::BoUpSLP &R);
95 
96  /// Try to vectorize a list of operands.
97  /// \param LimitForRegisterSize Vectorize only using maximal allowed register
98  /// size.
99  /// \returns true if a value was vectorized.
100  bool tryToVectorizeList(ArrayRef<Value *> VL, slpvectorizer::BoUpSLP &R,
101  bool LimitForRegisterSize = false);
102 
103  /// Try to vectorize a chain that may start at the operands of \p I.
104  bool tryToVectorize(Instruction *I, slpvectorizer::BoUpSLP &R);
105 
106  /// Vectorize the store instructions collected in Stores.
107  bool vectorizeStoreChains(slpvectorizer::BoUpSLP &R);
108 
109  /// Vectorize the index computations of the getelementptr instructions
110  /// collected in GEPs.
111  bool vectorizeGEPIndices(BasicBlock *BB, slpvectorizer::BoUpSLP &R);
112 
113  /// Try to find horizontal reduction or otherwise vectorize a chain of binary
114  /// operators.
115  bool vectorizeRootInstruction(PHINode *P, Value *V, BasicBlock *BB,
118 
119  /// Try to vectorize trees that start at insertvalue instructions.
120  bool vectorizeInsertValueInst(InsertValueInst *IVI, BasicBlock *BB,
122 
123  /// Try to vectorize trees that start at insertelement instructions.
124  bool vectorizeInsertElementInst(InsertElementInst *IEI, BasicBlock *BB,
126 
127  /// Tries to vectorize constructs started from CmpInst, InsertValueInst or
128  /// InsertElementInst instructions.
129  bool vectorizeSimpleInstructions(SmallVectorImpl<Instruction *> &Instructions,
131  bool AtTerminator);
132 
133  /// Scan the basic block and look for patterns that are likely to start
134  /// a vectorization chain.
135  bool vectorizeChainsInBlock(BasicBlock *BB, slpvectorizer::BoUpSLP &R);
136 
137  bool vectorizeStoreChain(ArrayRef<Value *> Chain, slpvectorizer::BoUpSLP &R,
138  unsigned Idx);
139 
140  bool vectorizeStores(ArrayRef<StoreInst *> Stores, slpvectorizer::BoUpSLP &R);
141 
142  /// The store instructions in a basic block organized by base pointer.
143  StoreListMap Stores;
144 
145  /// The getelementptr instructions in a basic block organized by base pointer.
146  GEPListMap GEPs;
147 };
148 
149 } // end namespace llvm
150 
151 #endif // LLVM_TRANSFORMS_VECTORIZE_SLPVECTORIZER_H
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
llvm::SLPVectorizerPass::AC
AssumptionCache * AC
Definition: SLPVectorizer.h:70
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
llvm::PassInfoMixin
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:374
llvm::Function
Definition: Function.h:62
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1177
llvm::TargetTransformInfo
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Definition: TargetTransformInfo.h:168
MapVector.h
llvm::ScalarEvolution
The main scalar evolution driver.
Definition: ScalarEvolution.h:460
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:151
Instructions
Code Generation Notes for reduce the size of the ISel and reduce repetition in the implementation In a small number of this can cause even when no optimisation has taken place Instructions
Definition: MSA.txt:11
llvm::MapVector< Value *, StoreList >
llvm::SLPVectorizerPass
Definition: SLPVectorizer.h:58
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
llvm::SLPVectorizerPass::runImpl
bool runImpl(Function &F, ScalarEvolution *SE_, TargetTransformInfo *TTI_, TargetLibraryInfo *TLI_, AAResults *AA_, LoopInfo *LI_, DominatorTree *DT_, AssumptionCache *AC_, DemandedBits *DB_, OptimizationRemarkEmitter *ORE_)
Definition: SLPVectorizer.cpp:8051
llvm::AAResults
Definition: AliasAnalysis.h:507
llvm::SLPVectorizerPass::DL
const DataLayout * DL
Definition: SLPVectorizer.h:72
llvm::InsertElementInst
This instruction inserts a single (scalar) element into a VectorType value.
Definition: Instructions.h:1940
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::Instruction
Definition: Instruction.h:45
llvm::SLPVectorizerPass::AA
AAResults * AA
Definition: SLPVectorizer.h:67
llvm::DemandedBits
Definition: DemandedBits.h:40
I
#define I(x, y, z)
Definition: MD5.cpp:58
ArrayRef.h
llvm::SLPVectorizerPass::LI
LoopInfo * LI
Definition: SLPVectorizer.h:68
llvm::SLPVectorizerPass::TLI
TargetLibraryInfo * TLI
Definition: SLPVectorizer.h:66
llvm::ISD::BasicBlock
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::LoopInfo
Definition: LoopInfo.h:1086
None.h
llvm::OptimizationRemarkEmitter
The optimization diagnostic interface.
Definition: OptimizationRemarkEmitter.h:33
llvm::SLPVectorizerPass::run
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Definition: SLPVectorizer.cpp:8031
llvm::AssumptionCache
A cache of @llvm.assume calls within a function.
Definition: AssumptionCache.h:42
llvm::SLPVectorizerPass::DB
DemandedBits * DB
Definition: SLPVectorizer.h:71
llvm::slpvectorizer::BoUpSLP
Bottom Up SLP Vectorizer.
Definition: SLPVectorizer.cpp:721
llvm::SLPVectorizerPass::SE
ScalarEvolution * SE
Definition: SLPVectorizer.h:64
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
PassManager.h
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:221
SmallVector.h
llvm::PHINode
Definition: Instructions.h:2657
llvm::SmallVectorImpl< Instruction * >
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::InsertValueInst
This instruction inserts a struct field of array element value into an aggregate value.
Definition: Instructions.h:2515
llvm::SLPVectorizerPass::DT
DominatorTree * DT
Definition: SLPVectorizer.h:69
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::codeview::PublicSymFlags::Function
@ Function