From a03aa8f8e72231673a35b6df5c42690630e2d186 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Sat, 10 Oct 2015 00:04:29 +0000 Subject: [PATCH] [WinEH] Remove more dead code wineh-parent is dead, so is ValueOrMBB. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249920 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineModuleInfo.h | 3 +- include/llvm/CodeGen/WinEHFuncInfo.h | 5 +- lib/CodeGen/AsmPrinter/WinException.cpp | 50 +++++++++---------- lib/CodeGen/MachineModuleInfo.cpp | 10 +--- .../SelectionDAG/FunctionLoweringInfo.cpp | 16 +++--- lib/CodeGen/WinEHPrepare.cpp | 8 +-- lib/Target/X86/X86ISelLowering.cpp | 6 +-- lib/Target/X86/X86WinEHState.cpp | 23 +++------ 8 files changed, 44 insertions(+), 77 deletions(-) diff --git a/include/llvm/CodeGen/MachineModuleInfo.h b/include/llvm/CodeGen/MachineModuleInfo.h index 70a771ee368..8cc5d6f242f 100644 --- a/include/llvm/CodeGen/MachineModuleInfo.h +++ b/include/llvm/CodeGen/MachineModuleInfo.h @@ -220,10 +220,9 @@ public: void setModule(const Module *M) { TheModule = M; } const Module *getModule() const { return TheModule; } - const Function *getWinEHParent(const Function *F) const; WinEHFuncInfo &getWinEHFuncInfo(const Function *F); bool hasWinEHFuncInfo(const Function *F) const { - return FuncInfoMap.count(getWinEHParent(F)) > 0; + return FuncInfoMap.count(F) > 0; } /// getInfo - Keep track of various per-function pieces of information for diff --git a/include/llvm/CodeGen/WinEHFuncInfo.h b/include/llvm/CodeGen/WinEHFuncInfo.h index 89a75058247..2eedf363d40 100644 --- a/include/llvm/CodeGen/WinEHFuncInfo.h +++ b/include/llvm/CodeGen/WinEHFuncInfo.h @@ -37,11 +37,10 @@ class Value; // Windows-related EH personalities. typedef PointerUnion MBBOrBasicBlock; -typedef PointerUnion ValueOrMBB; struct CxxUnwindMapEntry { int ToState; - ValueOrMBB Cleanup; + MBBOrBasicBlock Cleanup; }; /// Similar to CxxUnwindMapEntry, but supports SEH filters. @@ -69,7 +68,7 @@ struct WinEHHandlerType { int FrameIndex; } CatchObj = {}; GlobalVariable *TypeDescriptor; - ValueOrMBB Handler; + MBBOrBasicBlock Handler; }; struct WinEHTryBlockMapEntry { diff --git a/lib/CodeGen/AsmPrinter/WinException.cpp b/lib/CodeGen/AsmPrinter/WinException.cpp index adc47650235..f6945b1d1fb 100644 --- a/lib/CodeGen/AsmPrinter/WinException.cpp +++ b/lib/CodeGen/AsmPrinter/WinException.cpp @@ -67,7 +67,6 @@ void WinException::beginFunction(const MachineFunction *MF) { bool hasEHFunclets = MMI->hasEHFunclets(); const Function *F = MF->getFunction(); - const Function *ParentF = MMI->getWinEHParent(F); shouldEmitMoves = Asm->needsSEHMoves(); @@ -91,11 +90,8 @@ void WinException::beginFunction(const MachineFunction *MF) { // If we're not using CFI, we don't want the CFI or the personality, but we // might want EH tables if we had EH pads. - // FIXME: If WinEHPrepare outlined something, we should emit the LSDA. Remove - // this once WinEHPrepare stops doing that. if (!Asm->MAI->usesWindowsCFI()) { - shouldEmitLSDA = - hasEHFunclets || (F->hasFnAttribute("wineh-parent") && F == ParentF); + shouldEmitLSDA = hasEHFunclets; shouldEmitPersonality = false; return; } @@ -152,25 +148,23 @@ void WinException::endFunction(const MachineFunction *MF) { /// Retreive the MCSymbol for a GlobalValue or MachineBasicBlock. GlobalValues /// are used in the old WinEH scheme, and they will be removed eventually. -static MCSymbol *getMCSymbolForMBBOrGV(AsmPrinter *Asm, ValueOrMBB Handler) { - if (!Handler) +static MCSymbol *getMCSymbolForMBB(AsmPrinter *Asm, + const MachineBasicBlock *MBB) { + if (!MBB) return nullptr; - if (Handler.is()) { - auto *MBB = Handler.get(); - assert(MBB->isEHFuncletEntry()); - - // Give catches and cleanups a name based off of their parent function and - // their funclet entry block's number. - const MachineFunction *MF = MBB->getParent(); - const Function *F = MF->getFunction(); - StringRef FuncLinkageName = GlobalValue::getRealLinkageName(F->getName()); - MCContext &Ctx = MF->getContext(); - StringRef HandlerPrefix = MBB->isCleanupFuncletEntry() ? "dtor" : "catch"; - return Ctx.getOrCreateSymbol("?" + HandlerPrefix + "$" + - Twine(MBB->getNumber()) + "@?0?" + - FuncLinkageName + "@4HA"); - } - return Asm->getSymbol(cast(Handler.get())); + + assert(MBB->isEHFuncletEntry()); + + // Give catches and cleanups a name based off of their parent function and + // their funclet entry block's number. + const MachineFunction *MF = MBB->getParent(); + const Function *F = MF->getFunction(); + StringRef FuncLinkageName = GlobalValue::getRealLinkageName(F->getName()); + MCContext &Ctx = MF->getContext(); + StringRef HandlerPrefix = MBB->isCleanupFuncletEntry() ? "dtor" : "catch"; + return Ctx.getOrCreateSymbol("?" + HandlerPrefix + "$" + + Twine(MBB->getNumber()) + "@?0?" + + FuncLinkageName + "@4HA"); } void WinException::beginFunclet(const MachineBasicBlock &MBB, @@ -180,7 +174,7 @@ void WinException::beginFunclet(const MachineBasicBlock &MBB, const Function *F = Asm->MF->getFunction(); // If a symbol was not provided for the funclet, invent one. if (!Sym) { - Sym = getMCSymbolForMBBOrGV(Asm, &MBB); + Sym = getMCSymbolForMBB(Asm, &MBB); // Describe our funclet symbol as a function with internal linkage. Asm->OutStreamer->BeginCOFFSymbolDef(Sym); @@ -504,7 +498,7 @@ void WinException::emitSEHActionsForRange(WinEHFuncInfo &FuncInfo, const MCExpr *ExceptOrNull; auto *Handler = UME.Handler.get(); if (UME.IsFinally) { - FilterOrFinally = create32bitRef(getMCSymbolForMBBOrGV(Asm, Handler)); + FilterOrFinally = create32bitRef(getMCSymbolForMBB(Asm, Handler)); ExceptOrNull = MCConstantExpr::create(0, Ctx); } else { // For an except, the filter can be 1 (catch-all) or a function @@ -597,7 +591,8 @@ void WinException::emitCXXFrameHandler3Table(const MachineFunction *MF) { if (UnwindMapXData) { OS.EmitLabel(UnwindMapXData); for (const CxxUnwindMapEntry &UME : FuncInfo.CxxUnwindMap) { - MCSymbol *CleanupSym = getMCSymbolForMBBOrGV(Asm, UME.Cleanup); + MCSymbol *CleanupSym = + getMCSymbolForMBB(Asm, UME.Cleanup.dyn_cast()); OS.EmitIntValue(UME.ToState, 4); // ToState OS.EmitValue(create32bitRef(CleanupSym), 4); // Action } @@ -677,7 +672,8 @@ void WinException::emitCXXFrameHandler3Table(const MachineFunction *MF) { FrameAllocOffsetRef = MCConstantExpr::create(0, Asm->OutContext); } - MCSymbol *HandlerSym = getMCSymbolForMBBOrGV(Asm, HT.Handler); + MCSymbol *HandlerSym = + getMCSymbolForMBB(Asm, HT.Handler.dyn_cast()); OS.EmitIntValue(HT.Adjectives, 4); // Adjectives OS.EmitValue(create32bitRef(HT.TypeDescriptor), 4); // Type diff --git a/lib/CodeGen/MachineModuleInfo.cpp b/lib/CodeGen/MachineModuleInfo.cpp index ee5852a8f93..33db3edffb7 100644 --- a/lib/CodeGen/MachineModuleInfo.cpp +++ b/lib/CodeGen/MachineModuleInfo.cpp @@ -467,16 +467,8 @@ try_next:; return FilterID; } -const Function *MachineModuleInfo::getWinEHParent(const Function *F) const { - StringRef WinEHParentName = - F->getFnAttribute("wineh-parent").getValueAsString(); - if (WinEHParentName.empty() || WinEHParentName == F->getName()) - return F; - return F->getParent()->getFunction(WinEHParentName); -} - WinEHFuncInfo &MachineModuleInfo::getWinEHFuncInfo(const Function *F) { - auto &Ptr = FuncInfoMap[getWinEHParent(F)]; + auto &Ptr = FuncInfoMap[F]; if (!Ptr) Ptr.reset(new WinEHFuncInfo); return *Ptr; diff --git a/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp b/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp index d9b32d92c8e..b0d81030931 100644 --- a/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp +++ b/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp @@ -285,15 +285,14 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf, // Calculate state numbers if we haven't already. WinEHFuncInfo &EHInfo = MMI.getWinEHFuncInfo(&fn); - const Function *WinEHParentFn = MMI.getWinEHParent(&fn); if (Personality == EHPersonality::MSVC_CXX) - calculateWinCXXEHStateNumbers(WinEHParentFn, EHInfo); + calculateWinCXXEHStateNumbers(&fn, EHInfo); else if (isAsynchronousEHPersonality(Personality)) - calculateSEHStateNumbers(WinEHParentFn, EHInfo); + calculateSEHStateNumbers(&fn, EHInfo); else if (Personality == EHPersonality::CoreCLR) - calculateClrEHStateNumbers(WinEHParentFn, EHInfo); + calculateClrEHStateNumbers(&fn, EHInfo); - calculateCatchReturnSuccessorColors(WinEHParentFn, EHInfo); + calculateCatchReturnSuccessorColors(&fn, EHInfo); // Map all BB references in the WinEH data to MBBs. for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap) { @@ -304,14 +303,13 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf, } else { H.CatchObj.FrameIndex = INT_MAX; } - if (const auto *BB = dyn_cast(H.Handler.get())) - H.Handler = MBBMap[BB]; + if (H.Handler) + H.Handler = MBBMap[H.Handler.get()]; } } for (CxxUnwindMapEntry &UME : EHInfo.CxxUnwindMap) if (UME.Cleanup) - if (const auto *BB = dyn_cast(UME.Cleanup.get())) - UME.Cleanup = MBBMap[BB]; + UME.Cleanup = MBBMap[UME.Cleanup.get()]; for (SEHUnwindMapEntry &UME : EHInfo.SEHUnwindMap) { const BasicBlock *BB = UME.Handler.get(); UME.Handler = MBBMap[BB]; diff --git a/lib/CodeGen/WinEHPrepare.cpp b/lib/CodeGen/WinEHPrepare.cpp index 5affb3f0924..3872879cd74 100644 --- a/lib/CodeGen/WinEHPrepare.cpp +++ b/lib/CodeGen/WinEHPrepare.cpp @@ -144,10 +144,6 @@ bool WinEHPrepare::runOnFunction(Function &Fn) { if (!Fn.hasPersonalityFn()) return false; - // No need to prepare outlined handlers. - if (Fn.hasFnAttribute("wineh-parent")) - return false; - // Classify the personality to see what kind of preparation we need. Personality = classifyEHPersonality(Fn.getPersonalityFn()); @@ -173,10 +169,10 @@ void WinEHPrepare::getAnalysisUsage(AnalysisUsage &AU) const { } static int addUnwindMapEntry(WinEHFuncInfo &FuncInfo, int ToState, - const Value *V) { + const BasicBlock *BB) { CxxUnwindMapEntry UME; UME.ToState = ToState; - UME.Cleanup = V; + UME.Cleanup = BB; FuncInfo.CxxUnwindMap.push_back(UME); return FuncInfo.getLastStateNumber(); } diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index f6f137a1b92..069cfe49f2e 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -2701,10 +2701,6 @@ SDValue X86TargetLowering::LowerFormalArguments( } MachineModuleInfo &MMI = MF.getMMI(); - const Function *WinEHParent = nullptr; - if (MMI.hasWinEHFuncInfo(Fn)) - WinEHParent = MMI.getWinEHParent(Fn); - bool IsWinEHParent = WinEHParent && WinEHParent == Fn; // Figure out if XMM registers are in use. assert(!(Subtarget->useSoftFloat() && @@ -2861,7 +2857,7 @@ SDValue X86TargetLowering::LowerFormalArguments( FuncInfo->setArgumentStackSize(StackSize); - if (IsWinEHParent) { + if (MMI.hasWinEHFuncInfo(Fn)) { if (Is64Bit) { int UnwindHelpFI = MFI->CreateStackObject(8, 8, /*isSS=*/false); SDValue StackSlot = DAG.getFrameIndex(UnwindHelpFI, MVT::i64); diff --git a/lib/Target/X86/X86WinEHState.cpp b/lib/Target/X86/X86WinEHState.cpp index ed909c58e9b..a4ae396f826 100644 --- a/lib/Target/X86/X86WinEHState.cpp +++ b/lib/Target/X86/X86WinEHState.cpp @@ -149,13 +149,6 @@ void WinEHStatePass::getAnalysisUsage(AnalysisUsage &AU) const { } bool WinEHStatePass::runOnFunction(Function &F) { - // If this is an outlined handler, don't do anything. We'll do state insertion - // for it in the parent. - StringRef WinEHParentName = - F.getFnAttribute("wineh-parent").getValueAsString(); - if (WinEHParentName != F.getName() && !WinEHParentName.empty()) - return false; - // Check the personality. Do nothing if this personality doesn't use funclets. if (!F.hasPersonalityFn()) return false; @@ -169,17 +162,15 @@ bool WinEHStatePass::runOnFunction(Function &F) { // Skip this function if there are no EH pads and we aren't using IR-level // outlining. - if (WinEHParentName.empty()) { - bool HasPads = false; - for (BasicBlock &BB : F) { - if (BB.isEHPad()) { - HasPads = true; - break; - } + bool HasPads = false; + for (BasicBlock &BB : F) { + if (BB.isEHPad()) { + HasPads = true; + break; } - if (!HasPads) - return false; } + if (!HasPads) + return false; // Disable frame pointer elimination in this function. // FIXME: Do the nested handlers need to keep the parent ebp in ebp, or can we -- 2.34.1