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