LLVM: lib/Transforms/Vectorize/SandboxVectorizer/SeedCollector.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
17
18using namespace llvm;
20
23 cl::desc("Limit the size of the seed bundle to cap compilation time."));
24
27 cl::desc("Limit the number of collected seeds groups in a BB to "
28 "cap compilation time."));
29
31 unsigned MaxVecRegBits,
32 bool ForcePowerOf2) {
33
34
35
36
37
40
41 uint32_t NumElementsPowerOfTwo = 0;
42 uint32_t BitCountPowerOfTwo = 0;
43
44 assert((StartIdx) && "Expected unused at StartIdx");
46
47
48 if (isUsed(StartIdx + NumElements))
49 break;
51
52 if (BitCount + InstBits > MaxVecRegBits)
53 break;
54 NumElements++;
55 BitCount += InstBits;
57 NumElementsPowerOfTwo = NumElements;
58 BitCountPowerOfTwo = BitCount;
59 }
60 }
61 if (ForcePowerOf2) {
62 NumElements = NumElementsPowerOfTwo;
63 BitCount = BitCountPowerOfTwo;
64 }
65
66
67 if (NumElements > 1) {
69 "Must be a power of two");
71 }
72 return {};
73}
74
75template
76SeedContainer::KeyT SeedContainer::getKey(LoadOrStoreT *LSI,
77 bool AllowDiffTypes) const {
79 "Expected Load or Store!");
83 if (AllowDiffTypes) {
84 Ty = nullptr;
85 } else {
88 Ty = VTy->getElementType();
89 }
90 return {Ptr, Ty, Op};
91}
92
93
94template SeedContainer::KeyT
95SeedContainer::getKey(LoadInst *LSI, bool AllowDiffTypes) const;
96template SeedContainer::KeyT
97SeedContainer::getKey(StoreInst *LSI, bool AllowDiffTypes) const;
98
101 auto It = SeedLookupMap.find(I);
102 if (It == SeedLookupMap.end())
103 return false;
106 return true;
107}
108
109template
111
112 auto &BundleVec = Bundles[getKey(LSI, AllowDiffTypes)];
113
114
115
116 if (BundleVec.empty() || BundleVec.back()->size() == SeedBundleSizeLimit)
118 else
119 BundleVec.back()->insert(LSI, SE);
120
121 SeedLookupMap[LSI] = BundleVec.back().get();
122}
123
124
126 bool);
128 bool);
129
130#ifndef NDEBUG
132 for (const auto &Pair : Bundles) {
133 auto [I, Ty, Opc] = Pair.first;
134 const auto &SeedsVec = Pair.second;
137 : "Other";
138 OS << "[Inst=" << *I << " Ty=" << Ty << " " << RefType << "]\n";
139 for (const auto &SeedPtr : SeedsVec) {
140 SeedPtr->dump(OS);
141 OS << "\n";
142 }
143 }
144 OS << "\n";
145}
146
148#endif
149
150template static bool isValidMemSeed(LoadOrStoreT *LSI) {
151 if (!LSI->isSimple())
152 return false;
154
155 if (Ty->isX86_FP80Ty() || Ty->isPPC_FP128Ty())
156 return false;
157
159 return false;
163}
164
167
169 bool CollectStores, bool CollectLoads,
170 bool AllowDiffTypes)
171 : StoreSeeds(SE), LoadSeeds(SE), Ctx(BB->getContext()) {
172
173 if (!CollectStores && !CollectLoads)
174 return;
175
176 EraseCallbackID = Ctx.registerEraseInstrCallback([this](Instruction *I) {
178 StoreSeeds.erase(SI);
180 LoadSeeds.erase(LI);
181 });
182
183
184 for (auto &I : *BB) {
187 StoreSeeds.insert(SI, AllowDiffTypes);
190 LoadSeeds.insert(LI, AllowDiffTypes);
191
193 break;
194 }
195}
196
198 Ctx.unregisterEraseInstrCallback(EraseCallbackID);
199}
200
201#ifndef NDEBUG
203 OS << "=== StoreSeeds ===\n";
204 StoreSeeds.print(OS);
205 OS << "=== LoadSeeds ===\n";
206 LoadSeeds.print(OS);
207}
208
210#endif
211
212}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
#define LLVM_EXPORT_TEMPLATE
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
The main scalar evolution driver.
This class implements an extremely fast bulk output stream that can only output to a stream.
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
Specialization of SeedBundle for memory access instructions.
A set of candidate Instructions for vectorizing together.
bool isUsed(unsigned Element) const
\Returns whether or not Element has been used.
SmallVector< Instruction * > Seeds
LLVM_ABI ArrayRef< Instruction * > getSlice(unsigned StartIdx, unsigned MaxVecRegBits, bool ForcePowOf2)
\Returns a slice of seed elements, starting at the element StartIdx, with a total size <= MaxVecRegBi...
Definition SeedCollector.cpp:30
void setUsed(Instruction *I)
Marks instruction I "used" within the bundle.
LLVM_ABI ~SeedCollector()
Definition SeedCollector.cpp:197
LLVM_ABI SeedCollector(BasicBlock *BB, ScalarEvolution &SE, bool CollectStores, bool CollectLoads, bool AllowDiffTypes=false)
Definition SeedCollector.cpp:168
void print(raw_ostream &OS) const
Definition SeedCollector.cpp:202
LLVM_DUMP_METHOD void dump() const
Definition SeedCollector.cpp:209
void print(raw_ostream &OS) const
Definition SeedCollector.cpp:131
void insert(LoadOrStoreT *LSI, bool AllowDiffTypes)
Definition SeedCollector.cpp:110
LLVM_DUMP_METHOD void dump() const
Definition SeedCollector.cpp:147
LLVM_ABI bool erase(Instruction *I)
Definition SeedCollector.cpp:99
Just like llvm::Type these are immutable, unique, never get freed and can only be created via static ...
static unsigned getNumBits(Type *Ty, const DataLayout &DL)
\Returns the number of bits of Ty.
static Type * getExpectedType(const Value *V)
\Returns the expected type of Value V.
static Value * getMemInstructionBase(const LoadOrStoreT *LSI)
\Returns the base Value for load or store instruction LSI.
A SandboxIR Value has users. This is the base class.
static LLVM_ABI bool isValidElementType(Type *ElemTy)
initializer< Ty > init(const Ty &Val)
Context & getContext() const
template bool isValidMemSeed< StoreInst >(StoreInst *LSI)
static bool isValidMemSeed(LoadOrStoreT *LSI)
Definition SeedCollector.cpp:150
BasicBlock(llvm::BasicBlock *BB, Context &SBCtx)
template bool isValidMemSeed< LoadInst >(LoadInst *LSI)
static cl::opt< unsigned > SeedGroupsLimit("sbvec-seed-groups-limit", cl::init(256), cl::Hidden, cl::desc("Limit the number of collected seeds groups in a BB to " "cap compilation time."))
static cl::opt< unsigned > SeedBundleSizeLimit("sbvec-seed-bundle-size-limit", cl::init(32), cl::Hidden, cl::desc("Limit the size of the seed bundle to cap compilation time."))
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >