10 #ifndef LLVM_CODEGEN_STACKMAPPARSER_H
11 #define LLVM_CODEGEN_STACKMAPPARSER_H
23 template <support::endianness Endianness>
26 template <
typename AccessorT>
39 return A.P == Other.A.P;
58 return read<uint64_t>(
P);
63 return read<uint64_t>(
P +
sizeof(uint64_t));
68 return read<uint64_t>(
P + (2 *
sizeof(uint64_t)));
74 const static int FunctionAccessorSize = 3 *
sizeof(uint64_t);
76 FunctionAccessor next()
const {
77 return FunctionAccessor(
P + FunctionAccessorSize);
89 uint64_t
getValue()
const {
return read<uint64_t>(
P); }
94 const static int ConstantAccessorSize =
sizeof(uint64_t);
96 ConstantAccessor next()
const {
97 return ConstantAccessor(
P + ConstantAccessorSize);
120 return read<uint16_t>(
P + DwarfRegNumOffset);
126 return read<uint32_t>(
P + SmallConstantOffset);
132 "Not a constant-index.");
133 return read<uint32_t>(
P + SmallConstantOffset);
140 "Not direct or indirect.");
141 return read<int32_t>(
P + SmallConstantOffset);
147 LocationAccessor next()
const {
148 return LocationAccessor(
P + LocationAccessorSize);
151 static const int KindOffset = 0;
152 static const int DwarfRegNumOffset = KindOffset +
sizeof(uint16_t);
153 static const int SmallConstantOffset = DwarfRegNumOffset +
sizeof(uint16_t);
154 static const int LocationAccessorSize =
sizeof(uint64_t);
167 return read<uint16_t>(
P + DwarfRegNumOffset);
172 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;
266 unsigned getNumLiveOutsOffset()
const {
271 unsigned getSizeInBytes()
const {
272 unsigned RecordSize =
273 getNumLiveOutsOffset() +
sizeof(uint16_t) +
getNumLiveOuts() * LiveOutSize;
274 return (RecordSize + 7) & ~0x7;
277 RecordAccessor next()
const {
278 return RecordAccessor(
P + getSizeInBytes());
281 static const unsigned PatchpointIDOffset = 0;
282 static const unsigned InstructionOffsetOffset =
283 PatchpointIDOffset +
sizeof(uint64_t);
284 static const unsigned NumLocationsOffset =
285 InstructionOffsetOffset +
sizeof(
uint32_t) +
sizeof(uint16_t);
286 static const unsigned LocationListOffset =
287 NumLocationsOffset +
sizeof(uint16_t);
288 static const unsigned LocationSize =
sizeof(uint64_t);
289 static const unsigned LiveOutSize =
sizeof(
uint32_t);
297 : StackMapSection(StackMapSection) {
298 ConstantsListOffset = FunctionListOffset +
getNumFunctions() * FunctionSize;
300 assert(StackMapSection[0] == 2 &&
301 "StackMapV2Parser can only parse version 2 stackmaps");
303 unsigned CurrentRecordOffset =
307 StackMapRecordOffsets.push_back(CurrentRecordOffset);
308 CurrentRecordOffset +=
309 RecordAccessor(&StackMapSection[CurrentRecordOffset]).getSizeInBytes();
322 return read<uint32_t>(&StackMapSection[NumFunctionsOffset]);
327 return read<uint32_t>(&StackMapSection[NumConstantsOffset]);
332 return read<uint32_t>(&StackMapSection[NumRecordsOffset]);
338 getFunctionOffset(FunctionIndex));
361 getConstantOffset(ConstantIndex));
383 std::size_t RecordOffset = StackMapRecordOffsets[RecordIndex];
410 template <
typename T>
411 static T read(
const uint8_t *
P) {
412 return support::endian::read<T, Endianness, 1>(
P);
415 static const unsigned HeaderOffset = 0;
416 static const unsigned NumFunctionsOffset = HeaderOffset +
sizeof(
uint32_t);
417 static const unsigned NumConstantsOffset = NumFunctionsOffset +
sizeof(
uint32_t);
418 static const unsigned NumRecordsOffset = NumConstantsOffset +
sizeof(
uint32_t);
419 static const unsigned FunctionListOffset = NumRecordsOffset +
sizeof(
uint32_t);
421 static const unsigned FunctionSize = 3 *
sizeof(uint64_t);
422 static const unsigned ConstantSize =
sizeof(uint64_t);
424 std::size_t getFunctionOffset(
unsigned FunctionIndex)
const {
425 return FunctionListOffset + FunctionIndex * FunctionSize;
428 std::size_t getConstantOffset(
unsigned ConstantIndex)
const {
429 return ConstantsListOffset + ConstantIndex * ConstantSize;
432 ArrayRef<uint8_t> StackMapSection;
433 unsigned ConstantsListOffset;
434 std::vector<unsigned> StackMapRecordOffsets;
439 #endif // LLVM_CODEGEN_STACKMAPPARSER_H
iterator_range< location_iterator > locations() const
Iterator range for locations.
uint64_t getFunctionAddress() const
Get the function address.
uint64_t getID() const
Get the patchpoint/stackmap ID for this record.
uint32_t getNumRecords() const
Get the number of stackmap records in the stackmap.
bool operator!=(const AccessorIterator &Other)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
uint32_t getConstantIndex() const
Get the constant-index for this location. (Kind must be ConstantIndex).
uint32_t getSmallConstant() const
Get the small-constant for this location. (Kind must be Constant).
unsigned getVersion() const
Get the version number of this stackmap. (Always returns 2).
FunctionAccessor getFunction(unsigned FunctionIndex) const
Return an FunctionAccessor for the given function index.
location_iterator location_end() const
End iterator for locations.
Accessor for stackmap records.
function_iterator functions_begin() const
Begin iterator for functions.
location_iterator location_begin() const
Begin iterator for locations.
Accessor for function records.
uint64_t getValue() const
Return the value of this constant.
liveout_iterator liveouts_end() const
End iterator for live-outs.
LiveOutAccessor getLiveOut(unsigned LiveOutIndex) const
Get the live-out with the given index.
uint16_t getDwarfRegNum() const
Get the Dwarf register number for this location.
function_iterator functions_end() const
End iterator for functions.
AccessorIterator(AccessorT A)
AccessorIterator< RecordAccessor > record_iterator
uint64_t getRecordCount() const
Get the number of callsite records.
AccessorIterator & operator++()
uint16_t getNumLocations() const
Get the number of locations contained in this record.
uint16_t getDwarfRegNum() const
Get the Dwarf register number for this live-out.
bool operator==(const AccessorIterator &Other)
iterator_range< function_iterator > functions() const
Iterator range for functions.
Accessor for location records.
constant_iterator constants_begin() const
Begin iterator for constants.
This is an important base class in LLVM.
uint32_t getInstructionOffset() const
Get the instruction offset (from the start of the containing function) for this record.
liveout_iterator liveouts_begin() const
Begin iterator for live-outs.
ConstantAccessor getConstant(unsigned ConstantIndex) const
Return the large constant at the given index.
iterator_range< liveout_iterator > liveouts() const
Iterator range for live-outs.
AccessorIterator< LocationAccessor > location_iterator
LocationKind getKind() const
Get the Kind for this location.
AccessorIterator< ConstantAccessor > constant_iterator
unsigned getSizeInBytes() const
Get the size in bytes of live [sub]register.
record_iterator records_begin() const
Begin iterator for records.
AccessorIterator operator++(int)
AccessorIterator< FunctionAccessor > function_iterator
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
iterator_range< constant_iterator > constants() const
Iterator range for constants.
iterator_range< record_iterator > records() const
Iterator range for records.
AccessorIterator< LiveOutAccessor > liveout_iterator
RecordAccessor getRecord(unsigned RecordIndex) const
Return a RecordAccessor for the given record index.
LocationAccessor getLocation(unsigned LocationIndex) const
Get the location with the given index.
A range adaptor for a pair of iterators.
uint32_t getNumFunctions() const
Get the number of functions in the stack map.
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
constant_iterator constants_end() const
End iterator for constants.
uint64_t getStackSize() const
Get the function's stack size.
int32_t getOffset() const
Get the offset for this location. (Kind must be Direct or Indirect).
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StackMapV2Parser(ArrayRef< uint8_t > StackMapSection)
Construct a parser for a version-2 stackmap.
uint32_t getNumConstants() const
Get the number of large constants in the stack map.
Accessor for stackmap live-out fields.
record_iterator records_end() const
End iterator for records.
uint16_t getNumLiveOuts() const
Get the number of liveouts contained in this record.