9 #ifndef LLVM_CODEGEN_STACKMAPPARSER_H 10 #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);
89 uint64_t
getValue()
const {
return read<uint64_t>(
P); }
94 const static int ConstantAccessorSize =
sizeof(uint64_t);
120 return read<uint16_t>(
P + SizeOffset);
126 return read<uint16_t>(
P + DwarfRegNumOffset);
132 return read<uint32_t>(
P + SmallConstantOffset);
138 "Not a constant-index.");
139 return read<uint32_t>(
P + SmallConstantOffset);
146 "Not direct or indirect.");
147 return read<int32_t>(
P + SmallConstantOffset);
157 static const int KindOffset = 0;
158 static const int SizeOffset = KindOffset +
sizeof(
uint16_t);
159 static const int DwarfRegNumOffset = SizeOffset +
sizeof(
uint16_t);
160 static const int SmallConstantOffset = DwarfRegNumOffset +
sizeof(
uint32_t);
161 static const int LocationAccessorSize =
sizeof(uint64_t) +
sizeof(
uint32_t);
174 return read<uint16_t>(
P + DwarfRegNumOffset);
179 return read<uint8_t>(
P + SizeOffset);
189 static const int DwarfRegNumOffset = 0;
190 static const int SizeOffset =
191 DwarfRegNumOffset +
sizeof(
uint16_t) +
sizeof(uint8_t);
192 static const int LiveOutAccessorSize =
sizeof(
uint32_t);
207 return read<uint64_t>(
P + PatchpointIDOffset);
213 return read<uint32_t>(
P + InstructionOffsetOffset);
218 return read<uint16_t>(
P + NumLocationsOffset);
223 unsigned LocationOffset =
240 return make_range(location_begin(), location_end());
245 return read<uint16_t>(
P + getNumLiveOutsOffset());
250 unsigned LiveOutOffset =
251 getNumLiveOutsOffset() +
sizeof(
uint16_t) + LiveOutIndex * LiveOutSize;
267 return make_range(liveouts_begin(), liveouts_end());
273 unsigned getNumLiveOutsOffset()
const {
275 ((LocationListOffset +
LocationSize * getNumLocations()) + 7) & ~0x7;
276 return LocOffset +
sizeof(
uint16_t);
279 unsigned getSizeInBytes()
const {
280 unsigned RecordSize =
281 getNumLiveOutsOffset() +
sizeof(
uint16_t) + getNumLiveOuts() * LiveOutSize;
282 return (RecordSize + 7) & ~0x7;
289 static const unsigned PatchpointIDOffset = 0;
290 static const unsigned InstructionOffsetOffset =
291 PatchpointIDOffset +
sizeof(uint64_t);
292 static const unsigned NumLocationsOffset =
294 static const unsigned LocationListOffset =
295 NumLocationsOffset +
sizeof(
uint16_t);
297 static const unsigned LiveOutSize =
sizeof(
uint32_t);
305 : StackMapSection(StackMapSection) {
306 ConstantsListOffset = FunctionListOffset +
getNumFunctions() * FunctionSize;
308 assert(StackMapSection[0] == 3 &&
309 "StackMapParser can only parse version 3 stackmaps");
311 unsigned CurrentRecordOffset =
315 StackMapRecordOffsets.push_back(CurrentRecordOffset);
316 CurrentRecordOffset +=
317 RecordAccessor(&StackMapSection[CurrentRecordOffset]).getSizeInBytes();
330 return read<uint32_t>(&StackMapSection[NumFunctionsOffset]);
335 return read<uint32_t>(&StackMapSection[NumConstantsOffset]);
340 return read<uint32_t>(&StackMapSection[NumRecordsOffset]);
346 getFunctionOffset(FunctionIndex));
369 getConstantOffset(ConstantIndex));
391 std::size_t RecordOffset = StackMapRecordOffsets[RecordIndex];
418 template <
typename T>
419 static T read(
const uint8_t *
P) {
420 return support::endian::read<T, Endianness, 1>(
P);
423 static const unsigned HeaderOffset = 0;
424 static const unsigned NumFunctionsOffset = HeaderOffset +
sizeof(
uint32_t);
425 static const unsigned NumConstantsOffset = NumFunctionsOffset +
sizeof(
uint32_t);
426 static const unsigned NumRecordsOffset = NumConstantsOffset +
sizeof(
uint32_t);
427 static const unsigned FunctionListOffset = NumRecordsOffset +
sizeof(
uint32_t);
429 static const unsigned FunctionSize = 3 *
sizeof(uint64_t);
430 static const unsigned ConstantSize =
sizeof(uint64_t);
432 std::size_t getFunctionOffset(
unsigned FunctionIndex)
const {
433 return FunctionListOffset + FunctionIndex * FunctionSize;
436 std::size_t getConstantOffset(
unsigned ConstantIndex)
const {
437 return ConstantsListOffset + ConstantIndex * ConstantSize;
441 unsigned ConstantsListOffset;
442 std::vector<unsigned> StackMapRecordOffsets;
447 #endif // LLVM_CODEGEN_STACKMAPPARSER_H unsigned getVersion() const
Get the version number of this stackmap. (Always returns 3).
unsigned getSizeInBytes() const
Get the Size for this location.
uint16_t getDwarfRegNum() const
Get the Dwarf register number for this location.
uint64_t getRecordCount() const
Get the number of callsite records.
Accessor for stackmap live-out fields.
This class represents lattice values for constants.
liveout_iterator liveouts_begin() const
Begin iterator for live-outs.
AccessorIterator< ConstantAccessor > constant_iterator
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
uint64_t getStackSize() const
Get the function's stack size.
iterator_range< liveout_iterator > liveouts() const
Iterator range for live-outs.
uint32_t getNumConstants() const
Get the number of large constants in the stack map.
uint32_t getConstantIndex() const
Get the constant-index for this location. (Kind must be ConstantIndex).
Accessor for stackmap records.
location_iterator location_begin() const
Begin iterator for locations.
unsigned getSizeInBytes() const
Get the size in bytes of live [sub]register.
uint64_t getID() const
Get the patchpoint/stackmap ID for this record.
uint64_t getFunctionAddress() const
Get the function address.
AccessorIterator & operator++()
constant_iterator constants_end() const
End iterator for constants.
AccessorIterator(AccessorT A)
bool operator!=(const AccessorIterator &Other)
function_iterator functions_begin() const
Begin iterator for functions.
constant_iterator constants_begin() const
Begin iterator for constants.
liveout_iterator liveouts_end() const
End iterator for live-outs.
Accessor for function records.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
function_iterator functions_end() const
End iterator for functions.
RecordAccessor getRecord(unsigned RecordIndex) const
Return a RecordAccessor for the given record index.
iterator_range< function_iterator > functions() const
Iterator range for functions.
uint16_t getNumLocations() const
Get the number of locations contained in this record.
uint32_t getInstructionOffset() const
Get the instruction offset (from the start of the containing function) for this record.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
uint32_t getNumRecords() const
Get the number of stackmap records in the stackmap.
uint16_t getDwarfRegNum() const
Get the Dwarf register number for this live-out.
iterator_range< location_iterator > locations() const
Iterator range for locations.
iterator_range< constant_iterator > constants() const
Iterator range for constants.
location_iterator location_end() const
End iterator for locations.
bool operator==(const AccessorIterator &Other)
A range adaptor for a pair of iterators.
uint32_t getNumFunctions() const
Get the number of functions in the stack map.
uint16_t getNumLiveOuts() const
Get the number of liveouts contained in this record.
AccessorIterator< FunctionAccessor > function_iterator
A parser for the latest stackmap format. At the moment, latest=V3.
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
Accessor for location records.
record_iterator records_begin() const
Begin iterator for records.
AccessorIterator< RecordAccessor > record_iterator
static MemoryLocation getLocation(Instruction *I, AliasAnalysis *AA)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
FunctionAccessor getFunction(unsigned FunctionIndex) const
Return an FunctionAccessor for the given function index.
int32_t getOffset() const
Get the offset for this location. (Kind must be Direct or Indirect).
LocationAccessor getLocation(unsigned LocationIndex) const
Get the location with the given index.
LiveOutAccessor getLiveOut(unsigned LiveOutIndex) const
Get the live-out with the given index.
uint64_t getValue() const
Return the value of this constant.
StackMapParser(ArrayRef< uint8_t > StackMapSection)
Construct a parser for a version-3 stackmap.
iterator_range< record_iterator > records() const
Iterator range for records.
LocationKind getKind() const
Get the Kind for this location.
Wrapper class representing virtual and physical registers.
record_iterator records_end() const
End iterator for records.
AccessorIterator operator++(int)
uint32_t getSmallConstant() const
Get the small-constant for this location. (Kind must be Constant).
ConstantAccessor getConstant(unsigned ConstantIndex) const
Return the large constant at the given index.