WinEHFuncInfo.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/CodeGen/WinEHFuncInfo.h -----------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // Data structures and associated state for Windows exception handling schemes.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CODEGEN_WINEHFUNCINFO_H
  18. #define LLVM_CODEGEN_WINEHFUNCINFO_H
  19. #include "llvm/ADT/DenseMap.h"
  20. #include "llvm/ADT/PointerUnion.h"
  21. #include "llvm/ADT/SmallVector.h"
  22. #include <cstdint>
  23. #include <limits>
  24. #include <utility>
  25. namespace llvm {
  26. class AllocaInst;
  27. class BasicBlock;
  28. class FuncletPadInst;
  29. class Function;
  30. class GlobalVariable;
  31. class Instruction;
  32. class InvokeInst;
  33. class MachineBasicBlock;
  34. class MCSymbol;
  35. // The following structs respresent the .xdata tables for various
  36. // Windows-related EH personalities.
  37. using MBBOrBasicBlock = PointerUnion<const BasicBlock *, MachineBasicBlock *>;
  38. struct CxxUnwindMapEntry {
  39. int ToState;
  40. MBBOrBasicBlock Cleanup;
  41. };
  42. /// Similar to CxxUnwindMapEntry, but supports SEH filters.
  43. struct SEHUnwindMapEntry {
  44. /// If unwinding continues through this handler, transition to the handler at
  45. /// this state. This indexes into SEHUnwindMap.
  46. int ToState = -1;
  47. bool IsFinally = false;
  48. /// Holds the filter expression function.
  49. const Function *Filter = nullptr;
  50. /// Holds the __except or __finally basic block.
  51. MBBOrBasicBlock Handler;
  52. };
  53. struct WinEHHandlerType {
  54. int Adjectives;
  55. /// The CatchObj starts out life as an LLVM alloca and is eventually turned
  56. /// frame index.
  57. union {
  58. const AllocaInst *Alloca;
  59. int FrameIndex;
  60. } CatchObj = {};
  61. GlobalVariable *TypeDescriptor;
  62. MBBOrBasicBlock Handler;
  63. };
  64. struct WinEHTryBlockMapEntry {
  65. int TryLow = -1;
  66. int TryHigh = -1;
  67. int CatchHigh = -1;
  68. SmallVector<WinEHHandlerType, 1> HandlerArray;
  69. };
  70. enum class ClrHandlerType { Catch, Finally, Fault, Filter };
  71. struct ClrEHUnwindMapEntry {
  72. MBBOrBasicBlock Handler;
  73. uint32_t TypeToken;
  74. int HandlerParentState; ///< Outer handler enclosing this entry's handler
  75. int TryParentState; ///< Outer try region enclosing this entry's try region,
  76. ///< treating later catches on same try as "outer"
  77. ClrHandlerType HandlerType;
  78. };
  79. struct WinEHFuncInfo {
  80. DenseMap<const Instruction *, int> EHPadStateMap;
  81. DenseMap<const FuncletPadInst *, int> FuncletBaseStateMap;
  82. DenseMap<const InvokeInst *, int> InvokeStateMap;
  83. DenseMap<MCSymbol *, std::pair<int, MCSymbol *>> LabelToStateMap;
  84. SmallVector<CxxUnwindMapEntry, 4> CxxUnwindMap;
  85. SmallVector<WinEHTryBlockMapEntry, 4> TryBlockMap;
  86. SmallVector<SEHUnwindMapEntry, 4> SEHUnwindMap;
  87. SmallVector<ClrEHUnwindMapEntry, 4> ClrEHUnwindMap;
  88. int UnwindHelpFrameIdx = std::numeric_limits<int>::max();
  89. int PSPSymFrameIdx = std::numeric_limits<int>::max();
  90. int getLastStateNumber() const { return CxxUnwindMap.size() - 1; }
  91. void addIPToStateRange(const InvokeInst *II, MCSymbol *InvokeBegin,
  92. MCSymbol *InvokeEnd);
  93. int EHRegNodeFrameIndex = std::numeric_limits<int>::max();
  94. int EHRegNodeEndOffset = std::numeric_limits<int>::max();
  95. int EHGuardFrameIndex = std::numeric_limits<int>::max();
  96. int SEHSetFrameOffset = std::numeric_limits<int>::max();
  97. WinEHFuncInfo();
  98. };
  99. /// Analyze the IR in ParentFn and it's handlers to build WinEHFuncInfo, which
  100. /// describes the state numbers and tables used by __CxxFrameHandler3. This
  101. /// analysis assumes that WinEHPrepare has already been run.
  102. void calculateWinCXXEHStateNumbers(const Function *ParentFn,
  103. WinEHFuncInfo &FuncInfo);
  104. void calculateSEHStateNumbers(const Function *ParentFn,
  105. WinEHFuncInfo &FuncInfo);
  106. void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo);
  107. } // end namespace llvm
  108. #endif // LLVM_CODEGEN_WINEHFUNCINFO_H
  109. #ifdef __GNUC__
  110. #pragma GCC diagnostic pop
  111. #endif