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