RegisterPressure: Expose RegisterOperands API
[oota-llvm.git] / include / llvm / CodeGen / WinEHFuncInfo.h
index 5d122094ff8b0a477de98d1f40b243e57e29a1f2..46c1029f62cf33b63a8f75b953e2c00bb6c0902a 100644 (file)
@@ -22,6 +22,7 @@
 namespace llvm {
 class AllocaInst;
 class BasicBlock;
+class CatchReturnInst;
 class Constant;
 class Function;
 class GlobalVariable;
@@ -33,99 +34,17 @@ class MCSymbol;
 class MachineBasicBlock;
 class Value;
 
-enum ActionType { Catch, Cleanup };
-
-class ActionHandler {
-public:
-  ActionHandler(BasicBlock *BB, ActionType Type)
-      : StartBB(BB), Type(Type), EHState(-1), HandlerBlockOrFunc(nullptr) {}
-
-  ActionType getType() const { return Type; }
-  BasicBlock *getStartBlock() const { return StartBB; }
-
-  bool hasBeenProcessed() { return HandlerBlockOrFunc != nullptr; }
-
-  void setHandlerBlockOrFunc(Constant *F) { HandlerBlockOrFunc = F; }
-  Constant *getHandlerBlockOrFunc() { return HandlerBlockOrFunc; }
-
-  void setEHState(int State) { EHState = State; }
-  int getEHState() const { return EHState; }
-
-private:
-  BasicBlock *StartBB;
-  ActionType Type;
-  int EHState;
-
-  // Can be either a BlockAddress or a Function depending on the EH personality.
-  Constant *HandlerBlockOrFunc;
-};
-
-class CatchHandler : public ActionHandler {
-public:
-  CatchHandler(BasicBlock *BB, Constant *Selector, BasicBlock *NextBB)
-      : ActionHandler(BB, ActionType::Catch), Selector(Selector),
-      NextBB(NextBB), ExceptionObjectVar(nullptr),
-      ExceptionObjectIndex(-1) {}
-
-  // Method for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool classof(const ActionHandler *H) {
-    return H->getType() == ActionType::Catch;
-  }
-
-  Constant *getSelector() const { return Selector; }
-  BasicBlock *getNextBB() const { return NextBB; }
-
-  const Value *getExceptionVar() { return ExceptionObjectVar; }
-  TinyPtrVector<BasicBlock *> &getReturnTargets() { return ReturnTargets; }
-
-  void setExceptionVar(const Value *Val) { ExceptionObjectVar = Val; }
-  void setExceptionVarIndex(int Index) { ExceptionObjectIndex = Index;  }
-  int getExceptionVarIndex() const { return ExceptionObjectIndex; }
-  void setReturnTargets(TinyPtrVector<BasicBlock *> &Targets) {
-    ReturnTargets = Targets;
-  }
-
-private:
-  Constant *Selector;
-  BasicBlock *NextBB;
-  // While catch handlers are being outlined the ExceptionObjectVar field will
-  // be populated with the instruction in the parent frame that corresponds
-  // to the exception object (or nullptr if the catch does not use an
-  // exception object) and the ExceptionObjectIndex field will be -1.
-  // When the parseEHActions function is called to populate a vector of
-  // instances of this class, the ExceptionObjectVar field will be nullptr
-  // and the ExceptionObjectIndex will be the index of the exception object in
-  // the parent function's localescape block.
-  const Value *ExceptionObjectVar;
-  int ExceptionObjectIndex;
-  TinyPtrVector<BasicBlock *> ReturnTargets;
-};
-
-class CleanupHandler : public ActionHandler {
-public:
-  CleanupHandler(BasicBlock *BB) : ActionHandler(BB, ActionType::Cleanup) {}
-
-  // Method for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool classof(const ActionHandler *H) {
-    return H->getType() == ActionType::Cleanup;
-  }
-};
-
-void parseEHActions(const IntrinsicInst *II,
-                    SmallVectorImpl<std::unique_ptr<ActionHandler>> &Actions);
-
-// The following structs respresent the .xdata for functions using C++
-// exceptions on Windows.
+// The following structs respresent the .xdata tables for various
+// Windows-related EH personalities.
 
 typedef PointerUnion<const BasicBlock *, MachineBasicBlock *> MBBOrBasicBlock;
