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