35 #define DEBUG_TYPE "prune-eh"
37 STATISTIC(NumRemoved,
"Number of invokes removed");
38 STATISTIC(NumUnreach,
"Number of noreturn calls optimized");
57 "Remove unused exception handling info",
false,
false)
60 "Remove unused exception handling
info",
false, false)
66 bool MadeChange =
false;
86 bool SCCMightUnwind =
false, SCCMightReturn =
false;
88 (!SCCMightUnwind || !SCCMightReturn) &&
I !=
E; ++
I) {
91 SCCMightUnwind =
true;
92 SCCMightReturn =
true;
97 bool CheckUnwind = !SCCMightUnwind && !F->
doesNotThrow();
103 bool CheckReturnViaAsm = CheckReturn &&
107 if (!CheckUnwind && !CheckReturn)
112 if (CheckUnwind && TI->
mayThrow()) {
113 SCCMightUnwind =
true;
114 }
else if (CheckReturn && isa<ReturnInst>(TI)) {
115 SCCMightReturn =
true;
119 if ((!CheckUnwind || SCCMightUnwind) &&
120 (!CheckReturnViaAsm || SCCMightReturn))
125 if (CheckUnwind && !SCCMightUnwind &&
I.mayThrow()) {
126 bool InstMightUnwind =
true;
127 if (
const auto *CI = dyn_cast<CallInst>(&
I)) {
128 if (
Function *Callee = CI->getCalledFunction()) {
132 if (SCCNodes.
count(CalleeNode) > 0)
133 InstMightUnwind =
false;
136 SCCMightUnwind |= InstMightUnwind;
138 if (CheckReturnViaAsm && !SCCMightReturn)
140 if (
const auto *IA = dyn_cast<InlineAsm>(ICS.getCalledValue()))
141 if (IA->hasSideEffects())
142 SCCMightReturn =
true;
145 if (SCCMightUnwind && SCCMightReturn)
152 if (!SCCMightUnwind || !SCCMightReturn)
182 CallGraph &CG = getAnalysis<CallGraphWrapperPass>().getCallGraph();
191 bool MadeChange =
false;
193 if (
InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator()))
195 BasicBlock *UnwindBlock = II->getUnwindDest();
207 if (
CallInst *CI = dyn_cast<CallInst>(
I++))
208 if (CI->doesNotReturn() && !isa<UnreachableInst>(
I)) {
241 if (
I->getType()->isTokenTy()) {
247 const Function *Callee = CS.getCalledFunction();
259 if (!isa<TerminatorInst>(TokenInst))
265 for (
unsigned i = 0, e = Succs.size();
i != e; ++
i)
266 Succs[
i]->removePredecessor(BB);
Pass interface - Implemented by all 'passes'.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
STATISTIC(NumFunctions,"Total number of functions")
static bool runImpl(CallGraphSCC &SCC, CallGraph &CG)
This class represents a function call, abstracting a target machine's calling convention.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
size_type count(PtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
bool hasExactDefinition() const
Return true if this global has an exact defintion.
const Function * getParent() const
Return the enclosing method, or null if none.
unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap, bool PreserveLCSSA=false)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
A node in the call graph for a module.
std::vector< CallGraphNode * >::const_iterator iterator
iterator begin()
Instruction iterator methods.
void initializePruneEHPass(PassRegistry &)
#define INITIALIZE_PASS_DEPENDENCY(depName)
bool doesNotThrow() const
Determine if the function cannot unwind.
static bool SimplifyFunction(Function *F, CallGraph &CG)
INITIALIZE_PASS_BEGIN(PruneEH,"prune-eh","Remove unused exception handling info", false, false) INITIALIZE_PASS_END(PruneEH
bool canSimplifyInvokeNoUnwind(const Function *F)
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
Function Alias Analysis false
static void DeleteBasicBlock(BasicBlock *BB, CallGraph &CG)
DeleteBasicBlock - remove the specified basic block from the program, updating the callgraph to refle...
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
Interval::succ_iterator succ_end(Interval *I)
Subclasses of this class are all able to terminate a basic block.
The ModulePass which wraps up a CallGraph and the logic to build it.
bool isLeaf(ID id)
Returns true if the intrinsic is a leaf, i.e.
LLVM Basic Block Representation.
This function has undefined behavior.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool doesNotReturn() const
Determine if the function cannot return.
const InstListType & getInstList() const
Return the underlying instruction list container.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
bool pred_empty(const BasicBlock *BB)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
void removeUnwindEdge(BasicBlock *BB)
Replace 'BB's terminator with one that does not have an unwind successor block.
bool mayThrow() const
Return true if this instruction may throw an exception.
The basic data container for the call graph of a Module of IR.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
ImmutableCallSite - establish a view to a call site for examination.
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Pass * createPruneEHPass()
createPruneEHPass - Return a new pass object which transforms invoke instructions into calls...
CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
void removeCallEdgeFor(CallSite CS)
Removes the edge in the node for the specified call site.
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.