9#ifndef LLVM_SANDBOXIR_REGION_H
10#define LLVM_SANDBOXIR_REGION_H
76 static constexpr const char *
MDKind =
"sandboxvec";
77 static constexpr const char *
RegionStr =
"sandboxregion";
78 static constexpr const char *
AuxMDKind =
"sandboxaux";
120 template <
typename RegionT,
typename RegionFactoryT>
128 RegionT *R =
nullptr;
129 if (
auto *MDN = LLVMI->getMetadata(
MDKind)) {
130 auto [It, Inserted] = MDNToRegion.
try_emplace(MDN);
133 R = Regions.
back().get();
140 if (
auto *AuxMDN = LLVMI->getMetadata(
AuxMDKind)) {
145 errs() <<
"No region specified for Aux: '" << *LLVMI <<
"'\n";
148 R->setAux(Idx, &Inst);
154 for (
auto &RPtr : Regions)
155 for (
auto *
I : RPtr->getAux())
156 assert(
I !=
nullptr &&
"Gap in Aux!");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI_FOR_TEST
This file implements a set that has insertion order iteration characteristics.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
This is an important base class in LLVM.
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
A vector that has set insertion semantics.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
An ID for a registered callback.
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
A helper client-attorney class for unit tests.
static void add(Region &Rgn, Instruction *I)
static void remove(Region &Rgn, Instruction *I)
static constexpr const char * RegionStr
Context & getContext() const
RegionClassID getSubclassID() const
void addRaw(Instruction *I)
Adds I to the set.
bool contains(Instruction *I) const
Returns true if I is in the Region.
void removeFromAux(Instruction *I)
Remove instruction I from Aux and drop metadata.
static constexpr const char * MDKind
const SmallVector< Instruction * > & getAux() const
\Returns the auxiliary vector.
iterator_range< iterator > insts()
bool operator!=(const Region &other) const
Context::CallbackID EraseInstCB
ID (for later deregistration) of the "erase instruction" callback.
Region(const Region &)=delete
LLVM_ABI_FOR_TEST bool operator==(const Region &Other) const
This is an expensive check, meant for testing.
virtual LLVM_ABI void remove(Instruction *I)
Removes I from the set.
static SmallVector< std::unique_ptr< RegionT > > createRegionsFromMD(Function &F, RegionFactoryT Factory)
Context::CallbackID CreateInstCB
ID (for later deregistration) of the "create instruction" callback.
void dropAuxMetadata(Instruction *I)
Helper for dropping Aux metadata for I.
SetVector< Instruction * > Insts
All the instructions in the Region.
static constexpr const char * AuxMDKind
Region(Region &&)=default
friend class RegionInternalsAttorney
friend raw_ostream & operator<<(raw_ostream &OS, const Region &Rgn)
LLVM_ABI Region(Context &Ctx)
LLVM_ABI Region(Context &Ctx, RegionClassID ID)
virtual void add(Instruction *I)
Adds I to the set.
LLVM_ABI void clearAux()
Clears all auxiliary data.
decltype(Insts.begin()) iterator
virtual LLVM_ABI ~Region()
LLVM_ABI_FOR_TEST void dump(raw_ostream &OS) const
void setAux(unsigned Idx, Instruction *I)
Set I as the Idx'th element in the auxiliary vector.
bool empty() const
Returns true if the Region has no instructions.
MDNode * RegionMDN
MDNode that we'll use to mark instructions as being part of the region.
SmallVector< Instruction * > Aux
An auxiliary sequence of Instruction-Index pairs.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
RegionClassID
The main job of the Region is to point to new instructions generated by vectorization passes.
BasicBlock(llvm::BasicBlock *BB, Context &SBCtx)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.