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