18 std::unique_ptr<Value> Erased;
21 auto *Val = It->second.release();
22 Erased = std::unique_ptr<Value>(Val);
29 assert(V->getSubclassID() != Value::ClassID::Constant &&
30 "Can't detach a constant!");
31 assert(V->getSubclassID() != Value::ClassID::User &&
"Can't detach a user!");
36 assert(VPtr->getSubclassID() != Value::ClassID::User &&
37 "Can't register a user!");
39 Value *V = VPtr.get();
40 [[maybe_unused]]
auto Pair =
42 assert(Pair.second &&
"Already exists!");
48 if (
auto *
I = dyn_cast<Instruction>(V)) {
60 return It->second.get();
63 if (
auto *LLVMI = dyn_cast<llvm::Instruction>(LLVMV)) {
64 switch (LLVMI->getOpcode()) {
65 case llvm::Instruction::VAArg: {
66 auto *
LLVMVAArg = cast<llvm::VAArgInst>(LLVMV);
68 return It->second.get();
70 case llvm::Instruction::Freeze: {
71 auto *
LLVMFreeze = cast<llvm::FreezeInst>(LLVMV);
74 return It->second.get();
76 case llvm::Instruction::Fence: {
77 auto *
LLVMFence = cast<llvm::FenceInst>(LLVMV);
79 return It->second.get();
81 case llvm::Instruction::Select: {
82 auto *LLVMSel = cast<llvm::SelectInst>(LLVMV);
83 It->second = std::unique_ptr<SelectInst>(
new SelectInst(LLVMSel, *
this));
84 return It->second.get();
86 case llvm::Instruction::ExtractElement: {
87 auto *LLVMIns = cast<llvm::ExtractElementInst>(LLVMV);
88 It->second = std::unique_ptr<ExtractElementInst>(
90 return It->second.get();
92 case llvm::Instruction::InsertElement: {
93 auto *LLVMIns = cast<llvm::InsertElementInst>(LLVMV);
94 It->second = std::unique_ptr<InsertElementInst>(
96 return It->second.get();
98 case llvm::Instruction::ShuffleVector: {
99 auto *LLVMIns = cast<llvm::ShuffleVectorInst>(LLVMV);
100 It->second = std::unique_ptr<ShuffleVectorInst>(
102 return It->second.get();
104 case llvm::Instruction::ExtractValue: {
105 auto *LLVMIns = cast<llvm::ExtractValueInst>(LLVMV);
106 It->second = std::unique_ptr<ExtractValueInst>(
108 return It->second.get();
110 case llvm::Instruction::InsertValue: {
111 auto *LLVMIns = cast<llvm::InsertValueInst>(LLVMV);
114 return It->second.get();
116 case llvm::Instruction::Br: {
117 auto *
LLVMBr = cast<llvm::BranchInst>(LLVMV);
119 return It->second.get();
121 case llvm::Instruction::Load: {
122 auto *LLVMLd = cast<llvm::LoadInst>(LLVMV);
123 It->second = std::unique_ptr<LoadInst>(
new LoadInst(LLVMLd, *
this));
124 return It->second.get();
126 case llvm::Instruction::Store: {
127 auto *LLVMSt = cast<llvm::StoreInst>(LLVMV);
128 It->second = std::unique_ptr<StoreInst>(
new StoreInst(LLVMSt, *
this));
129 return It->second.get();
131 case llvm::Instruction::Ret: {
132 auto *
LLVMRet = cast<llvm::ReturnInst>(LLVMV);
134 return It->second.get();
136 case llvm::Instruction::Call: {
137 auto *
LLVMCall = cast<llvm::CallInst>(LLVMV);
139 return It->second.get();
141 case llvm::Instruction::Invoke: {
142 auto *
LLVMInvoke = cast<llvm::InvokeInst>(LLVMV);
145 return It->second.get();
147 case llvm::Instruction::CallBr: {
148 auto *
LLVMCallBr = cast<llvm::CallBrInst>(LLVMV);
151 return It->second.get();
153 case llvm::Instruction::LandingPad: {
154 auto *LLVMLPad = cast<llvm::LandingPadInst>(LLVMV);
156 std::unique_ptr<LandingPadInst>(
new LandingPadInst(LLVMLPad, *
this));
157 return It->second.get();
159 case llvm::Instruction::CatchPad: {
160 auto *LLVMCPI = cast<llvm::CatchPadInst>(LLVMV);
162 std::unique_ptr<CatchPadInst>(
new CatchPadInst(LLVMCPI, *
this));
163 return It->second.get();
165 case llvm::Instruction::CleanupPad: {
166 auto *LLVMCPI = cast<llvm::CleanupPadInst>(LLVMV);
168 std::unique_ptr<CleanupPadInst>(
new CleanupPadInst(LLVMCPI, *
this));
169 return It->second.get();
171 case llvm::Instruction::CatchRet: {
172 auto *LLVMCRI = cast<llvm::CatchReturnInst>(LLVMV);
175 return It->second.get();
177 case llvm::Instruction::CleanupRet: {
178 auto *LLVMCRI = cast<llvm::CleanupReturnInst>(LLVMV);
179 It->second = std::unique_ptr<CleanupReturnInst>(
181 return It->second.get();
183 case llvm::Instruction::GetElementPtr: {
184 auto *LLVMGEP = cast<llvm::GetElementPtrInst>(LLVMV);
185 It->second = std::unique_ptr<GetElementPtrInst>(
187 return It->second.get();
189 case llvm::Instruction::CatchSwitch: {
190 auto *LLVMCatchSwitchInst = cast<llvm::CatchSwitchInst>(LLVMV);
191 It->second = std::unique_ptr<CatchSwitchInst>(
193 return It->second.get();
195 case llvm::Instruction::Resume: {
196 auto *LLVMResumeInst = cast<llvm::ResumeInst>(LLVMV);
198 std::unique_ptr<ResumeInst>(
new ResumeInst(LLVMResumeInst, *
this));
199 return It->second.get();
201 case llvm::Instruction::Switch: {
202 auto *LLVMSwitchInst = cast<llvm::SwitchInst>(LLVMV);
204 std::unique_ptr<SwitchInst>(
new SwitchInst(LLVMSwitchInst, *
this));
205 return It->second.get();
207 case llvm::Instruction::FNeg: {
208 auto *LLVMUnaryOperator = cast<llvm::UnaryOperator>(LLVMV);
209 It->second = std::unique_ptr<UnaryOperator>(
211 return It->second.get();
213 case llvm::Instruction::Add:
214 case llvm::Instruction::FAdd:
215 case llvm::Instruction::Sub:
216 case llvm::Instruction::FSub:
217 case llvm::Instruction::Mul:
218 case llvm::Instruction::FMul:
219 case llvm::Instruction::UDiv:
220 case llvm::Instruction::SDiv:
221 case llvm::Instruction::FDiv:
222 case llvm::Instruction::URem:
223 case llvm::Instruction::SRem:
224 case llvm::Instruction::FRem:
225 case llvm::Instruction::Shl:
226 case llvm::Instruction::LShr:
227 case llvm::Instruction::AShr:
228 case llvm::Instruction::And:
229 case llvm::Instruction::Or:
230 case llvm::Instruction::Xor: {
231 auto *LLVMBinaryOperator = cast<llvm::BinaryOperator>(LLVMV);
232 It->second = std::unique_ptr<BinaryOperator>(
234 return It->second.get();
236 case llvm::Instruction::AtomicRMW: {
238 It->second = std::unique_ptr<AtomicRMWInst>(
240 return It->second.get();
242 case llvm::Instruction::AtomicCmpXchg: {
244 It->second = std::unique_ptr<AtomicCmpXchgInst>(
246 return It->second.get();
248 case llvm::Instruction::Alloca: {
249 auto *
LLVMAlloca = cast<llvm::AllocaInst>(LLVMV);
252 return It->second.get();
254 case llvm::Instruction::ZExt:
255 case llvm::Instruction::SExt:
256 case llvm::Instruction::FPToUI:
257 case llvm::Instruction::FPToSI:
258 case llvm::Instruction::FPExt:
259 case llvm::Instruction::PtrToAddr:
260 case llvm::Instruction::PtrToInt:
261 case llvm::Instruction::IntToPtr:
262 case llvm::Instruction::SIToFP:
263 case llvm::Instruction::UIToFP:
264 case llvm::Instruction::Trunc:
265 case llvm::Instruction::FPTrunc:
266 case llvm::Instruction::BitCast:
267 case llvm::Instruction::AddrSpaceCast: {
268 auto *LLVMCast = cast<llvm::CastInst>(LLVMV);
269 It->second = std::unique_ptr<CastInst>(
new CastInst(LLVMCast, *
this));
270 return It->second.get();
272 case llvm::Instruction::PHI: {
273 auto *LLVMPhi = cast<llvm::PHINode>(LLVMV);
274 It->second = std::unique_ptr<PHINode>(
new PHINode(LLVMPhi, *
this));
275 return It->second.get();
277 case llvm::Instruction::ICmp: {
278 auto *
LLVMICmp = cast<llvm::ICmpInst>(LLVMV);
280 return It->second.get();
282 case llvm::Instruction::FCmp: {
283 auto *
LLVMFCmp = cast<llvm::FCmpInst>(LLVMV);
285 return It->second.get();
287 case llvm::Instruction::Unreachable: {
289 It->second = std::unique_ptr<UnreachableInst>(
291 return It->second.get();
296 It->second = std::unique_ptr<OpaqueInst>(
297 new OpaqueInst(cast<llvm::Instruction>(LLVMV), *
this));
298 return It->second.get();
301 if (
auto *LLVMC = dyn_cast<llvm::Constant>(LLVMV)) {
302 switch (LLVMC->getValueID()) {
303 case llvm::Value::ConstantIntVal:
304 It->second = std::unique_ptr<ConstantInt>(
305 new ConstantInt(cast<llvm::ConstantInt>(LLVMC), *
this));
306 return It->second.get();
307 case llvm::Value::ConstantFPVal:
308 It->second = std::unique_ptr<ConstantFP>(
309 new ConstantFP(cast<llvm::ConstantFP>(LLVMC), *
this));
310 return It->second.get();
311 case llvm::Value::BlockAddressVal:
312 It->second = std::unique_ptr<BlockAddress>(
313 new BlockAddress(cast<llvm::BlockAddress>(LLVMC), *
this));
314 return It->second.get();
315 case llvm::Value::ConstantTokenNoneVal:
316 It->second = std::unique_ptr<ConstantTokenNone>(
318 return It->second.get();
319 case llvm::Value::ConstantAggregateZeroVal: {
320 auto *CAZ = cast<llvm::ConstantAggregateZero>(LLVMC);
321 It->second = std::unique_ptr<ConstantAggregateZero>(
323 auto *Ret = It->second.get();
325 auto EC = CAZ->getElementCount();
327 for (
auto ElmIdx : seq<unsigned>(0, EC.getFixedValue()))
332 case llvm::Value::ConstantPointerNullVal:
334 cast<llvm::ConstantPointerNull>(LLVMC), *
this));
335 return It->second.get();
336 case llvm::Value::PoisonValueVal:
337 It->second = std::unique_ptr<PoisonValue>(
338 new PoisonValue(cast<llvm::PoisonValue>(LLVMC), *
this));
339 return It->second.get();
340 case llvm::Value::UndefValueVal:
341 It->second = std::unique_ptr<UndefValue>(
342 new UndefValue(cast<llvm::UndefValue>(LLVMC), *
this));
343 return It->second.get();
344 case llvm::Value::DSOLocalEquivalentVal: {
345 auto *DSOLE = cast<llvm::DSOLocalEquivalent>(LLVMC);
346 It->second = std::unique_ptr<DSOLocalEquivalent>(
348 auto *Ret = It->second.get();
352 case llvm::Value::ConstantArrayVal:
353 It->second = std::unique_ptr<ConstantArray>(
356 case llvm::Value::ConstantStructVal:
357 It->second = std::unique_ptr<ConstantStruct>(
360 case llvm::Value::ConstantVectorVal:
361 It->second = std::unique_ptr<ConstantVector>(
364 case llvm::Value::ConstantDataArrayVal:
365 It->second = std::unique_ptr<ConstantDataArray>(
368 case llvm::Value::ConstantDataVectorVal:
369 It->second = std::unique_ptr<ConstantDataVector>(
372 case llvm::Value::FunctionVal:
373 It->second = std::unique_ptr<Function>(
374 new Function(cast<llvm::Function>(LLVMC), *
this));
376 case llvm::Value::GlobalIFuncVal:
377 It->second = std::unique_ptr<GlobalIFunc>(
378 new GlobalIFunc(cast<llvm::GlobalIFunc>(LLVMC), *
this));
380 case llvm::Value::GlobalVariableVal:
381 It->second = std::unique_ptr<GlobalVariable>(
384 case llvm::Value::GlobalAliasVal:
385 It->second = std::unique_ptr<GlobalAlias>(
386 new GlobalAlias(cast<llvm::GlobalAlias>(LLVMC), *
this));
388 case llvm::Value::NoCFIValueVal:
389 It->second = std::unique_ptr<NoCFIValue>(
390 new NoCFIValue(cast<llvm::NoCFIValue>(LLVMC), *
this));
392 case llvm::Value::ConstantPtrAuthVal:
393 It->second = std::unique_ptr<ConstantPtrAuth>(
396 case llvm::Value::ConstantExprVal:
397 It->second = std::unique_ptr<ConstantExpr>(
398 new ConstantExpr(cast<llvm::ConstantExpr>(LLVMC), *
this));
401 It->second = std::unique_ptr<Constant>(
new Constant(LLVMC, *
this));
404 auto *NewC = It->second.get();
410 if (
auto *LLVMArg = dyn_cast<llvm::Argument>(LLVMV)) {
411 It->second = std::unique_ptr<Argument>(
new Argument(LLVMArg, *
this));
412 return It->second.get();
415 if (
auto *LLVMBB = dyn_cast<llvm::BasicBlock>(LLVMV)) {
416 assert(isa<llvm::BlockAddress>(U) &&
417 "This won't create a SBBB, don't call this function directly!");
423 if (
auto *LLVMMD = dyn_cast<llvm::MetadataAsValue>(LLVMV)) {
424 It->second = std::unique_ptr<OpaqueValue>(
new OpaqueValue(LLVMMD, *
this));
425 return It->second.get();
428 if (
auto *LLVMAsm = dyn_cast<llvm::InlineAsm>(LLVMV)) {
429 It->second = std::unique_ptr<OpaqueValue>(
new OpaqueValue(LLVMAsm, *
this));
430 return It->second.get();
437 auto It = Pair.first;
439 It->second = std::unique_ptr<Argument>(
new Argument(LLVMArg, *
this));
440 return cast<Argument>(It->second.get());
442 return cast<Argument>(It->second.get());
451 auto NewBBPtr = std::unique_ptr<BasicBlock>(
new BasicBlock(LLVMBB, *
this));
452 auto *BB = cast<BasicBlock>(
registerValue(std::move(NewBBPtr)));
454 BB->buildBasicBlockFromLLVMIR(LLVMBB);
459 auto NewPtr = std::unique_ptr<VAArgInst>(
new VAArgInst(SI, *
this));
464 auto NewPtr = std::unique_ptr<FreezeInst>(
new FreezeInst(SI, *
this));
469 auto NewPtr = std::unique_ptr<FenceInst>(
new FenceInst(SI, *
this));
474 auto NewPtr = std::unique_ptr<SelectInst>(
new SelectInst(SI, *
this));
482 return cast<ExtractElementInst>(
registerValue(std::move(NewPtr)));
489 return cast<InsertElementInst>(
registerValue(std::move(NewPtr)));
496 return cast<ShuffleVectorInst>(
registerValue(std::move(NewPtr)));
502 return cast<ExtractValueInst>(
registerValue(std::move(NewPtr)));
508 return cast<InsertValueInst>(
registerValue(std::move(NewPtr)));
512 auto NewPtr = std::unique_ptr<BranchInst>(
new BranchInst(BI, *
this));
517 auto NewPtr = std::unique_ptr<LoadInst>(
new LoadInst(LI, *
this));
522 auto NewPtr = std::unique_ptr<StoreInst>(
new StoreInst(SI, *
this));
527 auto NewPtr = std::unique_ptr<ReturnInst>(
new ReturnInst(
I, *
this));
532 auto NewPtr = std::unique_ptr<CallInst>(
new CallInst(
I, *
this));
537 auto NewPtr = std::unique_ptr<InvokeInst>(
new InvokeInst(
I, *
this));
542 auto NewPtr = std::unique_ptr<CallBrInst>(
new CallBrInst(
I, *
this));
549 return cast<UnreachableInst>(
registerValue(std::move(NewPtr)));
552 auto NewPtr = std::unique_ptr<LandingPadInst>(
new LandingPadInst(
I, *
this));
553 return cast<LandingPadInst>(
registerValue(std::move(NewPtr)));
556 auto NewPtr = std::unique_ptr<CatchPadInst>(
new CatchPadInst(
I, *
this));
560 auto NewPtr = std::unique_ptr<CleanupPadInst>(
new CleanupPadInst(
I, *
this));
561 return cast<CleanupPadInst>(
registerValue(std::move(NewPtr)));
564 auto NewPtr = std::unique_ptr<CatchReturnInst>(
new CatchReturnInst(
I, *
this));
565 return cast<CatchReturnInst>(
registerValue(std::move(NewPtr)));
571 return cast<CleanupReturnInst>(
registerValue(std::move(NewPtr)));
577 return cast<GetElementPtrInst>(
registerValue(std::move(NewPtr)));
580 auto NewPtr = std::unique_ptr<CatchSwitchInst>(
new CatchSwitchInst(
I, *
this));
581 return cast<CatchSwitchInst>(
registerValue(std::move(NewPtr)));
584 auto NewPtr = std::unique_ptr<ResumeInst>(
new ResumeInst(
I, *
this));
588 auto NewPtr = std::unique_ptr<SwitchInst>(
new SwitchInst(
I, *
this));
592 auto NewPtr = std::unique_ptr<UnaryOperator>(
new UnaryOperator(
I, *
this));
593 return cast<UnaryOperator>(
registerValue(std::move(NewPtr)));
596 auto NewPtr = std::unique_ptr<BinaryOperator>(
new BinaryOperator(
I, *
this));
597 return cast<BinaryOperator>(
registerValue(std::move(NewPtr)));
600 auto NewPtr = std::unique_ptr<AtomicRMWInst>(
new AtomicRMWInst(
I, *
this));
601 return cast<AtomicRMWInst>(
registerValue(std::move(NewPtr)));
607 return cast<AtomicCmpXchgInst>(
registerValue(std::move(NewPtr)));
610 auto NewPtr = std::unique_ptr<AllocaInst>(
new AllocaInst(
I, *
this));
614 auto NewPtr = std::unique_ptr<CastInst>(
new CastInst(
I, *
this));
618 auto NewPtr = std::unique_ptr<PHINode>(
new PHINode(
I, *
this));
622 auto NewPtr = std::unique_ptr<ICmpInst>(
new ICmpInst(
I, *
this));
626 auto NewPtr = std::unique_ptr<FCmpInst>(
new FCmpInst(
I, *
this));
632 return It->second.get();
637 : LLVMCtx(LLVMCtx), IRTracker(*this),
651 return It->second.get();
657 auto It = Pair.first;
659 return It->second.get();
660 It->second = std::unique_ptr<Module>(
new Module(*LLVMM, *
this));
661 return It->second.get();
674 auto NewFPtr = std::unique_ptr<Function>(
new Function(
F, *
this));
675 auto *SBF = cast<Function>(
registerValue(std::move(NewFPtr)));
677 for (
auto &Arg :
F->args())
688 for (
auto &LLVMF : *LLVMM)
694 for (
auto &Alias : LLVMM->
aliases())
697 for (
auto &IFunc : LLVMM->
ifuncs())
715 CBEntry.second(
I, WhereIt);
720 CBEntry.second(U, NewSrc);
730 "EraseInstrCallbacks size limit exceeded");
738 "Callback ID not found in EraseInstrCallbacks during deregistration");
744 "CreateInstrCallbacks size limit exceeded");
752 "Callback ID not found in CreateInstrCallbacks during deregistration");
757 "MoveInstrCallbacks size limit exceeded");
765 "Callback ID not found in MoveInstrCallbacks during deregistration");
770 "SetUseCallbacks size limit exceeded");
778 "Callback ID not found in SetUseCallbacks during deregistration");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
an instruction to allocate memory on the stack
This class represents an incoming formal argument to a Function.
An instruction that atomically checks whether a specified value is in a memory location,...
an instruction that atomically reads a memory location, combines it with another value,...
LLVM Basic Block Representation.
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.
This is the base class for all instructions that perform data casts.
ConstantFolder - Create constants with minimum, target independent, folding.
This is an important base class in LLVM.
This instruction compares its operands according to the predicate given to the constructor.
An instruction for ordering other memory operations.
This class represents a freeze function that returns random concrete value if an operand is either a ...
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
This instruction compares its operands according to the predicate given to the constructor.
This instruction inserts a single (scalar) element into a VectorType value.
This instruction inserts a struct field of array element value into an aggregate value.
This is an important class for using LLVM in a threaded context.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
An instruction for reading from memory.
A Module instance is used to store all the information related to an LLVM module.
iterator_range< ifunc_iterator > ifuncs()
iterator_range< alias_iterator > aliases()
iterator_range< global_iterator > globals()
Resume the propagation of an exception.
Return a value (possibly void), from a function.
This class represents the LLVM 'select' instruction.
This instruction constructs a fixed permutation of two input vectors.
An instruction for storing to memory.
This function has undefined behavior.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
LLVM Value Representation.
Argument of a sandboxir::Function.
Iterator for Instructions in a `BasicBlock.
Contains a list of sandboxir::Instruction's.
A vector constant whose element type is a simple 1/2/4/8-byte integer or float/double,...
An ID for a registered callback.
LLVM_ABI BasicBlock * createBasicBlock(llvm::BasicBlock *BB)
Create a sandboxir::BasicBlock for an existing LLVM IR BB.
std::function< void(Instruction *)> CreateInstrCallback
LLVM_ABI GetElementPtrInst * createGetElementPtrInst(llvm::GetElementPtrInst *I)
MapVector< CallbackID, CreateInstrCallback > CreateInstrCallbacks
Callbacks called when an IR instruction is about to get created.
LLVM_ABI CallBrInst * createCallBrInst(llvm::CallBrInst *I)
LLVM_ABI Module * createModule(llvm::Module *LLVMM)
Create a sandboxir::Module corresponding to LLVMM.
std::function< void(const Use &, Value *)> SetUseCallback
MapVector< CallbackID, EraseInstrCallback > EraseInstrCallbacks
Callbacks called when an IR instruction is about to get erased.
LLVM_ABI sandboxir::Value * getValue(llvm::Value *V) const
LLVM_ABI Argument * getOrCreateArgument(llvm::Argument *LLVMArg)
Get or create a sandboxir::Argument for an existing LLVM IR LLVMArg.
LLVM_ABI void unregisterSetUseCallback(CallbackID ID)
LLVM_ABI ReturnInst * createReturnInst(llvm::ReturnInst *I)
LLVM_ABI void runEraseInstrCallbacks(Instruction *I)
LLVM_ABI Module * getModule(llvm::Module *LLVMM) const
friend ExtractElementInst
LLVM_ABI VAArgInst * createVAArgInst(llvm::VAArgInst *SI)
LLVM_ABI CleanupReturnInst * createCleanupReturnInst(llvm::CleanupReturnInst *I)
LLVM_ABI AllocaInst * createAllocaInst(llvm::AllocaInst *I)
LLVM_ABI void runCreateInstrCallbacks(Instruction *I)
LLVM_ABI AtomicRMWInst * createAtomicRMWInst(llvm::AtomicRMWInst *I)
LLVM_ABI InsertValueInst * createInsertValueInst(llvm::InsertValueInst *IVI)
LLVM_ABI FCmpInst * createFCmpInst(llvm::FCmpInst *I)
std::function< void(Instruction *)> EraseInstrCallback
CallbackID::ValTy NextCallbackID
A counter used for assigning callback IDs during registration.
std::function< void(Instruction *, const BBIterator &)> MoveInstrCallback
LLVM_ABI ExtractElementInst * createExtractElementInst(llvm::ExtractElementInst *EEI)
LLVM_ABI Constant * getOrCreateConstant(llvm::Constant *LLVMC)
Get or create a sandboxir::Constant from an existing LLVM IR LLVMC.
LLVM_ABI CallbackID registerSetUseCallback(SetUseCallback CB)
Register a callback that gets called when a Use gets set.
LLVM_ABI BranchInst * createBranchInst(llvm::BranchInst *I)
LLVM_ABI ShuffleVectorInst * createShuffleVectorInst(llvm::ShuffleVectorInst *SVI)
LLVM_ABI BinaryOperator * createBinaryOperator(llvm::BinaryOperator *I)
LLVM_ABI Module * getOrCreateModule(llvm::Module *LLVMM)
LLVM_ABI LoadInst * createLoadInst(llvm::LoadInst *LI)
DenseMap< llvm::Value *, std::unique_ptr< Value > > LLVMValueToValueMap
Maps LLVM Value to the corresponding sandboxir::Value.
LLVM_ABI FreezeInst * createFreezeInst(llvm::FreezeInst *SI)
LLVM_ABI PHINode * createPHINode(llvm::PHINode *I)
LLVM_ABI CallbackID registerCreateInstrCallback(CreateInstrCallback CB)
Register a callback that gets called right after a SandboxIR instruction is created.
LLVM_ABI Context(LLVMContext &LLVMCtx)
LLVM_ABI CatchPadInst * createCatchPadInst(llvm::CatchPadInst *I)
LLVM_ABI void clear()
Clears function-level state.
LLVM_ABI ICmpInst * createICmpInst(llvm::ICmpInst *I)
MapVector< CallbackID, MoveInstrCallback > MoveInstrCallbacks
Callbacks called when an IR instruction is about to get moved.
LLVM_ABI std::unique_ptr< Value > detach(Value *V)
Remove SBV from all SandboxIR maps and stop owning it.
LLVM_ABI void unregisterCreateInstrCallback(CallbackID ID)
LLVM_ABI ExtractValueInst * createExtractValueInst(llvm::ExtractValueInst *IVI)
LLVM_ABI CastInst * createCastInst(llvm::CastInst *I)
DenseMap< llvm::Module *, std::unique_ptr< Module > > LLVMModuleToModuleMap
Maps an LLVM Module to the corresponding sandboxir::Module.
LLVM_ABI StoreInst * createStoreInst(llvm::StoreInst *SI)
LLVM_ABI CatchReturnInst * createCatchReturnInst(llvm::CatchReturnInst *I)
LLVM_ABI CatchSwitchInst * createCatchSwitchInst(llvm::CatchSwitchInst *I)
LLVM_ABI void unregisterMoveInstrCallback(CallbackID ID)
LLVM_ABI CleanupPadInst * createCleanupPadInst(llvm::CleanupPadInst *I)
Value * getOrCreateValue(llvm::Value *LLVMV)
Get or create a sandboxir::Value for an existing LLVM IR LLVMV.
LLVM_ABI FenceInst * createFenceInst(llvm::FenceInst *SI)
LLVM_ABI CallInst * createCallInst(llvm::CallInst *I)
LLVM_ABI SwitchInst * createSwitchInst(llvm::SwitchInst *I)
LLVM_ABI void runMoveInstrCallbacks(Instruction *I, const BBIterator &Where)
LLVM_ABI UnaryOperator * createUnaryOperator(llvm::UnaryOperator *I)
LLVM_ABI 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...
LLVM_ABI InvokeInst * createInvokeInst(llvm::InvokeInst *I)
LLVM_ABI Value * registerValue(std::unique_ptr< Value > &&VPtr)
Take ownership of VPtr and store it in LLVMValueToValueMap.
LLVM_ABI LandingPadInst * createLandingPadInst(llvm::LandingPadInst *I)
LLVM_ABI InsertElementInst * createInsertElementInst(llvm::InsertElementInst *IEI)
LLVM_ABI Function * createFunction(llvm::Function *F)
Create a sandboxir::Function for an existing LLVM IR F, including all blocks and instructions.
LLVM_ABI SelectInst * createSelectInst(llvm::SelectInst *SI)
LLVM_ABI ResumeInst * createResumeInst(llvm::ResumeInst *I)
LLVM_ABI void unregisterEraseInstrCallback(CallbackID ID)
MapVector< CallbackID, SetUseCallback > SetUseCallbacks
Callbacks called when a Use gets its source set.
friend class BasicBlock
Various leaf nodes.
LLVM_ABI CallbackID registerMoveInstrCallback(MoveInstrCallback CB)
Register a callback that gets called when a SandboxIR instruction is about to be moved.
LLVM_ABI UnreachableInst * createUnreachableInst(llvm::UnreachableInst *UI)
LLVM_ABI AtomicCmpXchgInst * createAtomicCmpXchgInst(llvm::AtomicCmpXchgInst *I)
LLVM_ABI void runSetUseCallbacks(const Use &U, Value *NewSrc)
LLVM_ABI CallbackID registerEraseInstrCallback(EraseInstrCallback CB)
Register a callback that gets called when a SandboxIR instruction is about to be removed from its par...
LLVM_ABI std::unique_ptr< Value > detachLLVMValue(llvm::Value *V)
Remove V from the maps and returns the unique_ptr.
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
In SandboxIR the Module is mainly used to access the list of global objects.
An LLLVM Instruction that has no SandboxIR equivalent class gets mapped to an OpaqueInstr.
bool emplaceIfTracking(ArgsT... Args)
A convenience wrapper for track() that constructs and tracks the Change object if tracking is enabled...
Represents a Def-use/Use-def edge in SandboxIR.
A SandboxIR Value has users. This is the base class.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
static constexpr int MaxRegisteredCallbacks
@ Global
Append to llvm.global_dtors.