19#define OPCODES(...) __VA_ARGS__
20#define DEF_INSTR(ID, OPC, CLASS) OPC
21#include "llvm/SandboxIR/Values.def"
28 if (Prev ==
nullptr) {
30 return &*cast<llvm::BasicBlock>(
getParent()->
Val)->begin();
39 auto *
I = cast<llvm::Instruction>(
Val);
49 auto *LLVMI = cast<llvm::Instruction>(
Val);
50 assert(LLVMI->getParent() !=
nullptr &&
"LLVM IR instr is detached!");
51 auto *NextLLVMI = LLVMI->getNextNode();
52 auto *NextI = cast_or_null<Instruction>(
Ctx.
getValue(NextLLVMI));
71 I->removeFromParent();
75 assert(
users().empty() &&
"Still connected to users, can't erase!");
78 std::unique_ptr<Value> Detached =
Ctx.
detach(
this);
82 if (Tracker.isTracking()) {
83 Tracker.
track(std::make_unique<EraseFromParent>(std::move(Detached)));
88 I->removeFromParent();
92 I->dropAllReferences();
108 auto *LLVMBB = cast<llvm::BasicBlock>(BB.
Val);
110 if (WhereIt == BB.
end()) {
114 It = WhereI->getTopmostLLVMInstruction()->
getIterator();
118 [](
auto *I1,
auto *I2) {
return I1->comesBefore(I2); }) &&
119 "Expected program order!");
122 I->moveBefore(*LLVMBB, It);
132 I->insertBefore(BeforeTopI);
144 if (WhereIt != BB->
end()) {
150 LLVMBeforeI =
nullptr;
151 LLVMBeforeIt = LLVMBB->
end();
158 I->insertInto(LLVMBB, LLVMBeforeIt);
171 switch (
From->getSubclassID()) {
172#define DEF_INSTR(ID, OPC, CLASS) \
175#include "llvm/SandboxIR/Values.def"
186 cast<llvm::Instruction>(
Val)->setHasNoUnsignedWrap(
B);
193 cast<llvm::Instruction>(
Val)->setHasNoSignedWrap(
B);
199 GenericSetter<&Instruction::isFast, &Instruction::setFast>>(
this);
200 cast<llvm::Instruction>(
Val)->setFast(
B);
207 cast<llvm::Instruction>(
Val)->setIsExact(
B);
214 cast<llvm::Instruction>(
Val)->setHasAllowReassoc(
B);
222 cast<llvm::Instruction>(
Val)->setHasNoNaNs(
B);
230 cast<llvm::Instruction>(
Val)->setHasNoInfs(
B);
238 cast<llvm::Instruction>(
Val)->setHasNoSignedZeros(
B);
246 cast<llvm::Instruction>(
Val)->setHasAllowReciprocal(
B);
254 cast<llvm::Instruction>(
Val)->setHasAllowContract(
B);
261 cast<llvm::Instruction>(
Val)->setFastMathFlags(FMF);
268 cast<llvm::Instruction>(
Val)->copyFastMathFlags(FMF);
279 cast<llvm::Instruction>(
Val)->setHasApproxFunc(
B);
284 OS <<
"Unimplemented! Please override dump().";
292 cast<llvm::VAArgInst>(Builder.CreateVAArg(
List->Val, Ty->
LLVMTy,
Name));
303 auto *LLVMI = cast<llvm::FreezeInst>(Builder.CreateFreeze(V->Val,
Name));
317 GenericSetter<&FenceInst::getOrdering, &FenceInst::setOrdering>>(
319 cast<llvm::FenceInst>(
Val)->setOrdering(Ordering);
326 cast<llvm::FenceInst>(
Val)->setSyncScopeID(SSID);
334 if (
auto *NewSI = dyn_cast<llvm::SelectInst>(NewV))
336 assert(isa<llvm::Constant>(NewV) &&
"Expected constant");
343 cast<llvm::SelectInst>(
Val)->swapValues();
347 return From->getSubclassID() == ClassID::Select;
354 Builder.CreateBr(cast<llvm::BasicBlock>(IfTrue->
Val));
362 Builder.CreateCondBr(
Cond->Val, cast<llvm::BasicBlock>(IfTrue->
Val),
363 cast<llvm::BasicBlock>(IfFalse->
Val));
368 return From->getSubclassID() == ClassID::Br;
378 "Successor # out of range for Branch!");
379 return cast_or_null<BasicBlock>(
380 Ctx.
getValue(cast<llvm::BranchInst>(
Val)->getSuccessor(SuccIdx)));
392BranchInst::ConstLLVMBBToSBBB::operator()(
const llvm::BasicBlock *BB)
const {
393 return cast<BasicBlock>(Ctx.
getValue(BB));
399 GenericSetter<&LoadInst::isVolatile, &LoadInst::setVolatile>>(
this);
400 cast<llvm::LoadInst>(
Val)->setVolatile(V);
414 return From->getSubclassID() == ClassID::Load;
425 cast<llvm::StoreInst>(
Val)->setVolatile(V);
432 auto *NewSI = Builder.CreateAlignedStore(V->Val,
Ptr->Val,
Align, IsVolatile);
438 return From->getSubclassID() == ClassID::Store;
456 return From->getSubclassID() == ClassID::Unreachable;
462 if (RetVal !=
nullptr)
472 return createCommon(RetVal, Builder,
Ctx);
476 auto *LLVMRetVal = cast<llvm::ReturnInst>(
Val)->getReturnValue();
477 return LLVMRetVal !=
nullptr ?
Ctx.
getValue(LLVMRetVal) :
nullptr;
481 return cast<FunctionType>(
490 llvm::Use *LLVMUse = &cast<llvm::CallBase>(
Val)->getCalledOperandUse();
495 return cast_or_null<Function>(
499 return cast<Function>(
Ctx.
getValue(cast<llvm::CallBase>(
Val)->getCaller()));
510 cast<llvm::CallBase>(
Val)->setCalledFunction(
511 cast<llvm::FunctionType>(
F->getFunctionType()->LLVMTy),
512 cast<llvm::Function>(
F->Val));
521 for (
Value *Arg : Args)
524 cast<llvm::FunctionType>(FTy->
LLVMTy), Func->Val, LLVMArgs, NameStr);
535 for (
Value *Arg : Args)
538 cast<llvm::FunctionType>(FTy->
LLVMTy), Func->Val,
539 cast<llvm::BasicBlock>(IfNormal->
Val),
540 cast<llvm::BasicBlock>(IfException->
Val), LLVMArgs, NameStr);
545 return cast<BasicBlock>(
549 return cast<BasicBlock>(
561 return cast<LandingPadInst>(
566 return cast<BasicBlock>(
574 Context &Ctx,
const Twine &NameStr) {
579 LLVMIndirectDests.
push_back(cast<llvm::BasicBlock>(IndDest->Val));
583 for (
Value *Arg : Args)
588 cast<llvm::BasicBlock>(DefaultDest->
Val),
589 LLVMIndirectDests, LLVMArgs, NameStr);
601 return cast<BasicBlock>(
605 return cast<BasicBlock>(
619 cast<llvm::CallBrInst>(
Val)->setDefaultDest(cast<llvm::BasicBlock>(BB->
Val));
626 cast<llvm::CallBrInst>(
Val)->setIndirectDest(
Idx,
627 cast<llvm::BasicBlock>(BB->
Val));
630 return cast<BasicBlock>(
647 cast<llvm::LandingPadInst>(
Val)->setCleanup(V);
651 return cast<Constant>(
663 cast<llvm::FuncletPadInst>(
Val)->setParentPad(ParentPad->
Val);
675 cast<llvm::FuncletPadInst>(
Val)->setArgOperand(
Idx, V->Val);
679 return cast<CatchSwitchInst>(
689 for (
auto *Arg : Args)
702 for (
auto *Arg : Args)
713 cast<llvm::CatchPadInst>(CatchPad->
Val), cast<llvm::BasicBlock>(BB->
Val));
718 return cast<CatchPadInst>(
726 cast<llvm::CatchReturnInst>(
Val)->setCatchPad(
727 cast<llvm::CatchPadInst>(CatchPad->
Val));
731 return cast<BasicBlock>(
739 cast<llvm::CatchReturnInst>(
Val)->setSuccessor(
740 cast<llvm::BasicBlock>(NewSucc->Val));
753 UnwindBB !=
nullptr ? cast<llvm::BasicBlock>(UnwindBB->
Val) :
nullptr;
755 cast<llvm::CleanupPadInst>(CleanupPad->
Val), LLVMUnwindBB);
760 return cast<CleanupPadInst>(
761 Ctx.
getValue(cast<llvm::CleanupReturnInst>(
Val)->getCleanupPad()));
769 cast<llvm::CleanupReturnInst>(
Val)->setCleanupPad(
770 cast<llvm::CleanupPadInst>(CleanupPad->
Val));
774 return cast_or_null<BasicBlock>(
775 Ctx.
getValue(cast<llvm::CleanupReturnInst>(
Val)->getUnwindDest()));
783 cast<llvm::CleanupReturnInst>(
Val)->setUnwindDest(
784 cast<llvm::BasicBlock>(NewDest->
Val));
797 if (
auto *NewGEP = dyn_cast<llvm::GetElementPtrInst>(NewV))
799 assert(isa<llvm::Constant>(NewV) &&
"Expected constant");
823 return cast<BasicBlock>(Ctx.
getValue(LLVMBB));
835 return From->getSubclassID() == ClassID::PHI;
846 cast<llvm::PHINode>(
Val)->setIncomingValue(
Idx, V->Val);
849 return cast<BasicBlock>(
865 cast<llvm::PHINode>(
Val)->setIncomingBlock(
Idx,
866 cast<llvm::BasicBlock>(BB->
Val));
872 cast<llvm::PHINode>(
Val)->addIncoming(V->Val,
873 cast<llvm::BasicBlock>(BB->
Val));
879 cast<llvm::PHINode>(
Val)->removeIncomingValue(
Idx,
887 auto *LLVMBB = cast<llvm::BasicBlock>(BB->
Val);
889 cast<llvm::PHINode>(
Val)->removeIncomingValue(LLVMBB,
894 auto *LLVMBB = cast<llvm::BasicBlock>(BB->
Val);
895 return cast<llvm::PHINode>(
Val)->getBasicBlockIndex(LLVMBB);
898 auto *LLVMBB = cast<llvm::BasicBlock>(BB->
Val);
900 cast<llvm::PHINode>(
Val)->getIncomingValueForBlock(LLVMBB);
904 llvm::Value *LLVMV = cast<llvm::PHINode>(
Val)->hasConstantValue();
908 assert(New && Old &&
"Sandbox IR PHI node got a null basic block!");
923 if (Predicate(
Idx - 1))
934 if (
auto *LLVMC = dyn_cast<llvm::Constant>(LLVMV))
936 if (isa<llvm::ICmpInst>(LLVMV))
945 if (
auto *
C = dyn_cast<Constant>(V))
947 cast<llvm::CmpInst>(V->Val)->copyIRFlags(
F->Val);
952 if (
auto *VT = dyn_cast<VectorType>(OpndType)) {
957 cast<llvm::VectorType>(VT->LLVMTy)->getElementCount()));
966 cast<llvm::CmpInst>(
Val)->setPredicate(
P);
970 if (
ICmpInst *IC = dyn_cast<ICmpInst>(
this))
973 cast<FCmpInst>(
this)->swapOperands();
978 cast<llvm::ICmpInst>(
Val)->swapOperands();
983 cast<llvm::FCmpInst>(
Val)->swapOperands();
1000 case Instruction::Opcode::ZExt:
1002 case Instruction::Opcode::SExt:
1004 case Instruction::Opcode::FPToUI:
1006 case Instruction::Opcode::FPToSI:
1008 case Instruction::Opcode::FPExt:
1010 case Instruction::Opcode::PtrToInt:
1012 case Instruction::Opcode::IntToPtr:
1014 case Instruction::Opcode::SIToFP:
1016 case Instruction::Opcode::UIToFP:
1018 case Instruction::Opcode::Trunc:
1020 case Instruction::Opcode::FPTrunc:
1022 case Instruction::Opcode::BitCast:
1024 case Instruction::Opcode::AddrSpaceCast:
1026 llvm::Instruction::AddrSpaceCast);
1035 case Instruction::Opcode::FNeg:
1043 unsigned NumHandlers,
1048 ParentPad->
Val, cast<llvm::BasicBlock>(UnwindBB->
Val), NumHandlers,
Name);
1060 cast<llvm::CatchSwitchInst>(
Val)->setParentPad(ParentPad->Val);
1064 return cast_or_null<BasicBlock>(
1065 Ctx.
getValue(cast<llvm::CatchSwitchInst>(
Val)->getUnwindDest()));
1072 cast<llvm::CatchSwitchInst>(
Val)->setUnwindDest(
1073 cast<llvm::BasicBlock>(UnwindDest->
Val));
1078 cast<llvm::CatchSwitchInst>(
Val)->addHandler(
1079 cast<llvm::BasicBlock>(Dest->
Val));
1097 Builder.
CreateSwitch(V->Val, cast<llvm::BasicBlock>(Dest->
Val), NumCases);
1110 cast<llvm::SwitchInst>(
Val)->setCondition(V->Val);
1114 return cast<BasicBlock>(
1122 cast<llvm::SwitchInst>(
Val)->setDefaultDest(
1123 cast<llvm::BasicBlock>(DefaultCase->
Val));
1126 auto *LLVMC = cast<llvm::SwitchInst>(
Val)->findCaseDest(
1127 cast<llvm::BasicBlock>(BB->
Val));
1128 return LLVMC !=
nullptr ? cast<ConstantInt>(
Ctx.
getValue(LLVMC)) :
nullptr;
1134 cast<llvm::SwitchInst>(
Val)->addCase(cast<llvm::ConstantInt>(OnVal->
Val),
1135 cast<llvm::BasicBlock>(Dest->
Val));
1145 unsigned Num = LLVMCaseIt -
LLVMSwitch->case_begin();
1146 return CaseIt(
this, Num);
1150 return cast<BasicBlock>(
1159 cast<llvm::SwitchInst>(
Val)->setSuccessor(
1160 Idx, cast<llvm::BasicBlock>(NewSucc->
Val));
1168 if (
auto *NewUnOpV = dyn_cast<llvm::UnaryOperator>(NewLLVMV)) {
1171 assert(isa<llvm::Constant>(NewLLVMV) &&
"Expected constant");
1179 if (
auto *UnI = dyn_cast<llvm::UnaryOperator>(NewV->Val))
1180 UnI->copyIRFlags(CopyFrom->
Val);
1187 case Instruction::Opcode::Add:
1189 case Instruction::Opcode::FAdd:
1191 case Instruction::Opcode::Sub:
1193 case Instruction::Opcode::FSub:
1195 case Instruction::Opcode::Mul:
1197 case Instruction::Opcode::FMul:
1199 case Instruction::Opcode::UDiv:
1201 case Instruction::Opcode::SDiv:
1203 case Instruction::Opcode::FDiv:
1205 case Instruction::Opcode::URem:
1207 case Instruction::Opcode::SRem:
1209 case Instruction::Opcode::FRem:
1211 case Instruction::Opcode::Shl:
1213 case Instruction::Opcode::LShr:
1215 case Instruction::Opcode::AShr:
1217 case Instruction::Opcode::And:
1219 case Instruction::Opcode::Or:
1221 case Instruction::Opcode::Xor:
1233 if (
auto *NewBinOp = dyn_cast<llvm::BinaryOperator>(NewV))
1235 assert(isa<llvm::Constant>(NewV) &&
"Expected constant");
1245 if (
auto *NewBO = dyn_cast<BinaryOperator>(NewV))
1246 cast<llvm::BinaryOperator>(NewBO->Val)->copyIRFlags(CopyFrom->
Val);
1255 cast<llvm::PossiblyDisjointInst>(
Val)->setIsDisjoint(
B);
1262 cast<llvm::AtomicRMWInst>(
Val)->setAlignment(
Align);
1269 cast<llvm::AtomicRMWInst>(
Val)->setVolatile(V);
1276 cast<llvm::AtomicRMWInst>(
Val)->setOrdering(Ordering);
1283 cast<llvm::AtomicRMWInst>(
Val)->setSyncScopeID(SSID);
1310 cast<llvm::AtomicCmpXchgInst>(
Val)->setSyncScopeID(SSID);
1333 SuccessOrdering, FailureOrdering, SSID);
1342 cast<llvm::AtomicCmpXchgInst>(
Val)->setAlignment(
Align);
1349 cast<llvm::AtomicCmpXchgInst>(
Val)->setVolatile(V);
1356 cast<llvm::AtomicCmpXchgInst>(
Val)->setWeak(IsWeak);
1364 cast<llvm::AtomicCmpXchgInst>(
Val)->setSuccessOrdering(Ordering);
1372 cast<llvm::AtomicCmpXchgInst>(
Val)->setFailureOrdering(Ordering);
1392 cast<llvm::AllocaInst>(
Val)->setAllocatedType(Ty->
LLVMTy);
1400 cast<llvm::AllocaInst>(
Val)->setAlignment(
Align);
1407 cast<llvm::AllocaInst>(
Val)->setUsedWithInAlloca(V);
1415 return cast<PointerType>(
Ctx.
getType(cast<llvm::AllocaInst>(
Val)->getType()));
1424 if (
auto *NewCI = dyn_cast<llvm::CastInst>(NewV))
1426 assert(isa<llvm::Constant>(NewV) &&
"Expected constant");
1431 return From->getSubclassID() == ClassID::Cast;
1446 cast<llvm::PossiblyNonNegInst>(
Val)->setNonNeg(
B);
1455 if (
auto *NewInsert = dyn_cast<llvm::InsertElementInst>(NewV))
1457 assert(isa<llvm::Constant>(NewV) &&
"Expected constant");
1465 if (
auto *NewExtract = dyn_cast<llvm::ExtractElementInst>(NewV))
1467 assert(isa<llvm::Constant>(NewV) &&
"Expected constant");
1477 if (
auto *NewShuffle = dyn_cast<llvm::ShuffleVectorInst>(NewV))
1479 assert(isa<llvm::Constant>(NewV) &&
"Expected constant");
1488 if (
auto *NewShuffle = dyn_cast<llvm::ShuffleVectorInst>(NewV))
1490 assert(isa<llvm::Constant>(NewV) &&
"Expected constant");
1496 cast<llvm::ShuffleVectorInst>(
Val)->setShuffleMask(Mask);
1500 return cast<VectorType>(
1501 Ctx.
getType(cast<llvm::ShuffleVectorInst>(
Val)->getType()));
1508 cast<llvm::ShuffleVectorInst>(
Val)->commute();
1532 if (
auto *NewExtractValueInst = dyn_cast<llvm::ExtractValueInst>(NewV))
1534 assert(isa<llvm::Constant>(NewV) &&
"Expected constant");
1548 if (
auto *NewInsertValueInst = dyn_cast<llvm::InsertValueInst>(NewV))
1550 assert(isa<llvm::Constant>(NewV) &&
"Expected constant");
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
BinOp
This enumeration lists the possible modifications atomicrmw can make.
LLVM Basic Block Representation.
InstListType::iterator iterator
Instruction iterators...
Conditional or Unconditional Branch instruction.
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
This class represents a function call, abstracting a target machine's calling convention.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
static ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
This class represents an Operation in the Expression.
Convenience struct for specifying and reasoning about fast-math flags.
An instruction for ordering other memory operations.
CleanupPadInst * CreateCleanupPad(Value *ParentPad, ArrayRef< Value * > Args={}, const Twine &Name="")
CatchPadInst * CreateCatchPad(Value *ParentPad, ArrayRef< Value * > Args, const Twine &Name="")
Value * CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx, const Twine &Name="")
AtomicCmpXchgInst * CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New, MaybeAlign Align, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, SyncScope::ID SSID=SyncScope::System)
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
LandingPadInst * CreateLandingPad(Type *Ty, unsigned NumClauses, const Twine &Name="")
InvokeInst * CreateInvoke(FunctionType *Ty, Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Create an invoke instruction.
CallBrInst * CreateCallBr(FunctionType *Ty, Value *Callee, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args={}, const Twine &Name="")
Create a callbr instruction.
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr, FMFSource FMFSource={})
CatchReturnInst * CreateCatchRet(CatchPadInst *CatchPad, BasicBlock *BB)
CleanupReturnInst * CreateCleanupRet(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB=nullptr)
ReturnInst * CreateRet(Value *V)
Create a 'ret <val>' instruction.
Value * CreateGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
CatchSwitchInst * CreateCatchSwitch(Value *ParentPad, BasicBlock *UnwindBB, unsigned NumHandlers, const Twine &Name="")
Value * CreateUnOp(Instruction::UnaryOps Opc, Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateCmp(CmpInst::Predicate Pred, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
SwitchInst * CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases=10, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a switch instruction with the specified value, default dest, and with a hint for the number of...
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
ReturnInst * CreateRetVoid()
Create a 'ret void' instruction.
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
AtomicRMWInst * CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val, MaybeAlign Align, AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
ResumeInst * CreateResume(Value *Exn)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
The landingpad instruction holds all of the information necessary to generate correct exception handl...
Return a value (possibly void), from a function.
static Constant * convertShuffleMaskForBitcode(ArrayRef< int > Mask, Type *ResultTy)
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static IntegerType * getInt1Ty(LLVMContext &C)
This function has undefined behavior.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
An efficient, type-erasing, non-owning reference to a callable.
self_iterator getIterator()
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
This class implements an extremely fast bulk output stream that can only output to a stream.
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
void setAllocatedType(Type *Ty)
for use only in special circumstances that need to generically transform a whole instruction (eg: IR ...
Value * getArraySize()
Get the number of elements allocated.
PointerType * getType() const
Overload to return most specific pointer type.
void setUsedWithInAlloca(bool V)
Specify whether this alloca is used to represent the arguments to a call.
void setAlignment(Align Align)
static AllocaInst * create(Type *Ty, unsigned AddrSpace, InsertPosition Pos, Context &Ctx, Value *ArraySize=nullptr, const Twine &Name="")
Value * getPointerOperand()
void setSuccessOrdering(AtomicOrdering Ordering)
void setWeak(bool IsWeak)
void setVolatile(bool V)
Specify whether this is a volatile cmpxchg.
void setFailureOrdering(AtomicOrdering Ordering)
AtomicOrdering getFailureOrdering() const
void setAlignment(Align Align)
Value * getCompareOperand()
static AtomicCmpXchgInst * create(Value *Ptr, Value *Cmp, Value *New, MaybeAlign Align, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, InsertPosition Pos, Context &Ctx, SyncScope::ID SSID=SyncScope::System, const Twine &Name="")
bool isVolatile() const
Return true if this is a cmpxchg from a volatile memory location.
void setSyncScopeID(SyncScope::ID SSID)
AtomicOrdering getSuccessOrdering() const
SyncScope::ID getSyncScopeID() const
Value * getNewValOperand()
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
bool isWeak() const
Return true if this cmpxchg may spuriously fail.
static AtomicRMWInst * create(BinOp Op, Value *Ptr, Value *Val, MaybeAlign Align, AtomicOrdering Ordering, InsertPosition Pos, Context &Ctx, SyncScope::ID SSID=SyncScope::System, const Twine &Name="")
void setSyncScopeID(SyncScope::ID SSID)
void setOrdering(AtomicOrdering Ordering)
SyncScope::ID getSyncScopeID() const
AtomicOrdering getOrdering() const
Value * getPointerOperand()
void setAlignment(Align Align)
Iterator for Instructions in a `BasicBlock.
Contains a list of sandboxir::Instruction's.
Function * getParent() const
static Value * create(Instruction::Opcode Op, Value *LHS, Value *RHS, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static Value * createWithCopiedFlags(Instruction::Opcode Op, Value *LHS, Value *RHS, Value *CopyFrom, InsertPosition Pos, Context &Ctx, const Twine &Name="")
BasicBlock * getSuccessor(unsigned SuccIdx) const
Value * getCondition() const
void setSuccessor(unsigned Idx, BasicBlock *NewSucc)
unsigned getNumSuccessors() const
static BranchInst * create(BasicBlock *IfTrue, InsertPosition Pos, Context &Ctx)
static bool classof(const Value *From)
For isa/dyn_cast.
bool isConditional() const
Function * getCalledFunction() const
Use getCalledOperandUse() const
FunctionType * getFunctionType() const
void setCalledFunction(Function *F)
Value * getCalledOperand() const
void setCalledOperand(Value *V)
Value * getIndirectDestLabelUse(unsigned Idx) const
static CallBrInst * create(FunctionType *FTy, Value *Func, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, InsertPosition Pos, Context &Ctx, const Twine &NameStr="")
Value * getIndirectDestLabel(unsigned Idx) const
BasicBlock * getSuccessor(unsigned Idx) const
void setIndirectDest(unsigned Idx, BasicBlock *BB)
BasicBlock * getDefaultDest() const
BasicBlock * getIndirectDest(unsigned Idx) const
SmallVector< BasicBlock *, 16 > getIndirectDests() const
void setDefaultDest(BasicBlock *BB)
static CallInst * create(FunctionType *FTy, Value *Func, ArrayRef< Value * > Args, InsertPosition Pos, Context &Ctx, const Twine &NameStr="")
static Value * create(Type *DestTy, Opcode Op, Value *Operand, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static bool classof(const Value *From)
For isa/dyn_cast.
static CatchPadInst * create(Value *ParentPad, ArrayRef< Value * > Args, InsertPosition Pos, Context &Ctx, const Twine &Name="")
CatchSwitchInst * getCatchSwitch() const
CatchPadInst * getCatchPad() const
BasicBlock * getSuccessor() const
void setSuccessor(BasicBlock *NewSucc)
void setCatchPad(CatchPadInst *CatchPad)
Value * getCatchSwitchParentPad() const
static CatchReturnInst * create(CatchPadInst *CatchPad, BasicBlock *BB, InsertPosition Pos, Context &Ctx)
void addHandler(BasicBlock *Dest)
void setParentPad(Value *ParentPad)
void setUnwindDest(BasicBlock *UnwindDest)
static CatchSwitchInst * create(Value *ParentPad, BasicBlock *UnwindBB, unsigned NumHandlers, InsertPosition Pos, Context &Ctx, const Twine &Name="")
BasicBlock * getUnwindDest() const
Value * getParentPad() const
static CleanupPadInst * create(Value *ParentPad, ArrayRef< Value * > Args, InsertPosition Pos, Context &Ctx, const Twine &Name="")
CleanupPadInst * getCleanupPad() const
void setUnwindDest(BasicBlock *NewDest)
static CleanupReturnInst * create(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB, InsertPosition Pos, Context &Ctx)
BasicBlock * getUnwindDest() const
void setCleanupPad(CleanupPadInst *CleanupPad)
void dumpOS(raw_ostream &OS) const override
LLVM_DUMP_METHOD void dump() const
static Value * createWithCopiedFlags(Predicate Pred, Value *S1, Value *S2, const Instruction *FlagsSource, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static Type * makeCmpResultType(Type *OpndType)
Create a result type for fcmp/icmp.
static Value * create(Predicate Pred, Value *S1, Value *S2, InsertPosition Pos, Context &Ctx, const Twine &Name="")
void setPredicate(Predicate P)
static ConstantTokenNone * get(Context &Ctx)
Return the ConstantTokenNone.
GetElementPtrInst * createGetElementPtrInst(llvm::GetElementPtrInst *I)
CallBrInst * createCallBrInst(llvm::CallBrInst *I)
sandboxir::Value * getValue(llvm::Value *V) const
ReturnInst * createReturnInst(llvm::ReturnInst *I)
void runEraseInstrCallbacks(Instruction *I)
VAArgInst * createVAArgInst(llvm::VAArgInst *SI)
CleanupReturnInst * createCleanupReturnInst(llvm::CleanupReturnInst *I)
AllocaInst * createAllocaInst(llvm::AllocaInst *I)
Type * getType(llvm::Type *LLVMTy)
AtomicRMWInst * createAtomicRMWInst(llvm::AtomicRMWInst *I)
InsertValueInst * createInsertValueInst(llvm::InsertValueInst *IVI)
FCmpInst * createFCmpInst(llvm::FCmpInst *I)
ExtractElementInst * createExtractElementInst(llvm::ExtractElementInst *EEI)
Constant * getOrCreateConstant(llvm::Constant *LLVMC)
Get or create a sandboxir::Constant from an existing LLVM IR LLVMC.
BranchInst * createBranchInst(llvm::BranchInst *I)
ShuffleVectorInst * createShuffleVectorInst(llvm::ShuffleVectorInst *SVI)
BinaryOperator * createBinaryOperator(llvm::BinaryOperator *I)
LoadInst * createLoadInst(llvm::LoadInst *LI)
FreezeInst * createFreezeInst(llvm::FreezeInst *SI)
PHINode * createPHINode(llvm::PHINode *I)
CatchPadInst * createCatchPadInst(llvm::CatchPadInst *I)
ICmpInst * createICmpInst(llvm::ICmpInst *I)
std::unique_ptr< Value > detach(Value *V)
Remove SBV from all SandboxIR maps and stop owning it.
ExtractValueInst * createExtractValueInst(llvm::ExtractValueInst *IVI)
CastInst * createCastInst(llvm::CastInst *I)
StoreInst * createStoreInst(llvm::StoreInst *SI)
CatchReturnInst * createCatchReturnInst(llvm::CatchReturnInst *I)
CatchSwitchInst * createCatchSwitchInst(llvm::CatchSwitchInst *I)
CleanupPadInst * createCleanupPadInst(llvm::CleanupPadInst *I)
FenceInst * createFenceInst(llvm::FenceInst *SI)
CallInst * createCallInst(llvm::CallInst *I)
SwitchInst * createSwitchInst(llvm::SwitchInst *I)
void runMoveInstrCallbacks(Instruction *I, const BBIterator &Where)
UnaryOperator * createUnaryOperator(llvm::UnaryOperator *I)
InvokeInst * createInvokeInst(llvm::InvokeInst *I)
LandingPadInst * createLandingPadInst(llvm::LandingPadInst *I)
InsertElementInst * createInsertElementInst(llvm::InsertElementInst *IEI)
SelectInst * createSelectInst(llvm::SelectInst *SI)
ResumeInst * createResumeInst(llvm::ResumeInst *I)
UnreachableInst * createUnreachableInst(llvm::UnreachableInst *UI)
AtomicCmpXchgInst * createAtomicCmpXchgInst(llvm::AtomicCmpXchgInst *I)
Value * getVectorOperand()
static Value * create(Value *Vec, Value *Idx, InsertPosition Pos, Context &Ctx, const Twine &Name="")
VectorType * getVectorOperandType() const
static Value * create(Value *Agg, ArrayRef< unsigned > Idxs, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static Type * getIndexedType(Type *Agg, ArrayRef< unsigned > Idxs)
Returns the type of the element that would be extracted with an extractvalue instruction with the spe...
static FenceInst * create(AtomicOrdering Ordering, InsertPosition Pos, Context &Ctx, SyncScope::ID SSID=SyncScope::System)
void setOrdering(AtomicOrdering Ordering)
Sets the ordering constraint of this fence instruction.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this fence instruction.
void setSyncScopeID(SyncScope::ID SSID)
Sets the synchronization scope ID of this fence instruction.
static FreezeInst * create(Value *V, InsertPosition Pos, Context &Ctx, const Twine &Name="")
Value * getArgOperand(unsigned Idx) const
Return the Idx-th funcletpad argument.
Value * getParentPad() const
Return the outer EH-pad this funclet is nested within.
void setParentPad(Value *ParentPad)
void setArgOperand(unsigned Idx, Value *V)
Set the Idx-th funcletpad argument.
Similar to GenericSetter but the setters/getters have an index as their first argument.
This class can be used for tracking most instruction setters.
Type * getResultElementType() const
Type * getPointerOperandType() const
Type * getSourceElementType() const
Value * getPointerOperand() const
static Value * create(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, InsertPosition Pos, Context &Ctx, const Twine &NameStr="")
static Value * create(Value *Vec, Value *NewElt, Value *Idx, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static Value * create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, InsertPosition Pos, Context &Ctx, const Twine &Name="")
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
bool hasNoUnsignedWrap() const
Determine whether the no signed wrap flag is set.
static IRBuilder & setInsertPos(InsertPosition Pos)
Helper function for create().
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
bool hasAllowReassoc() const
Determine whether the allow-reassociation flag is set.
void setHasAllowReassoc(bool B)
Set or clear the reassociation flag on this instruction, which must be an operator which supports thi...
bool hasNoSignedZeros() const
Determine whether the no-signed-zeros flag is set.
const char * getOpcodeName() const
void setHasNoSignedWrap(bool B=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
void insertAfter(Instruction *AfterI)
Insert this detached instruction after AfterI.
void moveBefore(BasicBlock &BB, const BBIterator &WhereIt)
Move this instruction to WhereIt.
bool hasAllowContract() const
Determine whether the allow-contract flag is set.
void setIsExact(bool B=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
bool hasApproxFunc() const
Determine whether the approximate-math-functions flag is set.
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
void setHasNoUnsignedWrap(bool B=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
void dumpOS(raw_ostream &OS) const override
BBIterator getIterator() const
\Returns a BasicBlock::iterator for this Instruction.
void setFast(bool B)
Set or clear all fast-math-flags on this instruction, which must be an operator which supports this f...
void setHasApproxFunc(bool B)
Set or clear the approximate-math-functions flag on this instruction, which must be an operator which...
void setHasNoNaNs(bool B)
Set or clear the no-nans flag on this instruction, which must be an operator which supports this flag...
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction,...
void setHasNoSignedZeros(bool B)
Set or clear the no-signed-zeros flag on this instruction, which must be an operator which supports t...
void insertInto(BasicBlock *BB, const BBIterator &WhereIt)
Insert this detached instruction into BB at WhereIt.
llvm::Instruction * getTopmostLLVMInstruction() const
A SandboxIR Instruction may map to multiple LLVM IR Instruction.
void setHasAllowContract(bool B)
Set or clear the allow-contract flag on this instruction, which must be an operator which supports th...
virtual SmallVector< llvm::Instruction *, 1 > getLLVMInstrs() const =0
\Returns the LLVM IR Instructions that this SandboxIR maps to in program order.
Type * getAccessType() const
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
Instruction * getNextNode() const
\Returns the next sandboxir::Instruction in the block, or nullptr if at the end of the block.
void removeFromParent()
Detach this from its parent BasicBlock without deleting it.
Instruction * getPrevNode() const
\Returns the previous sandboxir::Instruction in the block, or nullptr if at the beginning of the bloc...
bool hasAllowReciprocal() const
Determine whether the allow-reciprocal flag is set.
void insertBefore(Instruction *BeforeI)
Insert this detached instruction before BeforeI.
void eraseFromParent()
Detach this Value from its parent and delete it.
void setHasAllowReciprocal(bool B)
Set or clear the allow-reciprocal flag on this instruction, which must be an operator which supports ...
void setHasNoInfs(bool B)
Set or clear the no-infs flag on this instruction, which must be an operator which supports this flag...
BasicBlock * getParent() const
\Returns the BasicBlock containing this Instruction, or null if it is detached.
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
BasicBlock * getUnwindDest() const
static InvokeInst * create(FunctionType *FTy, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, InsertPosition Pos, Context &Ctx, const Twine &NameStr="")
void setNormalDest(BasicBlock *BB)
void setUnwindDest(BasicBlock *BB)
BasicBlock * getSuccessor(unsigned SuccIdx) const
BasicBlock * getNormalDest() const
LandingPadInst * getLandingPadInst() const
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
void setCleanup(bool V)
Indicate that this landingpad instruction is a cleanup.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
static LandingPadInst * create(Type *RetTy, unsigned NumReservedClauses, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static LoadInst * create(Type *Ty, Value *Ptr, MaybeAlign Align, InsertPosition Pos, bool IsVolatile, Context &Ctx, const Twine &Name="")
void setVolatile(bool V)
Specify whether this is a volatile load or not.
Value * getPointerOperand() const
static bool classof(const Value *From)
For isa/dyn_cast.
Value * hasConstantValue() const
int getBasicBlockIndex(const BasicBlock *BB) const
unsigned getNumIncomingValues() const
Value * getIncomingValue(unsigned Idx) const
void setIncomingBlock(unsigned Idx, BasicBlock *BB)
void removeIncomingValueIf(function_ref< bool(unsigned)> Predicate)
static bool classof(const Value *From)
For isa/dyn_cast.
static PHINode * create(Type *Ty, unsigned NumReservedValues, InsertPosition Pos, Context &Ctx, const Twine &Name="")
Value * removeIncomingValue(unsigned Idx)
void setIncomingValue(unsigned Idx, Value *V)
BasicBlock * getIncomingBlock(unsigned Idx) const
void replaceIncomingBlockWith(const BasicBlock *Old, BasicBlock *New)
Value * getIncomingValueForBlock(const BasicBlock *BB) const
void addIncoming(Value *V, BasicBlock *BB)
void setIsDisjoint(bool B)
static ResumeInst * create(Value *Exn, InsertPosition Pos, Context &Ctx)
static ReturnInst * create(Value *RetVal, InsertPosition Pos, Context &Ctx)
Value * getReturnValue() const
\Returns null if there is no return value.
static bool classof(const Value *From)
For isa/dyn_cast.
static Value * create(Value *Cond, Value *True, Value *False, InsertPosition Pos, Context &Ctx, const Twine &Name="")
VectorType * getType() const
Overload to return most specific vector type.
Constant * getShuffleMaskForBitcode() const
Return the mask for this instruction, for use in bitcode.
void commute()
Swap the operands and adjust the mask to preserve the semantics of the instruction.
static Value * create(Value *V1, Value *V2, Value *Mask, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static Constant * convertShuffleMaskForBitcode(ArrayRef< int > Mask, Type *ResultTy)
void setShuffleMask(ArrayRef< int > Mask)
void setVolatile(bool V)
Specify whether this is a volatile store or not.
static bool classof(const Value *From)
For isa/dyn_cast.
static StoreInst * create(Value *V, Value *Ptr, MaybeAlign Align, InsertPosition Pos, bool IsVolatile, Context &Ctx)
Value * getPointerOperand() const
Value * getValueOperand() const
static SwitchInst * create(Value *V, BasicBlock *Dest, unsigned NumCases, InsertPosition Pos, Context &Ctx, const Twine &Name="")
void addCase(ConstantInt *OnVal, BasicBlock *Dest)
BasicBlock * getSuccessor(unsigned Idx) const
CaseIt case_begin()
Returns a read/write iterator that points to the first case in the SwitchInst.
void setDefaultDest(BasicBlock *DefaultCase)
llvm::SwitchInst::CaseIteratorImpl< CaseHandle > CaseIt
BasicBlock * getDefaultDest() const
Value * getCondition() const
void setSuccessor(unsigned Idx, BasicBlock *NewSucc)
void setCondition(Value *V)
ConstantInt * findCaseDest(BasicBlock *BB)
CaseIt removeCase(CaseIt It)
This method removes the specified case and its successor from the switch instruction.
The tracker collects all the change objects and implements the main API for saving / reverting / acce...
void track(std::unique_ptr< IRChangeBase > &&Change)
Record Change and take ownership.
bool emplaceIfTracking(ArgsT... Args)
A convenience wrapper for track() that constructs and tracks the Change object if tracking is enabled...
Just like llvm::Type these are immutable, unique, never get freed and can only be created via static ...
static Type * getInt1Ty(Context &Ctx)
Context & getContext() const
static Value * createWithCopiedFlags(Instruction::Opcode Op, Value *OpV, Value *CopyFrom, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static Value * create(Instruction::Opcode Op, Value *OpV, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static UnreachableInst * create(InsertPosition Pos, Context &Ctx)
static bool classof(const Value *From)
Tracks swapping a Use with another Use.
Represents a Def-use/Use-def edge in SandboxIR.
virtual void setOperand(unsigned OperandIdx, Value *Operand)
virtual unsigned getNumOperands() const
Use getOperandUse(unsigned OpIdx) const
\Returns the operand edge for OpIdx.
Value * getPointerOperand()
static VAArgInst * create(Value *List, Type *Ty, InsertPosition Pos, Context &Ctx, const Twine &Name="")
A SandboxIR Value has users. This is the base class.
llvm::Value * Val
The LLVM Value that corresponds to this SandboxIR Value.
void dumpCommonSuffix(raw_ostream &OS) const
Context & Ctx
All values point to the context.
iterator_range< user_iterator > users()
void dumpCommonPrefix(raw_ostream &OS) 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.
static llvm::Instruction::CastOps getLLVMCastOp(Instruction::Opcode Opc)
static llvm::Instruction::UnaryOps getLLVMUnaryOp(Instruction::Opcode Opc)
\Returns the LLVM opcode that corresponds to Opc.
static llvm::Instruction::BinaryOps getLLVMBinaryOp(Instruction::Opcode Opc)
\Returns the LLVM opcode that corresponds to Opc.
auto reverse(ContainerTy &&C)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
AtomicOrdering
Atomic ordering for LLVM's memory model.
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.