31 #define DEBUG_TYPE "dwarfehprepare"
33 STATISTIC(NumResumesLowered,
"Number of resume calls lowered");
45 bool InsertUnwindResumeCalls(
Function &Fn);
48 pruneUnreachableResumes(
Function &Fn,
65 bool runOnFunction(
Function &Fn)
override;
67 bool doFinalization(
Module &M)
override {
68 RewindFunction =
nullptr;
74 const char *getPassName()
const override {
75 return "Exception handling preparation";
82 "Prepare DWARF exceptions",
false,
false)
89 return new DwarfEHPrepare(TM);
92 void DwarfEHPrepare::getAnalysisUsage(
AnalysisUsage &AU)
const {
102 Value *ExnObj =
nullptr;
106 bool EraseIVIs =
false;
111 if (ExcIVI && isa<UndefValue>(ExcIVI->
getOperand(0)) &&
130 if (SelLoad && SelLoad->use_empty())
131 SelLoad->eraseFromParent();
139 size_t DwarfEHPrepare::pruneUnreachableResumes(
143 size_t ResumeIndex = 0;
144 for (
auto *RI : Resumes) {
145 for (
auto *LP : CleanupLPads) {
147 ResumeReachable.
set(ResumeIndex);
155 if (ResumeReachable.all())
156 return Resumes.
size();
159 getAnalysis<TargetTransformInfoWrapperPass>().getTTI(Fn);
163 size_t ResumesLeft = 0;
164 for (
size_t I = 0, E = Resumes.size();
I < E; ++
I) {
166 if (ResumeReachable[
I]) {
167 Resumes[ResumesLeft++] = RI;
175 Resumes.resize(ResumesLeft);
181 bool DwarfEHPrepare::InsertUnwindResumeCalls(
Function &Fn) {
202 size_t ResumesLeft = pruneUnreachableResumes(Fn, Resumes, CleanupLPads);
203 if (ResumesLeft == 0)
207 if (!RewindFunction) {
211 RewindFunction = Fn.getParent()->getOrInsertFunction(RewindName, FTy);
215 if (ResumesLeft == 1) {
220 Value *ExnObj = GetExceptionObject(RI);
233 "exn.obj", UnwindBB);
241 Value *ExnObj = GetExceptionObject(RI);
256 bool DwarfEHPrepare::runOnFunction(
Function &Fn) {
257 assert(
TM &&
"DWARF EH preparation requires a target machine");
258 DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
259 TLI =
TM->getSubtargetImpl(Fn)->getTargetLowering();
260 bool Changed = InsertUnwindResumeCalls(Fn);
INITIALIZE_TM_PASS_BEGIN(DwarfEHPrepare,"dwarfehprepare","Prepare DWARF exceptions", false, false) INITIALIZE_TM_PASS_END(DwarfEHPrepare
iplist< Instruction >::iterator eraseFromParent()
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)
addIncoming - 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. ...
CallInst - This class represents a function call, abstracting a target machine's calling convention...
unsigned getNumIndices() const
LoadInst - an instruction for reading from memory.
void setCallingConv(CallingConv::ID CC)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
FunctionType - Class to represent function types.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
FunctionType::get - This static method is the primary way of constructing a FunctionType.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
LLVM Basic Block Representation.
This is an important class for using LLVM in a threaded context.
UnreachableInst - This function has undefined behavior.
This is an important base class in LLVM.
ResumeInst - Resume the propagation of an exception.
LandingPadInst * getLandingPadInst()
Return the landingpad instruction associated with the landing pad.
#define INITIALIZE_TM_PASS_END(passName, arg, name, cfg, analysis)
Target machine pass initializer for passes with dependencies.
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)
FunctionPass class - This class is used to implement most global optimizations.
Value * getOperand(unsigned i) const
bool SimplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI, unsigned BonusInstThreshold, AssumptionCache *AC=nullptr)
SimplifyCFG - This function is used to do simplification of a CFG.
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)
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...
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)
FunctionPass * createDwarfEHPass(const TargetMachine *TM)
createDwarfEHPass - This pass mulches exception handling code into a form adapted to code generation...
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
LLVM Value Representation.
Primary interface to the complete machine description for the target machine.
Legacy analysis pass which computes a DominatorTree.
const BasicBlock * getParent() const
bool isMSVCEHPersonality(EHPersonality Pers)
Returns true if this is an MSVC personality function.
This file describes how to lower LLVM code to machine code.
InsertValueInst - This instruction inserts a struct field of array element value into an aggregate va...