32 #define DEBUG_TYPE "dwarfehprepare"
34 STATISTIC(NumResumesLowered,
"Number of resume calls lowered");
44 bool InsertUnwindResumeCalls(
Function &Fn);
47 pruneUnreachableResumes(
Function &Fn,
55 :
FunctionPass(
ID), RewindFunction(nullptr), DT(nullptr), TLI(nullptr) {
58 bool runOnFunction(
Function &Fn)
override;
60 bool doFinalization(
Module &M)
override {
61 RewindFunction =
nullptr;
68 return "Exception handling preparation";
75 "Prepare DWARF exceptions",
false,
false)
84 void DwarfEHPrepare::getAnalysisUsage(
AnalysisUsage &AU)
const {
95 Value *ExnObj =
nullptr;
99 bool EraseIVIs =
false;
104 if (ExcIVI && isa<UndefValue>(ExcIVI->
getOperand(0)) &&
123 if (SelLoad && SelLoad->use_empty())
124 SelLoad->eraseFromParent();
132 size_t DwarfEHPrepare::pruneUnreachableResumes(
136 size_t ResumeIndex = 0;
137 for (
auto *RI : Resumes) {
138 for (
auto *LP : CleanupLPads) {
140 ResumeReachable.
set(ResumeIndex);
148 if (ResumeReachable.all())
149 return Resumes.
size();
152 getAnalysis<TargetTransformInfoWrapperPass>().getTTI(Fn);
156 size_t ResumesLeft = 0;
157 for (
size_t I = 0,
E = Resumes.size();
I <
E; ++
I) {
159 if (ResumeReachable[
I]) {
160 Resumes[ResumesLeft++] = RI;
168 Resumes.resize(ResumesLeft);
174 bool DwarfEHPrepare::InsertUnwindResumeCalls(
Function &Fn) {
195 size_t ResumesLeft = pruneUnreachableResumes(Fn, Resumes, CleanupLPads);
196 if (ResumesLeft == 0)
200 if (!RewindFunction) {
204 RewindFunction = Fn.getParent()->getOrInsertFunction(RewindName, FTy);
208 if (ResumesLeft == 1) {
213 Value *ExnObj = GetExceptionObject(RI);
226 "exn.obj", UnwindBB);
234 Value *ExnObj = GetExceptionObject(RI);
249 bool DwarfEHPrepare::runOnFunction(
Function &Fn) {
251 getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
252 DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
254 bool Changed = InsertUnwindResumeCalls(Fn);
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void push_back(const T &Elt)
size_type size() const
size - Returns the number of bits in this bitvector.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
STATISTIC(NumFunctions,"Total number of functions")
A Module instance is used to store all the information related to an LLVM module. ...
This class represents a function call, abstracting a target machine's calling convention.
unsigned getNumIndices() const
An instruction for reading from memory.
void setCallingConv(CallingConv::ID CC)
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...
LLVM_NODISCARD bool empty() const
Class to represent function types.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
LLVM Basic Block Representation.
This is an important class for using LLVM in a threaded context.
This function has undefined behavior.
This is an important base class in LLVM.
Resume the propagation of an exception.
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)
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
FunctionPass class - This class is used to implement most global optimizations.
Value * getOperand(unsigned i) const
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.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
virtual const TargetSubtargetInfo * getSubtargetImpl(const Function &) const
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
idx_iterator idx_begin() const
bool isFuncletEHPersonality(EHPersonality Pers)
Returns true if this is a personality function that invokes handler funclets (which must return to it...
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
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.
virtual const TargetLowering * getTargetLowering() const
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...
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() 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)
LLVM Value Representation.
INITIALIZE_PASS_BEGIN(DwarfEHPrepare, DEBUG_TYPE,"Prepare DWARF exceptions", false, false) INITIALIZE_PASS_END(DwarfEHPrepare
Primary interface to the complete machine description for the target machine.
StringRef - Represent a constant reference to a string, i.e.
Legacy analysis pass which computes a DominatorTree.
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...
bool SimplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI, unsigned BonusInstThreshold, AssumptionCache *AC=nullptr, SmallPtrSetImpl< BasicBlock * > *LoopHeaders=nullptr, bool LateSimplifyCFG=false)
This function is used to do simplification of a CFG.
const BasicBlock * getParent() const
This file describes how to lower LLVM code to machine code.
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...