41 #define DEBUG_TYPE "dwarfehprepare" 43 STATISTIC(NumResumesLowered,
"Number of resume calls lowered");
54 bool InsertUnwindResumeCalls(
Function &Fn);
57 pruneUnreachableResumes(
Function &Fn,
68 bool doFinalization(
Module &M)
override {
69 RewindFunction =
nullptr;
76 return "Exception handling preparation";
85 "Prepare DWARF exceptions",
false,
false)
94 void DwarfEHPrepare::getAnalysisUsage(
AnalysisUsage &AU)
const {
105 Value *ExnObj =
nullptr;
109 bool EraseIVIs =
false;
114 if (ExcIVI && isa<UndefValue>(ExcIVI->
getOperand(0)) &&
133 if (SelLoad && SelLoad->use_empty())
134 SelLoad->eraseFromParent();
142 size_t DwarfEHPrepare::pruneUnreachableResumes(
146 size_t ResumeIndex = 0;
147 for (
auto *RI : Resumes) {
148 for (
auto *LP : CleanupLPads) {
150 ResumeReachable.
set(ResumeIndex);
158 if (ResumeReachable.all())
159 return Resumes.
size();
162 getAnalysis<TargetTransformInfoWrapperPass>().getTTI(Fn);
166 size_t ResumesLeft = 0;
167 for (
size_t I = 0,
E = Resumes.size();
I <
E; ++
I) {
169 if (ResumeReachable[
I]) {
170 Resumes[ResumesLeft++] = RI;
178 Resumes.resize(ResumesLeft);
184 bool DwarfEHPrepare::InsertUnwindResumeCalls(
Function &Fn) {
188 if (
auto *RI = dyn_cast<ResumeInst>(BB.getTerminator()))
190 if (
auto *LP = BB.getLandingPadInst())
205 size_t ResumesLeft = pruneUnreachableResumes(Fn, Resumes, CleanupLPads);
206 if (ResumesLeft == 0)
210 if (!RewindFunction) {
213 const char *RewindName = TLI->getLibcallName(RTLIB::UNWIND_RESUME);
214 RewindFunction = Fn.getParent()->getOrInsertFunction(RewindName, FTy);
218 if (ResumesLeft == 1) {
223 Value *ExnObj = GetExceptionObject(RI);
227 CI->
setCallingConv(TLI->getLibcallCallingConv(RTLIB::UNWIND_RESUME));
236 "exn.obj", UnwindBB);
244 Value *ExnObj = GetExceptionObject(RI);
252 CI->
setCallingConv(TLI->getLibcallCallingConv(RTLIB::UNWIND_RESUME));
261 getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
262 DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
264 bool Changed = InsertUnwindResumeCalls(Fn);
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
This class represents lattice values for constants.
unsigned getNumIndices() const
A Module instance is used to store all the information related to an LLVM module. ...
INITIALIZE_PASS_BEGIN(DwarfEHPrepare, DEBUG_TYPE, "Prepare DWARF exceptions", false, false) INITIALIZE_PASS_END(DwarfEHPrepare
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
void push_back(const T &Elt)
This class represents a function call, abstracting a target machine's calling convention.
virtual const TargetLowering * getTargetLowering() const
STATISTIC(NumFunctions, "Total number of functions")
An instruction for reading from memory.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Target-Independent Code Generator Pass Configuration Options.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
bool isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch, catchpad/ret, and cleanuppad/ret.
Class to represent function types.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Value * getOperand(unsigned i) const
static bool runOnFunction(Function &F, bool PostInlining)
LLVM Basic Block Representation.
This is an important class for using LLVM in a threaded context.
This function has undefined behavior.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Resume the propagation of an exception.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
Represent the analysis usage information of a pass.
static Type * getVoidTy(LLVMContext &C)
void setCallingConv(CallingConv::ID CC)
FunctionPass class - This class is used to implement most global optimizations.
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
bool isPotentiallyReachable(const Instruction *From, const Instruction *To, const DominatorTree *DT=nullptr, const LoopInfo *LI=nullptr)
Determine whether instruction 'To' is reachable from 'From', returning true if uncertain.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
idx_iterator idx_begin() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
virtual const TargetSubtargetInfo * getSubtargetImpl(const Function &) const
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
LLVM_NODISCARD bool empty() const
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
size_type size() const
size - Returns the number of bits in this bitvector.
LLVM Value Representation.
Primary interface to the complete machine description for the target machine.
StringRef - Represent a constant reference to a string, i.e.
bool simplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI, const SimplifyCFGOptions &Options={}, SmallPtrSetImpl< BasicBlock *> *LoopHeaders=nullptr)
This function is used to do simplification of a CFG.
Legacy analysis pass which computes a DominatorTree.
This file describes how to lower LLVM code to machine code.
const BasicBlock * getParent() const
This instruction inserts a struct field of array element value into an aggregate value.
FunctionPass * createDwarfEHPass()
createDwarfEHPass - This pass mulches exception handling code into a form adapted to code generation...