LLVM 24.0.0git
SjLjEHPrepare.cpp
Go to the documentation of this file.
1//===- SjLjEHPrepare.cpp - Eliminate Invoke & Unwind instructions ---------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This transformation is designed for use by code generators which use SjLj
10// based exception handling.
11//
12//===----------------------------------------------------------------------===//
13
15#include "llvm/ADT/SetVector.h"
18#include "llvm/ADT/Statistic.h"
19#include "llvm/CodeGen/Passes.h"
20#include "llvm/IR/Constants.h"
21#include "llvm/IR/DataLayout.h"
23#include "llvm/IR/IRBuilder.h"
25#include "llvm/IR/Intrinsics.h"
26#include "llvm/IR/Module.h"
28#include "llvm/Pass.h"
29#include "llvm/Support/Debug.h"
33using namespace llvm;
34
35#define DEBUG_TYPE "sjlj-eh-prepare"
36
37STATISTIC(NumInvokes, "Number of invokes replaced");
38STATISTIC(NumSpilled, "Number of registers live across unwind edges");
39
40namespace {
41class SjLjEHPrepareImpl {
42 IntegerType *DataTy = nullptr;
43 Type *doubleUnderDataTy = nullptr;
44 Type *doubleUnderJBufTy = nullptr;
45 Type *FunctionContextTy = nullptr;
46 FunctionCallee RegisterFn;
47 FunctionCallee UnregisterFn;
48 Function *BuiltinSetupDispatchFn = nullptr;
49 Function *FrameAddrFn = nullptr;
50 Function *StackAddrFn = nullptr;
51 Function *StackRestoreFn = nullptr;
52 Function *LSDAAddrFn = nullptr;
53 Function *CallSiteFn = nullptr;
54 Function *FuncCtxFn = nullptr;
55 AllocaInst *FuncCtx = nullptr;
56 const TargetMachine *TM = nullptr;
57
58 // The module's "exception-model" flag.
60
61public:
62 explicit SjLjEHPrepareImpl(const TargetMachine *TM = nullptr) : TM(TM) {}
63 bool doInitialization(Module &M);
65
66private:
67 bool setupEntryBlockAndCallSites(Function &F);
68 void substituteLPadValues(LandingPadInst *LPI, Value *ExnVal, Value *SelVal);
69 Value *setupFunctionContext(Function &F, ArrayRef<LandingPadInst *> LPads);
70 void lowerIncomingArguments(Function &F);
71 void lowerAcrossUnwindEdges(Function &F, ArrayRef<InvokeInst *> Invokes);
72 void insertCallSiteStore(Instruction *I, int Number);
73};
74
75class SjLjEHPrepare : public FunctionPass {
76 SjLjEHPrepareImpl Impl;
77
78public:
79 static char ID; // Pass identification, replacement for typeid
80 explicit SjLjEHPrepare(const TargetMachine *TM = nullptr)
81 : FunctionPass(ID), Impl(TM) {}
82 bool doInitialization(Module &M) override { return Impl.doInitialization(M); }
83 bool runOnFunction(Function &F) override { return Impl.runOnFunction(F); };
84
85 StringRef getPassName() const override {
86 return "SJLJ Exception Handling preparation";
87 }
88};
89
90} // end anonymous namespace
91
94 SjLjEHPrepareImpl Impl(TM);
95 Impl.doInitialization(*F.getParent());
96 bool Changed = Impl.runOnFunction(F);
98}
99
100char SjLjEHPrepare::ID = 0;
101INITIALIZE_PASS(SjLjEHPrepare, DEBUG_TYPE, "Prepare SjLj exceptions",
102 false, false)
103
104// Public Interface To the SjLjEHPrepare pass.
106 return new SjLjEHPrepare(TM);
107}
108
109// doInitialization - Set up decalarations and types needed to process
110// exceptions.
111bool SjLjEHPrepareImpl::doInitialization(Module &M) {
112 ExceptionModel = M.getExceptionModel();
113
114 // Build the function context structure.
115 // builtin_setjmp uses a five word jbuf
116 Type *VoidPtrTy = PointerType::getUnqual(M.getContext());
117 unsigned DataBits =
118 TM ? TM->getSjLjDataSize() : TargetMachine::DefaultSjLjDataSize;
119 DataTy = Type::getIntNTy(M.getContext(), DataBits);
120 doubleUnderDataTy = ArrayType::get(DataTy, 4);
121 doubleUnderJBufTy = ArrayType::get(VoidPtrTy, 5);
122 FunctionContextTy = StructType::get(VoidPtrTy, // __prev
123 DataTy, // call_site
124 doubleUnderDataTy, // __data
125 VoidPtrTy, // __personality
126 VoidPtrTy, // __lsda
127 doubleUnderJBufTy // __jbuf
128 );
129
130 return false;
131}
132
133/// insertCallSiteStore - Insert a store of the call-site value to the
134/// function context
135void SjLjEHPrepareImpl::insertCallSiteStore(Instruction *I, int Number) {
136 IRBuilder<> Builder(I);
137
138 // Get a reference to the call_site field.
139 Type *Int32Ty = Type::getInt32Ty(I->getContext());
140 Value *Zero = ConstantInt::get(Int32Ty, 0);
141 Value *One = ConstantInt::get(Int32Ty, 1);
142 Value *Idxs[2] = { Zero, One };
143 Value *CallSite =
144 Builder.CreateGEP(FunctionContextTy, FuncCtx, Idxs, "call_site");
145
146 // Insert a store of the call-site number
147 ConstantInt *CallSiteNoC = ConstantInt::getSigned(DataTy, Number);
148 Builder.CreateStore(CallSiteNoC, CallSite, true /*volatile*/);
149}
150
151/// MarkBlocksLiveIn - Insert BB and all of its predecessors into LiveBBs until
152/// we reach blocks we've already seen.
155 if (!LiveBBs.insert(BB).second)
156 return; // already been here.
157
159}
160
161/// substituteLPadValues - Substitute the values returned by the landingpad
162/// instruction with those returned by the personality function.
163void SjLjEHPrepareImpl::substituteLPadValues(LandingPadInst *LPI, Value *ExnVal,
164 Value *SelVal) {
165 SmallVector<Value *, 8> UseWorkList(LPI->users());
166 while (!UseWorkList.empty()) {
167 Value *Val = UseWorkList.pop_back_val();
168 auto *EVI = dyn_cast<ExtractValueInst>(Val);
169 if (!EVI)
170 continue;
171 if (EVI->getNumIndices() != 1)
172 continue;
173 if (*EVI->idx_begin() == 0)
174 EVI->replaceAllUsesWith(ExnVal);
175 else if (*EVI->idx_begin() == 1)
176 EVI->replaceAllUsesWith(SelVal);
177 if (EVI->use_empty())
178 EVI->eraseFromParent();
179 }
180
181 if (LPI->use_empty())
182 return;
183
184 // There are still some uses of LPI. Construct an aggregate with the exception
185 // values and replace the LPI with that aggregate.
186 Type *LPadType = LPI->getType();
187 Value *LPadVal = PoisonValue::get(LPadType);
188 auto *SelI = cast<Instruction>(SelVal);
189 IRBuilder<> Builder(std::next(SelI->getIterator()));
190 LPadVal = Builder.CreateInsertValue(LPadVal, ExnVal, 0, "lpad.val");
191 LPadVal = Builder.CreateInsertValue(LPadVal, SelVal, 1, "lpad.val");
192
193 LPI->replaceAllUsesWith(LPadVal);
194}
195
196/// setupFunctionContext - Allocate the function context on the stack and fill
197/// it with all of the data that we know at this point.
198Value *
199SjLjEHPrepareImpl::setupFunctionContext(Function &F,
201 BasicBlock *EntryBB = &F.front();
202
203 // Create an alloca for the incoming jump buffer ptr and the new jump buffer
204 // that needs to be restored on all exits from the function. This is an alloca
205 // because the value needs to be added to the global context list.
206 auto &DL = F.getDataLayout();
207 const Align Alignment = DL.getPrefTypeAlign(FunctionContextTy);
208 FuncCtx = new AllocaInst(FunctionContextTy, DL.getAllocaAddrSpace(), nullptr,
209 Alignment, "fn_context", EntryBB->begin());
210
211 // Fill in the function context structure.
212 for (LandingPadInst *LPI : LPads) {
213 IRBuilder<> Builder(LPI->getParent()->getFirstInsertionPt());
214
215 // Reference the __data field.
216 Value *FCData =
217 Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 2, "__data");
218
219 // The exception values come back in context->__data[0].
220 Value *ExceptionAddr = Builder.CreateConstGEP2_32(doubleUnderDataTy, FCData,
221 0, 0, "exception_gep");
222 Value *ExnVal = Builder.CreateLoad(DataTy, ExceptionAddr, true, "exn_val");
223 ExnVal = Builder.CreateIntToPtr(ExnVal, Builder.getPtrTy());
224
225 Value *SelectorAddr = Builder.CreateConstGEP2_32(doubleUnderDataTy, FCData,
226 0, 1, "exn_selector_gep");
227 Value *SelVal =
228 Builder.CreateLoad(DataTy, SelectorAddr, true, "exn_selector_val");
229
230 // SelVal must be Int32Ty, so trunc it
231 SelVal = Builder.CreateTrunc(SelVal, Type::getInt32Ty(F.getContext()));
232
233 substituteLPadValues(LPI, ExnVal, SelVal);
234 }
235
236 // Personality function
237 IRBuilder<> Builder(EntryBB->getTerminator());
238 Value *PersonalityFn = F.getPersonalityFn();
239 Value *PersonalityFieldPtr = Builder.CreateConstGEP2_32(
240 FunctionContextTy, FuncCtx, 0, 3, "pers_fn_gep");
241 Builder.CreateStore(PersonalityFn, PersonalityFieldPtr, /*isVolatile=*/true);
242
243 // LSDA address
244 Value *LSDA = Builder.CreateCall(LSDAAddrFn, {}, "lsda_addr");
245 Value *LSDAFieldPtr =
246 Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 4, "lsda_gep");
247 Builder.CreateStore(LSDA, LSDAFieldPtr, /*isVolatile=*/true);
248
249 return FuncCtx;
250}
251
252/// lowerIncomingArguments - To avoid having to handle incoming arguments
253/// specially, we lower each arg to a copy instruction in the entry block. This
254/// ensures that the argument value itself cannot be live out of the entry
255/// block.
256void SjLjEHPrepareImpl::lowerIncomingArguments(Function &F) {
257 BasicBlock::iterator AfterAllocaInsPt = F.begin()->begin();
258 while (isa<AllocaInst>(AfterAllocaInsPt) &&
259 cast<AllocaInst>(AfterAllocaInsPt)->isStaticAlloca())
260 ++AfterAllocaInsPt;
261 assert(AfterAllocaInsPt != F.front().end());
262
263 for (auto &AI : F.args()) {
264 // Swift error really is a register that we model as memory -- instruction
265 // selection will perform mem-to-reg for us and spill/reload appropriately
266 // around calls that clobber it. There is no need to spill this
267 // value to the stack and doing so would not be allowed.
268 if (AI.isSwiftError())
269 continue;
270
271 Type *Ty = AI.getType();
272
273 // Use 'select i8 true, %arg, poison' to simulate a 'no-op' instruction.
274 Value *TrueValue = ConstantInt::getTrue(F.getContext());
277 TrueValue, &AI, PoisonValue, AI.getName() + ".tmp", AfterAllocaInsPt);
278 AI.replaceAllUsesWith(SI);
279
280 // Reset the operand, because it was clobbered by the RAUW above.
281 SI->setOperand(1, &AI);
282 }
283}
284
285/// lowerAcrossUnwindEdges - Find all variables which are alive across an unwind
286/// edge and spill them.
287void SjLjEHPrepareImpl::lowerAcrossUnwindEdges(Function &F,
288 ArrayRef<InvokeInst *> Invokes) {
289 // Finally, scan the code looking for instructions with bad live ranges.
290 for (BasicBlock &BB : F) {
291 for (Instruction &Inst : BB) {
292 // Ignore obvious cases we don't have to handle. In particular, most
293 // instructions either have no uses or only have a single use inside the
294 // current block. Ignore them quickly.
295 if (Inst.use_empty())
296 continue;
297 if (Inst.hasOneUse() &&
298 cast<Instruction>(Inst.user_back())->getParent() == &BB &&
299 !isa<PHINode>(Inst.user_back()))
300 continue;
301
302 // If this is an alloca in the entry block, it's not a real register
303 // value.
304 if (auto *AI = dyn_cast<AllocaInst>(&Inst))
305 if (AI->isStaticAlloca())
306 continue;
307
308 // Avoid iterator invalidation by copying users to a temporary vector.
310 for (User *U : Inst.users()) {
312 if (UI->getParent() != &BB || isa<PHINode>(UI))
313 Users.push_back(UI);
314 }
315
316 // Find all of the blocks that this value is live in.
318 LiveBBs.insert(&BB);
319 while (!Users.empty()) {
320 Instruction *U = Users.pop_back_val();
321
322 if (!isa<PHINode>(U)) {
323 MarkBlocksLiveIn(U->getParent(), LiveBBs);
324 } else {
325 // Uses for a PHI node occur in their predecessor block.
326 PHINode *PN = cast<PHINode>(U);
327 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
328 if (PN->getIncomingValue(i) == &Inst)
329 MarkBlocksLiveIn(PN->getIncomingBlock(i), LiveBBs);
330 }
331 }
332
333 // Now that we know all of the blocks that this thing is live in, see if
334 // it includes any of the unwind locations.
335 bool NeedsSpill = false;
336 for (InvokeInst *Invoke : Invokes) {
337 BasicBlock *UnwindBlock = Invoke->getUnwindDest();
338 if (UnwindBlock != &BB && LiveBBs.count(UnwindBlock)) {
339 LLVM_DEBUG(dbgs() << "SJLJ Spill: " << Inst << " around "
340 << UnwindBlock->getName() << "\n");
341 NeedsSpill = true;
342 break;
343 }
344 }
345
346 // If we decided we need a spill, do it.
347 // FIXME: Spilling this way is overkill, as it forces all uses of
348 // the value to be reloaded from the stack slot, even those that aren't
349 // in the unwind blocks. We should be more selective.
350 if (NeedsSpill) {
351 DemoteRegToStack(Inst, true);
352 ++NumSpilled;
353 }
354 }
355 }
356
357 // Go through the landing pads and remove any PHIs there.
358 for (InvokeInst *Invoke : Invokes) {
359 BasicBlock *UnwindBlock = Invoke->getUnwindDest();
360 LandingPadInst *LPI = UnwindBlock->getLandingPadInst();
361
362 // Place PHIs into a set to avoid invalidating the iterator.
363 SmallPtrSet<PHINode *, 8> PHIsToDemote;
364 for (BasicBlock::iterator PN = UnwindBlock->begin(); isa<PHINode>(PN); ++PN)
365 PHIsToDemote.insert(cast<PHINode>(PN));
366 if (PHIsToDemote.empty())
367 continue;
368
369 // Demote the PHIs to the stack.
370 for (PHINode *PN : PHIsToDemote)
372
373 // Move the landingpad instruction back to the top of the landing pad block.
374 LPI->moveBefore(UnwindBlock->begin());
375 }
376}
377
378/// setupEntryBlockAndCallSites - Setup the entry block by creating and filling
379/// the function context and marking the call sites with the appropriate
380/// values. These values are used by the DWARF EH emitter.
381bool SjLjEHPrepareImpl::setupEntryBlockAndCallSites(Function &F) {
385
386 // Look through the terminators of the basic blocks to find invokes.
387 for (BasicBlock &BB : F)
388 if (auto *II = dyn_cast<InvokeInst>(BB.getTerminator())) {
389 if (Function *Callee = II->getCalledFunction())
390 if (Callee->getIntrinsicID() == Intrinsic::donothing) {
391 // Remove the NOP invoke.
392 UncondBrInst::Create(II->getNormalDest(), II->getIterator());
393 II->eraseFromParent();
394 continue;
395 }
396
397 Invokes.push_back(II);
398 LPads.insert(II->getUnwindDest()->getLandingPadInst());
399 } else if (auto *RI = dyn_cast<ReturnInst>(BB.getTerminator())) {
400 Returns.push_back(RI);
401 }
402
403 if (Invokes.empty())
404 return false;
405
406 NumInvokes += Invokes.size();
407
408 lowerIncomingArguments(F);
409 lowerAcrossUnwindEdges(F, Invokes);
410
411 Value *FuncCtx =
412 setupFunctionContext(F, ArrayRef(LPads.begin(), LPads.end()));
413 BasicBlock *EntryBB = &F.front();
414 IRBuilder<> Builder(EntryBB->getTerminator());
415
416 // Get a reference to the jump buffer.
417 Value *JBufPtr =
418 Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 5, "jbuf_gep");
419
420 // Save the frame pointer.
421 Value *FramePtr = Builder.CreateConstGEP2_32(doubleUnderJBufTy, JBufPtr, 0, 0,
422 "jbuf_fp_gep");
423
424 Value *Val = Builder.CreateCall(FrameAddrFn, Builder.getInt32(0), "fp");
425 Builder.CreateStore(Val, FramePtr, /*isVolatile=*/true);
426
427 // Save the stack pointer.
428 Value *StackPtr = Builder.CreateConstGEP2_32(doubleUnderJBufTy, JBufPtr, 0, 2,
429 "jbuf_sp_gep");
430
431 Val = Builder.CreateCall(StackAddrFn, {}, "sp");
432 Builder.CreateStore(Val, StackPtr, /*isVolatile=*/true);
433
434 // Call the setup_dispatch intrinsic. It fills in the rest of the jmpbuf.
435 Builder.CreateCall(BuiltinSetupDispatchFn, {});
436
437 // Store a pointer to the function context so that the back-end will know
438 // where to look for it.
439 Builder.CreateCall(FuncCtxFn, FuncCtx);
440
441 // Register the function context and make sure it's known to not throw.
442 CallInst *Register = Builder.CreateCall(RegisterFn, FuncCtx, "");
443 Register->setDoesNotThrow();
444
445 // At this point, we are all set up, update the invoke instructions to mark
446 // their call_site values.
447 for (unsigned I = 0, E = Invokes.size(); I != E; ++I) {
448 insertCallSiteStore(Invokes[I], I + 1);
449
450 ConstantInt *CallSiteNum =
451 ConstantInt::get(Type::getInt32Ty(F.getContext()), I + 1);
452
453 // Record the call site value for the back end so it stays associated with
454 // the invoke.
455 CallInst::Create(CallSiteFn, CallSiteNum, "", Invokes[I]->getIterator());
456 }
457
458 // Mark call instructions that aren't nounwind as no-action (call_site ==
459 // -1). Skip the entry block, as prior to then, no function context has been
460 // created for this function and any unexpected exceptions thrown will go
461 // directly to the caller's context, which is what we want anyway, so no need
462 // to do anything here.
463 for (BasicBlock &BB : F) {
464 if (&BB == &F.front())
465 continue;
466 for (Instruction &I : BB)
467 if (!isa<InvokeInst>(I) && I.mayThrow())
468 insertCallSiteStore(&I, -1);
469 }
470
471 // Following any allocas not in the entry block, update the saved SP in the
472 // jmpbuf to the new value.
473 for (BasicBlock &BB : F) {
474 if (&BB == &F.front())
475 continue;
476 for (Instruction &I : BB) {
477 if (auto *CI = dyn_cast<CallInst>(&I)) {
478 if (CI->getCalledFunction() != StackRestoreFn)
479 continue;
480 } else if (!isa<AllocaInst>(&I)) {
481 continue;
482 }
483 Instruction *StackAddr = CallInst::Create(StackAddrFn, "sp");
484 StackAddr->insertAfter(I.getIterator());
485 new StoreInst(StackAddr, StackPtr, true,
486 std::next(StackAddr->getIterator()));
487 }
488 }
489
490 // Finally, for any returns from this function, if this function contains an
491 // invoke, add a call to unregister the function context.
492 for (ReturnInst *Return : Returns) {
494 if (CallInst *CI = Return->getParent()->getTerminatingMustTailCall())
495 InsertPoint = CI;
496 CallInst::Create(UnregisterFn, FuncCtx, "", InsertPoint->getIterator());
497 }
498
499 return true;
500}
501
502bool SjLjEHPrepareImpl::runOnFunction(Function &F) {
503 if (ExceptionModel != ExceptionHandling::SjLj &&
504 ExceptionModel != ExceptionHandling::Default)
505 return false;
506
507 Module &M = *F.getParent();
508 RegisterFn = M.getOrInsertFunction(
509 "_Unwind_SjLj_Register", Type::getVoidTy(M.getContext()),
510 PointerType::getUnqual(FunctionContextTy->getContext()));
511 UnregisterFn = M.getOrInsertFunction(
512 "_Unwind_SjLj_Unregister", Type::getVoidTy(M.getContext()),
513 PointerType::getUnqual(FunctionContextTy->getContext()));
514
515 PointerType *AllocaPtrTy = M.getDataLayout().getAllocaPtrType(M.getContext());
516
517 FrameAddrFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::frameaddress,
518 {AllocaPtrTy});
519 StackAddrFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::stacksave,
520 {AllocaPtrTy});
521 StackRestoreFn = Intrinsic::getOrInsertDeclaration(
522 &M, Intrinsic::stackrestore, {AllocaPtrTy});
523 BuiltinSetupDispatchFn =
524 Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_setup_dispatch);
525 LSDAAddrFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_lsda);
526 CallSiteFn =
527 Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_callsite);
528 FuncCtxFn =
529 Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_functioncontext);
530
531 bool Res = setupEntryBlockAndCallSites(F);
532 return Res;
533}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool runOnFunction(Function &F, bool PostInlining)
#define DEBUG_TYPE
Module.h This file contains the declarations for the Module class.
iv Induction Variable Users
Definition IVUsers.cpp:48
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
uint64_t IntrinsicInst * II
FunctionAnalysisManager FAM
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
This file implements a set that has insertion order iteration characteristics.
static void MarkBlocksLiveIn(BasicBlock *BB, SmallPtrSetImpl< BasicBlock * > &LiveBBs)
MarkBlocksLiveIn - Insert BB and all of its predecessors into LiveBBs until we reach blocks we've alr...
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
#define LLVM_DEBUG(...)
Definition Debug.h:119
static const unsigned FramePtr
an instruction to allocate memory on the stack
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
iterator begin()
Instruction iterator methods.
Definition BasicBlock.h:446
LLVM_ABI const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
const Instruction & front() const
Definition BasicBlock.h:469
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:170
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Definition BasicBlock.h:237
This class represents a function call, abstracting a target machine's calling convention.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
This is the shared class of boolean and integer constants.
Definition Constants.h:87
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
static ConstantInt * getSigned(IntegerType *Ty, int64_t V, bool ImplicitTrunc=false)
Return a ConstantInt with the specified value for the specified type.
Definition Constants.h:135
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2918
LLVM_ABI void moveBefore(InstListType::iterator InsertPos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
iterator_range< user_iterator > users()
LLVM_ABI void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction.
Class to represent integer types.
Invoke instruction.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
Class to represent pointers.
static PointerType * getUnqual(LLVMContext &C)
This constructs an opaque pointer to an object in the default address space (address space zero).
In order to facilitate speculative execution, many instructions do not invoke immediate undefined beh...
Definition Constants.h:1705
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition Analysis.h:115
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Return a value (possibly void), from a function.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", InsertPosition InsertBefore=nullptr, const Instruction *MDFrom=nullptr)
iterator end()
Get an iterator to the end of the SetVector.
Definition SetVector.h:118
iterator begin()
Get an iterator to the beginning of the SetVector.
Definition SetVector.h:112
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition SetVector.h:157
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
void insert_range(Range &&R)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
Definition SetVector.h:345
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition Type.cpp:467
Primary interface to the complete machine description for the target machine.
static constexpr unsigned DefaultSjLjDataSize
The integer bit size to use for SjLj based exception handling.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:299
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:272
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:303
static UncondBrInst * Create(BasicBlock *Target, InsertPosition InsertBefore=nullptr)
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition Value.cpp:553
iterator_range< user_iterator > users()
Definition Value.h:428
bool use_empty() const
Definition Value.h:348
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:319
const ParentTy * getParent() const
Definition ilist_node.h:34
self_iterator getIterator()
Definition ilist_node.h:123
Changed
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > OverloadTys={})
Look up the Function declaration of the intrinsic id in the Module M.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
LLVM_ABI AllocaInst * DemoteRegToStack(Instruction &X, bool VolatileLoads=false, std::optional< BasicBlock::iterator > AllocaPoint=std::nullopt)
This function takes a virtual register computed by an Instruction and replaces it with a slot in the ...
LLVM_ABI AllocaInst * DemotePHIToStack(PHINode *P, std::optional< BasicBlock::iterator > AllocaPoint=std::nullopt)
This function takes a virtual register computed by a phi node and replaces it with a slot in the stac...
iterator_range< idf_iterator< T > > inverse_depth_first(const T &G)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI FunctionPass * createSjLjEHPreparePass(const TargetMachine *TM)
createSjLjEHPreparePass - This pass adapts exception handling code to use the GCC-style builtin setjm...
ExceptionHandling
Definition CodeGen.h:54
@ SjLj
setjmp/longjmp based exceptions
Definition CodeGen.h:58
@ Default
Not specified; resolve to the target's default model.
Definition CodeGen.h:55
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39