1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 03:23:01 +02:00

This analysis doesn't take 'throwing' into consideration, it looks at

'unwinding'

llvm-svn: 21581
This commit is contained in:
Chris Lattner 2005-04-26 23:53:25 +00:00
parent ddef064121
commit bd077a1945

View File

@ -29,9 +29,9 @@ namespace {
Statistic<> NumRemoved("prune-eh", "Number of invokes removed"); Statistic<> NumRemoved("prune-eh", "Number of invokes removed");
struct PruneEH : public CallGraphSCCPass { struct PruneEH : public CallGraphSCCPass {
/// DoesNotThrow - This set contains all of the functions which we have /// DoesNotUnwind - This set contains all of the functions which we have
/// determined cannot throw exceptions. /// determined cannot throw exceptions.
std::set<CallGraphNode*> DoesNotThrow; std::set<CallGraphNode*> DoesNotUnwind;
// runOnSCC - Analyze the SCC, performing the transformation if possible. // runOnSCC - Analyze the SCC, performing the transformation if possible.
bool runOnSCC(const std::vector<CallGraphNode *> &SCC); bool runOnSCC(const std::vector<CallGraphNode *> &SCC);
@ -50,17 +50,17 @@ bool PruneEH::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
// If this SCC includes the unwind instruction, we KNOW it throws, so // If this SCC includes the unwind instruction, we KNOW it throws, so
// obviously the SCC might throw. // obviously the SCC might throw.
// //
bool SCCMightThrow = false; bool SCCMightUnwind = false;
for (unsigned i = 0, e = SCC.size(); !SCCMightThrow && i != e; ++i) { for (unsigned i = 0, e = SCC.size(); !SCCMightUnwind && i != e; ++i) {
Function *F = SCC[i]->getFunction(); Function *F = SCC[i]->getFunction();
if (F == 0 || (F->isExternal() && !F->getIntrinsicID())) { if (F == 0 || (F->isExternal() && !F->getIntrinsicID())) {
SCCMightThrow = true; SCCMightUnwind = true;
} else { } else {
// Check to see if this function performs an unwind or calls an // Check to see if this function performs an unwind or calls an
// unwinding function. // unwinding function.
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) { for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
if (isa<UnwindInst>(BB->getTerminator())) { // Uses unwind! if (isa<UnwindInst>(BB->getTerminator())) { // Uses unwind!
SCCMightThrow = true; SCCMightUnwind = true;
break; break;
} }
@ -73,18 +73,18 @@ bool PruneEH::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
// If the callee is outside our current SCC, or if it is not // If the callee is outside our current SCC, or if it is not
// known to throw, then we might throw also. // known to throw, then we might throw also.
if (std::find(SCC.begin(), SCC.end(), CalleeNode) == SCC.end()&& if (std::find(SCC.begin(), SCC.end(), CalleeNode) == SCC.end()&&
!DoesNotThrow.count(CalleeNode)) { !DoesNotUnwind.count(CalleeNode)) {
SCCMightThrow = true; SCCMightUnwind = true;
break; break;
} }
} else { } else {
// Indirect call, it might throw. // Indirect call, it might throw.
SCCMightThrow = true; SCCMightUnwind = true;
break; break;
} }
} }
if (SCCMightThrow) break; if (SCCMightUnwind) break;
} }
} }
} }
@ -92,8 +92,8 @@ bool PruneEH::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
for (unsigned i = 0, e = SCC.size(); i != e; ++i) { for (unsigned i = 0, e = SCC.size(); i != e; ++i) {
// If the SCC can't throw, remember this for callers... // If the SCC can't throw, remember this for callers...
if (!SCCMightThrow) if (!SCCMightUnwind)
DoesNotThrow.insert(SCC[i]); DoesNotUnwind.insert(SCC[i]);
// Convert any invoke instructions to non-throwing functions in this node // Convert any invoke instructions to non-throwing functions in this node
// into call instructions with a branch. This makes the exception blocks // into call instructions with a branch. This makes the exception blocks
@ -102,7 +102,7 @@ bool PruneEH::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I)
if (InvokeInst *II = dyn_cast<InvokeInst>(I->getTerminator())) if (InvokeInst *II = dyn_cast<InvokeInst>(I->getTerminator()))
if (Function *F = II->getCalledFunction()) if (Function *F = II->getCalledFunction())
if (DoesNotThrow.count(CG[F])) { if (DoesNotUnwind.count(CG[F])) {
// Insert a call instruction before the invoke... // Insert a call instruction before the invoke...
std::string Name = II->getName(); II->setName(""); std::string Name = II->getName(); II->setName("");
Value *Call = new CallInst(II->getCalledValue(), Value *Call = new CallInst(II->getCalledValue(),