LLVM  10.0.0svn
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"
15 #include "llvm/ADT/SmallPtrSet.h"
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/ADT/Statistic.h"
19 #include "llvm/CodeGen/Passes.h"
20 #include "llvm/IR/Constants.h"
21 #include "llvm/IR/DataLayout.h"
22 #include "llvm/IR/DerivedTypes.h"
23 #include "llvm/IR/IRBuilder.h"
24 #include "llvm/IR/Instructions.h"
25 #include "llvm/IR/Intrinsics.h"
26 #include "llvm/IR/Module.h"
27 #include "llvm/Pass.h"
28 #include "llvm/Support/Debug.h"
30 using namespace llvm;
31 
32 #define DEBUG_TYPE "sjljehprepare"
33 
34 STATISTIC(NumInvokes, "Number of invokes replaced");
35 STATISTIC(NumSpilled, "Number of registers live across unwind edges");
36 
37 namespace {
38 class SjLjEHPrepare : public FunctionPass {
39  Type *doubleUnderDataTy;
40  Type *doubleUnderJBufTy;
41  Type *FunctionContextTy;
42  FunctionCallee RegisterFn;
43  FunctionCallee UnregisterFn;
44  Function *BuiltinSetupDispatchFn;
45  Function *FrameAddrFn;
46  Function *StackAddrFn;
47  Function *StackRestoreFn;
48  Function *LSDAAddrFn;
49  Function *CallSiteFn;
50  Function *FuncCtxFn;
51  AllocaInst *FuncCtx;
52 
53 public:
54  static char ID; // Pass identification, replacement for typeid
55  explicit SjLjEHPrepare() : FunctionPass(ID) {}
56  bool doInitialization(Module &M) override;
57  bool runOnFunction(Function &F) override;
58 
59  void getAnalysisUsage(AnalysisUsage &AU) const override {}
60  StringRef getPassName() const override {
61  return "SJLJ Exception Handling preparation";
62  }
63 
64 private:
65  bool setupEntryBlockAndCallSites(Function &F);
66  void substituteLPadValues(LandingPadInst *LPI, Value *ExnVal, Value *SelVal);
67  Value *setupFunctionContext(Function &F, ArrayRef<LandingPadInst *> LPads);
68  void lowerIncomingArguments(Function &F);
69  void lowerAcrossUnwindEdges(Function &F, ArrayRef<InvokeInst *> Invokes);
70  void insertCallSiteStore(Instruction *I, int Number);
71 };
72 } // end anonymous namespace
73 
74 char SjLjEHPrepare::ID = 0;
75 INITIALIZE_PASS(SjLjEHPrepare, DEBUG_TYPE, "Prepare SjLj exceptions",
76  false, false)
77 
78 // Public Interface To the SjLjEHPrepare pass.
79 FunctionPass *llvm::createSjLjEHPreparePass() { return new SjLjEHPrepare(); }
80 // doInitialization - Set up decalarations and types needed to process
81 // exceptions.
82 bool SjLjEHPrepare::doInitialization(Module &M) {
83  // Build the function context structure.
84  // builtin_setjmp uses a five word jbuf
85  Type *VoidPtrTy = Type::getInt8PtrTy(M.getContext());
87  doubleUnderDataTy = ArrayType::get(Int32Ty, 4);
88  doubleUnderJBufTy = ArrayType::get(VoidPtrTy, 5);
89  FunctionContextTy = StructType::get(VoidPtrTy, // __prev
90  Int32Ty, // call_site
91  doubleUnderDataTy, // __data
92  VoidPtrTy, // __personality
93  VoidPtrTy, // __lsda
94  doubleUnderJBufTy // __jbuf
95  );
96 
97  return true;
98 }
99 
100 /// insertCallSiteStore - Insert a store of the call-site value to the
101 /// function context
102 void SjLjEHPrepare::insertCallSiteStore(Instruction *I, int Number) {
103  IRBuilder<> Builder(I);
104 
105  // Get a reference to the call_site field.
107  Value *Zero = ConstantInt::get(Int32Ty, 0);
108  Value *One = ConstantInt::get(Int32Ty, 1);
109  Value *Idxs[2] = { Zero, One };
110  Value *CallSite =
111  Builder.CreateGEP(FunctionContextTy, FuncCtx, Idxs, "call_site");
112 
113  // Insert a store of the call-site number
114  ConstantInt *CallSiteNoC =
116  Builder.CreateStore(CallSiteNoC, CallSite, true /*volatile*/);
117 }
118 
119 /// MarkBlocksLiveIn - Insert BB and all of its predecessors into LiveBBs until
120 /// we reach blocks we've already seen.
121 static void MarkBlocksLiveIn(BasicBlock *BB,
123  if (!LiveBBs.insert(BB).second)
124  return; // already been here.
125 
127 
128  for (BasicBlock *B : inverse_depth_first_ext(BB, Visited))
129  LiveBBs.insert(B);
130 
131 }
132 
133 /// substituteLPadValues - Substitute the values returned by the landingpad
134 /// instruction with those returned by the personality function.
135 void SjLjEHPrepare::substituteLPadValues(LandingPadInst *LPI, Value *ExnVal,
136  Value *SelVal) {
137  SmallVector<Value *, 8> UseWorkList(LPI->user_begin(), LPI->user_end());
138  while (!UseWorkList.empty()) {
139  Value *Val = UseWorkList.pop_back_val();
140  auto *EVI = dyn_cast<ExtractValueInst>(Val);
141  if (!EVI)
142  continue;
143  if (EVI->getNumIndices() != 1)
144  continue;
145  if (*EVI->idx_begin() == 0)
146  EVI->replaceAllUsesWith(ExnVal);
147  else if (*EVI->idx_begin() == 1)
148  EVI->replaceAllUsesWith(SelVal);
149  if (EVI->use_empty())
150  EVI->eraseFromParent();
151  }
152 
153  if (LPI->use_empty())
154  return;
155 
156  // There are still some uses of LPI. Construct an aggregate with the exception
157  // values and replace the LPI with that aggregate.
158  Type *LPadType = LPI->getType();
159  Value *LPadVal = UndefValue::get(LPadType);
160  auto *SelI = cast<Instruction>(SelVal);
161  IRBuilder<> Builder(SelI->getParent(), std::next(SelI->getIterator()));
162  LPadVal = Builder.CreateInsertValue(LPadVal, ExnVal, 0, "lpad.val");
163  LPadVal = Builder.CreateInsertValue(LPadVal, SelVal, 1, "lpad.val");
164 
165  LPI->replaceAllUsesWith(LPadVal);
166 }
167 
168 /// setupFunctionContext - Allocate the function context on the stack and fill
169 /// it with all of the data that we know at this point.
170 Value *SjLjEHPrepare::setupFunctionContext(Function &F,
172  BasicBlock *EntryBB = &F.front();
173 
174  // Create an alloca for the incoming jump buffer ptr and the new jump buffer
175  // that needs to be restored on all exits from the function. This is an alloca
176  // because the value needs to be added to the global context list.
177  auto &DL = F.getParent()->getDataLayout();
178  unsigned Align = DL.getPrefTypeAlignment(FunctionContextTy);
179  FuncCtx = new AllocaInst(FunctionContextTy, DL.getAllocaAddrSpace(),
180  nullptr, Align, "fn_context", &EntryBB->front());
181 
182  // Fill in the function context structure.
183  for (LandingPadInst *LPI : LPads) {
184  IRBuilder<> Builder(LPI->getParent(),
185  LPI->getParent()->getFirstInsertionPt());
186 
187  // Reference the __data field.
188  Value *FCData =
189  Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 2, "__data");
190 
191  // The exception values come back in context->__data[0].
193  Value *ExceptionAddr = Builder.CreateConstGEP2_32(doubleUnderDataTy, FCData,
194  0, 0, "exception_gep");
195  Value *ExnVal = Builder.CreateLoad(Int32Ty, ExceptionAddr, true, "exn_val");
196  ExnVal = Builder.CreateIntToPtr(ExnVal, Builder.getInt8PtrTy());
197 
198  Value *SelectorAddr = Builder.CreateConstGEP2_32(doubleUnderDataTy, FCData,
199  0, 1, "exn_selector_gep");
200  Value *SelVal =
201  Builder.CreateLoad(Int32Ty, SelectorAddr, true, "exn_selector_val");
202 
203  substituteLPadValues(LPI, ExnVal, SelVal);
204  }
205 
206  // Personality function
207  IRBuilder<> Builder(EntryBB->getTerminator());
208  Value *PersonalityFn = F.getPersonalityFn();
209  Value *PersonalityFieldPtr = Builder.CreateConstGEP2_32(
210  FunctionContextTy, FuncCtx, 0, 3, "pers_fn_gep");
211  Builder.CreateStore(
212  Builder.CreateBitCast(PersonalityFn, Builder.getInt8PtrTy()),
213  PersonalityFieldPtr, /*isVolatile=*/true);
214 
215  // LSDA address
216  Value *LSDA = Builder.CreateCall(LSDAAddrFn, {}, "lsda_addr");
217  Value *LSDAFieldPtr =
218  Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 4, "lsda_gep");
219  Builder.CreateStore(LSDA, LSDAFieldPtr, /*isVolatile=*/true);
220 
221  return FuncCtx;
222 }
223 
224 /// lowerIncomingArguments - To avoid having to handle incoming arguments
225 /// specially, we lower each arg to a copy instruction in the entry block. This
226 /// ensures that the argument value itself cannot be live out of the entry
227 /// block.
228 void SjLjEHPrepare::lowerIncomingArguments(Function &F) {
229  BasicBlock::iterator AfterAllocaInsPt = F.begin()->begin();
230  while (isa<AllocaInst>(AfterAllocaInsPt) &&
231  cast<AllocaInst>(AfterAllocaInsPt)->isStaticAlloca())
232  ++AfterAllocaInsPt;
233  assert(AfterAllocaInsPt != F.front().end());
234 
235  for (auto &AI : F.args()) {
236  // Swift error really is a register that we model as memory -- instruction
237  // selection will perform mem-to-reg for us and spill/reload appropriately
238  // around calls that clobber it. There is no need to spill this
239  // value to the stack and doing so would not be allowed.
240  if (AI.isSwiftError())
241  continue;
242 
243  Type *Ty = AI.getType();
244 
245  // Use 'select i8 true, %arg, undef' to simulate a 'no-op' instruction.
246  Value *TrueValue = ConstantInt::getTrue(F.getContext());
249  TrueValue, &AI, UndefValue, AI.getName() + ".tmp", &*AfterAllocaInsPt);
250  AI.replaceAllUsesWith(SI);
251 
252  // Reset the operand, because it was clobbered by the RAUW above.
253  SI->setOperand(1, &AI);
254  }
255 }
256 
257 /// lowerAcrossUnwindEdges - Find all variables which are alive across an unwind
258 /// edge and spill them.
259 void SjLjEHPrepare::lowerAcrossUnwindEdges(Function &F,
260  ArrayRef<InvokeInst *> Invokes) {
261  // Finally, scan the code looking for instructions with bad live ranges.
262  for (BasicBlock &BB : F) {
263  for (Instruction &Inst : BB) {
264  // Ignore obvious cases we don't have to handle. In particular, most
265  // instructions either have no uses or only have a single use inside the
266  // current block. Ignore them quickly.
267  if (Inst.use_empty())
268  continue;
269  if (Inst.hasOneUse() &&
270  cast<Instruction>(Inst.user_back())->getParent() == &BB &&
271  !isa<PHINode>(Inst.user_back()))
272  continue;
273 
274  // If this is an alloca in the entry block, it's not a real register
275  // value.
276  if (auto *AI = dyn_cast<AllocaInst>(&Inst))
277  if (AI->isStaticAlloca())
278  continue;
279 
280  // Avoid iterator invalidation by copying users to a temporary vector.
282  for (User *U : Inst.users()) {
283  Instruction *UI = cast<Instruction>(U);
284  if (UI->getParent() != &BB || isa<PHINode>(UI))
285  Users.push_back(UI);
286  }
287 
288  // Find all of the blocks that this value is live in.
290  LiveBBs.insert(&BB);
291  while (!Users.empty()) {
292  Instruction *U = Users.pop_back_val();
293 
294  if (!isa<PHINode>(U)) {
295  MarkBlocksLiveIn(U->getParent(), LiveBBs);
296  } else {
297  // Uses for a PHI node occur in their predecessor block.
298  PHINode *PN = cast<PHINode>(U);
299  for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
300  if (PN->getIncomingValue(i) == &Inst)
301  MarkBlocksLiveIn(PN->getIncomingBlock(i), LiveBBs);
302  }
303  }
304 
305  // Now that we know all of the blocks that this thing is live in, see if
306  // it includes any of the unwind locations.
307  bool NeedsSpill = false;
308  for (InvokeInst *Invoke : Invokes) {
309  BasicBlock *UnwindBlock = Invoke->getUnwindDest();
310  if (UnwindBlock != &BB && LiveBBs.count(UnwindBlock)) {
311  LLVM_DEBUG(dbgs() << "SJLJ Spill: " << Inst << " around "
312  << UnwindBlock->getName() << "\n");
313  NeedsSpill = true;
314  break;
315  }
316  }
317 
318  // If we decided we need a spill, do it.
319  // FIXME: Spilling this way is overkill, as it forces all uses of
320  // the value to be reloaded from the stack slot, even those that aren't
321  // in the unwind blocks. We should be more selective.
322  if (NeedsSpill) {
323  DemoteRegToStack(Inst, true);
324  ++NumSpilled;
325  }
326  }
327  }
328 
329  // Go through the landing pads and remove any PHIs there.
330  for (InvokeInst *Invoke : Invokes) {
331  BasicBlock *UnwindBlock = Invoke->getUnwindDest();
332  LandingPadInst *LPI = UnwindBlock->getLandingPadInst();
333 
334  // Place PHIs into a set to avoid invalidating the iterator.
335  SmallPtrSet<PHINode *, 8> PHIsToDemote;
336  for (BasicBlock::iterator PN = UnwindBlock->begin(); isa<PHINode>(PN); ++PN)
337  PHIsToDemote.insert(cast<PHINode>(PN));
338  if (PHIsToDemote.empty())
339  continue;
340 
341  // Demote the PHIs to the stack.
342  for (PHINode *PN : PHIsToDemote)
343  DemotePHIToStack(PN);
344 
345  // Move the landingpad instruction back to the top of the landing pad block.
346  LPI->moveBefore(&UnwindBlock->front());
347  }
348 }
349 
350 /// setupEntryBlockAndCallSites - Setup the entry block by creating and filling
351 /// the function context and marking the call sites with the appropriate
352 /// values. These values are used by the DWARF EH emitter.
353 bool SjLjEHPrepare::setupEntryBlockAndCallSites(Function &F) {
357 
358  // Look through the terminators of the basic blocks to find invokes.
359  for (BasicBlock &BB : F)
360  if (auto *II = dyn_cast<InvokeInst>(BB.getTerminator())) {
361  if (Function *Callee = II->getCalledFunction())
362  if (Callee->getIntrinsicID() == Intrinsic::donothing) {
363  // Remove the NOP invoke.
364  BranchInst::Create(II->getNormalDest(), II);
365  II->eraseFromParent();
366  continue;
367  }
368 
369  Invokes.push_back(II);
370  LPads.insert(II->getUnwindDest()->getLandingPadInst());
371  } else if (auto *RI = dyn_cast<ReturnInst>(BB.getTerminator())) {
372  Returns.push_back(RI);
373  }
374 
375  if (Invokes.empty())
376  return false;
377 
378  NumInvokes += Invokes.size();
379 
380  lowerIncomingArguments(F);
381  lowerAcrossUnwindEdges(F, Invokes);
382 
383  Value *FuncCtx =
384  setupFunctionContext(F, makeArrayRef(LPads.begin(), LPads.end()));
385  BasicBlock *EntryBB = &F.front();
386  IRBuilder<> Builder(EntryBB->getTerminator());
387 
388  // Get a reference to the jump buffer.
389  Value *JBufPtr =
390  Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 5, "jbuf_gep");
391 
392  // Save the frame pointer.
393  Value *FramePtr = Builder.CreateConstGEP2_32(doubleUnderJBufTy, JBufPtr, 0, 0,
394  "jbuf_fp_gep");
395 
396  Value *Val = Builder.CreateCall(FrameAddrFn, Builder.getInt32(0), "fp");
397  Builder.CreateStore(Val, FramePtr, /*isVolatile=*/true);
398 
399  // Save the stack pointer.
400  Value *StackPtr = Builder.CreateConstGEP2_32(doubleUnderJBufTy, JBufPtr, 0, 2,
401  "jbuf_sp_gep");
402 
403  Val = Builder.CreateCall(StackAddrFn, {}, "sp");
404  Builder.CreateStore(Val, StackPtr, /*isVolatile=*/true);
405 
406  // Call the setup_dispatch instrinsic. It fills in the rest of the jmpbuf.
407  Builder.CreateCall(BuiltinSetupDispatchFn, {});
408 
409  // Store a pointer to the function context so that the back-end will know
410  // where to look for it.
411  Value *FuncCtxArg = Builder.CreateBitCast(FuncCtx, Builder.getInt8PtrTy());
412  Builder.CreateCall(FuncCtxFn, FuncCtxArg);
413 
414  // At this point, we are all set up, update the invoke instructions to mark
415  // their call_site values.
416  for (unsigned I = 0, E = Invokes.size(); I != E; ++I) {
417  insertCallSiteStore(Invokes[I], I + 1);
418 
419  ConstantInt *CallSiteNum =
420  ConstantInt::get(Type::getInt32Ty(F.getContext()), I + 1);
421 
422  // Record the call site value for the back end so it stays associated with
423  // the invoke.
424  CallInst::Create(CallSiteFn, CallSiteNum, "", Invokes[I]);
425  }
426 
427  // Mark call instructions that aren't nounwind as no-action (call_site ==
428  // -1). Skip the entry block, as prior to then, no function context has been
429  // created for this function and any unexpected exceptions thrown will go
430  // directly to the caller's context, which is what we want anyway, so no need
431  // to do anything here.
432  for (BasicBlock &BB : F) {
433  if (&BB == &F.front())
434  continue;
435  for (Instruction &I : BB)
436  if (I.mayThrow())
437  insertCallSiteStore(&I, -1);
438  }
439 
440  // Register the function context and make sure it's known to not throw
441  CallInst *Register =
442  CallInst::Create(RegisterFn, FuncCtx, "", EntryBB->getTerminator());
443  Register->setDoesNotThrow();
444 
445  // Following any allocas not in the entry block, update the saved SP in the
446  // jmpbuf to the new value.
447  for (BasicBlock &BB : F) {
448  if (&BB == &F.front())
449  continue;
450  for (Instruction &I : BB) {
451  if (auto *CI = dyn_cast<CallInst>(&I)) {
452  if (CI->getCalledFunction() != StackRestoreFn)
453  continue;
454  } else if (!isa<AllocaInst>(&I)) {
455  continue;
456  }
457  Instruction *StackAddr = CallInst::Create(StackAddrFn, "sp");
458  StackAddr->insertAfter(&I);
459  Instruction *StoreStackAddr = new StoreInst(StackAddr, StackPtr, true);
460  StoreStackAddr->insertAfter(StackAddr);
461  }
462  }
463 
464  // Finally, for any returns from this function, if this function contains an
465  // invoke, add a call to unregister the function context.
466  for (ReturnInst *Return : Returns)
467  CallInst::Create(UnregisterFn, FuncCtx, "", Return);
468 
469  return true;
470 }
471 
473  Module &M = *F.getParent();
474  RegisterFn = M.getOrInsertFunction(
475  "_Unwind_SjLj_Register", Type::getVoidTy(M.getContext()),
476  PointerType::getUnqual(FunctionContextTy));
477  UnregisterFn = M.getOrInsertFunction(
478  "_Unwind_SjLj_Unregister", Type::getVoidTy(M.getContext()),
479  PointerType::getUnqual(FunctionContextTy));
480  FrameAddrFn = Intrinsic::getDeclaration(
481  &M, Intrinsic::frameaddress,
484  StackAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::stacksave);
485  StackRestoreFn = Intrinsic::getDeclaration(&M, Intrinsic::stackrestore);
486  BuiltinSetupDispatchFn =
487  Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_setup_dispatch);
488  LSDAAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_lsda);
489  CallSiteFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_callsite);
490  FuncCtxFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_functioncontext);
491 
492  bool Res = setupEntryBlockAndCallSites(F);
493  return Res;
494 }
Return a value (possibly void), from a function.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks &#39;this&#39; from the containing basic block and deletes it.
Definition: Instruction.cpp:67
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
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 ...
This instruction extracts a struct member or array element value from an aggregate value...
#define DEBUG_TYPE
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:66
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:170
This class represents a function call, abstracting a target machine&#39;s calling convention.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:743
iterator_range< idf_ext_iterator< T, SetTy > > inverse_depth_first_ext(const T &G, SetTy &S)
STATISTIC(NumFunctions, "Total number of functions")
F(f)
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.cpp:144
iv Induction Variable Users
Definition: IVUsers.cpp:51
iterator end()
Get an iterator to the end of the SetVector.
Definition: SetVector.h:92
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:343
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:273
unsigned getAllocaAddrSpace() const
Definition: DataLayout.h:273
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:369
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:450
&#39;undef&#39; values are things that do not have specified contents.
Definition: Constants.h:1285
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:245
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:779
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:346
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition: IRBuilder.h:1604
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:246
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:141
iterator begin()
Get an iterator to the beginning of the SetVector.
Definition: SetVector.h:82
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
An instruction for storing to memory.
Definition: Instructions.h:325
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:429
iterator begin()
Definition: Function.h:685
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:1093
static bool runOnFunction(Function &F, bool PostInlining)
The landingpad instruction holds all of the information necessary to generate correct exception handl...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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:223
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_NODISCARD bool empty() const
Definition: SmallPtrSet.h:91
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const Instruction & front() const
Definition: BasicBlock.h:285
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:370
bool mayThrow() const
Return true if this instruction may throw an exception.
Represent the analysis usage information of a pass.
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:165
constexpr double e
Definition: MathExtras.h:57
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:284
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:381
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Definition: Function.cpp:205
static UndefValue * get(Type *T)
Static factory methods - Return an &#39;undef&#39; object of the specified type.
Definition: Constants.cpp:1446
size_t size() const
Definition: SmallVector.h:52
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
PointerType * getInt8PtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer to an 8-bit integer value.
Definition: IRBuilder.h:421
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:224
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:40
Value * CreateGEP(Value *Ptr, ArrayRef< Value *> IdxList, const Twine &Name="")
Definition: IRBuilder.h:1676
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:297
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:417
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the generic address space (address sp...
Definition: DerivedTypes.h:594
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
iterator end()
Definition: BasicBlock.h:275
Module.h This file contains the declarations for the Module class.
LLVM_NODISCARD T pop_back_val()
Definition: SmallVector.h:374
INITIALIZE_PASS(SjLjEHPrepare, DEBUG_TYPE, "Prepare SjLj exceptions", false, false) FunctionPass *llvm
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:653
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
Definition: Module.cpp:143
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:609
void setOperand(unsigned i, Value *Val)
Definition: User.h:174
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
amdgpu Simplify well known AMD library false FunctionCallee Callee
iterator_range< user_iterator > users()
Definition: Value.h:420
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:180
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:55
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:214
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction...
Definition: Instruction.cpp:79
#define I(x, y, z)
Definition: MD5.cpp:58
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Definition: Type.cpp:587
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:332
static void MarkBlocksLiveIn(BasicBlock *BB, SmallPtrSetImpl< BasicBlock *> &LiveBBs)
MarkBlocksLiveIn - Insert BB and all of its predecessors into LiveBBs until we reach blocks we&#39;ve alr...
FunctionPass * createSjLjEHPreparePass()
createSjLjEHPreparePass - This pass adapts exception handling code to use the GCC-style builtin setjm...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
Definition: Value.h:396
const BasicBlock & front() const
Definition: Function.h:692
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...
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:575
LLVM Value Representation.
Definition: Value.h:74
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1465
static const Function * getParent(const Value *V)
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
Definition: Instruction.cpp:86
Invoke instruction.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
Definition: BasicBlock.cpp:475
#define LLVM_DEBUG(X)
Definition: Debug.h:122
void setDoesNotThrow()
Definition: InstrTypes.h:1690
bool use_empty() const
Definition: Value.h:343
iterator_range< arg_iterator > args()
Definition: Function.h:724
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
IntegerType * Int32Ty
const BasicBlock * getParent() const
Definition: Instruction.h:66
an instruction to allocate memory on the stack
Definition: Instructions.h:59
user_iterator user_end()
Definition: Value.h:404