12#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_LEGALITY_H
13#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_LEGALITY_H
26class LegalityAnalysis;
39 ShuffleMask(std::initializer_list<int> Indices) : Indices(Indices) {}
60 return Indices ==
Other.Indices;
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";
263 : V(V), ExtractIdx(ExtractIdx) {}
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>
344 std::unique_ptr<ResultT>(
new ResultT(std::move(Args)...)));
345 return cast<ResultT>(*ResultPool.
back());
352 bool SkipScheduling =
false);
static SDValue Widen(SelectionDAG *CurDAG, SDValue N)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
BlockVerifier::State From
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.
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
A private abstract base class describing the concept of an individual alias analysis implementation.
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...
void reserve(size_type N)
void push_back(const T &Elt)
This class implements an extremely fast bulk output stream that can only output to a stream.
Describes how to get a value element.
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
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
Action * getVector() const
static bool classof(const LegalityResult *From)
Action * getVector() const
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'.
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.
Base class for results with reason.
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)
virtual ~LegalityResult()
LLVM_DUMP_METHOD void dump() const
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.
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
int operator[](int Idx) const
friend raw_ostream & operator<<(raw_ostream &OS, const ShuffleMask &Mask)
ShuffleMask(ArrayRef< int > Indices)
const_iterator begin() const
A SandboxIR Value has users. This is the base class.
static bool classof(const LegalityResult *From)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ DiamondReuse
Vectorize by combining scalars to a vector.
@ DiamondReuseWithShuffle
Don't generate new code, reuse existing vector.
@ Widen
Collect scalar values.
@ DiamondReuseMultiInput
Reuse the existing vector but add a shuffle.
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...
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.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
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)