FaultMaps.h 2.1 KB

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