58#ifndef LLVM_SANDBOXIR_SANDBOXIR_H
59#define LLVM_SANDBOXIR_SANDBOXIR_H
89#define DEF_INSTR(ID, OPC, CLASS) friend class CLASS;
90#include "llvm/SandboxIR/SandboxIRValues.def"
106 return !(*
this ==
Other);
132 return !(*
this ==
Other);
140#define DEF_VALUE(ID, CLASS) ID,
141#define DEF_USER(ID, CLASS) ID,
142#define DEF_INSTR(ID, OPC, CLASS) ID,
143#include "llvm/SandboxIR/SandboxIRValues.def"
149#define DEF_VALUE(ID, CLASS) \
152#define DEF_USER(ID, CLASS) \
155#define DEF_INSTR(ID, OPC, CLASS) \
158#include "llvm/SandboxIR/SandboxIRValues.def"
275 std::string
getUid()
const;
298 return From->getSubclassID() == ClassID::Argument;
302 assert(isa<llvm::Argument>(
Val) &&
"Expected Argument!");
334 return Use.LLVMUse->getOperandNo();
353 assert(isa<llvm::User>(
Val) &&
"Expect User value!");
357 assert(isa<llvm::User>(
Val) &&
"Expect User value!");
379 return isa<llvm::User>(
Val) ? cast<llvm::User>(
Val)->getNumOperands() : 0;
389 assert(isa<llvm::User>(
Val) &&
"Expected User!");
405 Use getOperandUseInternal(
unsigned OpIdx,
bool Verify)
const final {
412 return From->getSubclassID() == ClassID::Constant ||
413 From->getSubclassID() == ClassID::Function;
421 assert(isa<llvm::Constant>(
Val) &&
"Expected Constant!");
452 : BB(BB), It(It), Ctx(Ctx) {}
467 assert(Ctx ==
Other.Ctx &&
"BBIterators in different context!");
468 return It ==
Other.It;
481#define DEF_VALUE(ID, CLASS)
482#define DEF_USER(ID, CLASS)
484#define DEF_INSTR(ID, OPC, CLASS) OPC
485#include "llvm/SandboxIR/SandboxIRValues.def"
568 Use getOperandUseInternal(
unsigned OpIdx,
bool Verify)
const final {
572 return {cast<llvm::Instruction>(
Val)};
592 bool isSimple()
const {
return cast<llvm::LoadInst>(
Val)->isSimple(); }
595 assert(isa<llvm::LoadInst>(
Val) &&
"Expected LoadInst!");
610 Use getOperandUseInternal(
unsigned OpIdx,
bool Verify)
const final {
614 return {cast<llvm::Instruction>(
Val)};
619 return From->getSubclassID() == ClassID::Opaque;
649 buildBasicBlockFromLLVMIR(BB);
656 return From->getSubclassID() == Value::ClassID::Block;
662 auto *BB = cast<llvm::BasicBlock>(
Val);
665 std::reverse_iterator<iterator>
rbegin()
const {
666 return std::make_reverse_iterator(
end());
668 std::reverse_iterator<iterator>
rend()
const {
669 return std::make_reverse_iterator(
begin());
679 assert(isa<llvm::BasicBlock>(
Val) &&
"Expected BasicBlock!");
715 auto It = Pair.first;
717 It->second = std::unique_ptr<Argument>(
new Argument(LLVMArg, *
this));
718 return cast<Argument>(It->second.get());
720 return cast<Argument>(It->second.get());
768 LLVMBBToBB(
Context &Ctx) : Ctx(Ctx) {}
770 return *cast<BasicBlock>(Ctx.
getValue(&LLVMBB));
781 return From->getSubclassID() == ClassID::Function;
789 size_t arg_size()
const {
return cast<llvm::Function>(
Val)->arg_size(); }
790 bool arg_empty()
const {
return cast<llvm::Function>(
Val)->arg_empty(); }
794 LLVMBBToBB BBGetter(
Ctx);
798 LLVMBBToBB BBGetter(
Ctx);
804 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...
ConstantFolder - Create constants with minimum, target independent, folding.
This is an important base class in LLVM.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
This is an important class for using LLVM in a threaded context.
An instruction for reading from memory.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
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.
StringRef getName() const
Return a constant reference to the value's name.
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)
Iterator for Instructions in a `BasicBlock.
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
Contains a list of sandboxir::Instruction's.
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
IRBuilder< ConstantFolder > LLVMIRBuilder
Argument * getOrCreateArgument(llvm::Argument *LLVMArg)
Get or create a sandboxir::Argument for an existing LLVM IR LLVMArg.
Function * createFunction(llvm::Function *F)
Create a sandboxir::Function for an existing LLVM IR F, including all blocks and instructions.
Value * getOrCreateValueInternal(llvm::Value *V, llvm::User *U=nullptr)
This is the actual function that creates sandboxir values for V, and among others handles all instruc...
auto & getLLVMIRBuilder()
std::unique_ptr< Value > detach(Value *V)
Remove SBV from all SandboxIR maps and stop owning it.
const sandboxir::Value * getValue(const llvm::Value *V) const
void accept()
Convenience function for getTracker().accept()
BasicBlock * createBasicBlock(llvm::BasicBlock *BB)
Create a sandboxir::BasicBlock for an existing LLVM IR BB.
LoadInst * createLoadInst(llvm::LoadInst *LI)
Context(LLVMContext &LLVMCtx)
void revert()
Convenience function for getTracker().revert()
std::unique_ptr< Value > detachLLVMValue(llvm::Value *V)
Remove V from the maps and returns the unique_ptr.
void save()
Convenience function for getTracker().save()
Value * getOrCreateValue(llvm::Value *LLVMV)
Get or create a sandboxir::Value for an existing LLVM IR 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, opcode and linked with previous/next instructions in an instruction ...
BBIterator getIterator() const
\Returns a BasicBlock::iterator for this Instruction.
void removeFromParent()
Detach this from its parent BasicBlock without deleting it.
virtual unsigned getNumOfIRInstrs() const =0
This is used by BasicBlock::iterator.
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
void moveAfter(Instruction *After)
Move this instruction after After.
void insertInto(BasicBlock *BB, const BBIterator &WhereIt)
Insert this detached instruction into BB at WhereIt.
Opcode getOpcode() const
\Returns this Instruction's opcode.
static const char * getOpcodeName(Opcode Opc)
void dump(raw_ostream &OS) const override
void eraseFromParent()
Detach this Value from its parent and delete it.
Instruction * getNextNode() const
\Returns the next sandboxir::Instruction in the block, or nullptr if at the end of the block.
void moveBefore(BasicBlock &BB, const BBIterator &WhereIt)
Move this instruction to WhereIt.
friend raw_ostream & operator<<(raw_ostream &OS, Opcode Opc)
llvm::Instruction * getTopmostLLVMInstruction() const
A SandboxIR Instruction may map to multiple LLVM IR Instruction.
LLVM_DUMP_METHOD void dump() const override
void insertAfter(Instruction *AfterI)
Insert this detached instruction after AfterI.
virtual SmallVector< llvm::Instruction *, 1 > getLLVMInstrs() const =0
\Returns the LLVM IR Instructions that this SandboxIR maps to in program order.
void moveBefore(Instruction *Before)
Move this instruction before Before.
Instruction * getPrevNode() const
\Returns the previous sandboxir::Instruction in the block, or nullptr if at the beginning of the bloc...
Instruction(ClassID ID, Opcode Opc, llvm::Instruction *I, sandboxir::Context &SBCtx)
friend raw_ostream & operator<<(raw_ostream &OS, const sandboxir::Instruction &SBI)
void insertBefore(Instruction *BeforeI)
Insert this detached instruction before BeforeI.
BasicBlock * getParent() const
\Returns the BasicBlock containing this Instruction, or null if it is detached.
static bool classof(const 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
unsigned getNumOfIRInstrs() const final
This is used by BasicBlock::iterator.
static LoadInst * create(Type *Ty, Value *Ptr, MaybeAlign Align, Instruction *InsertBefore, Context &Ctx, const Twine &Name="")
Value * getPointerOperand() const
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)
Iterator for the Use edges of a User's operands.
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++()
The tracker collects all the change objects and implements the main API for saving / reverting / acce...
void revert()
Stops tracking and reverts to saved state.
void save()
Turns on IR tracking.
void accept()
Stops tracking and accept changes.
Represents a Def-use/Use-def edge in SandboxIR.
unsigned getOperandNo() const
class User * getUser() const
Iterator for the Use edges of a Value's users.
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
A sandboxir::User has operands.
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
\Returns the Use for the OpIdx'th operand.
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
std::string getUid() const
Returns the unique id in the form 'SB<number>.' like 'SB1.'.
const_use_iterator use_end() const
user_iterator user_begin()
void replaceAllUsesWith(Value *Other)
ClassID getSubclassID() const
StringRef getName() const
\Returns the LLVM IR name of the bottom-most LLVM value.
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.
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.
This struct is a compact representation of a valid (non-zero power of two) alignment.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Helper for mapped_iterator.
User * operator()(const Use &Use) const