Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:28

0001 //===- FaultMaps.h - The "FaultMaps" section --------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CODEGEN_FAULTMAPS_H
0010 #define LLVM_CODEGEN_FAULTMAPS_H
0011 
0012 #include "llvm/MC/MCSymbol.h"
0013 #include <map>
0014 #include <vector>
0015 
0016 namespace llvm {
0017 
0018 class AsmPrinter;
0019 class MCExpr;
0020 
0021 class FaultMaps {
0022 public:
0023   enum FaultKind {
0024     FaultingLoad = 1,
0025     FaultingLoadStore,
0026     FaultingStore,
0027     FaultKindMax
0028   };
0029 
0030   explicit FaultMaps(AsmPrinter &AP);
0031 
0032   static const char *faultTypeToString(FaultKind);
0033 
0034   void recordFaultingOp(FaultKind FaultTy, const MCSymbol *FaultingLabel,
0035                         const MCSymbol *HandlerLabel);
0036   void serializeToFaultMapSection();
0037   void reset() {
0038     FunctionInfos.clear();
0039   }
0040 
0041 private:
0042   static const char *WFMP;
0043 
0044   struct FaultInfo {
0045     FaultKind Kind = FaultKindMax;
0046     const MCExpr *FaultingOffsetExpr = nullptr;
0047     const MCExpr *HandlerOffsetExpr = nullptr;
0048 
0049     FaultInfo() = default;
0050 
0051     explicit FaultInfo(FaultMaps::FaultKind Kind, const MCExpr *FaultingOffset,
0052                        const MCExpr *HandlerOffset)
0053         : Kind(Kind), FaultingOffsetExpr(FaultingOffset),
0054           HandlerOffsetExpr(HandlerOffset) {}
0055   };
0056 
0057   using FunctionFaultInfos = std::vector<FaultInfo>;
0058 
0059   // We'd like to keep a stable iteration order for FunctionInfos to help
0060   // FileCheck based testing.
0061   struct MCSymbolComparator {
0062     bool operator()(const MCSymbol *LHS, const MCSymbol *RHS) const {
0063       return LHS->getName() < RHS->getName();
0064     }
0065   };
0066 
0067   std::map<const MCSymbol *, FunctionFaultInfos, MCSymbolComparator>
0068       FunctionInfos;
0069   AsmPrinter &AP;
0070 
0071   void emitFunctionInfo(const MCSymbol *FnLabel, const FunctionFaultInfos &FFI);
0072 };
0073 
0074 } // end namespace llvm
0075 
0076 #endif // LLVM_CODEGEN_FAULTMAPS_H