12#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_LEGALITY_H
13#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_LEGALITY_H
39 ShuffleMask(std::initializer_list<int> Indices) : Indices(Indices) {}
53 for (
auto [Idx, Elm] :
enumerate(Indices)) {
60 return Indices ==
Other.Indices;
63 size_t size()
const {
return Indices.size(); }
74 interleave(Indices, OS, [&OS](
auto Elm) { OS << Elm; },
",");
113 return "DiamondReuse";
115 return "DiamondReuseWithShuffle";
117 return "DiamondReuseMultiInput";
125 return "NotInstructions";
127 return "DiffOpcodes";
131 return "DiffMathFlags";
133 return "DiffWrapFlags";
137 return "RepeatedInstrs";
139 return "NotConsecutive";
141 return "CantSchedule";
143 return "Unimplemented";
147 return "ForcePackForDebugging";
240class Pack final :
public LegalityResultWithReason {
263 : V(V), ExtractIdx(ExtractIdx) {}
280 const auto &Descr0 = *
Descrs.begin();
281 if (!Descr0.needsExtract())
283 auto *V0 = Descr0.getValue();
285 MaskIndices.
push_back(Descr0.getExtractIdx());
287 if (!Descr.needsExtract())
289 if (Descr.getValue() != V0)
291 MaskIndices.
push_back(Descr.getExtractIdx());
293 return std::make_pair(V0,
ShuffleMask(std::move(MaskIndices)));
296 return any_of(
Descrs, [](
const auto &
D) {
return D.needsExtract(); });
324 std::optional<ResultReason>
339 : Sched(
AA, Ctx), SE(SE), DL(DL), IMaps(IMaps) {}
341 template <
typename ResultT,
typename... ArgsT>
343 ResultPool.push_back(
344 std::unique_ptr<ResultT>(
new ResultT(std::move(Args)...)));
349 template <
typename ValueT>
360 return Unique.
size() == Values.
size();
368 bool SkipScheduling =
false);
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),...
size_t size() const
size - Get the array size.
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 bits of the poi...
The main scalar evolution driver.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
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)
Action * getValue() const
ExtractElementDescr(Value *V)
bool needsExtract() const
Value * getScalar() const
int getExtractIdx() const
Describes how to collect the values needed by each lane.
const SmallVector< ExtractElementDescr, 4 > & getDescrs() const
SmallVector< ExtractElementDescr, 4 > DescrVecT
bool hasVectorInputs() const
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...
CollectDescr(SmallVectorImpl< ExtractElementDescr > &&Descrs)
const ShuffleMask & getMask() const
friend class LegalityAnalysis
Action * getVector() const
static bool classof(const LegalityResult *From)
Action * getVector() const
friend class LegalityAnalysis
static bool classof(const LegalityResult *From)
Maps the original instructions to the vectorized instrs and the reverse.
Performs the legality analysis and returns a LegalityResult object.
const LegalityResult & getForcedPackForDebugging()
\Returns a Pack with reason 'ForcePackForDebugging'.
static bool differentBlock(ArrayRef< ValueT * > Instrs)
static bool areUnique(ArrayRef< ValueT * > Values)
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)
ResultT & createLegalityResult(ArgsT &&...Args)
A LegalityResult factory.
ResultReason getReason() const
void print(raw_ostream &OS) const override
The legality outcome is represented by a class rather than an enum class because in some cases the le...
LegalityResult & operator=(const LegalityResult &)=delete
friend raw_ostream & operator<<(raw_ostream &OS, const LegalityResult &LR)
friend class LegalityAnalysis
LLVM_DUMP_METHOD void dump() const
virtual ~LegalityResult()=default
LegalityResultID getSubclassID() const
virtual void print(raw_ostream &OS) const
LegalityResult(LegalityResultID ID)
Only Legality can create LegalityResults.
LegalityResult(const LegalityResult &)=delete
We shouldn't need copies.
friend class LegalityAnalysis
static bool classof(const LegalityResult *From)
ShuffleMask(std::initializer_list< int > Indices)
void print(raw_ostream &OS) const
bool isIdentity() const
\Returns true if the mask is a perfect identity mask with consecutive indices, i.e....
const_iterator end() const
ShuffleMask(SmallVectorImpl< int > &&Indices)
static ShuffleMask getIdentity(unsigned Sz)
Creates and returns an identity shuffle mask of size Sz.
LLVM_DUMP_METHOD void dump() const
bool operator==(const ShuffleMask &Other) const
bool operator!=(const ShuffleMask &Other) const
IndicesVecT::const_iterator const_iterator
int operator[](int Idx) const
friend raw_ostream & operator<<(raw_ostream &OS, const ShuffleMask &Mask)
ShuffleMask(ArrayRef< int > Indices)
const_iterator begin() const
SmallVector< int, 8 > IndicesVecT
A SandboxIR Value has users. This is the base class.
friend class LegalityAnalysis
static bool classof(const LegalityResult *From)
#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.
@ DiamondReuseWithShuffle
ResultReason
The reason for vectorizing or not vectorizing.
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...
constexpr from_range_t from_range
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<X> - 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<X> - 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.
static const char * getVecReason(ResultReason Reason)
static const char * getLegalityResultID(LegalityResultID ID)