[WinEH] Make FuncletLayout more robust against catchret
[oota-llvm.git] / include / llvm / CodeGen / WinEHFuncInfo.h
index 31021f12858f4956c09a7fc135b719c0a905c9ca..79f216873024bc8526b1a571b106324cb81912c6 100644 (file)
@@ -28,6 +28,7 @@ class GlobalVariable;
 class InvokeInst;
 class IntrinsicInst;
 class LandingPadInst;
+class MCExpr;
 class MCSymbol;
 class MachineBasicBlock;
 class Value;
@@ -117,7 +118,7 @@ void parseEHActions(const IntrinsicInst *II,
 // exceptions on Windows.
 
 typedef PointerUnion<const BasicBlock *, MachineBasicBlock *> MBBOrBasicBlock;
-typedef PointerUnion<const Value *, MachineBasicBlock *> ValueOrMBB;
+typedef PointerUnion<const Value *, const MachineBasicBlock *> ValueOrMBB;
 
 struct WinEHUnwindMapEntry {
   int ToState;
@@ -139,8 +140,15 @@ struct SEHUnwindMapEntry {
 
 struct WinEHHandlerType {
   int Adjectives;
-  GlobalVariable *TypeDescriptor;
   int CatchObjRecoverIdx;
+  /// The CatchObj starts out life as an LLVM alloca, is turned into a frame
+  /// index, and after PEI, becomes a raw offset.
+  union {
+    const AllocaInst *Alloca;
+    int FrameOffset;
+    int FrameIndex;
+  } CatchObj = {};
+  GlobalVariable *TypeDescriptor;
   ValueOrMBB Handler;
 };
 
@@ -152,30 +160,27 @@ struct WinEHTryBlockMapEntry {
 };
 
 struct WinEHFuncInfo {
-  DenseMap<const Function *, const LandingPadInst *> RootLPad;
-  DenseMap<const Function *, const InvokeInst *> LastInvoke;
-  DenseMap<const Function *, int> HandlerEnclosedState;
-  DenseMap<const Function *, bool> LastInvokeVisited;
   DenseMap<const Instruction *, int> EHPadStateMap;
-  DenseMap<const Function *, int> CatchHandlerParentFrameObjIdx;
-  DenseMap<const Function *, int> CatchHandlerParentFrameObjOffset;
-  DenseMap<const Function *, int> CatchHandlerMaxState;
-  DenseMap<const Function *, int> HandlerBaseState;
+  DenseMap<const CatchReturnInst *, const BasicBlock *>
+      CatchRetSuccessorColorMap;
+  DenseMap<MCSymbol *, std::pair<int, MCSymbol *>> InvokeToStateMap;
   SmallVector<WinEHUnwindMapEntry, 4> UnwindMap;
   SmallVector<WinEHTryBlockMapEntry, 4> TryBlockMap;
   SmallVector<SEHUnwindMapEntry, 4> SEHUnwindMap;
-  SmallVector<std::pair<MCSymbol *, int>, 4> IPToStateList;
   int UnwindHelpFrameIdx = INT_MAX;
   int UnwindHelpFrameOffset = -1;
-  unsigned NumIPToStateFuncsVisited = 0;
 
   int getLastStateNumber() const { return UnwindMap.size() - 1; }
 
+  void addIPToStateRange(const BasicBlock *PadBB, MCSymbol *InvokeBegin,
+                         MCSymbol *InvokeEnd);
+
   /// localescape index of the 32-bit EH registration node. Set by
   /// WinEHStatePass and used indirectly by SEH filter functions of the parent.
   int EHRegNodeEscapeIndex = INT_MAX;
   const AllocaInst *EHRegNode = nullptr;
   int EHRegNodeFrameIndex = INT_MAX;
+  int EHRegNodeEndOffset = INT_MAX;
 
   WinEHFuncInfo() {}
 };
@@ -188,5 +193,8 @@ void calculateWinCXXEHStateNumbers(const Function *ParentFn,
 
 void calculateSEHStateNumbers(const Function *ParentFn,
                               WinEHFuncInfo &FuncInfo);
+
+void calculateCatchReturnSuccessorColors(const Function *Fn,
+                                         WinEHFuncInfo &FuncInfo);
 }
 #endif // LLVM_CODEGEN_WINEHFUNCINFO_H