LLVM 20.0.0git
FaultMapParser.h
Go to the documentation of this file.
1//===-- FaultMapParser.h - Parser for 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_OBJECT_FAULTMAPPARSER_H
10#define LLVM_OBJECT_FAULTMAPPARSER_H
11
12#include "llvm/Support/Endian.h"
13#include <cassert>
14#include <cstdint>
15
16namespace llvm {
17
18class raw_ostream;
19
20/// A parser for the __llvm_faultmaps section generated by the FaultMaps class
21/// declared in llvm/CodeGen/FaultMaps.h. This parser is version locked with
22/// with the __llvm_faultmaps section generated by the version of LLVM that
23/// includes it. No guarantees are made with respect to forward or backward
24/// compatibility.
27 using Reserved0Type = uint8_t;
28 using Reserved1Type = uint16_t;
30
31 static const size_t FaultMapVersionOffset = 0;
32 static const size_t Reserved0Offset =
33 FaultMapVersionOffset + sizeof(FaultMapVersionType);
34 static const size_t Reserved1Offset = Reserved0Offset + sizeof(Reserved0Type);
35 static const size_t NumFunctionsOffset =
36 Reserved1Offset + sizeof(Reserved1Type);
37 static const size_t FunctionInfosOffset =
38 NumFunctionsOffset + sizeof(NumFunctionsType);
39
40 const uint8_t *P;
41 const uint8_t *E;
42
43 template <typename T> static T read(const uint8_t *P, const uint8_t *E) {
44 assert(P + sizeof(T) <= E && "out of bounds read!");
45 return support::endian::read<T, llvm::endianness::little>(P);
46 }
47
48public:
49 enum FaultKind {
54 };
55
57 using FaultKindType = uint32_t;
60
61 static const size_t FaultKindOffset = 0;
62 static const size_t FaultingPCOffsetOffset =
63 FaultKindOffset + sizeof(FaultKindType);
64 static const size_t HandlerPCOffsetOffset =
65 FaultingPCOffsetOffset + sizeof(FaultingPCOffsetType);
66
67 const uint8_t *P;
68 const uint8_t *E;
69
70 public:
71 static const size_t Size =
72 HandlerPCOffsetOffset + sizeof(HandlerPCOffsetType);
73
74 explicit FunctionFaultInfoAccessor(const uint8_t *P, const uint8_t *E)
75 : P(P), E(E) {}
76
78 return read<FaultKindType>(P + FaultKindOffset, E);
79 }
80
82 return read<FaultingPCOffsetType>(P + FaultingPCOffsetOffset, E);
83 }
84
86 return read<HandlerPCOffsetType>(P + HandlerPCOffsetOffset, E);
87 }
88 };
89
93 using ReservedType = uint32_t;
94
95 static const size_t FunctionAddrOffset = 0;
96 static const size_t NumFaultingPCsOffset =
97 FunctionAddrOffset + sizeof(FunctionAddrType);
98 static const size_t ReservedOffset =
99 NumFaultingPCsOffset + sizeof(NumFaultingPCsType);
100 static const size_t FunctionFaultInfosOffset =
101 ReservedOffset + sizeof(ReservedType);
102 static const size_t FunctionInfoHeaderSize = FunctionFaultInfosOffset;
103
104 const uint8_t *P = nullptr;
105 const uint8_t *E = nullptr;
106
107 public:
109
110 explicit FunctionInfoAccessor(const uint8_t *P, const uint8_t *E)
111 : P(P), E(E) {}
112
114 return read<FunctionAddrType>(P + FunctionAddrOffset, E);
115 }
116
118 return read<NumFaultingPCsType>(P + NumFaultingPCsOffset, E);
119 }
120
122 assert(Index < getNumFaultingPCs() && "index out of bounds!");
123 const uint8_t *Begin = P + FunctionFaultInfosOffset +
125 return FunctionFaultInfoAccessor(Begin, E);
126 }
127
129 size_t MySize = FunctionInfoHeaderSize +
131
132 const uint8_t *Begin = P + MySize;
133 assert(Begin < E && "out of bounds!");
134 return FunctionInfoAccessor(Begin, E);
135 }
136 };
137
138 explicit FaultMapParser(const uint8_t *Begin, const uint8_t *End)
139 : P(Begin), E(End) {}
140
142 auto Version = read<FaultMapVersionType>(P + FaultMapVersionOffset, E);
143 assert(Version == 1 && "only version 1 supported!");
144 return Version;
145 }
146
148 return read<NumFunctionsType>(P + NumFunctionsOffset, E);
149 }
150
152 const uint8_t *Begin = P + FunctionInfosOffset;
153 return FunctionInfoAccessor(Begin, E);
154 }
155};
156
157raw_ostream &operator<<(raw_ostream &OS,
158 const FaultMapParser::FunctionFaultInfoAccessor &);
159
160raw_ostream &operator<<(raw_ostream &OS,
161 const FaultMapParser::FunctionInfoAccessor &);
162
163raw_ostream &operator<<(raw_ostream &OS, const FaultMapParser &);
164
165} // namespace llvm
166
167#endif
uint32_t Index
bool End
Definition: ELF_riscv.cpp:480
#define P(N)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
FunctionFaultInfoAccessor(const uint8_t *P, const uint8_t *E)
HandlerPCOffsetType getHandlerPCOffset() const
FaultingPCOffsetType getFaultingPCOffset() const
FunctionInfoAccessor(const uint8_t *P, const uint8_t *E)
FunctionInfoAccessor getNextFunctionInfo() const
NumFaultingPCsType getNumFaultingPCs() const
FunctionFaultInfoAccessor getFunctionFaultInfoAt(uint32_t Index) const
A parser for the __llvm_faultmaps section generated by the FaultMaps class declared in llvm/CodeGen/F...
NumFunctionsType getNumFunctions() const
FunctionInfoAccessor getFirstFunctionInfo() const
FaultMapParser(const uint8_t *Begin, const uint8_t *End)
FaultMapVersionType getFaultMapVersion() const
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:303