LLVM 19.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());
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
154
155 for (BasicBlock *B : inverse_depth_first_ext(BB, Visited))
156 LiveBBs.insert(B);
157}
158
159/// substituteLPadValues - Substitute the values returned by the landingpad
160/// instruction with those returned by the personality function.
161void SjLjEHPrepareImpl::substituteLPadValues(LandingPadInst *LPI, Value *ExnVal,
162 Value *SelVal) {
163 SmallVector<Value *, 8> UseWorkList(LPI->users());
164 while (!UseWorkList.empty()) {
165 Value *Val = UseWorkList.pop_back_val();
166 auto *EVI = dyn_cast<ExtractValueInst>(Val);
167 if (!EVI)
168 continue;
169 if (EVI->getNumIndices() != 1)
170 continue;
171 if (*EVI->idx_begin() == 0)
172 EVI->replaceAllUsesWith(ExnVal);
173 else if (*EVI->idx_begin() == 1)
174 EVI->replaceAllUsesWith(SelVal);
175 if (EVI->use_empty())
176 EVI->eraseFromParent();
177 }
178
179 if (LPI->use_empty())
180 return;
181
182 // There are still some uses of LPI. Construct an aggregate with the exception
183 // values and replace the LPI with that aggregate.
184 Type *LPadType = LPI->getType();
185 Value *LPadVal = PoisonValue::get(LPadType);
186 auto *SelI = cast<Instruction>(SelVal);
187 IRBuilder<> Builder(SelI->getParent(), std::next(SelI->getIterator()));
188 LPadVal = Builder.CreateInsertValue(LPadVal, ExnVal, 0, "lpad.val");
189 LPadVal = Builder.CreateInsertValue(LPadVal, SelVal, 1, "lpad.val");
190
191 LPI->replaceAllUsesWith(LPadVal);
192}
193
194/// setupFunctionContext - Allocate the function context on the stack and fill
195/// it with all of the data that we know at this point.
196Value *
197SjLjEHPrepareImpl::setupFunctionContext(Function &F,
199 BasicBlock *EntryBB = &F.front();
200
201 // Create an alloca for the incoming jump buffer ptr and the new jump buffer
202 // that needs to be restored on all exits from the function. This is an alloca
203 // because the value needs to be added to the global context list.
204 auto &DL = F.getParent()->getDataLayout();
205 const Align Alignment = DL.getPrefTypeAlign(FunctionContextTy);
206 FuncCtx = new AllocaInst(FunctionContextTy, DL.getAllocaAddrSpace(), nullptr,
207 Alignment, "fn_context", &EntryBB->front());
208
209 // Fill in the function context structure.
210 for (LandingPadInst *LPI : LPads) {
211 IRBuilder<> Builder(LPI->getParent(),
213
214 // Reference the __data field.
215 Value *FCData =
216 Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 2, "__data");
217
218 // The exception values come back in context->__data[0].
219 Value *ExceptionAddr = Builder.CreateConstGEP2_32(doubleUnderDataTy, FCData,
220 0, 0, "exception_gep");
221 Value *ExnVal = Builder.CreateLoad(DataTy, ExceptionAddr, true, "exn_val");
222 ExnVal = Builder.CreateIntToPtr(ExnVal, Builder.getPtrTy());
223
224 Value *SelectorAddr = Builder.CreateConstGEP2_32(doubleUnderDataTy, FCData,
225 0, 1, "exn_selector_gep");
226 Value *SelVal =
227 Builder.CreateLoad(DataTy, SelectorAddr, true, "exn_selector_val");
228
229 // SelVal must be Int32Ty, so trunc it
230 SelVal = Builder.CreateTrunc(SelVal, Type::getInt32Ty(F.getContext()));
231
232 substituteLPadValues(LPI, ExnVal, SelVal);
233 }
234
235 // Personality function
236 IRBuilder<> Builder(EntryBB->getTerminator());
237 Value *PersonalityFn = F.getPersonalityFn();
238 Value *PersonalityFieldPtr = Builder.CreateConstGEP2_32(
239 FunctionContextTy, FuncCtx, 0, 3, "pers_fn_gep");
240 Builder.CreateStore(PersonalityFn, PersonalityFieldPtr, /*isVolatile=*/true);
241
242 // LSDA address
243 Value *LSDA = Builder.CreateCall(LSDAAddrFn, {}, "lsda_addr");
244 Value *LSDAFieldPtr =
245 Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 4, "lsda_gep");
246 Builder.CreateStore(LSDA, LSDAFieldPtr, /*isVolatile=*/true);
247
248 return FuncCtx;
249}
250
251/// lowerIncomingArguments - To avoid having to handle incoming arguments
252/// specially, we lower each arg to a copy instruction in the entry block. This
253/// ensures that the argument value itself cannot be live out of the entry
254/// block.
255void SjLjEHPrepareImpl::lowerIncomingArguments(Function &F) {
256 BasicBlock::iterator AfterAllocaInsPt = F.begin()->begin();
257 while (isa<AllocaInst>(AfterAllocaInsPt) &&
258 cast<AllocaInst>(AfterAllocaInsPt)->isStaticAlloca())
259 ++AfterAllocaInsPt;
260 assert(AfterAllocaInsPt != F.front().end());
261
262 for (auto &AI : F.args()) {
263 // Swift error really is a register that we model as memory -- instruction
264 // selection will perform mem-to-reg for us and spill/reload appropriately
265 // around calls that clobber it. There is no need to spill this
266 // value to the stack and doing so would not be allowed.
267 if (AI.isSwiftError())
268 continue;
269
270 Type *Ty = AI.getType();
271
272 // Use 'select i8 true, %arg, undef' to simulate a 'no-op' instruction.
273 Value *TrueValue = ConstantInt::getTrue(F.getContext());
276 TrueValue, &AI, UndefValue, AI.getName() + ".tmp", &*AfterAllocaInsPt);
277 AI.replaceAllUsesWith(SI);
278
279 // Reset the operand, because it was clobbered by the RAUW above.
280 SI->setOperand(1, &AI);
281 }
282}
283
284/// lowerAcrossUnwindEdges - Find all variables which are alive across an unwind
285/// edge and spill them.
286void SjLjEHPrepareImpl::lowerAcrossUnwindEdges(Function &F,
287 ArrayRef<InvokeInst *> Invokes) {
288 // Finally, scan the code looking for instructions with bad live ranges.
289 for (BasicBlock &BB : F) {
290 for (Instruction &Inst : BB) {
291 // Ignore obvious cases we don't have to handle. In particular, most
292 // instructions either have no uses or only have a single use inside the
293 // current block. Ignore them quickly.
294 if (Inst.use_empty())
295 continue;
296 if (Inst.hasOneUse() &&
297 cast<Instruction>(Inst.user_back())->getParent() == &BB &&
298 !isa<PHINode>(Inst.user_back()))
299 continue;
300
301 // If this is an alloca in the entry block, it's not a real register
302 // value.
303 if (auto *AI = dyn_cast<AllocaInst>(&Inst))
304 if (AI->isStaticAlloca())
305 continue;
306
307 // Avoid iterator invalidation by copying users to a temporary vector.
309 for (User *U : Inst.users()) {
310 Instruction *UI = cast<Instruction>(U);
311 if (UI->getParent() != &BB || isa<PHINode>(UI))
312 Users.push_back(UI);
313 }
314
315 // Find all of the blocks that this value is live in.
317 LiveBBs.insert(&BB);
318 while (!Users.empty()) {
319 Instruction *U = Users.pop_back_val();
320
321 if (!isa<PHINode>(U)) {
322 MarkBlocksLiveIn(U->getParent(), LiveBBs);
323 } else {
324 // Uses for a PHI node occur in their predecessor block.
325 PHINode *PN = cast<PHINode>(U);
326 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
327 if (PN->getIncomingValue(i) == &Inst)
328 MarkBlocksLiveIn(PN->getIncomingBlock(i), LiveBBs);
329 }
330 }
331
332 // Now that we know all of the blocks that this thing is live in, see if
333 // it includes any of the unwind locations.
334 bool NeedsSpill = false;
335 for (InvokeInst *Invoke : Invokes) {
336 BasicBlock *UnwindBlock = Invoke->getUnwindDest();
337 if (UnwindBlock != &BB && LiveBBs.count(UnwindBlock)) {
338 LLVM_DEBUG(dbgs() << "SJLJ Spill: " << Inst << " around "
339 << UnwindBlock->getName() << "\n");
340 NeedsSpill = true;
341 break;
342 }
343 }
344
345 // If we decided we need a spill, do it.
346 // FIXME: Spilling this way is overkill, as it forces all uses of
347 // the value to be reloaded from the stack slot, even those that aren't
348 // in the unwind blocks. We should be more selective.
349 if (NeedsSpill) {
350 DemoteRegToStack(Inst, true);
351 ++NumSpilled;
352 }
353 }
354 }
355
356 // Go through the landing pads and remove any PHIs there.
357 for (InvokeInst *Invoke : Invokes) {
358 BasicBlock *UnwindBlock = Invoke->getUnwindDest();
359 LandingPadInst *LPI = UnwindBlock->getLandingPadInst();
360
361 // Place PHIs into a set to avoid invalidating the iterator.
362 SmallPtrSet<PHINode *, 8> PHIsToDemote;
363 for (BasicBlock::iterator PN = UnwindBlock->begin(); isa<PHINode>(PN); ++PN)
364 PHIsToDemote.insert(cast<PHINode>(PN));
365 if (PHIsToDemote.empty())
366 continue;
367
368 // Demote the PHIs to the stack.
369 for (PHINode *PN : PHIsToDemote)
371
372 // Move the landingpad instruction back to the top of the landing pad block.
373 LPI->moveBefore(&UnwindBlock->front());
374 }
375}
376
377/// setupEntryBlockAndCallSites - Setup the entry block by creating and filling
378/// the function context and marking the call sites with the appropriate
379/// values. These values are used by the DWARF EH emitter.
380bool SjLjEHPrepareImpl::setupEntryBlockAndCallSites(Function &F) {
384
385 // Look through the terminators of the basic blocks to find invokes.
386 for (BasicBlock &BB : F)
387 if (auto *II = dyn_cast<InvokeInst>(BB.getTerminator())) {
388 if (Function *Callee = II->getCalledFunction())
389 if (Callee->getIntrinsicID() == Intrinsic::donothing) {
390 // Remove the NOP invoke.
391 BranchInst::Create(II->getNormalDest(), II);
392 II->eraseFromParent();
393 continue;
394 }
395
396 Invokes.push_back(II);
397 LPads.insert(II->getUnwindDest()->getLandingPadInst());
398 } else if (auto *RI = dyn_cast<ReturnInst>(BB.getTerminator())) {
399 Returns.push_back(RI);
400 }
401
402 if (Invokes.empty())
403 return false;
404
405 NumInvokes += Invokes.size();
406
407 lowerIncomingArguments(F);
408 lowerAcrossUnwindEdges(F, Invokes);
409
410 Value *FuncCtx =
411 setupFunctionContext(F, ArrayRef(LPads.begin(), LPads.end()));
412 BasicBlock *EntryBB = &F.front();
413 IRBuilder<> Builder(EntryBB->getTerminator());
414
415 // Get a reference to the jump buffer.
416 Value *JBufPtr =
417 Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 5, "jbuf_gep");
418
419 // Save the frame pointer.
420 Value *FramePtr = Builder.CreateConstGEP2_32(doubleUnderJBufTy, JBufPtr, 0, 0,
421 "jbuf_fp_gep");
422
423 Value *Val = Builder.CreateCall(FrameAddrFn, Builder.getInt32(0), "fp");
424 Builder.CreateStore(Val, FramePtr, /*isVolatile=*/true);
425
426 // Save the stack pointer.
427 Value *StackPtr = Builder.CreateConstGEP2_32(doubleUnderJBufTy, JBufPtr, 0, 2,
428 "jbuf_sp_gep");
429
430 Val = Builder.CreateCall(StackAddrFn, {}, "sp");
431 Builder.CreateStore(Val, StackPtr, /*isVolatile=*/true);
432
433 // Call the setup_dispatch intrinsic. It fills in the rest of the jmpbuf.
434 Builder.CreateCall(BuiltinSetupDispatchFn, {});
435
436 // Store a pointer to the function context so that the back-end will know
437 // where to look for it.
438 Builder.CreateCall(FuncCtxFn, FuncCtx);
439
440 // At this point, we are all set up, update the invoke instructions to mark
441 // their call_site values.
442 for (unsigned I = 0, E = Invokes.size(); I != E; ++I) {
443 insertCallSiteStore(Invokes[I], I + 1);
444
445 ConstantInt *CallSiteNum =
446 ConstantInt::get(Type::getInt32Ty(F.getContext()), I + 1);
447
448 // Record the call site value for the back end so it stays associated with
449 // the invoke.
450 CallInst::Create(CallSiteFn, CallSiteNum, "", Invokes[I]);
451 }
452
453 // Mark call instructions that aren't nounwind as no-action (call_site ==
454 // -1). Skip the entry block, as prior to then, no function context has been
455 // created for this function and any unexpected exceptions thrown will go
456 // directly to the caller's context, which is what we want anyway, so no need
457 // to do anything here.
458 for (BasicBlock &BB : F) {
459 if (&BB == &F.front())
460 continue;
461 for (Instruction &I : BB)
462 if (I.mayThrow())
463 insertCallSiteStore(&I, -1);
464 }
465
466 // Register the function context and make sure it's known to not throw
468 CallInst::Create(RegisterFn, FuncCtx, "", EntryBB->getTerminator());
469 Register->setDoesNotThrow();
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);
485 new StoreInst(StackAddr, StackPtr, true, StackAddr->getNextNode());
486 }
487 }
488
489 // Finally, for any returns from this function, if this function contains an
490 // invoke, add a call to unregister the function context.
491 for (ReturnInst *Return : Returns) {
492 Instruction *InsertPoint = Return;
493 if (CallInst *CI = Return->getParent()->getTerminatingMustTailCall())
494 InsertPoint = CI;
495 CallInst::Create(UnregisterFn, FuncCtx, "", InsertPoint);
496 }
497
498 return true;
499}
500
501bool SjLjEHPrepareImpl::runOnFunction(Function &F) {
502 Module &M = *F.getParent();
503 RegisterFn = M.getOrInsertFunction(
504 "_Unwind_SjLj_Register", Type::getVoidTy(M.getContext()),
505 PointerType::getUnqual(FunctionContextTy));
506 UnregisterFn = M.getOrInsertFunction(
507 "_Unwind_SjLj_Unregister", Type::getVoidTy(M.getContext()),
508 PointerType::getUnqual(FunctionContextTy));
509
510 PointerType *AllocaPtrTy = M.getDataLayout().getAllocaPtrType(M.getContext());
511
512 FrameAddrFn =
513 Intrinsic::getDeclaration(&M, Intrinsic::frameaddress, {AllocaPtrTy});
514 StackAddrFn =
515 Intrinsic::getDeclaration(&M, Intrinsic::stacksave, {AllocaPtrTy});
516 StackRestoreFn =
517 Intrinsic::getDeclaration(&M, Intrinsic::stackrestore, {AllocaPtrTy});
518 BuiltinSetupDispatchFn =
519 Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_setup_dispatch);
520 LSDAAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_lsda);
521 CallSiteFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_callsite);
522 FuncCtxFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_functioncontext);
523
524 bool Res = setupEntryBlockAndCallSites(F);
525 return Res;
526}
aarch64 promote const
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-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.
IntegerType * Int32Ty
FunctionAnalysisManager FAM
const char LLVMTargetMachineRef TM
#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:167
static const unsigned FramePtr
an instruction to allocate memory on the stack
Definition: Instructions.h:59
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:348
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:647
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:438
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
Definition: BasicBlock.cpp:719
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
Definition: BasicBlock.cpp:452
const Instruction & front() const
Definition: BasicBlock.h:461
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:173
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:229
static BranchInst * Create(BasicBlock *IfTrue, Instruction *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="", Instruction *InsertBefore=nullptr)
This is the shared class of boolean and integer constants.
Definition: Constants.h:79
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:833
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:888
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:311
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:2649
const BasicBlock * getParent() const
Definition: Instruction.h:150
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:1743
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:109
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:115
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="", Instruction *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:321
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:360
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:342
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:427
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:302
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:373
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:78
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:1336
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1724
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
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
Definition: ilist_node.h:316
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:1447
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...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
iterator_range< idf_ext_iterator< T, SetTy > > inverse_depth_first_ext(const T &G, SetTy &S)
AllocaInst * DemoteRegToStack(Instruction &X, bool VolatileLoads=false, Instruction *AllocaPoint=nullptr)
This function takes a virtual register computed by an Instruction and replaces it with a slot in the ...
AllocaInst * DemotePHIToStack(PHINode *P, Instruction *AllocaPoint=nullptr)
This function takes a virtual register computed by a phi node and replaces it with a slot in the stac...
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39