9#ifndef LLVM_OBJECT_STACKMAPPARSER_H
10#define LLVM_OBJECT_STACKMAPPARSER_H
24template <support::endianness Endianness>
27 template <
typename AccessorT>
40 return A.P ==
Other.A.P;
44 return !(*
this ==
Other);
61 return read<uint64_t>(
P);
66 return read<uint64_t>(
P +
sizeof(
uint64_t));
71 return read<uint64_t>(
P + (2 *
sizeof(
uint64_t)));
77 const static int FunctionAccessorSize = 3 *
sizeof(
uint64_t);
79 FunctionAccessor next()
const {
80 return FunctionAccessor(
P + FunctionAccessorSize);
97 const static int ConstantAccessorSize =
sizeof(
uint64_t);
99 ConstantAccessor next()
const {
100 return ConstantAccessor(
P + ConstantAccessorSize);
123 return read<uint16_t>(
P + SizeOffset);
129 return read<uint16_t>(
P + DwarfRegNumOffset);
135 return read<uint32_t>(
P + SmallConstantOffset);
141 "Not a constant-index.");
142 return read<uint32_t>(
P + SmallConstantOffset);
149 "Not direct or indirect.");
150 return read<int32_t>(
P + SmallConstantOffset);
156 LocationAccessor next()
const {
157 return LocationAccessor(
P + LocationAccessorSize);
160 static const int KindOffset = 0;
161 static const int SizeOffset = KindOffset +
sizeof(
uint16_t);
162 static const int DwarfRegNumOffset = SizeOffset +
sizeof(
uint16_t);
163 static const int SmallConstantOffset = DwarfRegNumOffset +
sizeof(
uint32_t);
164 static const int LocationAccessorSize =
sizeof(
uint64_t) +
sizeof(
uint32_t);
177 return read<uint16_t>(
P + DwarfRegNumOffset);
182 return read<uint8_t>(
P + SizeOffset);
188 LiveOutAccessor next()
const {
189 return LiveOutAccessor(
P + LiveOutAccessorSize);
192 static const int DwarfRegNumOffset = 0;
193 static const int SizeOffset =
194 DwarfRegNumOffset +
sizeof(
uint16_t) +
sizeof(uint8_t);
195 static const int LiveOutAccessorSize =
sizeof(
uint32_t);
210 return read<uint64_t>(
P + PatchpointIDOffset);
216 return read<uint32_t>(
P + InstructionOffsetOffset);
221 return read<uint16_t>(
P + NumLocationsOffset);
226 unsigned LocationOffset =
248 return read<uint16_t>(
P + getNumLiveOutsOffset());
253 unsigned LiveOutOffset =
254 getNumLiveOutsOffset() +
sizeof(
uint16_t) + LiveOutIndex * LiveOutSize;
276 unsigned getNumLiveOutsOffset()
const {
279 return LocOffset +
sizeof(
uint16_t);
283 unsigned RecordSize =
285 return (RecordSize + 7) & ~0x7;
288 RecordAccessor next()
const {
292 static const unsigned PatchpointIDOffset = 0;
293 static const unsigned InstructionOffsetOffset =
294 PatchpointIDOffset +
sizeof(
uint64_t);
295 static const unsigned NumLocationsOffset =
297 static const unsigned LocationListOffset =
298 NumLocationsOffset +
sizeof(
uint16_t);
300 static const unsigned LiveOutSize =
sizeof(
uint32_t);
308 : StackMapSection(StackMapSection) {
309 ConstantsListOffset = FunctionListOffset +
getNumFunctions() * FunctionSize;
311 assert(StackMapSection[0] == 3 &&
312 "StackMapParser can only parse version 3 stackmaps");
314 unsigned CurrentRecordOffset =
318 StackMapRecordOffsets.push_back(CurrentRecordOffset);
319 CurrentRecordOffset +=
320 RecordAccessor(&StackMapSection[CurrentRecordOffset]).getSizeInBytes();
327 if (StackMapSection.
size() < 16)
329 "the stack map section size (" +
Twine(StackMapSection.
size()) +
330 ") is less than the minimum possible size of its header (16)");
332 unsigned Version = StackMapSection[0];
335 "the version (" +
Twine(Version) +
336 ") of the stack map section is unsupported, the "
337 "supported version is 3");
350 return read<uint32_t>(&StackMapSection[NumFunctionsOffset]);
355 return read<uint32_t>(&StackMapSection[NumConstantsOffset]);
360 return read<uint32_t>(&StackMapSection[NumRecordsOffset]);
366 getFunctionOffset(FunctionIndex));
411 std::size_t RecordOffset = StackMapRecordOffsets[RecordIndex];
438 template <
typename T>
439 static T read(
const uint8_t *
P) {
440 return support::endian::read<T, Endianness, 1>(
P);
443 static const unsigned HeaderOffset = 0;
444 static const unsigned NumFunctionsOffset = HeaderOffset +
sizeof(
uint32_t);
445 static const unsigned NumConstantsOffset = NumFunctionsOffset +
sizeof(
uint32_t);
446 static const unsigned NumRecordsOffset = NumConstantsOffset +
sizeof(
uint32_t);
447 static const unsigned FunctionListOffset = NumRecordsOffset +
sizeof(
uint32_t);
449 static const unsigned FunctionSize = 3 *
sizeof(
uint64_t);
450 static const unsigned ConstantSize =
sizeof(
uint64_t);
452 std::size_t getFunctionOffset(
unsigned FunctionIndex)
const {
453 return FunctionListOffset + FunctionIndex * FunctionSize;
456 std::size_t getConstantOffset(
unsigned ConstantIndex)
const {
460 ArrayRef<uint8_t> StackMapSection;
461 unsigned ConstantsListOffset;
462 std::vector<unsigned> StackMapRecordOffsets;
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
This is an important base class in LLVM.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Wrapper class representing virtual and physical registers.
bool operator==(const AccessorIterator &Other) const
AccessorIterator(AccessorT A)
AccessorIterator & operator++()
bool operator!=(const AccessorIterator &Other) const
AccessorIterator operator++(int)
uint64_t getValue() const
Return the value of this constant.
Accessor for function records.
uint64_t getRecordCount() const
Get the number of callsite records.
uint64_t getFunctionAddress() const
Get the function address.
uint64_t getStackSize() const
Get the function's stack size.
Accessor for stackmap live-out fields.
uint16_t getDwarfRegNum() const
Get the Dwarf register number for this live-out.
unsigned getSizeInBytes() const
Get the size in bytes of live [sub]register.
Accessor for location records.
unsigned getSizeInBytes() const
Get the Size for this location.
uint16_t getDwarfRegNum() const
Get the Dwarf register number for this location.
LocationKind getKind() const
Get the Kind for this location.
int32_t getOffset() const
Get the offset for this location. (Kind must be Direct or Indirect).
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).
Accessor for stackmap records.
iterator_range< liveout_iterator > liveouts() const
Iterator range for live-outs.
uint16_t getNumLocations() const
Get the number of locations contained in this record.
LocationAccessor getLocation(unsigned LocationIndex) const
Get the location with the given index.
uint32_t getInstructionOffset() const
Get the instruction offset (from the start of the containing function) for this record.
liveout_iterator liveouts_end() const
End iterator for live-outs.
iterator_range< location_iterator > locations() const
Iterator range for locations.
LiveOutAccessor getLiveOut(unsigned LiveOutIndex) const
Get the live-out with the given index.
AccessorIterator< LiveOutAccessor > liveout_iterator
AccessorIterator< LocationAccessor > location_iterator
location_iterator location_begin() const
Begin iterator for locations.
uint64_t getID() const
Get the patchpoint/stackmap ID for this record.
uint16_t getNumLiveOuts() const
Get the number of liveouts contained in this record.
liveout_iterator liveouts_begin() const
Begin iterator for live-outs.
location_iterator location_end() const
End iterator for locations.
A parser for the latest stackmap format. At the moment, latest=V3.
constant_iterator constants_end() const
End iterator for constants.
record_iterator records_end() const
End iterator for records.
FunctionAccessor getFunction(unsigned FunctionIndex) const
Return an FunctionAccessor for the given function index.
AccessorIterator< FunctionAccessor > function_iterator
AccessorIterator< ConstantAccessor > constant_iterator
function_iterator functions_end() const
End iterator for functions.
iterator_range< record_iterator > records() const
Iterator range for records.
iterator_range< constant_iterator > constants() const
Iterator range for constants.
unsigned getVersion() const
Get the version number of this stackmap. (Always returns 3).
uint32_t getNumConstants() const
Get the number of large constants in the stack map.
function_iterator functions_begin() const
Begin iterator for functions.
record_iterator records_begin() const
Begin iterator for records.
uint32_t getNumRecords() const
Get the number of stackmap records in the stackmap.
constant_iterator constants_begin() const
Begin iterator for constants.
iterator_range< function_iterator > functions() const
Iterator range for functions.
AccessorIterator< RecordAccessor > record_iterator
ConstantAccessor getConstant(unsigned ConstantIndex) const
Return the large constant at the given index.
StackMapParser(ArrayRef< uint8_t > StackMapSection)
Construct a parser for a version-3 stackmap.
RecordAccessor getRecord(unsigned RecordIndex) const
Return a RecordAccessor for the given record index.
static Error validateHeader(ArrayRef< uint8_t > StackMapSection)
Validates the header of the specified stack map section.
uint32_t getNumFunctions() const
Get the number of functions in the stack map.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
A range adaptor for a pair of iterators.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
Error createError(const Twine &Err)
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.