[WinEH] Remove more dead code
authorDavid Majnemer <david.majnemer@gmail.com>
Sat, 10 Oct 2015 00:04:29 +0000 (00:04 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sat, 10 Oct 2015 00:04:29 +0000 (00:04 +0000)
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
include/llvm/CodeGen/WinEHFuncInfo.h
lib/CodeGen/AsmPrinter/WinException.cpp
lib/CodeGen/MachineModuleInfo.cpp
lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
lib/CodeGen/WinEHPrepare.cpp
lib/Target/X86/X86ISelLowering.cpp
lib/Target/X86/X86WinEHState.cpp

index 70a771ee368f72a1641111b255a39e12d8cbc52d..8cc5d6f242f0880fb27e5810a601a8e1a571ffeb 100644 (file)
@@ -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
index 89a750582472d82994f0e001cfab6edca13b76a2..2eedf363d4044e852a7fa95c7fbf76086654345f 100644 (file)
@@ -37,11 +37,10 @@ class Value;
 // Windows-related EH personalities.
 
 typedef PointerUnion<const BasicBlock *, MachineBasicBlock *> MBBOrBasicBlock;
-typedef PointerUnion<const Value *, const MachineBasicBlock *> 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 {
index adc476502354411802fb20f415f3986874ccaa2f..f6945b1d1fb0c1b888968ddddf42b54ea1a2bf60 100644 (file)
@@ -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<const MachineBasicBlock *>()) {
-    auto *MBB = Handler.get<const MachineBasicBlock *>();
-    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<GlobalValue>(Handler.get<const Value *>()));
+
+  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<MachineBasicBlock *>();
     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<MachineBasicBlock *>());
       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<MachineBasicBlock *>());
 
         OS.EmitIntValue(HT.Adjectives, 4);                  // Adjectives
         OS.EmitValue(create32bitRef(HT.TypeDescriptor), 4); // Type
index ee5852a8f9314b5845fe53e8b8c4868b05c3896b..33db3edffb70439fd63cf147c33c3ff8d7d1d06a 100644 (file)
@@ -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;
index d9b32d92c8e135253bea9ebc2bad86f282815b19..b0d8103093192d60175702ef965a547f62982d7e 100644 (file)
@@ -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<BasicBlock>(H.Handler.get<const Value *>()))
-        H.Handler = MBBMap[BB];
+      if (H.Handler)
+        H.Handler = MBBMap[H.Handler.get<const BasicBlock *>()];
     }
   }
   for (CxxUnwindMapEntry &UME : EHInfo.CxxUnwindMap)
     if (UME.Cleanup)
-      if (const auto *BB = dyn_cast<BasicBlock>(UME.Cleanup.get<const Value *>()))
-        UME.Cleanup = MBBMap[BB];
+      UME.Cleanup = MBBMap[UME.Cleanup.get<const BasicBlock *>()];
   for (SEHUnwindMapEntry &UME : EHInfo.SEHUnwindMap) {
     const BasicBlock *BB = UME.Handler.get<const BasicBlock *>();
     UME.Handler = MBBMap[BB];
index 5affb3f0924cfeb091dab9e1cefd0ce3b2cc05ec..3872879cd741e5f27a87f1cd1afe4c6581e0d11c 100644 (file)
@@ -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();
 }
index f6f137a1b92546505ac77bb09258a553ec35132c..069cfe49f2e43f69191a4b7a7eaf71c969dc7639 100644 (file)
@@ -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);
index ed909c58e9b2d1d0e5c1a50c93672f7b2fea56e1..a4ae396f826e8af968f9e17727238815ebc30dad 100644 (file)
@@ -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