summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2009-09-14 20:52:37 +0000
committerBill Wendling <isanbard@gmail.com>2009-09-14 20:52:37 +0000
commit6dcc9d1b4be0d8d35b95ba8b3b8908e2bdb75fa3 (patch)
treec5a71d1738b42eb1de436bb8328071ced9255745 /llvm/lib/CodeGen
parentf4061e39a38cdd113eda7f0023eefca1ccdcdfe1 (diff)
downloadbcm5719-llvm-6dcc9d1b4be0d8d35b95ba8b3b8908e2bdb75fa3.tar.gz
bcm5719-llvm-6dcc9d1b4be0d8d35b95ba8b3b8908e2bdb75fa3.zip
Pull the creation of the "RewindFunction" function out of the loop. It's only
created once, so shouldn't be stuck in the middle of the loop. Also early exit if there are no uses of UnwindInst in the function. llvm-svn: 81785
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/DwarfEHPrepare.cpp39
1 files changed, 25 insertions, 14 deletions
diff --git a/llvm/lib/CodeGen/DwarfEHPrepare.cpp b/llvm/lib/CodeGen/DwarfEHPrepare.cpp
index a2e6068ff87..be6205e174a 100644
--- a/llvm/lib/CodeGen/DwarfEHPrepare.cpp
+++ b/llvm/lib/CodeGen/DwarfEHPrepare.cpp
@@ -219,29 +219,40 @@ bool DwarfEHPrepare::NormalizeLandingPads() {
/// at runtime if there is no such exception: using unwind to throw a new
/// exception is currently not supported.
bool DwarfEHPrepare::LowerUnwinds() {
- bool Changed = false;
+ SmallVector<TerminatorInst*, 16> UnwindInsts;
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
TerminatorInst *TI = I->getTerminator();
- if (!isa<UnwindInst>(TI))
- continue;
+ if (isa<UnwindInst>(TI))
+ UnwindInsts.push_back(TI);
+ }
+
+ if (UnwindInsts.empty()) return false;
+
+ // Find the rewind function if we didn't already.
+ if (!RewindFunction) {
+ LLVMContext &Ctx = UnwindInsts[0]->getContext();
+ std::vector<const Type*>
+ Params(1, PointerType::getUnqual(Type::getInt8Ty(Ctx)));
+ FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx),
+ Params, false);
+ const char *RewindName = TLI->getLibcallName(RTLIB::UNWIND_RESUME);
+ RewindFunction = F->getParent()->getOrInsertFunction(RewindName, FTy);
+ }
+
+ bool Changed = false;
+
+ for (SmallVectorImpl<TerminatorInst*>::iterator
+ I = UnwindInsts.begin(), E = UnwindInsts.end(); I != E; ++I) {
+ TerminatorInst *TI = *I;
// Replace the unwind instruction with a call to _Unwind_Resume (or the
// appropriate target equivalent) followed by an UnreachableInst.
- // Find the rewind function if we didn't already.
- if (!RewindFunction) {
- std::vector<const Type*> Params(1,
- PointerType::getUnqual(Type::getInt8Ty(TI->getContext())));
- FunctionType *FTy = FunctionType::get(Type::getVoidTy(TI->getContext()),
- Params, false);
- const char *RewindName = TLI->getLibcallName(RTLIB::UNWIND_RESUME);
- RewindFunction = F->getParent()->getOrInsertFunction(RewindName, FTy);
- }
-
// Create the call...
CallInst *CI = CallInst::Create(RewindFunction,
- CreateReadOfExceptionValue(I), "", TI);
+ CreateReadOfExceptionValue(TI->getParent()),
+ "", TI);
CI->setCallingConv(TLI->getLibcallCallingConv(RTLIB::UNWIND_RESUME));
// ...followed by an UnreachableInst.
new UnreachableInst(TI->getContext(), TI);
OpenPOWER on IntegriCloud