FaultMaps.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- FaultMaps.h - The "FaultMaps" section --------------------*- 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. #ifndef LLVM_CODEGEN_FAULTMAPS_H
  14. #define LLVM_CODEGEN_FAULTMAPS_H
  15. #include "llvm/MC/MCSymbol.h"
  16. #include "llvm/Support/Endian.h"
  17. #include <map>
  18. #include <vector>
  19. namespace llvm {
  20. class AsmPrinter;
  21. class MCExpr;
  22. class FaultMaps {
  23. public:
  24. enum FaultKind {
  25. FaultingLoad = 1,
  26. FaultingLoadStore,
  27. FaultingStore,
  28. FaultKindMax
  29. };
  30. explicit FaultMaps(AsmPrinter &AP);
  31. static const char *faultTypeToString(FaultKind);
  32. void recordFaultingOp(FaultKind FaultTy, const MCSymbol *FaultingLabel,
  33. const MCSymbol *HandlerLabel);
  34. void serializeToFaultMapSection();
  35. void reset() {
  36. FunctionInfos.clear();
  37. }
  38. private:
  39. static const char *WFMP;
  40. struct FaultInfo {
  41. FaultKind Kind = FaultKindMax;
  42. const MCExpr *FaultingOffsetExpr = nullptr;
  43. const MCExpr *HandlerOffsetExpr = nullptr;
  44. FaultInfo() = default;
  45. explicit FaultInfo(FaultMaps::FaultKind Kind, const MCExpr *FaultingOffset,
  46. const MCExpr *HandlerOffset)
  47. : Kind(Kind), FaultingOffsetExpr(FaultingOffset),
  48. HandlerOffsetExpr(HandlerOffset) {}
  49. };
  50. using FunctionFaultInfos = std::vector<FaultInfo>;
  51. // We'd like to keep a stable iteration order for FunctionInfos to help
  52. // FileCheck based testing.
  53. struct MCSymbolComparator {
  54. bool operator()(const MCSymbol *LHS, const MCSymbol *RHS) const {
  55. return LHS->getName() < RHS->getName();
  56. }
  57. };
  58. std::map<const MCSymbol *, FunctionFaultInfos, MCSymbolComparator>
  59. FunctionInfos;
  60. AsmPrinter &AP;
  61. void emitFunctionInfo(const MCSymbol *FnLabel, const FunctionFaultInfos &FFI);
  62. };
  63. } // end namespace llvm
  64. #endif // LLVM_CODEGEN_FAULTMAPS_H
  65. #ifdef __GNUC__
  66. #pragma GCC diagnostic pop
  67. #endif