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"
32using namespace llvm;
33
34#define DEBUG_TYPE "sjlj-eh-prepare"
35
36STATISTIC(NumInvokes, "Number of invokes replaced");
37STATISTIC(NumSpilled, "Number of registers live across unwind edges");
38
39namespace {
40class SjLjEHPrepareImpl {
41 IntegerType *DataTy = nullptr;
42 Type *doubleUnderDataTy = nullptr;
43 Type *doubleUnderJBufTy = nullptr;
44 StructType *FunctionContextTy = nullptr;
45 FunctionCallee RegisterFn;
46 FunctionCallee UnregisterFn;
47 Function *BuiltinSetupDispatchFn = nullptr;
48 Function *FrameAddrFn = nullptr;
49 Function *StackAddrFn = nullptr;
50 Function *StackRestoreFn = nullptr;
51 Function *LSDAAddrFn = nullptr;
52 Function *CallSiteFn = nullptr;
53 Function *FuncCtxFn = nullptr;
54 AllocaInst *FuncCtx = nullptr;
55
56 // The module's "exception-model" flag.
58
59public:
60 bool doInitialization(Module &M);
62
63private:
64 bool setupEntryBlockAndCallSites(Function &F);
65 void substituteLPadValues(LandingPadInst *LPI, Value *ExnVal, Value *SelVal);
66 Value *setupFunctionContext(Function &F, ArrayRef<LandingPadInst *> LPads);
67 void lowerIncomingArguments(Function &F);
68 void lowerAcrossUnwindEdges(Function &F, ArrayRef<InvokeInst *> Invokes);
69 void insertCallSiteStore(Instruction *I, int Number);
70};
71
72class SjLjEHPrepare : public FunctionPass {
73 SjLjEHPrepareImpl Impl;
74
75public:
76 static char ID; // Pass identification, replacement for typeid
77 SjLjEHPrepare() : FunctionPass(ID) {}
78 bool doInitialization(Module &M) override { return Impl.doInitialization(M); }
79 bool runOnFunction(Function &F) override { return Impl.runOnFunction(F); };
80
81 StringRef getPassName() const override {
82 return "SJLJ Exception Handling preparation";
83 }
84};
85
86} // end anonymous namespace
87
90 SjLjEHPrepareImpl Impl;
91 Impl.doInitialization(*F.getParent());
92 bool Changed = Impl.runOnFunction(F);
94}
95
96char SjLjEHPrepare::ID = 0;
97INITIALIZE_PASS(SjLjEHPrepare, DEBUG_TYPE, "Prepare SjLj exceptions",
98 false, false)
99
100// Public Interface To the SjLjEHPrepare pass.
101FunctionPass *llvm::createSjLjEHPreparePass() { return new SjLjEHPrepare(); }
102
104 LLVMContext &Ctx = M.getContext();
105 unsigned DataBits = M.getTargetTriple().getArchPointerBitWidth();
106 if (DataBits == 0)
107 DataBits = M.getDataLayout().getPointerSizeInBits();
108 Type *DataTy = Type::getIntNTy(Ctx, DataBits);
109 // builtin_setjmp uses a five word jbuf
110 Type *VoidPtrTy = PointerType::getUnqual(Ctx);
111 return StructType::get(VoidPtrTy, // __prev
112 Type::getInt32Ty(Ctx), // call_site
113 ArrayType::get(DataTy, 4), // __data
114 VoidPtrTy, // __personality
115 VoidPtrTy, // __lsda
116 ArrayType::get(VoidPtrTy, 5) // __jbuf
117 );
118}
119
120// doInitialization - Set up decalarations and types needed to process
121// exceptions.
122bool SjLjEHPrepareImpl::doInitialization(Module &M) {
123 ExceptionModel = M.getExceptionModel();
124
125 FunctionContextTy = getSjLjFunctionContextType(M);
126 doubleUnderDataTy = FunctionContextTy->getElementType(2);
127 doubleUnderJBufTy = FunctionContextTy->getElementType(5);
128 DataTy = cast<IntegerType>(doubleUnderDataTy->getArrayElementType());
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 Builder.disableGEPCanonicalization();
138
139 // Get a reference to the call_site field.
140 Type *Int32Ty = Type::getInt32Ty(I->getContext());
141 Value *Zero = ConstantInt::get(Int32Ty, 0);
142 Value *One = ConstantInt::get(Int32Ty, 1);
143 Value *Idxs[2] = { Zero, One };
144 Value *CallSite =
145 Builder.CreateGEP(FunctionContextTy, FuncCtx, Idxs, "call_site");
146
147 // Insert a store of the call-site number
148 ConstantInt *CallSiteNoC = Builder.getInt32(Number);
149 Builder.CreateStore(CallSiteNoC, CallSite, true /*volatile*/);
150}
151
152/// MarkBlocksLiveIn - Insert BB and all of its predecessors into LiveBBs until
153/// we reach blocks we've already seen.
156 if (!LiveBBs.insert(BB).second)
157 return; // already been here.
158
160}
161
162/// substituteLPadValues - Substitute the values returned by the landingpad
163/// instruction with those returned by the personality function.
164void SjLjEHPrepareImpl::substituteLPadValues(LandingPadInst *LPI, Value *ExnVal,
165 Value *SelVal) {
166 SmallVector<Value *, 8> UseWorkList(LPI->users());
167 while (!UseWorkList.empty()) {
168 Value *Val = UseWorkList.pop_back_val();
169 auto *EVI = dyn_cast<ExtractValueInst>(Val);
170 if (!EVI)
171 continue;
172 if (EVI->getNumIndices() != 1)
173 continue;
174 if (*EVI->idx_begin() == 0)
175 EVI->replaceAllUsesWith(ExnVal);
176 else if (*EVI->idx_begin() == 1)
177 EVI->replaceAllUsesWith(SelVal);
178 if (EVI->use_empty())
179 EVI->eraseFromParent();
180 }
181
182 if (LPI->use_empty())
183 return;
184
185 // There are still some uses of LPI. Construct an aggregate with the exception
186 // values and replace the LPI with that aggregate.
187 Type *LPadType = LPI->getType();
188 Value *LPadVal = PoisonValue::get(LPadType);
189 auto *SelI = cast<Instruction>(SelVal);
190 IRBuilder<> Builder(std::next(SelI->getIterator()));
191 LPadVal = Builder.CreateInsertValue(LPadVal, ExnVal, 0, "lpad.val");
192 LPadVal = Builder.CreateInsertValue(LPadVal, SelVal, 1, "lpad.val");
193
194 LPI->replaceAllUsesWith(LPadVal);
195}
196
197/// setupFunctionContext - Allocate the function context on the stack and fill
198/// it with all of the data that we know at this point.
199Value *
200SjLjEHPrepareImpl::setupFunctionContext(Function &F,
202 BasicBlock *EntryBB = &F.front();
203
204 // Create an alloca for the incoming jump buffer ptr and the new jump buffer
205 // that needs to be restored on all exits from the function. This is an alloca
206 // because the value needs to be added to the global context list.
207 auto &DL = F.getDataLayout();
208 const Align Alignment = DL.getPrefTypeAlign(FunctionContextTy);
209 FuncCtx = new AllocaInst(FunctionContextTy, DL.getAllocaAddrSpace(), nullptr,
210 Alignment, "fn_context", EntryBB->begin());
211
212 // Fill in the function context structure.
213 for (LandingPadInst *LPI : LPads) {
214 IRBuilder<> Builder(LPI->getParent()->getFirstInsertionPt());
215 Builder.disableGEPCanonicalization();
216
217 // Reference the __data field.
218 Value *FCData =
219 Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 2, "__data");
220
221 // The exception values come back in context->__data[0].
222 Value *ExceptionAddr = Builder.CreateConstGEP2_32(doubleUnderDataTy, FCData,
223 0, 0, "exception_gep");
224 Value *ExnVal = Builder.CreateLoad(DataTy, ExceptionAddr, true, "exn_val");
225 ExnVal = Builder.CreateIntToPtr(ExnVal, Builder.getPtrTy());
226
227 Value *SelectorAddr = Builder.CreateConstGEP2_32(doubleUnderDataTy, FCData,
228 0, 1, "exn_selector_gep");
229 Value *SelVal =
230 Builder.CreateLoad(DataTy, SelectorAddr, true, "exn_selector_val");
231
232 // SelVal must be Int32Ty, so trunc it
233 SelVal = Builder.CreateTrunc(SelVal, Type::getInt32Ty(F.getContext()));
234
235 substituteLPadValues(LPI, ExnVal, SelVal);
236 }
237
238 // Personality function
239 IRBuilder<> Builder(EntryBB->getTerminator());
240 Builder.disableGEPCanonicalization();
241 Value *PersonalityFn = F.getPersonalityFn();
242 Value *PersonalityFieldPtr = Builder.CreateConstGEP2_32(
243 FunctionContextTy, FuncCtx, 0, 3, "pers_fn_gep");
244 Builder.CreateStore(PersonalityFn, PersonalityFieldPtr, /*isVolatile=*/true);
245
246 // LSDA address
247 Value *LSDA = Builder.CreateCall(LSDAAddrFn, {}, "lsda_addr");
248 Value *LSDAFieldPtr =
249 Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 4, "lsda_gep");
250 Builder.CreateStore(LSDA, LSDAFieldPtr, /*isVolatile=*/true);
251
252 return FuncCtx;
253}
254
255/// lowerIncomingArguments - To avoid having to handle incoming arguments
256/// specially, we lower each arg to a copy instruction in the entry block. This
257/// ensures that the argument value itself cannot be live out of the entry
258/// block.
259void SjLjEHPrepareImpl::lowerIncomingArguments(Function &F) {
260 BasicBlock::iterator AfterAllocaInsPt = F.begin()->begin();
261 while (isa<AllocaInst>(AfterAllocaInsPt) &&
262 cast<AllocaInst>(AfterAllocaInsPt)->isStaticAlloca())
263 ++AfterAllocaInsPt;
264 assert(AfterAllocaInsPt != F.front().end());
265
266 for (auto &AI : F.args()) {
267 // Swift error really is a register that we model as memory -- instruction
268 // selection will perform mem-to-reg for us and spill/reload appropriately
269 // around calls that clobber it. There is no need to spill this
270 // value to the stack and doing so would not be allowed.
271 if (AI.isSwiftError())
272 continue;
273
274 Type *Ty = AI.getType();
275
276 // Use 'select i8 true, %arg, poison' to simulate a 'no-op' instruction.
277 Value *TrueValue = ConstantInt::getTrue(F.getContext());
280 TrueValue, &AI, PoisonValue, AI.getName() + ".tmp", AfterAllocaInsPt);
281 AI.replaceAllUsesWith(SI);
282
283 // Reset the operand, because it was clobbered by the RAUW above.
284 SI->setOperand(1, &AI);
285 }
286}
287
288/// lowerAcrossUnwindEdges - Find all variables which are alive across an unwind
289/// edge and spill them.
290void SjLjEHPrepareImpl::lowerAcrossUnwindEdges(Function &F,
291 ArrayRef<InvokeInst *> Invokes) {
292 // Finally, scan the code looking for instructions with bad live ranges.
293 for (BasicBlock &BB : F) {
294 for (Instruction &Inst : BB) {
295 // Ignore obvious cases we don't have to handle. In particular, most
296 // instructions either have no uses or only have a single use inside the
297 // current block. Ignore them quickly.
298 if (Inst.use_empty())
299 continue;
300 if (Inst.hasOneUse() &&
301 cast<Instruction>(Inst.user_back())->getParent() == &BB &&
302 !isa<PHINode>(Inst.user_back()))
303 continue;
304
305 // If this is an alloca in the entry block, it's not a real register
306 // value.
307 if (auto *AI = dyn_cast<AllocaInst>(&Inst))
308 if (AI->isStaticAlloca())
309 continue;
310
311 // Avoid iterator invalidation by copying users to a temporary vector.
313 for (User *U : Inst.users()) {
315 if (UI->getParent() != &BB || isa<PHINode>(UI))
316 Users.push_back(UI);
317 }
318
319 // Find all of the blocks that this value is live in.
321 LiveBBs.insert(&BB);
322 while (!Users.empty()) {
323 Instruction *U = Users.pop_back_val();
324
325 if (!isa<PHINode>(U)) {
326 MarkBlocksLiveIn(U->getParent(), LiveBBs);
327 } else {
328 // Uses for a PHI node occur in their predecessor block.
329 PHINode *PN = cast<PHINode>(U);
330 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
331 if (PN->getIncomingValue(i) == &Inst)
332 MarkBlocksLiveIn(PN->getIncomingBlock(i), LiveBBs);
333 }
334 }
335
336 // Now that we know all of the blocks that this thing is live in, see if
337 // it includes any of the unwind locations.
338 bool NeedsSpill = false;
339 for (InvokeInst *Invoke : Invokes) {
340 BasicBlock *UnwindBlock = Invoke->getUnwindDest();
341 if (UnwindBlock != &BB && LiveBBs.count(UnwindBlock)) {
342 LLVM_DEBUG(dbgs() << "SJLJ Spill: " << Inst << " around "
343 << UnwindBlock->getName() << "\n");
344 NeedsSpill = true;
345 break;
346 }
347 }
348
349 // If we decided we need a spill, do it.
350 // FIXME: Spilling this way is overkill, as it forces all uses of
351 // the value to be reloaded from the stack slot, even those that aren't
352 // in the unwind blocks. We should be more selective.
353 if (NeedsSpill) {
354 DemoteRegToStack(Inst, true);
355 ++NumSpilled;
356 }
357 }
358 }
359
360 // Go through the landing pads and remove any PHIs there.
361 for (InvokeInst *Invoke : Invokes) {
362 BasicBlock *UnwindBlock = Invoke->getUnwindDest();
363 LandingPadInst *LPI = UnwindBlock->getLandingPadInst();
364
365 // Place PHIs into a set to avoid invalidating the iterator.
366 SmallPtrSet<PHINode *, 8> PHIsToDemote;
367 for (BasicBlock::iterator PN = UnwindBlock->begin(); isa<PHINode>(PN); ++PN)
368 PHIsToDemote.insert(cast<PHINode>(PN));
369 if (PHIsToDemote.empty())
370 continue;
371
372 // Demote the PHIs to the stack.
373 for (PHINode *PN : PHIsToDemote)
375
376 // Move the landingpad instruction back to the top of the landing pad block.
377 LPI->moveBefore(UnwindBlock->begin());
378 }
379}
380
381/// setupEntryBlockAndCallSites - Setup the entry block by creating and filling
382/// the function context and marking the call sites with the appropriate
383/// values. These values are used by the DWARF EH emitter.
384bool SjLjEHPrepareImpl::setupEntryBlockAndCallSites(Function &F) {
388
389 // Look through the terminators of the basic blocks to find invokes.
390 for (BasicBlock &BB : F)
391 if (auto *II = dyn_cast<InvokeInst>(BB.getTerminator())) {
392 if (Function *Callee = II->getCalledFunction())
393 if (Callee->getIntrinsicID() == Intrinsic::donothing) {
394 // Remove the NOP invoke.
395 UncondBrInst::Create(II->getNormalDest(), II->getIterator());
396 II->eraseFromParent();
397 continue;
398 }
399
400 Invokes.push_back(II);
401 LPads.insert(II->getUnwindDest()->getLandingPadInst());
402 } else if (auto *RI = dyn_cast<ReturnInst>(BB.getTerminator())) {
403 Returns.push_back(RI);
404 }
405
406 if (Invokes.empty())
407 return false;
408
409 NumInvokes += Invokes.size();
410
411 lowerIncomingArguments(F);
412 lowerAcrossUnwindEdges(F, Invokes);
413
414 Value *FuncCtx =
415 setupFunctionContext(F, ArrayRef(LPads.begin(), LPads.end()));
416 BasicBlock *EntryBB = &F.front();
417 IRBuilder<> Builder(EntryBB->getTerminator());
418 Builder.disableGEPCanonicalization();
419
420 // Get a reference to the jump buffer.
421 Value *JBufPtr =
422 Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 5, "jbuf_gep");
423
424 // Save the frame pointer.
425 Value *FramePtr = Builder.CreateConstGEP2_32(doubleUnderJBufTy, JBufPtr, 0, 0,
426 "jbuf_fp_gep");
427
428 Value *Val = Builder.CreateCall(FrameAddrFn, Builder.getInt32(0), "fp");
429 Builder.CreateStore(Val, FramePtr, /*isVolatile=*/true);
430
431 // Save the stack pointer.
432 Value *StackPtr = Builder.CreateConstGEP2_32(doubleUnderJBufTy, JBufPtr, 0, 2,
433 "jbuf_sp_gep");
434
435 Val = Builder.CreateCall(StackAddrFn, {}, "sp");
436 Builder.CreateStore(Val, StackPtr, /*isVolatile=*/true);
437
438 // Call the setup_dispatch intrinsic. It fills in the rest of the jmpbuf.
439 Builder.CreateCall(BuiltinSetupDispatchFn, {});
440
441 // Store a pointer to the function context so that the back-end will know
442 // where to look for it.
443 Builder.CreateCall(FuncCtxFn, FuncCtx);
444
445 // Register the function context and make sure it's known to not throw.
446 CallInst *Register = Builder.CreateCall(RegisterFn, FuncCtx, "");
447 Register->setDoesNotThrow();
448
449 // At this point, we are all set up, update the invoke instructions to mark
450 // their call_site values.
451 for (unsigned I = 0, E = Invokes.size(); I != E; ++I) {
452 insertCallSiteStore(Invokes[I], I + 1);
453
454 ConstantInt *CallSiteNum =
455 ConstantInt::get(Type::getInt32Ty(F.getContext()), I + 1);
456
457 // Record the call site value for the back end so it stays associated with
458 // the invoke.
459 CallInst::Create(CallSiteFn, CallSiteNum, "", Invokes[I]->getIterator());
460 }
461
462 // Mark call instructions that aren't nounwind as no-action (call_site ==
463 // -1). Skip the entry block, as prior to then, no function context has been
464 // created for this function and any unexpected exceptions thrown will go
465 // directly to the caller's context, which is what we want anyway, so no need
466 // to do anything here.
467 for (BasicBlock &BB : F) {
468 if (&BB == &F.front())
469 continue;
470 for (Instruction &I : BB)
471 if (!isa<InvokeInst>(I) && I.mayThrow())
472 insertCallSiteStore(&I, -1);
473 }
474
475 // Following any allocas not in the entry block, update the saved SP in the
476 // jmpbuf to the new value.
477 for (BasicBlock &BB : F) {
478 if (&BB == &F.front())
479 continue;
480 for (Instruction &I : BB) {
481 if (auto *CI = dyn_cast<CallInst>(&I)) {
482 if (CI->getCalledFunction() != StackRestoreFn)
483 continue;
484 } else if (!isa<AllocaInst>(&I)) {
485 continue;
486 }
487 Instruction *StackAddr = CallInst::Create(StackAddrFn, "sp");
488 StackAddr->insertAfter(I.getIterator());
489 new StoreInst(StackAddr, StackPtr, true,
490 std::next(StackAddr->getIterator()));
491 }
492 }
493
494 // Finally, for any returns from this function, if this function contains an
495 // invoke, add a call to unregister the function context.
496 for (ReturnInst *Return : Returns) {
498 if (CallInst *CI = Return->getParent()->getTerminatingMustTailCall())
499 InsertPoint = CI;
500 CallInst::Create(UnregisterFn, FuncCtx, "", InsertPoint->getIterator());
501 }
502
503 return true;
504}
505
506bool SjLjEHPrepareImpl::runOnFunction(Function &F) {
507 if (ExceptionModel != ExceptionHandling::SjLj)
508 return false;
509
510 Module &M = *F.getParent();
511 RegisterFn = M.getOrInsertFunction(
512 "_Unwind_SjLj_Register", Type::getVoidTy(M.getContext()),
513 PointerType::getUnqual(FunctionContextTy->getContext()));
514 UnregisterFn = M.getOrInsertFunction(
515 "_Unwind_SjLj_Unregister", Type::getVoidTy(M.getContext()),
516 PointerType::getUnqual(FunctionContextTy->getContext()));
517
518 PointerType *AllocaPtrTy = M.getDataLayout().getAllocaPtrType(M.getContext());
519
520 FrameAddrFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::frameaddress,
521 {AllocaPtrTy});
522 StackAddrFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::stacksave,
523 {AllocaPtrTy});
524 StackRestoreFn = Intrinsic::getOrInsertDeclaration(
525 &M, Intrinsic::stackrestore, {AllocaPtrTy});
526 BuiltinSetupDispatchFn =
527 Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_setup_dispatch);
528 LSDAAddrFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_lsda);
529 CallSiteFn =
530 Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_callsite);
531 FuncCtxFn =
532 Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_functioncontext);
533
534 bool Res = setupEntryBlockAndCallSites(F);
535 return Res;
536}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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:440
LLVM_ABI const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
const Instruction & front() const
Definition BasicBlock.h:463
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)
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:312
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2990
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.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
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:346
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.
Class to represent struct types.
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
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:548
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:314
const ParentTy * getParent() const
Definition ilist_node.h:34
self_iterator getIterator()
Definition ilist_node.h:123
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.
LLVM_ABI StructType * getSjLjFunctionContextType(const Module &M)
Returns the type of the function context registered with the SjLj unwinder, laid out like libgcc's Sj...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
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...
LLVM_ABI FunctionPass * createSjLjEHPreparePass()
createSjLjEHPreparePass - This pass adapts exception handling code to use the GCC-style builtin setjm...
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 >
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