LLVM  6.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"
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"
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  bool undoSwiftErrorSelect(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 } // end anonymous namespace
75 
76 char SjLjEHPrepare::ID = 0;
77 INITIALIZE_PASS(SjLjEHPrepare, DEBUG_TYPE, "Prepare SjLj exceptions",
78  false, false)
79 
80 // Public Interface To the SjLjEHPrepare pass.
81 FunctionPass *llvm::createSjLjEHPreparePass() { return new SjLjEHPrepare(); }
82 // doInitialization - Set up decalarations and types needed to process
83 // exceptions.
84 bool SjLjEHPrepare::doInitialization(Module &M) {
85  // Build the function context structure.
86  // builtin_setjmp uses a five word jbuf
87  Type *VoidPtrTy = Type::getInt8PtrTy(M.getContext());
89  doubleUnderDataTy = ArrayType::get(Int32Ty, 4);
90  doubleUnderJBufTy = ArrayType::get(VoidPtrTy, 5);
91  FunctionContextTy = StructType::get(VoidPtrTy, // __prev
92  Int32Ty, // call_site
93  doubleUnderDataTy, // __data
94  VoidPtrTy, // __personality
95  VoidPtrTy, // __lsda
96  doubleUnderJBufTy // __jbuf
97  );
98 
99  return true;
100 }
101 
102 /// insertCallSiteStore - Insert a store of the call-site value to the
103 /// function context
104 void SjLjEHPrepare::insertCallSiteStore(Instruction *I, int Number) {
105  IRBuilder<> Builder(I);
106 
107  // Get a reference to the call_site field.
109  Value *Zero = ConstantInt::get(Int32Ty, 0);
110  Value *One = ConstantInt::get(Int32Ty, 1);
111  Value *Idxs[2] = { Zero, One };
112  Value *CallSite =
113  Builder.CreateGEP(FunctionContextTy, FuncCtx, Idxs, "call_site");
114 
115  // Insert a store of the call-site number
116  ConstantInt *CallSiteNoC =
118  Builder.CreateStore(CallSiteNoC, CallSite, true /*volatile*/);
119 }
120 
121 /// MarkBlocksLiveIn - Insert BB and all of its predecessors into LiveBBs until
122 /// we reach blocks we've already seen.
123 static void MarkBlocksLiveIn(BasicBlock *BB,
125  if (!LiveBBs.insert(BB).second)
126  return; // already been here.
127 
129 
130  for (BasicBlock *B : inverse_depth_first_ext(BB, Visited))
131  LiveBBs.insert(B);
132 
133 }
134 
135 /// substituteLPadValues - Substitute the values returned by the landingpad
136 /// instruction with those returned by the personality function.
137 void SjLjEHPrepare::substituteLPadValues(LandingPadInst *LPI, Value *ExnVal,
138  Value *SelVal) {
139  SmallVector<Value *, 8> UseWorkList(LPI->user_begin(), LPI->user_end());
140  while (!UseWorkList.empty()) {
141  Value *Val = UseWorkList.pop_back_val();
142  auto *EVI = dyn_cast<ExtractValueInst>(Val);
143  if (!EVI)
144  continue;
145  if (EVI->getNumIndices() != 1)
146  continue;
147  if (*EVI->idx_begin() == 0)
148  EVI->replaceAllUsesWith(ExnVal);
149  else if (*EVI->idx_begin() == 1)
150  EVI->replaceAllUsesWith(SelVal);
151  if (EVI->use_empty())
152  EVI->eraseFromParent();
153  }
154 
155  if (LPI->use_empty())
156  return;
157 
158  // There are still some uses of LPI. Construct an aggregate with the exception
159  // values and replace the LPI with that aggregate.
160  Type *LPadType = LPI->getType();
161  Value *LPadVal = UndefValue::get(LPadType);
162  auto *SelI = cast<Instruction>(SelVal);
163  IRBuilder<> Builder(SelI->getParent(), std::next(SelI->getIterator()));
164  LPadVal = Builder.CreateInsertValue(LPadVal, ExnVal, 0, "lpad.val");
165  LPadVal = Builder.CreateInsertValue(LPadVal, SelVal, 1, "lpad.val");
166 
167  LPI->replaceAllUsesWith(LPadVal);
168 }
169 
170 /// setupFunctionContext - Allocate the function context on the stack and fill
171 /// it with all of the data that we know at this point.
172 Value *SjLjEHPrepare::setupFunctionContext(Function &F,
174  BasicBlock *EntryBB = &F.front();
175 
176  // Create an alloca for the incoming jump buffer ptr and the new jump buffer
177  // that needs to be restored on all exits from the function. This is an alloca
178  // because the value needs to be added to the global context list.
179  auto &DL = F.getParent()->getDataLayout();
180  unsigned Align = DL.getPrefTypeAlignment(FunctionContextTy);
181  FuncCtx = new AllocaInst(FunctionContextTy, DL.getAllocaAddrSpace(),
182  nullptr, Align, "fn_context", &EntryBB->front());
183 
184  // Fill in the function context structure.
185  for (LandingPadInst *LPI : LPads) {
186  IRBuilder<> Builder(LPI->getParent(),
187  LPI->getParent()->getFirstInsertionPt());
188 
189  // Reference the __data field.
190  Value *FCData =
191  Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 2, "__data");
192 
193  // The exception values come back in context->__data[0].
194  Value *ExceptionAddr = Builder.CreateConstGEP2_32(doubleUnderDataTy, FCData,
195  0, 0, "exception_gep");
196  Value *ExnVal = Builder.CreateLoad(ExceptionAddr, true, "exn_val");
197  ExnVal = Builder.CreateIntToPtr(ExnVal, Builder.getInt8PtrTy());
198 
199  Value *SelectorAddr = Builder.CreateConstGEP2_32(doubleUnderDataTy, FCData,
200  0, 1, "exn_selector_gep");
201  Value *SelVal = Builder.CreateLoad(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  Type *Ty = AI.getType();
237 
238  // Use 'select i8 true, %arg, undef' to simulate a 'no-op' instruction.
239  Value *TrueValue = ConstantInt::getTrue(F.getContext());
242  TrueValue, &AI, UndefValue, AI.getName() + ".tmp", &*AfterAllocaInsPt);
243  AI.replaceAllUsesWith(SI);
244 
245  // Reset the operand, because it was clobbered by the RAUW above.
246  SI->setOperand(1, &AI);
247  }
248 }
249 
250 /// lowerAcrossUnwindEdges - Find all variables which are alive across an unwind
251 /// edge and spill them.
252 void SjLjEHPrepare::lowerAcrossUnwindEdges(Function &F,
253  ArrayRef<InvokeInst *> Invokes) {
254  // Finally, scan the code looking for instructions with bad live ranges.
255  for (BasicBlock &BB : F) {
256  for (Instruction &Inst : BB) {
257  // Ignore obvious cases we don't have to handle. In particular, most
258  // instructions either have no uses or only have a single use inside the
259  // current block. Ignore them quickly.
260  if (Inst.use_empty())
261  continue;
262  if (Inst.hasOneUse() &&
263  cast<Instruction>(Inst.user_back())->getParent() == &BB &&
264  !isa<PHINode>(Inst.user_back()))
265  continue;
266 
267  // If this is an alloca in the entry block, it's not a real register
268  // value.
269  if (auto *AI = dyn_cast<AllocaInst>(&Inst))
270  if (AI->isStaticAlloca())
271  continue;
272 
273  // Avoid iterator invalidation by copying users to a temporary vector.
275  for (User *U : Inst.users()) {
276  Instruction *UI = cast<Instruction>(U);
277  if (UI->getParent() != &BB || isa<PHINode>(UI))
278  Users.push_back(UI);
279  }
280 
281  // Find all of the blocks that this value is live in.
283  LiveBBs.insert(&BB);
284  while (!Users.empty()) {
285  Instruction *U = Users.pop_back_val();
286 
287  if (!isa<PHINode>(U)) {
288  MarkBlocksLiveIn(U->getParent(), LiveBBs);
289  } else {
290  // Uses for a PHI node occur in their predecessor block.
291  PHINode *PN = cast<PHINode>(U);
292  for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
293  if (PN->getIncomingValue(i) == &Inst)
294  MarkBlocksLiveIn(PN->getIncomingBlock(i), LiveBBs);
295  }
296  }
297 
298  // Now that we know all of the blocks that this thing is live in, see if
299  // it includes any of the unwind locations.
300  bool NeedsSpill = false;
301  for (InvokeInst *Invoke : Invokes) {
302  BasicBlock *UnwindBlock = Invoke->getUnwindDest();
303  if (UnwindBlock != &BB && LiveBBs.count(UnwindBlock)) {
304  DEBUG(dbgs() << "SJLJ Spill: " << Inst << " around "
305  << UnwindBlock->getName() << "\n");
306  NeedsSpill = true;
307  break;
308  }
309  }
310 
311  // If we decided we need a spill, do it.
312  // FIXME: Spilling this way is overkill, as it forces all uses of
313  // the value to be reloaded from the stack slot, even those that aren't
314  // in the unwind blocks. We should be more selective.
315  if (NeedsSpill) {
316  DemoteRegToStack(Inst, true);
317  ++NumSpilled;
318  }
319  }
320  }
321 
322  // Go through the landing pads and remove any PHIs there.
323  for (InvokeInst *Invoke : Invokes) {
324  BasicBlock *UnwindBlock = Invoke->getUnwindDest();
325  LandingPadInst *LPI = UnwindBlock->getLandingPadInst();
326 
327  // Place PHIs into a set to avoid invalidating the iterator.
328  SmallPtrSet<PHINode *, 8> PHIsToDemote;
329  for (BasicBlock::iterator PN = UnwindBlock->begin(); isa<PHINode>(PN); ++PN)
330  PHIsToDemote.insert(cast<PHINode>(PN));
331  if (PHIsToDemote.empty())
332  continue;
333 
334  // Demote the PHIs to the stack.
335  for (PHINode *PN : PHIsToDemote)
336  DemotePHIToStack(PN);
337 
338  // Move the landingpad instruction back to the top of the landing pad block.
339  LPI->moveBefore(&UnwindBlock->front());
340  }
341 }
342 
343 /// setupEntryBlockAndCallSites - Setup the entry block by creating and filling
344 /// the function context and marking the call sites with the appropriate
345 /// values. These values are used by the DWARF EH emitter.
346 bool SjLjEHPrepare::setupEntryBlockAndCallSites(Function &F) {
350 
351  // Look through the terminators of the basic blocks to find invokes.
352  for (BasicBlock &BB : F)
353  if (auto *II = dyn_cast<InvokeInst>(BB.getTerminator())) {
354  if (Function *Callee = II->getCalledFunction())
355  if (Callee->getIntrinsicID() == Intrinsic::donothing) {
356  // Remove the NOP invoke.
357  BranchInst::Create(II->getNormalDest(), II);
358  II->eraseFromParent();
359  continue;
360  }
361 
362  Invokes.push_back(II);
363  LPads.insert(II->getUnwindDest()->getLandingPadInst());
364  } else if (auto *RI = dyn_cast<ReturnInst>(BB.getTerminator())) {
365  Returns.push_back(RI);
366  }
367 
368  if (Invokes.empty())
369  return false;
370 
371  NumInvokes += Invokes.size();
372 
373  lowerIncomingArguments(F);
374  lowerAcrossUnwindEdges(F, Invokes);
375 
376  Value *FuncCtx =
377  setupFunctionContext(F, makeArrayRef(LPads.begin(), LPads.end()));
378  BasicBlock *EntryBB = &F.front();
379  IRBuilder<> Builder(EntryBB->getTerminator());
380 
381  // Get a reference to the jump buffer.
382  Value *JBufPtr =
383  Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 5, "jbuf_gep");
384 
385  // Save the frame pointer.
386  Value *FramePtr = Builder.CreateConstGEP2_32(doubleUnderJBufTy, JBufPtr, 0, 0,
387  "jbuf_fp_gep");
388 
389  Value *Val = Builder.CreateCall(FrameAddrFn, Builder.getInt32(0), "fp");
390  Builder.CreateStore(Val, FramePtr, /*isVolatile=*/true);
391 
392  // Save the stack pointer.
393  Value *StackPtr = Builder.CreateConstGEP2_32(doubleUnderJBufTy, JBufPtr, 0, 2,
394  "jbuf_sp_gep");
395 
396  Val = Builder.CreateCall(StackAddrFn, {}, "sp");
397  Builder.CreateStore(Val, StackPtr, /*isVolatile=*/true);
398 
399  // Call the setup_dispatch instrinsic. It fills in the rest of the jmpbuf.
400  Builder.CreateCall(BuiltinSetupDispatchFn, {});
401 
402  // Store a pointer to the function context so that the back-end will know
403  // where to look for it.
404  Value *FuncCtxArg = Builder.CreateBitCast(FuncCtx, Builder.getInt8PtrTy());
405  Builder.CreateCall(FuncCtxFn, FuncCtxArg);
406 
407  // At this point, we are all set up, update the invoke instructions to mark
408  // their call_site values.
409  for (unsigned I = 0, E = Invokes.size(); I != E; ++I) {
410  insertCallSiteStore(Invokes[I], I + 1);
411 
412  ConstantInt *CallSiteNum =
413  ConstantInt::get(Type::getInt32Ty(F.getContext()), I + 1);
414 
415  // Record the call site value for the back end so it stays associated with
416  // the invoke.
417  CallInst::Create(CallSiteFn, CallSiteNum, "", Invokes[I]);
418  }
419 
420  // Mark call instructions that aren't nounwind as no-action (call_site ==
421  // -1). Skip the entry block, as prior to then, no function context has been
422  // created for this function and any unexpected exceptions thrown will go
423  // directly to the caller's context, which is what we want anyway, so no need
424  // to do anything here.
425  for (BasicBlock &BB : F) {
426  if (&BB == &F.front())
427  continue;
428  for (Instruction &I : BB)
429  if (I.mayThrow())
430  insertCallSiteStore(&I, -1);
431  }
432 
433  // Register the function context and make sure it's known to not throw
434  CallInst *Register =
435  CallInst::Create(RegisterFn, FuncCtx, "", EntryBB->getTerminator());
436  Register->setDoesNotThrow();
437 
438  // Following any allocas not in the entry block, update the saved SP in the
439  // jmpbuf to the new value.
440  for (BasicBlock &BB : F) {
441  if (&BB == &F.front())
442  continue;
443  for (Instruction &I : BB) {
444  if (auto *CI = dyn_cast<CallInst>(&I)) {
445  if (CI->getCalledFunction() != StackRestoreFn)
446  continue;
447  } else if (!isa<AllocaInst>(&I)) {
448  continue;
449  }
450  Instruction *StackAddr = CallInst::Create(StackAddrFn, "sp");
451  StackAddr->insertAfter(&I);
452  Instruction *StoreStackAddr = new StoreInst(StackAddr, StackPtr, true);
453  StoreStackAddr->insertAfter(StackAddr);
454  }
455  }
456 
457  // Finally, for any returns from this function, if this function contains an
458  // invoke, add a call to unregister the function context.
459  for (ReturnInst *Return : Returns)
460  CallInst::Create(UnregisterFn, FuncCtx, "", Return);
461 
462  return true;
463 }
464 
465 bool SjLjEHPrepare::undoSwiftErrorSelect(Function &F) {
466  // We have inserted dummy copies 'select true, arg, undef' in the entry block
467  // for arguments to simplify this pass.
468  // swifterror arguments cannot be used in this way. Undo the select for the
469  // swifterror argument.
470  for (auto &AI : F.args()) {
471  if (AI.isSwiftError()) {
472  assert(AI.hasOneUse() && "Must have converted the argument to a select");
473  auto *Select = dyn_cast<SelectInst>(AI.use_begin()->getUser());
474  assert(Select && "There must be single select user");
475  auto *OrigSwiftError = cast<Argument>(Select->getTrueValue());
476  Select->replaceAllUsesWith(OrigSwiftError);
477  Select->eraseFromParent();
478  return true;
479  }
480  }
481  return false;
482 }
483 
484 bool SjLjEHPrepare::runOnFunction(Function &F) {
485  Module &M = *F.getParent();
486  RegisterFn = M.getOrInsertFunction(
487  "_Unwind_SjLj_Register", Type::getVoidTy(M.getContext()),
488  PointerType::getUnqual(FunctionContextTy));
489  UnregisterFn = M.getOrInsertFunction(
490  "_Unwind_SjLj_Unregister", Type::getVoidTy(M.getContext()),
491  PointerType::getUnqual(FunctionContextTy));
492  FrameAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::frameaddress);
493  StackAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::stacksave);
494  StackRestoreFn = Intrinsic::getDeclaration(&M, Intrinsic::stackrestore);
495  BuiltinSetupDispatchFn =
496  Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_setup_dispatch);
497  LSDAAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_lsda);
498  CallSiteFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_callsite);
499  FuncCtxFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_functioncontext);
500 
501  bool Res = setupEntryBlockAndCallSites(F);
502  if (Res)
503  Res |= undoSwiftErrorSelect(F);
504  return Res;
505 }
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:69
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
void setDoesNotThrow()
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
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:136
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:697
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:51
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:252
This class represents the LLVM &#39;select&#39; instruction.
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:1247
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:237
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:664
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:1176
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:306
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:428
iterator begin()
Definition: Function.h:588
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:980
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:200
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:264
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:1320
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:386
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:1223
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:254
Module.h This file contains the declarations for the Module class.
Promote Memory to Register
Definition: Mem2Reg.cpp:101
LLVM_NODISCARD T pop_back_val()
Definition: SmallVector.h:385
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:560
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:516
void setOperand(unsigned i, Value *Val)
Definition: User.h:159
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
iterator_range< user_iterator > users()
Definition: Value.h:395
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:176
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:61
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:218
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:81
#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: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:371
const BasicBlock & front() const
Definition: Function.h:595
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:545
LLVM Value Representation.
Definition: Value.h:73
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1260
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:88
static const unsigned FramePtr
Invoke instruction.
#define DEBUG(X)
Definition: Debug.h:118
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:447
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:120
bool use_empty() const
Definition: Value.h:322
iterator_range< arg_iterator > args()
Definition: Function.h:621
IntegerType * Int32Ty
const BasicBlock * getParent() const
Definition: Instruction.h:66
an instruction to allocate memory on the stack
Definition: Instructions.h:60
user_iterator user_end()
Definition: Value.h:379