[WinEHPrepare] Don't rely on the order of IR
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 10 Apr 2015 04:56:17 +0000 (04:56 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 10 Apr 2015 04:56:17 +0000 (04:56 +0000)
The IPToState table must be emitted after we have generated labels for
all functions in the table.  Don't rely on the order of the list of
globals.  Instead, utilize WinEHFuncInfo to tell us how many catch
handlers we expect to outline.  Once we know we've visited all the catch
handlers, emit the cppxdata.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234566 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/WinEHFuncInfo.h
lib/CodeGen/AsmPrinter/Win64Exception.cpp
lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp

index 9b826754015f1dd33ac9ab3464143553705ddcc1..5fc2b126db83f1a917a9d3eaa98ba55f7e956dd8 100644 (file)
@@ -142,7 +142,11 @@ struct WinEHFuncInfo {
   int UnwindHelpFrameIdx;
   int UnwindHelpFrameOffset;
 
-  WinEHFuncInfo() : UnwindHelpFrameIdx(INT_MAX), UnwindHelpFrameOffset(-1) {}
+  unsigned NumIPToStateFuncsVisited;
+
+  WinEHFuncInfo()
+      : UnwindHelpFrameIdx(INT_MAX), UnwindHelpFrameOffset(-1),
+        NumIPToStateFuncsVisited(0) {}
 };
 
 }
index a685d2e23d5fbeaf0fd3b4a8a9c831eb333bd1be..39f7875cb3fcd5be5ff63954a21e72c806abf67d 100644 (file)
@@ -343,7 +343,11 @@ void Win64Exception::emitCXXFrameHandler3Table(const MachineFunction *MF) {
     }
   }
 
-  if (ParentF != F)
+  // Defer emission until we've visited the parent function and all the catch
+  // handlers.
+  if (ParentF == F || FuncInfo.CatchHandlerMaxState.count(F))
+    ++FuncInfo.NumIPToStateFuncsVisited;
+  if (FuncInfo.NumIPToStateFuncsVisited != FuncInfo.CatchHandlerMaxState.size())
     return;
 
   MCSymbol *UnwindMapXData = nullptr;
index 8eac8eb4f1b055a5a806dd6db947d8646461cf5b..65a67265d7942a597b9e8466194349d3268ae0b6 100644 (file)
@@ -275,11 +275,15 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
       MBBMap[Invoke->getSuccessor(1)]->setIsLandingPad();
 
   // Calculate EH numbers for WinEH.
-  if (fn.getFnAttribute("wineh-parent").getValueAsString() == fn.getName()) {
-    WinEHNumbering Num(MMI.getWinEHFuncInfo(&fn));
-    Num.calculateStateNumbers(fn);
-    // Pop everything on the handler stack.
-    Num.processCallSite(None, ImmutableCallSite());
+  if (fn.hasFnAttribute("wineh-parent")) {
+    const Function *WinEHParentFn = MMI.getWinEHParent(&fn);
+    WinEHFuncInfo &FI = MMI.getWinEHFuncInfo(WinEHParentFn);
+    if (FI.LandingPadStateMap.empty()) {
+      WinEHNumbering Num(FI);
+      Num.calculateStateNumbers(*WinEHParentFn);
+      // Pop everything on the handler stack.
+      Num.processCallSite(None, ImmutableCallSite());
+    }
   }
 }