-typedef PointerUnion<const Value *, const MachineBasicBlock *> ValueOrMBB;
 
-struct WinEHUnwindMapEntry {
+struct CxxUnwindMapEntry {
   int ToState;
-  ValueOrMBB Cleanup;
+  MBBOrBasicBlock Cleanup;
 };
 
-/// Similar to WinEHUnwindMapEntry, but supports SEH filters.
+/// Similar to CxxUnwindMapEntry, but supports SEH filters.
 struct SEHUnwindMapEntry {
   /// If unwinding continues through this handler, transition to the handler at
   /// this state. This indexes into SEHUnwindMap.
@@ -142,16 +61,14 @@ struct SEHUnwindMapEntry {
 
 struct WinEHHandlerType {
   int Adjectives;
-  int CatchObjRecoverIdx;
-  /// The CatchObj starts out life as an LLVM alloca, is turned into a frame
-  /// index, and after PEI, becomes a raw offset.
+  /// The CatchObj starts out life as an LLVM alloca and is eventually turned
+  /// frame index.
   union {
     const AllocaInst *Alloca;
-    int FrameOffset;
     int FrameIndex;
   } CatchObj = {};
   GlobalVariable *TypeDescriptor;
-  ValueOrMBB Handler;
+  MBBOrBasicBlock Handler;
 };
 
 struct WinEHTryBlockMapEntry {
@@ -161,30 +78,39 @@ struct WinEHTryBlockMapEntry {
   SmallVector<WinEHHandlerType, 1> HandlerArray;
 };
 
+enum class ClrHandlerType { Catch, Finally, Fault, Filter };
+
+struct ClrEHUnwindMapEntry {
+  MBBOrBasicBlock Handler;
+  uint32_t TypeToken;
+  int HandlerParentState; ///< Outer handler enclosing this entry's handler
+  int TryParentState; ///< Outer try region enclosing this entry's try region,
+                      ///< treating later catches on same try as "outer"
+  ClrHandlerType HandlerType;
+};
+
 struct WinEHFuncInfo {
   DenseMap<const Instruction *, int> EHPadStateMap;
-  DenseMap<const CatchReturnInst *, const BasicBlock *>
-      CatchRetSuccessorColorMap;
-  DenseMap<MCSymbol *, std::pair<int, MCSymbol *>> InvokeToStateMap;
-  SmallVector<WinEHUnwindMapEntry, 4> UnwindMap;
+  DenseMap<const FuncletPadInst *, int> FuncletBaseStateMap;
+  DenseMap<const InvokeInst *, int> InvokeStateMap;
+  DenseMap<MCSymbol *, std::pair<int, MCSymbol *>> LabelToStateMap;
+  SmallVector<CxxUnwindMapEntry, 4> CxxUnwindMap;
   SmallVector<WinEHTryBlockMapEntry, 4> TryBlockMap;
   SmallVector<SEHUnwindMapEntry, 4> SEHUnwindMap;
+  SmallVector<ClrEHUnwindMapEntry, 4> ClrEHUnwindMap;
   int UnwindHelpFrameIdx = INT_MAX;
-  int UnwindHelpFrameOffset = -1;
+  int PSPSymFrameIdx = INT_MAX;
 
-  int getLastStateNumber() const { return UnwindMap.size() - 1; }
+  int getLastStateNumber() const { return CxxUnwindMap.size() - 1; }
 
-  void addIPToStateRange(const BasicBlock *PadBB, MCSymbol *InvokeBegin,
+  void addIPToStateRange(const InvokeInst *II, 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;
+  int SEHSetFrameOffset = INT_MAX;
 
-  WinEHFuncInfo() {}
+  WinEHFuncInfo();
 };
 
 /// Analyze the IR in ParentFn and it's handlers to build WinEHFuncInfo, which
@@ -196,7 +122,6 @@ void calculateWinCXXEHStateNumbers(const Function *ParentFn,
 void calculateSEHStateNumbers(const Function *ParentFn,
                               WinEHFuncInfo &FuncInfo);
 
-void calculateCatchReturnSuccessorColors(const Function *Fn,
-                                         WinEHFuncInfo &FuncInfo);
+void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo);
 }
 #endif // LLVM_CODEGEN_WINEHFUNCINFO_H