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;
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
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. ...
bool SimplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI, unsigned BonusInstThreshold, AssumptionCache *AC=nullptr, SmallPtrSetImpl< BasicBlock * > *LoopHeaders=nullptr)
This function is used to do simplification of a CFG.
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...
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...
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
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.
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
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
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.
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...
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_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)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
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 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.