27 CustomEventMarkerKind,
39 if (T >= static_cast<uint8_t>(MetadataRecordKinds::EnumEndMarker))
41 "Invalid metadata record type: %d", T);
43 case MetadataRecordKinds::NewBufferKind:
44 return make_unique<NewBufferRecord>();
45 case MetadataRecordKinds::EndOfBufferKind:
49 "End of buffer records are no longer supported starting version " 51 return make_unique<EndBufferRecord>();
52 case MetadataRecordKinds::NewCPUIdKind:
53 return make_unique<NewCPUIDRecord>();
54 case MetadataRecordKinds::TSCWrapKind:
55 return make_unique<TSCWrapRecord>();
56 case MetadataRecordKinds::WalltimeMarkerKind:
57 return make_unique<WallclockRecord>();
58 case MetadataRecordKinds::CustomEventMarkerKind:
60 return make_unique<CustomEventRecordV5>();
61 return make_unique<CustomEventRecord>();
62 case MetadataRecordKinds::CallArgumentKind:
63 return make_unique<CallArgRecord>();
64 case MetadataRecordKinds::BufferExtentsKind:
65 return make_unique<BufferExtents>();
66 case MetadataRecordKinds::TypedEventMarkerKind:
67 return make_unique<TypedEventRecord>();
68 case MetadataRecordKinds::PidKind:
69 return make_unique<PIDRecord>();
70 case MetadataRecordKinds::EnumEndMarker:
76 constexpr
bool isMetadataIntroducer(uint8_t FirstByte) {
77 return FirstByte & 0x01u;
83 FileBasedRecordProducer::findNextBufferExtent() {
86 std::unique_ptr<Record> R;
88 auto PreReadOffset = OffsetPtr;
89 uint8_t FirstByte = E.
getU8(&OffsetPtr);
90 if (OffsetPtr == PreReadOffset)
93 "Failed reading one byte from offset %d.", OffsetPtr);
95 if (isMetadataIntroducer(FirstByte)) {
96 auto LoadedType = FirstByte >> 1;
97 if (LoadedType == MetadataRecordKinds::BufferExtentsKind) {
98 auto MetadataRecordOrErr = metadataRecordType(Header, LoadedType);
99 if (!MetadataRecordOrErr)
100 return MetadataRecordOrErr.takeError();
102 R = std::move(MetadataRecordOrErr.get());
104 if (
auto Err = R->apply(RI))
105 return std::move(Err);
110 llvm_unreachable(
"Must always terminate with either an error or a record.");
115 std::unique_ptr<Record> R;
121 if (Header.
Version >= 3 && CurrentBufferBytes == 0) {
123 auto BufferExtentsOrError = findNextBufferExtent();
124 if (!BufferExtentsOrError)
126 BufferExtentsOrError.takeError(),
129 "Failed to find the next BufferExtents record."));
131 R = std::move(BufferExtentsOrError.get());
133 assert(isa<BufferExtents>(R.get()));
135 CurrentBufferBytes = BE->size();
150 auto PreReadOffset = OffsetPtr;
151 uint8_t FirstByte = E.
getU8(&OffsetPtr);
152 if (OffsetPtr == PreReadOffset)
155 "Failed reading one byte from offset %d.", OffsetPtr);
158 if (isMetadataIntroducer(FirstByte)) {
159 auto LoadedType = FirstByte >> 1;
160 auto MetadataRecordOrErr = metadataRecordType(Header, LoadedType);
161 if (!MetadataRecordOrErr)
163 MetadataRecordOrErr.takeError(),
166 "Encountered an unsupported metadata record (%d) at offset %d.",
167 LoadedType, PreReadOffset));
168 R = std::move(MetadataRecordOrErr.get());
170 R = llvm::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)
186 "Buffer over-read at offset %d (over-read by %d bytes); Record Type " 188 OffsetPtr, (OffsetPtr - PreReadOffset) - CurrentBufferBytes,
191 CurrentBufferBytes -= OffsetPtr - PreReadOffset;
This class represents lattice values for constants.
Expected< std::unique_ptr< Record > > produce() override
This producer encapsulates the logic for loading a File-backed RecordProducer hidden behind a DataExt...
std::error_code make_error_code(BitcodeError E)
Tagged union holding either a T or a Error.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Error joinErrors(Error E1, Error E2)
Concatenate errors.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static StringRef kindToString(RecordKind K)
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.