WinException.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //===-- WinException.h - Windows Exception Handling ----------*- C++ -*--===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file contains support for writing windows exception info into asm files.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_WIN64EXCEPTION_H
  13. #define LLVM_LIB_CODEGEN_ASMPRINTER_WIN64EXCEPTION_H
  14. #include "EHStreamer.h"
  15. namespace llvm {
  16. class Function;
  17. class GlobalValue;
  18. class MachineFunction;
  19. class MCExpr;
  20. class MCSection;
  21. class Value;
  22. struct WinEHFuncInfo;
  23. class LLVM_LIBRARY_VISIBILITY WinException : public EHStreamer {
  24. /// Per-function flag to indicate if personality info should be emitted.
  25. bool shouldEmitPersonality = false;
  26. /// Per-function flag to indicate if the LSDA should be emitted.
  27. bool shouldEmitLSDA = false;
  28. /// Per-function flag to indicate if frame moves info should be emitted.
  29. bool shouldEmitMoves = false;
  30. /// True if this is a 64-bit target and we should use image relative offsets.
  31. bool useImageRel32 = false;
  32. /// True if we are generating exception handling on Windows for ARM64.
  33. bool isAArch64 = false;
  34. /// Pointer to the current funclet entry BB.
  35. const MachineBasicBlock *CurrentFuncletEntry = nullptr;
  36. /// The section of the last funclet start.
  37. MCSection *CurrentFuncletTextSection = nullptr;
  38. void emitCSpecificHandlerTable(const MachineFunction *MF);
  39. void emitSEHActionsForRange(const WinEHFuncInfo &FuncInfo,
  40. const MCSymbol *BeginLabel,
  41. const MCSymbol *EndLabel, int State);
  42. /// Emit the EH table data for 32-bit and 64-bit functions using
  43. /// the __CxxFrameHandler3 personality.
  44. void emitCXXFrameHandler3Table(const MachineFunction *MF);
  45. /// Emit the EH table data for _except_handler3 and _except_handler4
  46. /// personality functions. These are only used on 32-bit and do not use CFI
  47. /// tables.
  48. void emitExceptHandlerTable(const MachineFunction *MF);
  49. void emitCLRExceptionTable(const MachineFunction *MF);
  50. void computeIP2StateTable(
  51. const MachineFunction *MF, const WinEHFuncInfo &FuncInfo,
  52. SmallVectorImpl<std::pair<const MCExpr *, int>> &IPToStateTable);
  53. /// Emits the label used with llvm.eh.recoverfp, which is used by
  54. /// outlined funclets.
  55. void emitEHRegistrationOffsetLabel(const WinEHFuncInfo &FuncInfo,
  56. StringRef FLinkageName);
  57. const MCExpr *create32bitRef(const MCSymbol *Value);
  58. const MCExpr *create32bitRef(const GlobalValue *GV);
  59. const MCExpr *getLabel(const MCSymbol *Label);
  60. const MCExpr *getOffset(const MCSymbol *OffsetOf, const MCSymbol *OffsetFrom);
  61. const MCExpr *getOffsetPlusOne(const MCSymbol *OffsetOf,
  62. const MCSymbol *OffsetFrom);
  63. /// Gets the offset that we should use in a table for a stack object with the
  64. /// given index. For targets using CFI (Win64, etc), this is relative to the
  65. /// established SP at the end of the prologue. For targets without CFI (Win32
  66. /// only), it is relative to the frame pointer.
  67. int getFrameIndexOffset(int FrameIndex, const WinEHFuncInfo &FuncInfo);
  68. void endFuncletImpl();
  69. public:
  70. //===--------------------------------------------------------------------===//
  71. // Main entry points.
  72. //
  73. WinException(AsmPrinter *A);
  74. ~WinException() override;
  75. /// Emit all exception information that should come after the content.
  76. void endModule() override;
  77. /// Gather pre-function exception information. Assumes being emitted
  78. /// immediately after the function entry point.
  79. void beginFunction(const MachineFunction *MF) override;
  80. void markFunctionEnd() override;
  81. /// Gather and emit post-function exception information.
  82. void endFunction(const MachineFunction *) override;
  83. /// Emit target-specific EH funclet machinery.
  84. void beginFunclet(const MachineBasicBlock &MBB, MCSymbol *Sym) override;
  85. void endFunclet() override;
  86. };
  87. }
  88. #endif