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