12#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_LEGALITY_H
13#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_LEGALITY_H
24class LegalityAnalysis;
37 ShuffleMask(std::initializer_list<int> Indices) : Indices(Indices) {}
45 for (
auto Idx : seq<int>(0, (
int)Sz))
59 return Indices ==
Other.Indices;
108 return "DiamondReuse";
110 return "DiamondReuseWithShuffle";
118 return "NotInstructions";
120 return "DiffOpcodes";
124 return "DiffMathFlags";
126 return "DiffWrapFlags";
128 return "NotConsecutive";
130 return "CantSchedule";
132 return "Unimplemented";
247 std::optional<int> ExtractIdx;
251 : V(V), ExtractIdx(ExtractIdx) {}
268 Value *V0 = Descr0.getValue();
269 if (!Descr0.needsExtract())
272 MaskIndices.
push_back(Descr0.getExtractIdx());
274 if (!Descr.needsExtract())
276 if (Descr.getValue() != V0)
278 MaskIndices.
push_back(Descr.getExtractIdx());
280 return std::make_pair(V0,
ShuffleMask(std::move(MaskIndices)));
283 return any_of(
Descrs, [](
const auto &
D) {
return D.needsExtract(); });
297 std::optional<ResultReason>
312 : Sched(AA, Ctx), SE(SE),
DL(
DL), IMaps(IMaps) {}
314 template <
typename ResultT,
typename... ArgsT>
316 ResultPool.
push_back(std::unique_ptr<ResultT>(
new ResultT(Args...)));
317 return cast<ResultT>(*ResultPool.
back());
324 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
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.
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(Value *V, int ExtractIdx)
ExtractElementDescr(Value *V)
bool needsExtract() const
int getExtractIdx() const
Describes how to collect the values needed by each lane.
const SmallVector< ExtractElementDescr, 4 > & getDescrs() const
std::optional< std::pair< Value *, ShuffleMask > > getSingleInput() const
If all elements come from a single vector input, then return that vector and also the shuffle mask re...
bool hasVectorInputs() const
CollectDescr(SmallVectorImpl< ExtractElementDescr > &&Descrs)
const ShuffleMask & getMask() const
static bool classof(const LegalityResult *From)
Value * getVector() const
Value * 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.
ResultT & createLegalityResult(ArgsT... Args)
A LegalityResult factory.
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)
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.
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...
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)