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