20enum MetadataRecordKinds : uint8_t {
26 CustomEventMarkerKind,
35Expected<std::unique_ptr<Record>>
36metadataRecordType(
const XRayFileHeader &Header, uint8_t
T) {
38 if (
T >=
static_cast<uint8_t
>(MetadataRecordKinds::EnumEndMarker))
40 "Invalid metadata record type: %d",
T);
42 case MetadataRecordKinds::NewBufferKind:
43 return std::make_unique<NewBufferRecord>();
44 case MetadataRecordKinds::EndOfBufferKind:
45 if (Header.Version >= 2)
47 std::make_error_code(std::errc::executable_format_error),
48 "End of buffer records are no longer supported starting version "
50 return std::make_unique<EndBufferRecord>();
51 case MetadataRecordKinds::NewCPUIdKind:
52 return std::make_unique<NewCPUIDRecord>();
53 case MetadataRecordKinds::TSCWrapKind:
54 return std::make_unique<TSCWrapRecord>();
55 case MetadataRecordKinds::WalltimeMarkerKind:
56 return std::make_unique<WallclockRecord>();
57 case MetadataRecordKinds::CustomEventMarkerKind:
58 if (Header.Version >= 5)
59 return std::make_unique<CustomEventRecordV5>();
60 return std::make_unique<CustomEventRecord>();
61 case MetadataRecordKinds::CallArgumentKind:
62 return std::make_unique<CallArgRecord>();
63 case MetadataRecordKinds::BufferExtentsKind:
64 return std::make_unique<BufferExtents>();
65 case MetadataRecordKinds::TypedEventMarkerKind:
66 return std::make_unique<TypedEventRecord>();
67 case MetadataRecordKinds::PidKind:
68 return std::make_unique<PIDRecord>();
69 case MetadataRecordKinds::EnumEndMarker:
75constexpr bool isMetadataIntroducer(uint8_t FirstByte) {
76 return FirstByte & 0x01u;
81Expected<std::unique_ptr<Record>>
82FileBasedRecordProducer::findNextBufferExtent() {
85 std::unique_ptr<Record>
R;
87 auto PreReadOffset = OffsetPtr;
88 uint8_t FirstByte = E.
getU8(&OffsetPtr);
89 if (OffsetPtr == PreReadOffset)
91 std::make_error_code(std::errc::executable_format_error),
92 "Failed reading one byte from offset %" PRId64
".", OffsetPtr);
94 if (isMetadataIntroducer(FirstByte)) {
95 auto LoadedType = FirstByte >> 1;
96 if (LoadedType == MetadataRecordKinds::BufferExtentsKind) {
97 auto MetadataRecordOrErr = metadataRecordType(Header, LoadedType);
98 if (!MetadataRecordOrErr)
99 return MetadataRecordOrErr.takeError();
101 R = std::move(MetadataRecordOrErr.get());
102 RecordInitializer RI(E, OffsetPtr);
103 if (
auto Err =
R->apply(RI))
104 return std::move(Err);
109 llvm_unreachable(
"Must always terminate with either an error or a record.");
114 std::unique_ptr<Record> R;
120 if (Header.Version >= 3 && CurrentBufferBytes == 0) {
122 auto BufferExtentsOrError = findNextBufferExtent();
123 if (!BufferExtentsOrError)
125 BufferExtentsOrError.takeError(),
127 std::make_error_code(std::errc::executable_format_error),
128 "Failed to find the next BufferExtents record."));
130 R = std::move(BufferExtentsOrError.get());
132 assert(isa<BufferExtents>(R.get()));
133 auto BE = cast<BufferExtents>(R.get());
134 CurrentBufferBytes = BE->size();
149 auto PreReadOffset = OffsetPtr;
150 uint8_t FirstByte = E.
getU8(&OffsetPtr);
151 if (OffsetPtr == PreReadOffset)
153 std::make_error_code(std::errc::executable_format_error),
154 "Failed reading one byte from offset %" PRId64
".", OffsetPtr);
157 if (isMetadataIntroducer(FirstByte)) {
158 auto LoadedType = FirstByte >> 1;
159 auto MetadataRecordOrErr = metadataRecordType(Header, LoadedType);
160 if (!MetadataRecordOrErr)
162 MetadataRecordOrErr.takeError(),
164 std::make_error_code(std::errc::executable_format_error),
165 "Encountered an unsupported metadata record (%d) "
166 "at offset %" PRId64
".",
167 LoadedType, PreReadOffset));
168 R = std::move(MetadataRecordOrErr.get());
170 R = std::make_unique<FunctionRecord>();
174 if (
auto Err = R->apply(RI))
175 return std::move(Err);
180 if (
auto BE = dyn_cast<BufferExtents>(R.get())) {
181 CurrentBufferBytes = BE->size();
182 }
else if (Header.Version >= 3) {
183 if (OffsetPtr - PreReadOffset > CurrentBufferBytes)
185 std::make_error_code(std::errc::executable_format_error),
186 "Buffer over-read at offset %" PRId64
" (over-read by %" PRId64
187 " bytes); Record Type = %s.",
188 OffsetPtr, (OffsetPtr - PreReadOffset) - CurrentBufferBytes,
191 CurrentBufferBytes -= OffsetPtr - PreReadOffset;
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Tagged union holding either a T or a Error.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Expected< std::unique_ptr< Record > > produce() override
This producer encapsulates the logic for loading a File-backed RecordProducer hidden behind a DataExt...
static StringRef kindToString(RecordKind K)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Error joinErrors(Error E1, Error E2)
Concatenate errors.