diff --git a/lib/API/DX/DXFeatures.cpp b/lib/API/DX/DXFeatures.cpp index 7cc59ac2b..a63bf0a92 100644 --- a/lib/API/DX/DXFeatures.cpp +++ b/lib/API/DX/DXFeatures.cpp @@ -10,73 +10,55 @@ //===----------------------------------------------------------------------===// #include "DXFeatures.h" -#include "llvm/Support/ScopedPrinter.h" +#include "llvm/ADT/Enum.h" using namespace offloadtest; using namespace offloadtest::directx; using namespace llvm; -#define SHADER_MODEL_ENUM(NewCase, Str, Value) {#Str, NewCase}, -static const EnumEntry ShaderModelNames[]{ +#define SHADER_MODEL_ENUM(NewCase, Str, Value) {{#Str}, NewCase}, +static constexpr EnumStringDef ShaderModelDefs[]{ #include "DXFeatures.def" }; +static constexpr auto ShaderModelNames = BUILD_ENUM_STRINGS(ShaderModelDefs); -static ArrayRef> getShaderModels() { - return ArrayRef(ShaderModelNames); -} - -#define ROOT_SIGNATURE_ENUM(NewCase, Str, Value) {#Str, NewCase}, -static const EnumEntry RootSignatureNames[]{ +#define ROOT_SIGNATURE_ENUM(NewCase, Str, Value) {{#Str}, NewCase}, +static constexpr EnumStringDef RootSignatureDefs[]{ #include "DXFeatures.def" }; +static constexpr auto RootSignatureNames = + BUILD_ENUM_STRINGS(RootSignatureDefs); -static ArrayRef> getRootSignatures() { - return ArrayRef(RootSignatureNames); -} - -#define MESH_SHADER_TIER_ENUM(NewCase, Str, Value) {#Str, NewCase}, -static const EnumEntry MeshShaderTierNames[]{ +#define MESH_SHADER_TIER_ENUM(NewCase, Str, Value) {{#Str}, NewCase}, +static constexpr EnumStringDef MeshShaderTierDefs[]{ #include "DXFeatures.def" }; +static constexpr auto MeshShaderTierNames = + BUILD_ENUM_STRINGS(MeshShaderTierDefs); -static ArrayRef> getMeshShaderTiers() { - return ArrayRef(MeshShaderTierNames); -} - -#define RAYTRACING_TIER_ENUM(NewCase, Str, Value) {#Str, NewCase}, -static const EnumEntry RaytracingTierNames[]{ +#define RAYTRACING_TIER_ENUM(NewCase, Str, Value) {{#Str}, NewCase}, +static constexpr EnumStringDef RaytracingTierDefs[]{ #include "DXFeatures.def" }; - -static ArrayRef> getRaytracingTiers() { - return ArrayRef(RaytracingTierNames); -} - -template -static std::string enumEntryToString(ArrayRef> EnumValues, - T Value) { - for (const EnumEntry &I : EnumValues) - if (I.Value == Value) - return I.Name.str(); - llvm_unreachable("All cases must be covered"); -} +static constexpr auto RaytracingTierNames = + BUILD_ENUM_STRINGS(RaytracingTierDefs); std::string CapabilityPrinter::toString( const directx::ShaderModel &V) { - return enumEntryToString(getShaderModels(), V); + return EnumStrings(ShaderModelNames).toString(V).str(); } std::string CapabilityPrinter::toString( const directx::RootSignature &V) { - return enumEntryToString(getRootSignatures(), V); + return EnumStrings(RootSignatureNames).toString(V).str(); } std::string CapabilityPrinter::toString( const directx::MeshShaderTier &V) { - return enumEntryToString(getMeshShaderTiers(), V); + return EnumStrings(MeshShaderTierNames).toString(V).str(); } std::string CapabilityPrinter::toString( const directx::RaytracingTier &V) { - return enumEntryToString(getRaytracingTiers(), V); + return EnumStrings(RaytracingTierNames).toString(V).str(); } diff --git a/lib/API/DX/DXFeatures.h b/lib/API/DX/DXFeatures.h index fff4cb19a..db0b53424 100644 --- a/lib/API/DX/DXFeatures.h +++ b/lib/API/DX/DXFeatures.h @@ -13,11 +13,6 @@ #define OFFLOADTEST_API_DXFEATURES_H #include "API/Capabilities.h" -#include "llvm/ADT/ArrayRef.h" - -namespace llvm { -template struct EnumEntry; -} // namespace llvm namespace offloadtest { namespace directx {