10 #ifndef LLVM_CODEGEN_STACKMAPPARSER_H
11 #define LLVM_CODEGEN_STACKMAPPARSER_H
19 template <support::endianness Endianness>
23 template <
typename AccessorT>
36 return A.P == Other.A.P;
55 return read<uint64_t>(
P);
60 return read<uint64_t>(
P +
sizeof(uint64_t));
65 return read<uint64_t>(
P + (2 *
sizeof(uint64_t)));
71 const static int FunctionAccessorSize = 3 *
sizeof(uint64_t);
73 FunctionAccessor next()
const {
74 return FunctionAccessor(
P + FunctionAccessorSize);
86 uint64_t
getValue()
const {
return read<uint64_t>(
P); }
92 const static int ConstantAccessorSize =
sizeof(uint64_t);
94 ConstantAccessor next()
const {
95 return ConstantAccessor(
P + ConstantAccessorSize);
102 class RecordAccessor;
122 return read<uint16_t>(
P + DwarfRegNumOffset);
128 return read<uint32_t>(
P + SmallConstantOffset);
134 "Not a constant-index.");
135 return read<uint32_t>(
P + SmallConstantOffset);
142 "Not direct or indirect.");
143 return read<int32_t>(
P + SmallConstantOffset);
150 LocationAccessor next()
const {
151 return LocationAccessor(
P + LocationAccessorSize);
154 static const int KindOffset = 0;
155 static const int DwarfRegNumOffset = KindOffset +
sizeof(uint16_t);
156 static const int SmallConstantOffset = DwarfRegNumOffset +
sizeof(uint16_t);
157 static const int LocationAccessorSize =
sizeof(uint64_t);
170 return read<uint16_t>(
P + DwarfRegNumOffset);
175 return read<uint8_t>(
P + SizeOffset);
182 LiveOutAccessor next()
const {
183 return LiveOutAccessor(
P + LiveOutAccessorSize);
186 static const int DwarfRegNumOffset = 0;
187 static const int SizeOffset =
188 DwarfRegNumOffset +
sizeof(uint16_t) +
sizeof(uint8_t);
189 static const int LiveOutAccessorSize =
sizeof(
uint32_t);
204 return read<uint64_t>(
P + PatchpointIDOffset);
210 return read<uint32_t>(
P + InstructionOffsetOffset);
215 return read<uint16_t>(
P + NumLocationsOffset);
220 unsigned LocationOffset =
221 LocationListOffset + LocationIndex * LocationSize;
242 return read<uint16_t>(
P + getNumLiveOutsOffset());
247 unsigned LiveOutOffset =
248 getNumLiveOutsOffset() +
sizeof(uint16_t) + LiveOutIndex * LiveOutSize;
272 unsigned getNumLiveOutsOffset()
const {
277 unsigned getSizeInBytes()
const {
278 unsigned RecordSize =
279 getNumLiveOutsOffset() +
sizeof(uint16_t) +
getNumLiveOuts() * LiveOutSize;
280 return (RecordSize + 7) & ~0x7;
283 RecordAccessor next()
const {
284 return RecordAccessor(
P + getSizeInBytes());
287 static const unsigned PatchpointIDOffset = 0;
288 static const unsigned InstructionOffsetOffset =
289 PatchpointIDOffset +
sizeof(uint64_t);
290 static const unsigned NumLocationsOffset =
291 InstructionOffsetOffset +
sizeof(
uint32_t) +
sizeof(uint16_t);
292 static const unsigned LocationListOffset =
293 NumLocationsOffset +
sizeof(uint16_t);
294 static const unsigned LocationSize =
sizeof(uint64_t);
295 static const unsigned LiveOutSize =
sizeof(
uint32_t);
303 : StackMapSection(StackMapSection) {
304 ConstantsListOffset = FunctionListOffset +
getNumFunctions() * FunctionSize;
306 assert(StackMapSection[0] == 2 &&
307 "StackMapV2Parser can only parse version 2 stackmaps");
309 unsigned CurrentRecordOffset =
313 StackMapRecordOffsets.push_back(CurrentRecordOffset);
314 CurrentRecordOffset +=
315 RecordAccessor(&StackMapSection[CurrentRecordOffset]).getSizeInBytes();
328 return read<uint32_t>(&StackMapSection[NumFunctionsOffset]);
333 return read<uint32_t>(&StackMapSection[NumConstantsOffset]);
338 return read<uint32_t>(&StackMapSection[NumRecordsOffset]);
344 getFunctionOffset(FunctionIndex));
367 getConstantOffset(ConstantIndex));
389 std::size_t RecordOffset = StackMapRecordOffsets[RecordIndex];
417 template <
typename T>
418 static T read(
const uint8_t *
P) {
419 return support::endian::read<T, Endianness, 1>(
P);
422 static const unsigned HeaderOffset = 0;
423 static const unsigned NumFunctionsOffset = HeaderOffset +
sizeof(
uint32_t);
424 static const unsigned NumConstantsOffset = NumFunctionsOffset +
sizeof(
uint32_t);
425 static const unsigned NumRecordsOffset = NumConstantsOffset +
sizeof(
uint32_t);
426 static const unsigned FunctionListOffset = NumRecordsOffset +
sizeof(
uint32_t);
428 static const unsigned FunctionSize = 3 *
sizeof(uint64_t);
429 static const unsigned ConstantSize =
sizeof(uint64_t);
431 std::size_t getFunctionOffset(
unsigned FunctionIndex)
const {
432 return FunctionListOffset + FunctionIndex * FunctionSize;
435 std::size_t getConstantOffset(
unsigned ConstantIndex)
const {
436 return ConstantsListOffset + ConstantIndex * ConstantSize;
439 ArrayRef<uint8_t> StackMapSection;
440 unsigned ConstantsListOffset;
441 std::vector<unsigned> StackMapRecordOffsets;
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.
value_type read(const void *memory)
Read a value of a particular endianness from memory.
uint32_t getNumRecords() const
Get the number of stackmap records in the stackmap.
bool operator!=(const AccessorIterator &Other)
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)
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.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
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.
AccessorIterator< ConstantAccessor > constant_iterator
ConstantAccessor getConstant(unsigned ConstantIndex) const
Return the large constant at the given index.
iterator_range< liveout_iterator > liveouts() const
Iterator range for live-outs.
LocationKind getKind() const
Get the Kind for this location.
unsigned getSizeInBytes() const
Get the size in bytes of live [sub]register.
record_iterator records_begin() const
Begin iterator for records.
AccessorIterator< FunctionAccessor > function_iterator
AccessorIterator operator++(int)
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.
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.
AccessorIterator< LiveOutAccessor > liveout_iterator
AccessorIterator< RecordAccessor > record_iterator
AccessorIterator< LocationAccessor > location_iterator
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.