From: Chris Lattner Date: Sun, 27 Nov 2011 05:56:16 +0000 (+0000) Subject: remove autoupgrade support for LLVM 2.9 exception stuff. Mainline supports X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=9d5f6ccd26615592361baa299fc5b450501fb1b0;p=oota-llvm.git remove autoupgrade support for LLVM 2.9 exception stuff. Mainline supports LLVM 3.0 and later. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145165 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/AutoUpgrade.h b/include/llvm/AutoUpgrade.h index 8ca3548f533..5ce20b69e2f 100644 --- a/include/llvm/AutoUpgrade.h +++ b/include/llvm/AutoUpgrade.h @@ -43,10 +43,6 @@ namespace llvm { /// This function checks debug info intrinsics. If an intrinsic is invalid /// then this function simply removes the intrinsic. void CheckDebugInfoIntrinsics(Module *M); - - /// This function upgrades the old pre-3.0 exception handling system to the - /// new one. N.B. This will be removed in 3.1. - void UpgradeExceptionHandling(Module *M); } // End llvm namespace #endif diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index cafaab01afd..d2c91dd21c8 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -120,9 +120,6 @@ bool LLParser::ValidateEndOfModule() { for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ) UpgradeCallsToIntrinsic(FI++); // must be post-increment, as we remove - // Upgrade to new EH scheme. N.B. This will go away in 3.1. - UpgradeExceptionHandling(M); - // Check debug info intrinsics. CheckDebugInfoIntrinsics(M); return false; diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 1d1600a0f28..43cab159220 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2701,9 +2701,6 @@ bool BitcodeReader::MaterializeModule(Module *M, std::string *ErrInfo) { } std::vector >().swap(UpgradedIntrinsics); - // Upgrade to new EH scheme. N.B. This will go away in 3.1. - UpgradeExceptionHandling(M); - // Check debug info intrinsics. CheckDebugInfoIntrinsics(TheModule); diff --git a/lib/VMCore/AutoUpgrade.cpp b/lib/VMCore/AutoUpgrade.cpp index b849d3ef8dc..7b4a8f7ddf4 100644 --- a/lib/VMCore/AutoUpgrade.cpp +++ b/lib/VMCore/AutoUpgrade.cpp @@ -420,249 +420,3 @@ void llvm::CheckDebugInfoIntrinsics(Module *M) { } } } - -/// FindExnAndSelIntrinsics - Find the eh_exception and eh_selector intrinsic -/// calls reachable from the unwind basic block. -static void FindExnAndSelIntrinsics(BasicBlock *BB, CallInst *&Exn, - CallInst *&Sel, - SmallPtrSet &Visited) { - if (!Visited.insert(BB)) return; - - for (BasicBlock::iterator - I = BB->begin(), E = BB->end(); I != E; ++I) { - if (CallInst *CI = dyn_cast(I)) { - switch (CI->getCalledFunction()->getIntrinsicID()) { - default: break; - case Intrinsic::eh_exception: - assert(!Exn && "Found more than one eh.exception call!"); - Exn = CI; - break; - case Intrinsic::eh_selector: - assert(!Sel && "Found more than one eh.selector call!"); - Sel = CI; - break; - } - - if (Exn && Sel) return; - } - } - - if (Exn && Sel) return; - - for (succ_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I) { - FindExnAndSelIntrinsics(*I, Exn, Sel, Visited); - if (Exn && Sel) return; - } -} - -/// TransferClausesToLandingPadInst - Transfer the exception handling clauses -/// from the eh_selector call to the new landingpad instruction. -static void TransferClausesToLandingPadInst(LandingPadInst *LPI, - CallInst *EHSel) { - LLVMContext &Context = LPI->getContext(); - unsigned N = EHSel->getNumArgOperands(); - - for (unsigned i = N - 1; i > 1; --i) { - if (const ConstantInt *CI = dyn_cast(EHSel->getArgOperand(i))){ - unsigned FilterLength = CI->getZExtValue(); - unsigned FirstCatch = i + FilterLength + !FilterLength; - assert(FirstCatch <= N && "Invalid filter length"); - - if (FirstCatch < N) - for (unsigned j = FirstCatch; j < N; ++j) { - Value *Val = EHSel->getArgOperand(j); - if (!Val->hasName() || Val->getName() != "llvm.eh.catch.all.value") { - LPI->addClause(EHSel->getArgOperand(j)); - } else { - GlobalVariable *GV = cast(Val); - LPI->addClause(GV->getInitializer()); - } - } - - if (!FilterLength) { - // Cleanup. - LPI->setCleanup(true); - } else { - // Filter. - SmallVector TyInfo; - TyInfo.reserve(FilterLength - 1); - for (unsigned j = i + 1; j < FirstCatch; ++j) - TyInfo.push_back(cast(EHSel->getArgOperand(j))); - ArrayType *AType = - ArrayType::get(!TyInfo.empty() ? TyInfo[0]->getType() : - PointerType::getUnqual(Type::getInt8Ty(Context)), - TyInfo.size()); - LPI->addClause(ConstantArray::get(AType, TyInfo)); - } - - N = i; - } - } - - if (N > 2) - for (unsigned j = 2; j < N; ++j) { - Value *Val = EHSel->getArgOperand(j); - if (!Val->hasName() || Val->getName() != "llvm.eh.catch.all.value") { - LPI->addClause(EHSel->getArgOperand(j)); - } else { - GlobalVariable *GV = cast(Val); - LPI->addClause(GV->getInitializer()); - } - } -} - -/// This function upgrades the old pre-3.0 exception handling system to the new -/// one. N.B. This will be removed in 3.1. -void llvm::UpgradeExceptionHandling(Module *M) { - Function *EHException = M->getFunction("llvm.eh.exception"); - Function *EHSelector = M->getFunction("llvm.eh.selector"); - if (!EHException || !EHSelector) - return; - - LLVMContext &Context = M->getContext(); - Type *ExnTy = PointerType::getUnqual(Type::getInt8Ty(Context)); - Type *SelTy = Type::getInt32Ty(Context); - Type *LPadSlotTy = StructType::get(ExnTy, SelTy, NULL); - - // This map links the invoke instruction with the eh.exception and eh.selector - // calls associated with it. - DenseMap > InvokeToIntrinsicsMap; - for (Module::iterator - I = M->begin(), E = M->end(); I != E; ++I) { - Function &F = *I; - - for (Function::iterator - II = F.begin(), IE = F.end(); II != IE; ++II) { - BasicBlock *BB = &*II; - InvokeInst *Inst = dyn_cast(BB->getTerminator()); - if (!Inst) continue; - BasicBlock *UnwindDest = Inst->getUnwindDest(); - if (UnwindDest->isLandingPad()) continue; // Already converted. - - SmallPtrSet Visited; - CallInst *Exn = 0; - CallInst *Sel = 0; - FindExnAndSelIntrinsics(UnwindDest, Exn, Sel, Visited); - assert(Exn && Sel && "Cannot find eh.exception and eh.selector calls!"); - InvokeToIntrinsicsMap[Inst] = std::make_pair(Exn, Sel); - } - } - - // This map stores the slots where the exception object and selector value are - // stored within a function. - DenseMap > FnToLPadSlotMap; - SmallPtrSet DeadInsts; - for (DenseMap >::iterator - I = InvokeToIntrinsicsMap.begin(), E = InvokeToIntrinsicsMap.end(); - I != E; ++I) { - InvokeInst *Invoke = I->first; - BasicBlock *UnwindDest = Invoke->getUnwindDest(); - Function *F = UnwindDest->getParent(); - std::pair EHIntrinsics = I->second; - CallInst *Exn = cast(EHIntrinsics.first); - CallInst *Sel = cast(EHIntrinsics.second); - - // Store the exception object and selector value in the entry block. - Value *ExnSlot = 0; - Value *SelSlot = 0; - if (!FnToLPadSlotMap[F].first) { - BasicBlock *Entry = &F->front(); - ExnSlot = new AllocaInst(ExnTy, "exn", Entry->getTerminator()); - SelSlot = new AllocaInst(SelTy, "sel", Entry->getTerminator()); - FnToLPadSlotMap[F] = std::make_pair(ExnSlot, SelSlot); - } else { - ExnSlot = FnToLPadSlotMap[F].first; - SelSlot = FnToLPadSlotMap[F].second; - } - - if (!UnwindDest->getSinglePredecessor()) { - // The unwind destination doesn't have a single predecessor. Create an - // unwind destination which has only one predecessor. - BasicBlock *NewBB = BasicBlock::Create(Context, "new.lpad", - UnwindDest->getParent()); - BranchInst::Create(UnwindDest, NewBB); - Invoke->setUnwindDest(NewBB); - - // Fix up any PHIs in the original unwind destination block. - for (BasicBlock::iterator - II = UnwindDest->begin(); isa(II); ++II) { - PHINode *PN = cast(II); - int Idx = PN->getBasicBlockIndex(Invoke->getParent()); - if (Idx == -1) continue; - PN->setIncomingBlock(Idx, NewBB); - } - - UnwindDest = NewBB; - } - - IRBuilder<> Builder(Context); - Builder.SetInsertPoint(UnwindDest, UnwindDest->getFirstInsertionPt()); - - Value *PersFn = Sel->getArgOperand(1); - LandingPadInst *LPI = Builder.CreateLandingPad(LPadSlotTy, PersFn, 0); - Value *LPExn = Builder.CreateExtractValue(LPI, 0); - Value *LPSel = Builder.CreateExtractValue(LPI, 1); - Builder.CreateStore(LPExn, ExnSlot); - Builder.CreateStore(LPSel, SelSlot); - - TransferClausesToLandingPadInst(LPI, Sel); - - DeadInsts.insert(Exn); - DeadInsts.insert(Sel); - } - - // Replace the old intrinsic calls with the values from the landingpad - // instruction(s). These values were stored in allocas for us to use here. - for (DenseMap >::iterator - I = InvokeToIntrinsicsMap.begin(), E = InvokeToIntrinsicsMap.end(); - I != E; ++I) { - std::pair EHIntrinsics = I->second; - CallInst *Exn = cast(EHIntrinsics.first); - CallInst *Sel = cast(EHIntrinsics.second); - BasicBlock *Parent = Exn->getParent(); - - std::pair ExnSelSlots = FnToLPadSlotMap[Parent->getParent()]; - - IRBuilder<> Builder(Context); - Builder.SetInsertPoint(Parent, Exn); - LoadInst *LPExn = Builder.CreateLoad(ExnSelSlots.first, "exn.load"); - LoadInst *LPSel = Builder.CreateLoad(ExnSelSlots.second, "sel.load"); - - Exn->replaceAllUsesWith(LPExn); - Sel->replaceAllUsesWith(LPSel); - } - - // Remove the dead instructions. - for (SmallPtrSet::iterator - I = DeadInsts.begin(), E = DeadInsts.end(); I != E; ++I) { - Instruction *Inst = *I; - Inst->eraseFromParent(); - } - - // Replace calls to "llvm.eh.resume" with the 'resume' instruction. Load the - // exception and selector values from the stored place. - Function *EHResume = M->getFunction("llvm.eh.resume"); - if (!EHResume) return; - - while (!EHResume->use_empty()) { - CallInst *Resume = cast(EHResume->use_back()); - BasicBlock *BB = Resume->getParent(); - - IRBuilder<> Builder(Context); - Builder.SetInsertPoint(BB, Resume); - - Value *LPadVal = - Builder.CreateInsertValue(UndefValue::get(LPadSlotTy), - Resume->getArgOperand(0), 0, "lpad.val"); - LPadVal = Builder.CreateInsertValue(LPadVal, Resume->getArgOperand(1), - 1, "lpad.val"); - Builder.CreateResume(LPadVal); - - // Remove all instructions after the 'resume.' - BasicBlock::iterator I = Resume; - while (I != BB->end()) { - Instruction *Inst = &*I++; - Inst->eraseFromParent(); - } - } -}