10 #ifndef LLVM_CODEGEN_STACKMAPPARSER_H
11 #define LLVM_CODEGEN_STACKMAPPARSER_H
20 template <support::endianness Endianness>
24 template <
typename AccessorT>
37 return A.P == Other.A.P;
56 return read<uint64_t>(
P);
61 return read<uint64_t>(
P +
sizeof(uint64_t));
67 const static int FunctionAccessorSize = 2 *
sizeof(uint64_t);
69 FunctionAccessor next()
const {
70 return FunctionAccessor(
P + FunctionAccessorSize);
82 uint64_t
getValue()
const {
return read<uint64_t>(
P); }
88 const static int ConstantAccessorSize =
sizeof(uint64_t);
90 ConstantAccessor next()
const {
91 return ConstantAccessor(
P + ConstantAccessorSize);
118 return read<uint16_t>(
P + DwarfRegNumOffset);
124 return read<uint32_t>(
P + SmallConstantOffset);
130 "Not a constant-index.");
131 return read<uint32_t>(
P + SmallConstantOffset);
138 "Not direct or indirect.");
139 return read<int32_t>(
P + SmallConstantOffset);
146 LocationAccessor next()
const {
147 return LocationAccessor(
P + LocationAccessorSize);
150 static const int KindOffset = 0;
151 static const int DwarfRegNumOffset = KindOffset +
sizeof(uint16_t);
152 static const int SmallConstantOffset = DwarfRegNumOffset +
sizeof(uint16_t);
153 static const int LocationAccessorSize =
sizeof(uint64_t);
166 return read<uint16_t>(
P + DwarfRegNumOffset);
171 return read<uint8_t>(
P + SizeOffset);
178 LiveOutAccessor next()
const {
179 return LiveOutAccessor(
P + LiveOutAccessorSize);
182 static const int DwarfRegNumOffset = 0;
183 static const int SizeOffset =
184 DwarfRegNumOffset +
sizeof(uint16_t) +
sizeof(uint8_t);
185 static const int LiveOutAccessorSize =
sizeof(uint32_t);
200 return read<uint64_t>(
P + PatchpointIDOffset);
206 return read<uint32_t>(
P + InstructionOffsetOffset);
211 return read<uint16_t>(
P + NumLocationsOffset);
216 unsigned LocationOffset =
217 LocationListOffset + LocationIndex * LocationSize;
238 return read<uint16_t>(
P + getNumLiveOutsOffset());
243 unsigned LiveOutOffset =
244 getNumLiveOutsOffset() +
sizeof(uint16_t) + LiveOutIndex * LiveOutSize;
268 unsigned getNumLiveOutsOffset()
const {
273 unsigned getSizeInBytes()
const {
274 unsigned RecordSize =
275 getNumLiveOutsOffset() +
sizeof(uint16_t) +
getNumLiveOuts() * LiveOutSize;
276 return (RecordSize + 7) & ~0x7;
279 RecordAccessor next()
const {
280 return RecordAccessor(
P + getSizeInBytes());
283 static const unsigned PatchpointIDOffset = 0;
284 static const unsigned InstructionOffsetOffset =
285 PatchpointIDOffset +
sizeof(uint64_t);
286 static const unsigned NumLocationsOffset =
287 InstructionOffsetOffset +
sizeof(uint32_t) +
sizeof(uint16_t);
288 static const unsigned LocationListOffset =
289 NumLocationsOffset +
sizeof(uint16_t);
290 static const unsigned LocationSize =
sizeof(uint64_t);
291 static const unsigned LiveOutSize =
sizeof(uint32_t);
299 : StackMapSection(StackMapSection) {
300 ConstantsListOffset = FunctionListOffset +
getNumFunctions() * FunctionSize;
302 assert(StackMapSection[0] == 1 &&
303 "StackMapV1Parser can only parse version 1 stackmaps");
305 unsigned CurrentRecordOffset =
309 StackMapRecordOffsets.push_back(CurrentRecordOffset);
310 CurrentRecordOffset +=
311 RecordAccessor(&StackMapSection[CurrentRecordOffset]).getSizeInBytes();
324 return read<uint32_t>(&StackMapSection[NumFunctionsOffset]);
329 return read<uint32_t>(&StackMapSection[NumConstantsOffset]);
334 return read<uint32_t>(&StackMapSection[NumRecordsOffset]);
340 getFunctionOffset(FunctionIndex));
363 getConstantOffset(ConstantIndex));
385 std::size_t RecordOffset = StackMapRecordOffsets[RecordIndex];
413 template <
typename T>
414 static T read(
const uint8_t *
P) {
415 return support::endian::read<T, Endianness, 1>(
P);
418 static const unsigned HeaderOffset = 0;
419 static const unsigned NumFunctionsOffset = HeaderOffset +
sizeof(uint32_t);
420 static const unsigned NumConstantsOffset = NumFunctionsOffset +
sizeof(uint32_t);
421 static const unsigned NumRecordsOffset = NumConstantsOffset +
sizeof(uint32_t);
422 static const unsigned FunctionListOffset = NumRecordsOffset +
sizeof(uint32_t);
424 static const unsigned FunctionSize = 2 *
sizeof(uint64_t);
425 static const unsigned ConstantSize =
sizeof(uint64_t);
427 std::size_t getFunctionOffset(
unsigned FunctionIndex)
const {
428 return FunctionListOffset + FunctionIndex * FunctionSize;
431 std::size_t getConstantOffset(
unsigned ConstantIndex)
const {
432 return ConstantsListOffset + ConstantIndex * ConstantSize;
435 ArrayRef<uint8_t> StackMapSection;
436 unsigned ConstantsListOffset;
437 std::vector<unsigned> StackMapRecordOffsets;
LocationAccessor getLocation(unsigned LocationIndex) const
Get the location with the given index.
AccessorIterator< LiveOutAccessor > liveout_iterator
LiveOutAccessor getLiveOut(unsigned LiveOutIndex) const
Get the live-out with the given index.
value_type read(const void *memory)
Read a value of a particular endianness from memory.
record_iterator records_begin() const
Begin iterator for records.
StackMapV1Parser(ArrayRef< uint8_t > StackMapSection)
Construct a parser for a version-1 stackmap.
liveout_iterator liveouts_end() const
End iterator for live-outs.
constant_iterator constants_end() const
End iterator for constants.
uint32_t getInstructionOffset() const
Get the instruction offset (from the start of the containing function) for this record.
function_iterator functions_end() const
End iterator for functions.
unsigned getVersion() const
Get the version number of this stackmap. (Always returns 1).
iterator_range< location_iterator > locations() const
Iterator range for locations.
FunctionAccessor getFunction(unsigned FunctionIndex) const
Return an FunctionAccessor for the given function index.
Accessor for function records.
AccessorIterator(AccessorT A)
iterator_range< liveout_iterator > liveouts() const
Iterator range for live-outs.
location_iterator location_end() const
End iterator for locations.
uint64_t getID() const
Get the patchpoint/stackmap ID for this record.
function_iterator functions_begin() const
Begin iterator for functions.
liveout_iterator liveouts_begin() const
Begin iterator for live-outs.
uint32_t getNumConstants() const
Get the number of large constants in the stack map.
uint16_t getDwarfRegNum() const
Get the Dwarf register number for this location.
uint32_t getNumFunctions() const
Get the number of functions in the stack map.
AccessorIterator< RecordAccessor > record_iterator
AccessorIterator< ConstantAccessor > constant_iterator
AccessorIterator operator++(int)
Accessor for location records.
RecordAccessor getRecord(unsigned RecordIndex) const
Return a RecordAccessor for the given record index.
uint16_t getDwarfRegNum() const
Get the Dwarf register number for this live-out.
This is an important base class in LLVM.
record_iterator records_end() const
End iterator for records.
bool operator==(const AccessorIterator &Other)
Accessor for stackmap records.
unsigned getSizeInBytes() const
Get the size in bytes of live [sub]register.
int32_t getOffset() const
Get the offset for this location. (Kind must be Direct or Indirect).
AccessorIterator & operator++()
iterator_range< record_iterator > records() const
Iterator range for records.
uint32_t getConstantIndex() const
Get the constant-index for this location. (Kind must be ConstantIndex).
uint32_t getNumRecords() const
Get the number of stackmap records in the stackmap.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Accessor for stackmap live-out fields.
uint64_t getFunctionAddress() const
Get the function address.
iterator_range< constant_iterator > constants() const
Iterator range for constants.
AccessorIterator< LocationAccessor > location_iterator
A range adaptor for a pair of iterators.
uint32_t getSmallConstant() const
Get the small-constant for this location. (Kind must be Constant).
location_iterator location_begin() const
Begin iterator for locations.
bool operator!=(const AccessorIterator &Other)
AccessorIterator< FunctionAccessor > function_iterator
uint16_t getNumLocations() const
Get the number of locations contained in this record.
constant_iterator constants_begin() const
Begin iterator for constants.
uint64_t getValue() const
Return the value of this constant.
ConstantAccessor getConstant(unsigned ConstantIndex) const
Return the large constant at the given index.
uint16_t getNumLiveOuts() const
Get the number of liveouts contained in this record.
uint32_t getStackSize() const
Get the function's stack size.
iterator_range< function_iterator > functions() const
Iterator range for functions.
LocationKind getKind() const
Get the Kind for this location.