58#ifndef LLVM_TRANSFORMS_SANDBOXIR_SANDBOXIR_H
59#define LLVM_TRANSFORMS_SANDBOXIR_SANDBOXIR_H
88 : LLVMUse(LLVMUse), Usr(Usr), Ctx(&Ctx) {}
89 Use() : LLVMUse(
nullptr), Ctx(
nullptr) {}
104 return LLVMUse ==
Other.LLVMUse && Usr ==
Other.Usr;
119#define DEF_INSTR(ID, OPC, CLASS) friend class CLASS;
120#include "llvm/SandboxIR/SandboxIRValues.def"
136 return !(*
this ==
Other);
161 return !(*
this ==
Other);
169#define DEF_VALUE(ID, CLASS) ID,
170#define DEF_USER(ID, CLASS) ID,
171#define DEF_INSTR(ID, OPC, CLASS) ID,
172#include "llvm/SandboxIR/SandboxIRValues.def"
178#define DEF_VALUE(ID, CLASS) \
181#define DEF_USER(ID, CLASS) \
184#define DEF_INSTR(ID, OPC, CLASS) \
187#include "llvm/SandboxIR/SandboxIRValues.def"
320 return From->getSubclassID() == ClassID::Argument;
324 assert(isa<llvm::Argument>(
Val) &&
"Expected Argument!");
352 return Use.LLVMUse->getOperandNo();
371 assert(isa<llvm::User>(
Val) &&
"Expect User value!");
375 assert(isa<llvm::User>(
Val) &&
"Expect User value!");
397 return isa<llvm::User>(
Val) ? cast<llvm::User>(
Val)->getNumOperands() : 0;
407 assert(isa<llvm::User>(
Val) &&
"Expected User!");
423 Use getOperandUseInternal(
unsigned OpIdx,
bool Verify)
const final {
430 return From->getSubclassID() == ClassID::Constant ||
431 From->getSubclassID() == ClassID::Function;
439 assert(isa<llvm::Constant>(
Val) &&
"Expected Constant!");
469 : BB(BB), It(It), Ctx(Ctx) {}
484 assert(Ctx ==
Other.Ctx &&
"BBIterators in different context!");
485 return It ==
Other.It;
497#define DEF_VALUE(ID, CLASS)
498#define DEF_USER(ID, CLASS)
500#define DEF_INSTR(ID, OPC, CLASS) OPC
501#include "llvm/SandboxIR/SandboxIRValues.def"
543 Use getOperandUseInternal(
unsigned OpIdx,
bool Verify)
const final {
549 return From->getSubclassID() == ClassID::Opaque;
577 buildBasicBlockFromLLVMIR(BB);
584 return From->getSubclassID() == Value::ClassID::Block;
590 auto *BB = cast<llvm::BasicBlock>(
Val);
593 std::reverse_iterator<iterator>
rbegin()
const {
594 return std::make_reverse_iterator(
end());
596 std::reverse_iterator<iterator>
rend()
const {
597 return std::make_reverse_iterator(
begin());
607 assert(isa<llvm::BasicBlock>(
Val) &&
"Expected BasicBlock!");
633 auto It = Pair.first;
635 It->second = std::unique_ptr<Argument>(
new Argument(LLVMArg, *
this));
636 return cast<Argument>(It->second.get());
638 return cast<Argument>(It->second.get());
667 LLVMBBToBB(
Context &Ctx) : Ctx(Ctx) {}
669 return *cast<BasicBlock>(Ctx.
getValue(&LLVMBB));
680 return From->getSubclassID() == ClassID::Function;
688 size_t arg_size()
const {
return cast<llvm::Function>(
Val)->arg_size(); }
689 bool arg_empty()
const {
return cast<llvm::Function>(
Val)->arg_empty(); }
693 LLVMBBToBB BBGetter(
Ctx);
697 LLVMBBToBB BBGetter(
Ctx);
703 assert(isa<llvm::Function>(
Val) &&
"Expected Function!");
BlockVerifier::State From
#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
ppc ctr loops PowerPC CTR Loops Verify
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class represents an incoming formal argument to a Function.
LLVM Basic Block Representation.
InstListType::iterator iterator
Instruction iterators...
This is an important base class in LLVM.
This is an important class for using LLVM in a threaded context.
The instances of the Type class are immutable: once they are created, they are never changed.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
An efficient, type-erasing, non-owning reference to a callable.
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Argument of a sandboxir::Function.
friend raw_ostream & operator<<(raw_ostream &OS, const sandboxir::Argument &TArg)
void dump(raw_ostream &OS) const final
void printAsOperand(raw_ostream &OS) const
LLVM_DUMP_METHOD void dump() const final
void verify() const final
Should crash if there is something wrong with the instruction.
static bool classof(const sandboxir::Value *From)
The BasicBlock::iterator.
BBIterator & operator++()
BBIterator operator++(int)
bool operator!=(const BBIterator &Other) const
BBIterator operator--(int)
pointer get() const
\Returns the SBInstruction that corresponds to this iterator, or null if the instruction is not found...
reference operator*() const
BBIterator & operator--()
std::bidirectional_iterator_tag iterator_category
std::ptrdiff_t difference_type
BBIterator(llvm::BasicBlock *BB, llvm::BasicBlock::iterator It, Context *Ctx)
bool operator==(const BBIterator &Other) const
std::reverse_iterator< iterator > rbegin() const
static bool classof(const Value *From)
For isa/dyn_cast.
void verify() const final
Should crash if there is something wrong with the instruction.
std::reverse_iterator< iterator > rend() const
Function * getParent() const
void dump(raw_ostream &OS) const final
Instruction & front() const
Instruction * getTerminator() const
Context & getContext() const
Instruction & back() const
friend raw_ostream & operator<<(raw_ostream &OS, const BasicBlock &SBBB)
LLVM_DUMP_METHOD void dump() const final
sandboxir::Context & getParent() const
friend raw_ostream & operator<<(raw_ostream &OS, const sandboxir::Constant &SBC)
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
void verify() const final
Should crash if there is something wrong with the instruction.
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
LLVM_DUMP_METHOD void dump() const override
DenseMap< llvm::Value *, std::unique_ptr< sandboxir::Value > > LLVMValueToValueMap
Maps LLVM Value to the corresponding sandboxir::Value.
Value * registerValue(std::unique_ptr< Value > &&VPtr)
Take ownership of VPtr and store it in LLVMValueToValueMap.
sandboxir::Value * getValue(llvm::Value *V) const
Argument * getOrCreateArgument(llvm::Argument *LLVMArg)
Function * createFunction(llvm::Function *F)
Value * getOrCreateValueInternal(llvm::Value *V, llvm::User *U=nullptr)
const sandboxir::Value * getValue(const llvm::Value *V) const
BasicBlock * createBasicBlock(llvm::BasicBlock *BB)
Context(LLVMContext &LLVMCtx)
Value * getOrCreateValue(llvm::Value *LLVMV)
size_t getNumValues() const
\Returns the number of values registered with Context.
Argument * getArg(unsigned Idx) const
void dumpNameAndArgs(raw_ostream &OS) const
LLVM_DUMP_METHOD void dump() const final
void verify() const final
Should crash if there is something wrong with the instruction.
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
mapped_iterator< llvm::Function::iterator, LLVMBBToBB > iterator
A sandboxir::User with operands and opcode.
virtual unsigned getNumOfIRInstrs() const =0
This is used by BasicBlock::iterator.
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
static const char * getOpcodeName(Opcode Opc)
void dump(raw_ostream &OS) const override
friend raw_ostream & operator<<(raw_ostream &OS, Opcode Opc)
LLVM_DUMP_METHOD void dump() const override
Instruction(ClassID ID, Opcode Opc, llvm::Instruction *I, sandboxir::Context &SBCtx)
friend raw_ostream & operator<<(raw_ostream &OS, const sandboxir::Instruction &SBI)
An LLLVM Instruction that has no SandboxIR equivalent class gets mapped to an OpaqueInstr.
void dump(raw_ostream &OS) const override
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
unsigned getNumOfIRInstrs() const final
This is used by BasicBlock::iterator.
void verify() const final
Should crash if there is something wrong with the instruction.
friend raw_ostream & operator<<(raw_ostream &OS, const sandboxir::OpaqueInst &OI)
LLVM_DUMP_METHOD void dump() const override
static bool classof(const sandboxir::Value *From)
Returns the operand edge when dereferenced.
OperandUseIterator()=default
std::ptrdiff_t difference_type
value_type operator*() const
std::input_iterator_tag iterator_category
bool operator!=(const OperandUseIterator &Other) const
bool operator==(const OperandUseIterator &Other) const
OperandUseIterator & operator++()
Represents a Def-use/Use-def edge in SandboxIR.
unsigned getOperandNo() const
bool operator==(const Use &Other) const
bool operator!=(const Use &Other) const
Context * getContext() const
class User * getUser() const
Returns user edge when dereferenced.
std::input_iterator_tag iterator_category
std::ptrdiff_t difference_type
bool operator!=(const UserUseIterator &Other) const
UserUseIterator & operator++()
value_type operator*() const
bool operator==(const UserUseIterator &Other) const
UserUseIterator()=default
virtual op_iterator op_begin()
friend class OperandUseIterator
Value * getOperand(unsigned OpIdx) const
virtual unsigned getUseOperandNo(const Use &Use) const =0
\Returns the operand index of Use.
unsigned getUseOperandNoDefault(const Use &Use) const
The default implementation works only for single-LLVMIR-instruction Users and only if they match exac...
virtual const_op_iterator op_end() const
static bool classof(const Value *From)
For isa/dyn_cast.
void dump(raw_ostream &OS) const override
bool replaceUsesOfWith(Value *FromV, Value *ToV)
Replaces any operands that match FromV with ToV.
void verifyUserOfLLVMUse(const llvm::Use &Use) const
void verify() const override
Should crash if there is something wrong with the instruction.
Use getOperandUseDefault(unsigned OpIdx, bool Verify) const
\Returns the Use edge that corresponds to OpIdx.
LLVM_DUMP_METHOD void dump() const override
OperandUseIterator op_iterator
const_op_range operands() const
virtual void setOperand(unsigned OperandIdx, Value *Operand)
virtual Use getOperandUseInternal(unsigned OpIdx, bool Verify) const =0
virtual unsigned getNumOperands() const
virtual const_op_iterator op_begin() const
Use getOperandUse(unsigned OpIdx) const
\Returns the operand edge for OpIdx.
virtual op_iterator op_end()
User(ClassID ID, llvm::Value *V, Context &Ctx)
void dumpCommonHeader(raw_ostream &OS) const final
A SandboxIR Value has users. This is the base class.
mapped_iterator< sandboxir::UserUseIterator, UseToUser > user_iterator
llvm::Value * Val
The LLVM Value that corresponds to this SandboxIR Value.
virtual void dump(raw_ostream &OS) const =0
const_use_iterator use_end() const
user_iterator user_begin()
void replaceAllUsesWith(Value *Other)
ClassID getSubclassID() const
virtual void verify() const =0
Should crash if there is something wrong with the instruction.
void dumpCommonFooter(raw_ostream &OS) const
virtual void dumpCommonHeader(raw_ostream &OS) const
UserUseIterator use_iterator
Context & Ctx
All values point to the context.
ClassID SubclassID
For isa/dyn_cast.
void dumpCommonSuffix(raw_ostream &OS) const
friend class LLVMOpUserItToSBTy
const_use_iterator use_begin() const
Context & getContext() const
const_user_iterator user_begin() const
bool hasNUsesOrMore(unsigned Num) const
Return true if this value has N uses or more.
std::string getName() const
Returns the name in the form 'SB<number>.' like 'SB1.'.
iterator_range< const_user_iterator > users() const
iterator_range< user_iterator > users()
virtual LLVM_DUMP_METHOD void dump() const =0
void replaceUsesWithIf(Value *OtherV, llvm::function_ref< bool(const Use &)> ShouldReplace)
unsigned getNumUses() const
\Returns the number of user edges (not necessarily to unique users).
bool hasNUses(unsigned Num) const
Return true if this Value has exactly N uses.
unsigned UID
A unique ID used for forming the name (used for debugging).
iterator_range< use_iterator > uses()
const_user_iterator user_end() const
void dumpCommonPrefix(raw_ostream &OS) const
void printAsOperandCommon(raw_ostream &OS) const
static const char * getSubclassIDStr(ClassID ID)
friend raw_ostream & operator<<(raw_ostream &OS, const sandboxir::Value &V)
iterator_range< const_use_iterator > uses() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
Helper for mapped_iterator.
User * operator()(const Use &Use) const