From fc774e29d291de7b85ccb059b3319048b5cdbdbd Mon Sep 17 00:00:00 2001 From: Dean Michael Berris Date: Fri, 31 Aug 2018 11:41:08 +0000 Subject: [PATCH] [XRay] Remove array for Metadata Record Types This simplifies the implementation of the metadata lookup by using scoped enums, rather than using enum classes. This way we can get the number-name mapping without having to resort to comments. Follow-up to D51289. llvm-svn: 341205 --- llvm/lib/XRay/FDRRecordProducer.cpp | 68 +++++++++++++++---------------------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/llvm/lib/XRay/FDRRecordProducer.cpp b/llvm/lib/XRay/FDRRecordProducer.cpp index ef2f6a4..4b010f1 100644 --- a/llvm/lib/XRay/FDRRecordProducer.cpp +++ b/llvm/lib/XRay/FDRRecordProducer.cpp @@ -14,66 +14,54 @@ namespace xray { namespace { -// Keep this in sync with the values written in the XRay FDR mode runtime in -// compiler-rt. -enum class MetadataRecordKinds : uint8_t { - NewBuffer, - EndOfBuffer, - NewCPUId, - TSCWrap, - WalltimeMarker, - CustomEventMarker, - CallArgument, - BufferExtents, - TypedEventMarker, - Pid, - // This is an end marker, used to identify the upper bound for this enum. - EnumEndMarker, -}; - Expected> metadataRecordType(const XRayFileHeader &Header, uint8_t T) { + // Keep this in sync with the values written in the XRay FDR mode runtime in + // compiler-rt. + enum MetadataRecordKinds : uint8_t { + NewBufferKind, + EndOfBufferKind, + NewCPUIdKind, + TSCWrapKind, + WalltimeMarkerKind, + CustomEventMarkerKind, + CallArgumentKind, + BufferExtentsKind, + TypedEventMarkerKind, + PidKind, + // This is an end marker, used to identify the upper bound for this enum. + EnumEndMarker, + }; + if (T >= static_cast(MetadataRecordKinds::EnumEndMarker)) return createStringError(std::make_error_code(std::errc::invalid_argument), "Invalid metadata record type: %d", T); - static constexpr MetadataRecordKinds Mapping[] = { - MetadataRecordKinds::NewBuffer, - MetadataRecordKinds::EndOfBuffer, - MetadataRecordKinds::NewCPUId, - MetadataRecordKinds::TSCWrap, - MetadataRecordKinds::WalltimeMarker, - MetadataRecordKinds::CustomEventMarker, - MetadataRecordKinds::CallArgument, - MetadataRecordKinds::BufferExtents, - MetadataRecordKinds::TypedEventMarker, - MetadataRecordKinds::Pid, - }; - switch (Mapping[T]) { - case MetadataRecordKinds::NewBuffer: + switch (T) { + case MetadataRecordKinds::NewBufferKind: return make_unique(); - case MetadataRecordKinds::EndOfBuffer: + case MetadataRecordKinds::EndOfBufferKind: if (Header.Version >= 2) return createStringError( std::make_error_code(std::errc::executable_format_error), "End of buffer records are no longer supported starting version " "2 of the log."); return make_unique(); - case MetadataRecordKinds::NewCPUId: + case MetadataRecordKinds::NewCPUIdKind: return make_unique(); - case MetadataRecordKinds::TSCWrap: + case MetadataRecordKinds::TSCWrapKind: return make_unique(); - case MetadataRecordKinds::WalltimeMarker: + case MetadataRecordKinds::WalltimeMarkerKind: return make_unique(); - case MetadataRecordKinds::CustomEventMarker: + case MetadataRecordKinds::CustomEventMarkerKind: return make_unique(); - case MetadataRecordKinds::CallArgument: + case MetadataRecordKinds::CallArgumentKind: return make_unique(); - case MetadataRecordKinds::BufferExtents: + case MetadataRecordKinds::BufferExtentsKind: return make_unique(); - case MetadataRecordKinds::TypedEventMarker: + case MetadataRecordKinds::TypedEventMarkerKind: return createStringError(std::make_error_code(std::errc::invalid_argument), "Encountered an unsupported TypedEventMarker."); - case MetadataRecordKinds::Pid: + case MetadataRecordKinds::PidKind: return make_unique(); case MetadataRecordKinds::EnumEndMarker: llvm_unreachable("Invalid MetadataRecordKind"); -- 2.7.4