LLVM: include/llvm/Transforms/Vectorize/SandboxVectorizer/Legality.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_LEGALITY_H
13#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_LEGALITY_H
14
23
25
29
31public:
33
34private:
36
37public:
39 ShuffleMask(std::initializer_list Indices) : Indices(Indices) {}
42
43
46 Indices.reserve(Sz);
49 }
50
51
53 for (auto [Idx, Elm] : enumerate(Indices)) {
54 if ((int)Idx != Elm)
55 return false;
56 }
57 return true;
58 }
60 return Indices == Other.Indices;
61 }
63 size_t size() const { return Indices.size(); }
64 int operator[](int Idx) const { return Indices[Idx]; }
68#ifndef NDEBUG
70 Mask.print(OS);
71 return OS;
72 }
74 interleave(Indices, OS, [&OS](auto Elm) { OS << Elm; }, ",");
75 }
77#endif
78};
79
87
88
103
104#ifndef NDEBUG
107 switch (ID) {
109 return "Pack";
111 return "Widen";
113 return "DiamondReuse";
115 return "DiamondReuseWithShuffle";
117 return "DiamondReuseMultiInput";
118 }
120 }
121
123 switch (Reason) {
125 return "NotInstructions";
127 return "DiffOpcodes";
129 return "DiffTypes";
131 return "DiffMathFlags";
133 return "DiffWrapFlags";
135 return "DiffBBs";
137 return "RepeatedInstrs";
139 return "NotConsecutive";
141 return "CantSchedule";
143 return "Unimplemented";
145 return "Infeasible";
147 return "ForcePackForDebugging";
148 }
150 }
151};
152#endif
153
154
155
156
157
159protected:
161
164
165
168
169public:
172#ifndef NDEBUG
181#endif
182};
183
184
190
191public:
193#ifndef NDEBUG
198#endif
199};
200
210
223
230 Mask(Mask) {}
231
232public:
238};
239
240class Pack final : public LegalityResultWithReason {
244
245public:
249};
250
251
253public:
254
255
258
259 int ExtractIdx = 0;
260
261 public:
263 : V(V), ExtractIdx(ExtractIdx) {}
269 };
270
273
274public:
277
278
279 std::optional<std::pair<Action *, ShuffleMask>> getSingleInput() const {
280 const auto &Descr0 = *Descrs.begin();
281 if (!Descr0.needsExtract())
282 return std::nullopt;
283 auto *V0 = Descr0.getValue();
285 MaskIndices.push_back(Descr0.getExtractIdx());
287 if (!Descr.needsExtract())
288 return std::nullopt;
289 if (Descr.getValue() != V0)
290 return std::nullopt;
291 MaskIndices.push_back(Descr.getExtractIdx());
292 }
293 return std::make_pair(V0, ShuffleMask(std::move(MaskIndices)));
294 }
296 return any_of(Descrs, [](const auto &D) { return D.needsExtract(); });
297 }
301};
302
308 Descr(std::move(Descr)) {}
309
310public:
315};
316
317
320
322
323
324 std::optional
326
330
331
332
333
335
336public:
339 : Sched(AA, Ctx), SE(SE), DL(DL), IMaps(IMaps) {}
340
341 template <typename ResultT, typename... ArgsT>
343 ResultPool.push_back(
344 std::unique_ptr(new ResultT(std::move(Args)...)));
346 }
347
348
349
350
352 bool SkipScheduling = false);
353
358};
359
360}
361
362#endif
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
A parsed version of the target data layout string in and methods for querying it.
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
The main scalar evolution driver.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
typename SuperClass::const_iterator const_iterator
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This class implements an extremely fast bulk output stream that can only output to a stream.
ExtractElementDescr(Action *V, int ExtractIdx)
Definition Legality.h:262
Action * getValue() const
Definition Legality.h:265
ExtractElementDescr(Value *V)
Definition Legality.h:264
bool needsExtract() const
Definition Legality.h:267
Value * getScalar() const
Definition Legality.h:266
int getExtractIdx() const
Definition Legality.h:268
Describes how to collect the values needed by each lane.
Definition Legality.h:252
const SmallVector< ExtractElementDescr, 4 > & getDescrs() const
Definition Legality.h:298
SmallVector< ExtractElementDescr, 4 > DescrVecT
Definition Legality.h:271
bool hasVectorInputs() const
Definition Legality.h:295
std::optional< std::pair< Action *, ShuffleMask > > getSingleInput() const
If all elements come from a single vector input, then return that vector and also the shuffle mask re...
Definition Legality.h:279
DescrVecT Descrs
Definition Legality.h:272
CollectDescr(SmallVectorImpl< ExtractElementDescr > &&Descrs)
Definition Legality.h:275
Definition Legality.h:303
friend class LegalityAnalysis
Definition Legality.h:304
static bool classof(const LegalityResult *From)
Definition Legality.h:311
const CollectDescr & getCollectDescr() const
Definition Legality.h:314
Definition Legality.h:224
const ShuffleMask & getMask() const
Definition Legality.h:237
friend class LegalityAnalysis
Definition Legality.h:225
Action * getVector() const
Definition Legality.h:236
static bool classof(const LegalityResult *From)
Definition Legality.h:233
Definition Legality.h:211
Action * getVector() const
Definition Legality.h:221
friend class LegalityAnalysis
Definition Legality.h:212
static bool classof(const LegalityResult *From)
Definition Legality.h:218
Maps the original instructions to the vectorized instrs and the reverse.
Performs the legality analysis and returns a LegalityResult object.
Definition Legality.h:318
const LegalityResult & getForcedPackForDebugging()
\Returns a Pack with reason 'ForcePackForDebugging'.
Definition Legality.h:354
LLVM_ABI const LegalityResult & canVectorize(ArrayRef< Value * > Bndl, bool SkipScheduling=false)
Checks if it's legal to vectorize the instructions in Bndl.
LegalityAnalysis(AAResults &AA, ScalarEvolution &SE, const DataLayout &DL, Context &Ctx, InstrMaps &IMaps)
Definition Legality.h:337
ResultT & createLegalityResult(ArgsT &&...Args)
A LegalityResult factory.
Definition Legality.h:342
ResultReason getReason() const
Definition Legality.h:192
void print(raw_ostream &OS) const override
Definition Legality.h:194
friend class Pack
Definition Legality.h:189
The legality outcome is represented by a class rather than an enum class because in some cases the le...
Definition Legality.h:158
LegalityResult & operator=(const LegalityResult &)=delete
friend raw_ostream & operator<<(raw_ostream &OS, const LegalityResult &LR)
Definition Legality.h:177
friend class LegalityAnalysis
Definition Legality.h:163
LegalityResultID ID
Definition Legality.h:160
LLVM_DUMP_METHOD void dump() const
virtual ~LegalityResult()=default
LegalityResultID getSubclassID() const
Definition Legality.h:171
virtual void print(raw_ostream &OS) const
Definition Legality.h:173
LegalityResult(LegalityResultID ID)
Only Legality can create LegalityResults.
Definition Legality.h:162
LegalityResult(const LegalityResult &)=delete
We shouldn't need copies.
Definition Legality.h:240
friend class LegalityAnalysis
Definition Legality.h:243
static bool classof(const LegalityResult *From)
Definition Legality.h:246
ShuffleMask(std::initializer_list< int > Indices)
Definition Legality.h:39
void print(raw_ostream &OS) const
Definition Legality.h:73
bool isIdentity() const
\Returns true if the mask is a perfect identity mask with consecutive indices, i.e....
Definition Legality.h:52
const_iterator end() const
Definition Legality.h:67
ShuffleMask(SmallVectorImpl< int > &&Indices)
Definition Legality.h:38
static ShuffleMask getIdentity(unsigned Sz)
Creates and returns an identity shuffle mask of size Sz.
Definition Legality.h:44
LLVM_DUMP_METHOD void dump() const
bool operator==(const ShuffleMask &Other) const
Definition Legality.h:59
bool operator!=(const ShuffleMask &Other) const
Definition Legality.h:62
IndicesVecT::const_iterator const_iterator
Definition Legality.h:65
int operator[](int Idx) const
Definition Legality.h:64
size_t size() const
Definition Legality.h:63
friend raw_ostream & operator<<(raw_ostream &OS, const ShuffleMask &Mask)
Definition Legality.h:69
ShuffleMask(ArrayRef< int > Indices)
Definition Legality.h:40
const_iterator begin() const
Definition Legality.h:66
SmallVector< int, 8 > IndicesVecT
Definition Legality.h:32
A SandboxIR Value has users. This is the base class.
Definition Legality.h:201
friend class LegalityAnalysis
Definition Legality.h:202
static bool classof(const LegalityResult *From)
Definition Legality.h:206
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Abstract Attribute helper functions.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
LegalityResultID
Definition Legality.h:80
@ DiamondReuse
Definition Legality.h:83
@ DiamondReuseWithShuffle
Definition Legality.h:84
@ Pack
Definition Legality.h:81
@ Widen
Definition Legality.h:82
@ DiamondReuseMultiInput
Definition Legality.h:85
ResultReason
The reason for vectorizing or not vectorizing.
Definition Legality.h:89
@ DiffWrapFlags
Definition Legality.h:94
@ DiffMathFlags
Definition Legality.h:93
@ NotConsecutive
Definition Legality.h:97
@ CantSchedule
Definition Legality.h:98
@ RepeatedInstrs
Definition Legality.h:96
@ Infeasible
Definition Legality.h:100
@ ForcePackForDebugging
Definition Legality.h:101
@ DiffTypes
Definition Legality.h:92
@ NotInstructions
Definition Legality.h:90
@ DiffOpcodes
Definition Legality.h:91
@ Unimplemented
Definition Legality.h:99
@ DiffBBs
Definition Legality.h:95
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
void interleave(ForwardIterator begin, ForwardIterator end, UnaryFunctor each_fn, NullaryFunctor between_fn)
An STL-style algorithm similar to std::for_each that applies a second functor between every pair of e...
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Implement std::hash so that hash_code can be used in STL containers.
Definition Legality.h:105
static const char * getVecReason(ResultReason Reason)
Definition Legality.h:122
static const char * getLegalityResultID(LegalityResultID ID)
Definition Legality.h:106