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(SelI->getParent(), 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(),
214 LPI->getParent()->getFirstInsertionPt());
215
216 // Reference the __data field.
217 Value *FCData =
218 Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 2, "__data");
219
220 // The exception values come back in context->__data[0].
221 Value *ExceptionAddr = Builder.CreateConstGEP2_32(doubleUnderDataTy, FCData,
222 0, 0, "exception_gep");
223 Value *ExnVal = Builder.CreateLoad(DataTy, ExceptionAddr, true, "exn_val");
224 ExnVal = Builder.CreateIntToPtr(ExnVal, Builder.getPtrTy());
225
226 Value *SelectorAddr = Builder.CreateConstGEP2_32(doubleUnderDataTy, FCData,
227 0, 1, "exn_selector_gep");
228 Value *SelVal =
229 Builder.CreateLoad(DataTy, SelectorAddr, true, "exn_selector_val");
230
231 // SelVal must be Int32Ty, so trunc it
232 SelVal = Builder.CreateTrunc(SelVal, Type::getInt32Ty(F.getContext()));
233
234 substituteLPadValues(LPI, ExnVal, SelVal);
235 }
236
237 // Personality function
238 IRBuilder<> Builder(EntryBB->getTerminator());
239 Value *PersonalityFn = F.getPersonalityFn();
240 Value *PersonalityFieldPtr = Builder.CreateConstGEP2_32(
241 FunctionContextTy, FuncCtx, 0, 3, "pers_fn_gep");
242 Builder.CreateStore(PersonalityFn, PersonalityFieldPtr, /*isVolatile=*/true);
243
244 // LSDA address
245 Value *LSDA = Builder.CreateCall(LSDAAddrFn, {}, "lsda_addr");
246 Value *LSDAFieldPtr =
247 Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 4, "lsda_gep");
248 Builder.CreateStore(LSDA, LSDAFieldPtr, /*isVolatile=*/true);
249
250 return FuncCtx;
251}
252
253/// lowerIncomingArguments - To avoid having to handle incoming arguments
254/// specially, we lower each arg to a copy instruction in the entry block. This
255/// ensures that the argument value itself cannot be live out of the entry
256/// block.
257void SjLjEHPrepareImpl::lowerIncomingArguments(Function &F) {
258 BasicBlock::iterator AfterAllocaInsPt = F.begin()->begin();
259 while (isa<AllocaInst>(AfterAllocaInsPt) &&
260 cast<AllocaInst>(AfterAllocaInsPt)->isStaticAlloca())
261 ++AfterAllocaInsPt;
262 assert(AfterAllocaInsPt != F.front().end());
263
264 for (auto &AI : F.args()) {
265 // Swift error really is a register that we model as memory -- instruction
266 // selection will perform mem-to-reg for us and spill/reload appropriately
267 // around calls that clobber it. There is no need to spill this
268 // value to the stack and doing so would not be allowed.
269 if (AI.isSwiftError())
270 continue;
271
272 Type *Ty = AI.getType();
273
274 // Use 'select i8 true, %arg, poison' to simulate a 'no-op' instruction.
275 Value *TrueValue = ConstantInt::getTrue(F.getContext());
278 TrueValue, &AI, PoisonValue, AI.getName() + ".tmp", AfterAllocaInsPt);
279 AI.replaceAllUsesWith(SI);
280
281 // Reset the operand, because it was clobbered by the RAUW above.
282 SI->setOperand(1, &AI);
283 }
284}
285
286/// lowerAcrossUnwindEdges - Find all variables which are alive across an unwind
287/// edge and spill them.
288void SjLjEHPrepareImpl::lowerAcrossUnwindEdges(Function &F,
289 ArrayRef<InvokeInst *> Invokes) {
290 // Finally, scan the code looking for instructions with bad live ranges.
291 for (BasicBlock &BB : F) {
292 for (Instruction &Inst : BB) {
293 // Ignore obvious cases we don't have to handle. In particular, most
294 // instructions either have no uses or only have a single use inside the
295 // current block. Ignore them quickly.
296 if (Inst.use_empty())
297 continue;
298 if (Inst.hasOneUse() &&
299 cast<Instruction>(Inst.user_back())->getParent() == &BB &&
300 !isa<PHINode>(Inst.user_back()))
301 continue;
302
303 // If this is an alloca in the entry block, it's not a real register
304 // value.
305 if (auto *AI = dyn_cast<AllocaInst>(&Inst))
306 if (AI->isStaticAlloca())
307 continue;
308
309 // Avoid iterator invalidation by copying users to a temporary vector.
311 for (User *U : Inst.users()) {
313 if (UI->getParent() != &BB || isa<PHINode>(UI))
314 Users.push_back(UI);
315 }
316
317 // Find all of the blocks that this value is live in.
319 LiveBBs.insert(&BB);
320 while (!Users.empty()) {
321 Instruction *U = Users.pop_back_val();
322
323 if (!isa<PHINode>(U)) {
324 MarkBlocksLiveIn(U->getParent(), LiveBBs);
325 } else {
326 // Uses for a PHI node occur in their predecessor block.
327 PHINode *PN = cast<PHINode>(U);
328 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
329 if (PN->getIncomingValue(i) == &Inst)
330 MarkBlocksLiveIn(PN->getIncomingBlock(i), LiveBBs);
331 }
332 }
333
334 // Now that we know all of the blocks that this thing is live in, see if
335 // it includes any of the unwind locations.
336 bool NeedsSpill = false;
337 for (InvokeInst *Invoke : Invokes) {
338 BasicBlock *UnwindBlock = Invoke->getUnwindDest();
339 if (UnwindBlock != &BB && LiveBBs.count(UnwindBlock)) {
340 LLVM_DEBUG(dbgs() << "SJLJ Spill: " << Inst << " around "
341 << UnwindBlock->getName() << "\n");
342 NeedsSpill = true;
343 break;
344 }
345 }
346
347 // If we decided we need a spill, do it.
348 // FIXME: Spilling this way is overkill, as it forces all uses of
349 // the value to be reloaded from the stack slot, even those that aren't
350 // in the unwind blocks. We should be more selective.
351 if (NeedsSpill) {
352 DemoteRegToStack(Inst, true);
353 ++NumSpilled;
354 }
355 }
356 }
357
358 // Go through the landing pads and remove any PHIs there.
359 for (InvokeInst *Invoke : Invokes) {
360 BasicBlock *UnwindBlock = Invoke->getUnwindDest();
361 LandingPadInst *LPI = UnwindBlock->getLandingPadInst();
362
363 // Place PHIs into a set to avoid invalidating the iterator.
364 SmallPtrSet<PHINode *, 8> PHIsToDemote;
365 for (BasicBlock::iterator PN = UnwindBlock->begin(); isa<PHINode>(PN); ++PN)
366 PHIsToDemote.insert(cast<PHINode>(PN));
367 if (PHIsToDemote.empty())
368 continue;
369
370 // Demote the PHIs to the stack.
371 for (PHINode *PN : PHIsToDemote)
373
374 // Move the landingpad instruction back to the top of the landing pad block.
375 LPI->moveBefore(UnwindBlock->begin());
376 }
377}
378
379/// setupEntryBlockAndCallSites - Setup the entry block by creating and filling
380/// the function context and marking the call sites with the appropriate
381/// values. These values are used by the DWARF EH emitter.
382bool SjLjEHPrepareImpl::setupEntryBlockAndCallSites(Function &F) {
386
387 // Look through the terminators of the basic blocks to find invokes.
388 for (BasicBlock &BB : F)
389 if (auto *II = dyn_cast<InvokeInst>(BB.getTerminator())) {
390 if (Function *Callee = II->getCalledFunction())
391 if (Callee->getIntrinsicID() == Intrinsic::donothing) {
392 // Remove the NOP invoke.
393 UncondBrInst::Create(II->getNormalDest(), II->getIterator());
394 II->eraseFromParent();
395 continue;
396 }
397
398 Invokes.push_back(II);
399 LPads.insert(II->getUnwindDest()->getLandingPadInst());
400 } else if (auto *RI = dyn_cast<ReturnInst>(BB.getTerminator())) {
401 Returns.push_back(RI);
402 }
403
404 if (Invokes.empty())
405 return false;
406
407 NumInvokes += Invokes.size();
408
409 lowerIncomingArguments(F);
410 lowerAcrossUnwindEdges(F, Invokes);
411
412 Value *FuncCtx =
413 setupFunctionContext(F, ArrayRef(LPads.begin(), LPads.end()));
414 BasicBlock *EntryBB = &F.front();
415 IRBuilder<> Builder(EntryBB->getTerminator());
416
417 // Get a reference to the jump buffer.
418 Value *JBufPtr =
419 Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 5, "jbuf_gep");
420
421 // Save the frame pointer.
422 Value *FramePtr = Builder.CreateConstGEP2_32(doubleUnderJBufTy, JBufPtr, 0, 0,
423 "jbuf_fp_gep");
424
425 Value *Val = Builder.CreateCall(FrameAddrFn, Builder.getInt32(0), "fp");
426 Builder.CreateStore(Val, FramePtr, /*isVolatile=*/true);
427
428 // Save the stack pointer.
429 Value *StackPtr = Builder.CreateConstGEP2_32(doubleUnderJBufTy, JBufPtr, 0, 2,
430 "jbuf_sp_gep");
431
432 Val = Builder.CreateCall(StackAddrFn, {}, "sp");
433 Builder.CreateStore(Val, StackPtr, /*isVolatile=*/true);
434
435 // Call the setup_dispatch intrinsic. It fills in the rest of the jmpbuf.
436 Builder.CreateCall(BuiltinSetupDispatchFn, {});
437
438 // Store a pointer to the function context so that the back-end will know
439 // where to look for it.
440 Builder.CreateCall(FuncCtxFn, FuncCtx);
441
442 // Register the function context and make sure it's known to not throw.
443 CallInst *Register = Builder.CreateCall(RegisterFn, FuncCtx, "");
444 Register->setDoesNotThrow();
445
446 // At this point, we are all set up, update the invoke instructions to mark
447 // their call_site values.
448 for (unsigned I = 0, E = Invokes.size(); I != E; ++I) {
449 insertCallSiteStore(Invokes[I], I + 1);
450
451 ConstantInt *CallSiteNum =
452 ConstantInt::get(Type::getInt32Ty(F.getContext()), I + 1);
453
454 // Record the call site value for the back end so it stays associated with
455 // the invoke.
456 CallInst::Create(CallSiteFn, CallSiteNum, "", Invokes[I]->getIterator());
457 }
458
459 // Mark call instructions that aren't nounwind as no-action (call_site ==
460 // -1). Skip the entry block, as prior to then, no function context has been
461 // created for this function and any unexpected exceptions thrown will go
462 // directly to the caller's context, which is what we want anyway, so no need
463 // to do anything here.
464 for (BasicBlock &BB : F) {
465 if (&BB == &F.front())
466 continue;
467 for (Instruction &I : BB)
468 if (!isa<InvokeInst>(I) && I.mayThrow())
469 insertCallSiteStore(&I, -1);
470 }
471
472 // Following any allocas not in the entry block, update the saved SP in the
473 // jmpbuf to the new value.
474 for (BasicBlock &BB : F) {
475 if (&BB == &F.front())
476 continue;
477 for (Instruction &I : BB) {
478 if (auto *CI = dyn_cast<CallInst>(&I)) {
479 if (CI->getCalledFunction() != StackRestoreFn)
480 continue;
481 } else if (!isa<AllocaInst>(&I)) {
482 continue;
483 }
484 Instruction *StackAddr = CallInst::Create(StackAddrFn, "sp");
485 StackAddr->insertAfter(I.getIterator());
486 new StoreInst(StackAddr, StackPtr, true,
487 std::next(StackAddr->getIterator()));
488 }
489 }
490
491 // Finally, for any returns from this function, if this function contains an
492 // invoke, add a call to unregister the function context.
493 for (ReturnInst *Return : Returns) {
495 if (CallInst *CI = Return->getParent()->getTerminatingMustTailCall())
496 InsertPoint = CI;
497 CallInst::Create(UnregisterFn, FuncCtx, "", InsertPoint->getIterator());
498 }
499
500 return true;
501}
502
503bool SjLjEHPrepareImpl::runOnFunction(Function &F) {
504 if (ExceptionModel != ExceptionHandling::SjLj &&
505 ExceptionModel != ExceptionHandling::Default)
506 return false;
507
508 Module &M = *F.getParent();
509 RegisterFn = M.getOrInsertFunction(
510 "_Unwind_SjLj_Register", Type::getVoidTy(M.getContext()),
511 PointerType::getUnqual(FunctionContextTy->getContext()));
512 UnregisterFn = M.getOrInsertFunction(
513 "_Unwind_SjLj_Unregister", Type::getVoidTy(M.getContext()),
514 PointerType::getUnqual(FunctionContextTy->getContext()));
515
516 PointerType *AllocaPtrTy = M.getDataLayout().getAllocaPtrType(M.getContext());
517
518 FrameAddrFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::frameaddress,
519 {AllocaPtrTy});
520 StackAddrFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::stacksave,
521 {AllocaPtrTy});
522 StackRestoreFn = Intrinsic::getOrInsertDeclaration(
523 &M, Intrinsic::stackrestore, {AllocaPtrTy});
524 BuiltinSetupDispatchFn =
525 Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_setup_dispatch);
526 LSDAAddrFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_lsda);
527 CallSiteFn =
528 Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_callsite);
529 FuncCtxFn =
530 Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_functioncontext);
531
532 bool Res = setupEntryBlockAndCallSites(F);
533 return Res;
534}
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:2903
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:1695
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