24 if (LLVMUse ==
nullptr)
25 OS <<
"<null> LLVM Use! ";
56 assert(
Use.LLVMUse !=
nullptr &&
"Already at end!");
64 assert(LLVMUse !=
nullptr &&
"Already at end!");
65 LLVMUse = LLVMUse->getNext();
66 if (LLVMUse ==
nullptr) {
71 auto *LLVMUser = LLVMUse->getUser();
72 Use.Usr = cast_or_null<sandboxir::User>(Ctx->getValue(LLVMUser));
77 : SubclassID(SubclassID), Val(Val), Ctx(Ctx) {
96 bool AtEnd = UseBegin == UseEnd;
97 llvm::Use *LLVMUse = AtEnd ? nullptr : &*UseBegin;
100 : cast_or_null<sandboxir::User>(
Ctx.
getValue(&*LLVMUse->getUser()));
111 OtherVal, [&ShouldReplace,
this](
llvm::Use &LLVMUse) ->
bool {
115 return ShouldReplace(
Use(&LLVMUse, DstU,
Ctx));
121 "Replacing with Value of different type!");
127 std::stringstream SS;
128 SS <<
"SB" <<
UID <<
".";
137 OS.indent(2) <<
"Val: ";
178 assert(isa<llvm::User>(
Val) &&
"Non-users have no operands!");
181 LLVMUse = &cast<llvm::User>(
Val)->getOperandUse(OpIdx);
183 LLVMUse = cast<llvm::User>(
Val)->op_end();
184 return Use(LLVMUse,
const_cast<User *
>(
this),
Ctx);
190 "Use not found in this SBUser's operands!");
195 switch (
From->getSubclassID()) {
196#define DEF_VALUE(ID, CLASS)
197#define DEF_USER(ID, CLASS) \
200#define DEF_INSTR(ID, OPC, CLASS) \
203#include "llvm/SandboxIR/SandboxIRValues.def"
210 assert(isa<llvm::User>(
Val) &&
"No operands!");
211 cast<llvm::User>(
Val)->setOperand(OperandIdx, Operand->
Val);
215 return cast<llvm::User>(
Val)->replaceUsesOfWith(FromV->
Val, ToV->
Val);
226 auto ItE = BB->
end();
227 assert(It != ItE &&
"Already at end!");
233 assert(Num > 0 &&
"Bad getNumOfIRInstrs()");
234 It = std::next(It, Num - 1);
240 if (It == BB->
end()) {
246 assert(Num > 0 &&
"Bad getNumOfIRInstrs()");
247 assert(std::prev(It, Num - 1) != BB->
begin() &&
"Already at begin!");
248 It = std::prev(It, Num);
254#define DEF_VALUE(ID, CLASS)
255#define DEF_USER(ID, CLASS)
259#define DEF_INSTR(ID, OPC, CLASS) OPC
260#include "llvm/SandboxIR/SandboxIRValues.def"
266 switch (
From->getSubclassID()) {
267#define DEF_INSTR(ID, OPC, CLASS) \
270#include "llvm/SandboxIR/SandboxIRValues.def"
278 OS <<
"Unimplemented! Please override dump().";
306 auto *
F = cast<llvm::Function>(
Val);
307 OS << *
F->getReturnType() <<
" @" <<
F->getName() <<
"(";
311 auto *SBArg = cast_or_null<Argument>(Ctx.getValue(&LLVMArg));
312 if (SBArg == nullptr)
315 SBArg->printAsOperand(OS);
317 [&] { OS <<
", "; });
323 auto *LLVMF = cast<llvm::Function>(
Val);
327 auto *BB = cast_or_null<BasicBlock>(
Ctx.
getValue(&LLVMBB));
333 [&
OS] {
OS <<
"\n"; });
344 return cast_or_null<Instruction>(Ctx->
getValue(&*It));
348 assert(VPtr->getSubclassID() != Value::ClassID::User &&
349 "Can't register a user!");
350 Value *V = VPtr.get();
358 auto It = Pair.first;
360 return It->second.get();
362 if (
auto *
C = dyn_cast<llvm::Constant>(LLVMV)) {
363 It->second = std::unique_ptr<Constant>(
new Constant(
C, *
this));
364 auto *NewC = It->second.get();
369 if (
auto *Arg = dyn_cast<llvm::Argument>(LLVMV)) {
370 It->second = std::unique_ptr<Argument>(
new Argument(Arg, *
this));
371 return It->second.get();
373 if (
auto *BB = dyn_cast<llvm::BasicBlock>(LLVMV)) {
374 assert(isa<BlockAddress>(U) &&
375 "This won't create a SBBB, don't call this function directly!");
380 assert(isa<llvm::Instruction>(LLVMV) &&
"Expected Instruction");
381 It->second = std::unique_ptr<OpaqueInst>(
382 new OpaqueInst(cast<llvm::Instruction>(LLVMV), *
this));
383 return It->second.get();
388 auto NewBBPtr = std::unique_ptr<BasicBlock>(
new BasicBlock(LLVMBB, *
this));
389 auto *BB = cast<BasicBlock>(
registerValue(std::move(NewBBPtr)));
391 BB->buildBasicBlockFromLLVMIR(LLVMBB);
398 return It->second.get();
404 auto NewFPtr = std::unique_ptr<Function>(
new Function(
F, *
this));
406 for (
auto &Arg :
F->args())
411 auto *SBF = cast<Function>(
registerValue(std::move(NewFPtr)));
416 auto *BB = cast<llvm::BasicBlock>(
Val);
417 auto *
F = BB->getParent();
430 if (isa<llvm::BasicBlock>(
Op))
433 if (isa<llvm::MetadataAsValue>(
Op))
436 if (isa<llvm::InlineAsm>(
Op))
441#if !defined(NDEBUG) && defined(SBVEC_EXPENSIVE_CHECKS)
451 assert(V !=
nullptr &&
"No SandboxIR for BB->begin()!");
452 auto *
I = cast<Instruction>(V);
453 unsigned Num =
I->getNumOfIRInstrs();
454 assert(Num >= 1u &&
"Bad getNumOfIRInstrs()");
455 It = std::next(It, Num - 1);
463 return cast_or_null<Instruction>(TerminatorV);
467 auto *BB = cast<llvm::BasicBlock>(
Val);
468 assert(!BB->empty() &&
"Empty block!");
469 auto *SBI = cast<Instruction>(
getContext().getValue(&*BB->begin()));
470 assert(SBI !=
nullptr &&
"Expected Instr!");
475 auto *BB = cast<llvm::BasicBlock>(
Val);
476 assert(!BB->empty() &&
"Empty block!");
477 auto *SBI = cast<Instruction>(
getContext().getValue(&*BB->rbegin()));
478 assert(SBI !=
nullptr &&
"Expected Instr!");
494 OS <<
"<Crash-proof mode!>\n";
499 OS << IRef <<
" *** No SandboxIR ***\n";
501 auto *SBI = dyn_cast<Instruction>(SBV);
502 if (SBI ==
nullptr) {
503 OS << IRef <<
" *** Not a SBInstruction!!! ***\n";
505 if (Visited.
insert(SBI).second)
511 for (
auto &SBI : *
this) {
BlockVerifier::State From
This file contains the declarations for the subclasses of Constant, which represent the different fla...
ppc ctr loops PowerPC CTR Loops Verify
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallPtrSet class.
This class represents an incoming formal argument to a Function.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
InstListType::iterator iterator
Instruction iterators...
This class represents an Operation in the Expression.
Implements a dense probed hash-table based set.
const char * getOpcodeName() const
A Use represents the edge between a Value definition and its users.
User * getUser() const
Returns the User that contains this Use.
LLVM Value Representation.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
iterator_range< user_iterator > users()
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
void replaceUsesWithIf(Value *New, llvm::function_ref< bool(Use &U)> ShouldReplace)
Go through the uses list for this definition and make each use point to "V" if the callback ShouldRep...
StringRef getName() const
Return a constant reference to the value's name.
std::pair< iterator, bool > insert(const ValueT &V)
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
Argument of a sandboxir::Function.
void printAsOperand(raw_ostream &OS) const
LLVM_DUMP_METHOD void dump() const final
The BasicBlock::iterator.
BBIterator & operator++()
BBIterator & operator--()
void verify() const final
Should crash if there is something wrong with the instruction.
Function * getParent() const
Instruction & front() const
Instruction * getTerminator() const
Context & getContext() const
Instruction & back() const
LLVM_DUMP_METHOD void dump() const final
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)
BasicBlock * createBasicBlock(llvm::BasicBlock *BB)
Value * getOrCreateValue(llvm::Value *LLVMV)
friend class BasicBlock
Various leaf nodes.
size_t getNumValues() const
\Returns the number of values registered with Context.
void dumpNameAndArgs(raw_ostream &OS) const
LLVM_DUMP_METHOD void dump() const final
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.
LLVM_DUMP_METHOD void dump() const override
An LLLVM Instruction that has no SandboxIR equivalent class gets mapped to an OpaqueInstr.
LLVM_DUMP_METHOD void dump() const override
Returns the operand edge when dereferenced.
value_type operator*() const
OperandUseIterator & operator++()
Represents a Def-use/Use-def edge in SandboxIR.
unsigned getOperandNo() const
class User * getUser() const
Returns user edge when dereferenced.
UserUseIterator & operator++()
virtual unsigned getUseOperandNo(const Use &Use) const =0
\Returns the operand index of Use.
static bool classof(const Value *From)
For isa/dyn_cast.
bool replaceUsesOfWith(Value *FromV, Value *ToV)
Replaces any operands that match FromV with ToV.
void verifyUserOfLLVMUse(const llvm::Use &Use) const
Use getOperandUseDefault(unsigned OpIdx, bool Verify) const
\Returns the Use edge that corresponds to OpIdx.
virtual void setOperand(unsigned OperandIdx, Value *Operand)
virtual Use getOperandUseInternal(unsigned OpIdx, bool Verify) const =0
virtual unsigned getNumOperands() const
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.
user_iterator user_begin()
void replaceAllUsesWith(Value *Other)
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
Value(ClassID SubclassID, llvm::Value *Val, Context &Ctx)
std::string getName() const
Returns the name in the form 'SB<number>.' like 'SB1.'.
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).
unsigned UID
A unique ID used for forming the name (used for debugging).
void dumpCommonPrefix(raw_ostream &OS) const
void printAsOperandCommon(raw_ostream &OS) const
static const char * getSubclassIDStr(ClassID ID)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are are tuples (A,...
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.
auto reverse(ContainerTy &&C)
constexpr size_t range_size(R &&Range)
Returns the size of the Range, i.e., the number of elements.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Helper for mapped_iterator.