[llvm] [HLSL] Refactoring DXILABI.h to not depend on scope printer (PR #153840)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 15 15:13:14 PDT 2025
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/153840
>From f2d933e2faf820edabc7d7e23cfcbb07558ccbc2 Mon Sep 17 00:00:00 2001
From: Joao Saffran <{ID}+{username}@users.noreply.github.com>
Date: Fri, 15 Aug 2025 10:12:49 -0700
Subject: [PATCH 1/4] refactoring
---
llvm/include/llvm/Support/DXILABI.h | 4 +---
llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp | 5 ++---
llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp | 9 +++------
llvm/lib/Support/DXILABI.cpp | 7 ++++++-
4 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/llvm/include/llvm/Support/DXILABI.h b/llvm/include/llvm/Support/DXILABI.h
index 2dcdd73415be2..47b3a6619344f 100644
--- a/llvm/include/llvm/Support/DXILABI.h
+++ b/llvm/include/llvm/Support/DXILABI.h
@@ -18,7 +18,6 @@
#define LLVM_SUPPORT_DXILABI_H
#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/ScopedPrinter.h"
#include <cstdint>
namespace llvm {
@@ -101,9 +100,8 @@ enum class SamplerFeedbackType : uint32_t {
const unsigned MinWaveSize = 4;
const unsigned MaxWaveSize = 128;
-LLVM_ABI ArrayRef<EnumEntry<ResourceClass>> getResourceClasses();
-
LLVM_ABI StringRef getResourceClassName(ResourceClass RC);
+LLVM_ABI StringRef getResourceClassName(uint8_t RC);
} // namespace dxil
} // namespace llvm
diff --git a/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp b/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
index 050cc46e8c9b0..30b597dbad497 100644
--- a/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
+++ b/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
+#include "llvm/Support/DXILABI.h"
#include "llvm/Support/ScopedPrinter.h"
namespace llvm {
@@ -93,9 +94,7 @@ static raw_ostream &operator<<(raw_ostream &OS,
}
static raw_ostream &operator<<(raw_ostream &OS, const ClauseType &Type) {
- OS << enumToStringRef(dxil::ResourceClass(llvm::to_underlying(Type)),
- dxil::getResourceClasses());
-
+ OS << dxil::getResourceClassName(llvm::to_underlying(Type));
return OS;
}
diff --git a/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp b/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp
index 157bfc665b207..c0fef52bb2e88 100644
--- a/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp
+++ b/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp
@@ -15,6 +15,7 @@
#include "llvm/Frontend/HLSL/RootSignatureValidations.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Metadata.h"
+#include "llvm/Support/DXILABI.h"
#include "llvm/Support/ScopedPrinter.h"
using namespace llvm;
@@ -119,9 +120,7 @@ MDNode *MetadataBuilder::BuildRootConstants(const RootConstants &Constants) {
MDNode *MetadataBuilder::BuildRootDescriptor(const RootDescriptor &Descriptor) {
IRBuilder<> Builder(Ctx);
- StringRef ResName =
- enumToStringRef(dxil::ResourceClass(to_underlying(Descriptor.Type)),
- dxil::getResourceClasses());
+ StringRef ResName = dxil::getResourceClassName(to_underlying(Descriptor.Type));
assert(!ResName.empty() && "Provided an invalid Resource Class");
SmallString<7> Name({"Root", ResName});
Metadata *Operands[] = {
@@ -161,9 +160,7 @@ MDNode *MetadataBuilder::BuildDescriptorTable(const DescriptorTable &Table) {
MDNode *MetadataBuilder::BuildDescriptorTableClause(
const DescriptorTableClause &Clause) {
IRBuilder<> Builder(Ctx);
- StringRef ResName =
- enumToStringRef(dxil::ResourceClass(to_underlying(Clause.Type)),
- dxil::getResourceClasses());
+ StringRef ResName = dxil::getResourceClassName(to_underlying(Clause.Type));
assert(!ResName.empty() && "Provided an invalid Resource Class");
Metadata *Operands[] = {
MDString::get(Ctx, ResName),
diff --git a/llvm/lib/Support/DXILABI.cpp b/llvm/lib/Support/DXILABI.cpp
index 261fe1ef98278..8a719f7677aba 100644
--- a/llvm/lib/Support/DXILABI.cpp
+++ b/llvm/lib/Support/DXILABI.cpp
@@ -16,6 +16,7 @@
#include "llvm/Support/DXILABI.h"
#include "llvm/Support/ScopedPrinter.h"
+
using namespace llvm;
static const EnumEntry<dxil::ResourceClass> ResourceClassNames[] = {
@@ -25,10 +26,14 @@ static const EnumEntry<dxil::ResourceClass> ResourceClassNames[] = {
{"Sampler", llvm::dxil::ResourceClass::Sampler},
};
-ArrayRef<EnumEntry<llvm::dxil::ResourceClass>> dxil::getResourceClasses() {
+ArrayRef<EnumEntry<llvm::dxil::ResourceClass>> getResourceClasses() {
return ArrayRef(ResourceClassNames);
}
StringRef dxil::getResourceClassName(dxil::ResourceClass RC) {
return enumToStringRef(RC, getResourceClasses());
}
+
+StringRef dxil::getResourceClassName(uint8_t RC) {
+ return enumToStringRef(ResourceClass(RC), getResourceClasses());
+}
>From 9073f07bda9f1a32b79bc4ec172a558e5e54b90e Mon Sep 17 00:00:00 2001
From: Joao Saffran <{ID}+{username}@users.noreply.github.com>
Date: Fri, 15 Aug 2025 10:24:03 -0700
Subject: [PATCH 2/4] clean up
---
llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp | 1 -
llvm/lib/Support/DXILABI.cpp | 1 -
2 files changed, 2 deletions(-)
diff --git a/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp b/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp
index c0fef52bb2e88..c24475ed1bcf6 100644
--- a/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp
+++ b/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp
@@ -15,7 +15,6 @@
#include "llvm/Frontend/HLSL/RootSignatureValidations.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Metadata.h"
-#include "llvm/Support/DXILABI.h"
#include "llvm/Support/ScopedPrinter.h"
using namespace llvm;
diff --git a/llvm/lib/Support/DXILABI.cpp b/llvm/lib/Support/DXILABI.cpp
index 8a719f7677aba..5b7c0669881ea 100644
--- a/llvm/lib/Support/DXILABI.cpp
+++ b/llvm/lib/Support/DXILABI.cpp
@@ -16,7 +16,6 @@
#include "llvm/Support/DXILABI.h"
#include "llvm/Support/ScopedPrinter.h"
-
using namespace llvm;
static const EnumEntry<dxil::ResourceClass> ResourceClassNames[] = {
>From 1f4332c03ca4af02d4771a1c93536d9087a4b8bb Mon Sep 17 00:00:00 2001
From: Joao Saffran <{ID}+{username}@users.noreply.github.com>
Date: Fri, 15 Aug 2025 11:18:21 -0700
Subject: [PATCH 3/4] removing API and removing enumToStringRef
---
llvm/include/llvm/Support/DXILABI.h | 1 -
llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp | 3 +-
.../Frontend/HLSL/RootSignatureMetadata.cpp | 6 ++--
llvm/lib/Support/DXILABI.cpp | 29 ++++++++-----------
4 files changed, 18 insertions(+), 21 deletions(-)
diff --git a/llvm/include/llvm/Support/DXILABI.h b/llvm/include/llvm/Support/DXILABI.h
index 47b3a6619344f..b25b3632f6c3b 100644
--- a/llvm/include/llvm/Support/DXILABI.h
+++ b/llvm/include/llvm/Support/DXILABI.h
@@ -101,7 +101,6 @@ const unsigned MinWaveSize = 4;
const unsigned MaxWaveSize = 128;
LLVM_ABI StringRef getResourceClassName(ResourceClass RC);
-LLVM_ABI StringRef getResourceClassName(uint8_t RC);
} // namespace dxil
} // namespace llvm
diff --git a/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp b/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
index 30b597dbad497..0d70fc1e57786 100644
--- a/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
+++ b/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
@@ -94,7 +94,8 @@ static raw_ostream &operator<<(raw_ostream &OS,
}
static raw_ostream &operator<<(raw_ostream &OS, const ClauseType &Type) {
- OS << dxil::getResourceClassName(llvm::to_underlying(Type));
+ OS << dxil::getResourceClassName(
+ dxil::ResourceClass(llvm::to_underlying(Type)));
return OS;
}
diff --git a/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp b/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp
index c24475ed1bcf6..6c270344212e8 100644
--- a/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp
+++ b/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp
@@ -119,7 +119,8 @@ MDNode *MetadataBuilder::BuildRootConstants(const RootConstants &Constants) {
MDNode *MetadataBuilder::BuildRootDescriptor(const RootDescriptor &Descriptor) {
IRBuilder<> Builder(Ctx);
- StringRef ResName = dxil::getResourceClassName(to_underlying(Descriptor.Type));
+ StringRef ResName = dxil::getResourceClassName(
+ dxil::ResourceClass(to_underlying(Descriptor.Type)));
assert(!ResName.empty() && "Provided an invalid Resource Class");
SmallString<7> Name({"Root", ResName});
Metadata *Operands[] = {
@@ -159,7 +160,8 @@ MDNode *MetadataBuilder::BuildDescriptorTable(const DescriptorTable &Table) {
MDNode *MetadataBuilder::BuildDescriptorTableClause(
const DescriptorTableClause &Clause) {
IRBuilder<> Builder(Ctx);
- StringRef ResName = dxil::getResourceClassName(to_underlying(Clause.Type));
+ StringRef ResName = dxil::getResourceClassName(
+ dxil::ResourceClass(to_underlying(Clause.Type)));
assert(!ResName.empty() && "Provided an invalid Resource Class");
Metadata *Operands[] = {
MDString::get(Ctx, ResName),
diff --git a/llvm/lib/Support/DXILABI.cpp b/llvm/lib/Support/DXILABI.cpp
index 5b7c0669881ea..082e32061bd45 100644
--- a/llvm/lib/Support/DXILABI.cpp
+++ b/llvm/lib/Support/DXILABI.cpp
@@ -15,24 +15,19 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/DXILABI.h"
-#include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/ErrorHandling.h"
using namespace llvm;
-static const EnumEntry<dxil::ResourceClass> ResourceClassNames[] = {
- {"SRV", llvm::dxil::ResourceClass::SRV},
- {"UAV", llvm::dxil::ResourceClass::UAV},
- {"CBV", llvm::dxil::ResourceClass::CBuffer},
- {"Sampler", llvm::dxil::ResourceClass::Sampler},
-};
-
-ArrayRef<EnumEntry<llvm::dxil::ResourceClass>> getResourceClasses() {
- return ArrayRef(ResourceClassNames);
-}
-
StringRef dxil::getResourceClassName(dxil::ResourceClass RC) {
- return enumToStringRef(RC, getResourceClasses());
-}
-
-StringRef dxil::getResourceClassName(uint8_t RC) {
- return enumToStringRef(ResourceClass(RC), getResourceClasses());
+ switch (RC) {
+ case dxil::ResourceClass::SRV:
+ return "SRV";
+ case dxil::ResourceClass::UAV:
+ return "UAV";
+ case dxil::ResourceClass::CBuffer:
+ return "CBV";
+ case dxil::ResourceClass::Sampler:
+ return "Sampler";
+ }
+ llvm_unreachable("Invalid ResourceClass enum value");
}
>From be68476f70e64a4ce95e87374a77e2e8c9bc550e Mon Sep 17 00:00:00 2001
From: Joao Saffran <{ID}+{username}@users.noreply.github.com>
Date: Fri, 15 Aug 2025 15:12:59 -0700
Subject: [PATCH 4/4] fix
---
llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp | 2 +-
llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp b/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
index 0d70fc1e57786..b5481bc568e89 100644
--- a/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
+++ b/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
@@ -95,7 +95,7 @@ static raw_ostream &operator<<(raw_ostream &OS,
static raw_ostream &operator<<(raw_ostream &OS, const ClauseType &Type) {
OS << dxil::getResourceClassName(
- dxil::ResourceClass(llvm::to_underlying(Type)));
+ dxil::ResourceClass(Type));
return OS;
}
diff --git a/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp b/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp
index 6c270344212e8..6a92834710550 100644
--- a/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp
+++ b/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp
@@ -120,7 +120,7 @@ MDNode *MetadataBuilder::BuildRootConstants(const RootConstants &Constants) {
MDNode *MetadataBuilder::BuildRootDescriptor(const RootDescriptor &Descriptor) {
IRBuilder<> Builder(Ctx);
StringRef ResName = dxil::getResourceClassName(
- dxil::ResourceClass(to_underlying(Descriptor.Type)));
+ dxil::ResourceClass(Descriptor.Type));
assert(!ResName.empty() && "Provided an invalid Resource Class");
SmallString<7> Name({"Root", ResName});
Metadata *Operands[] = {
@@ -161,7 +161,7 @@ MDNode *MetadataBuilder::BuildDescriptorTableClause(
const DescriptorTableClause &Clause) {
IRBuilder<> Builder(Ctx);
StringRef ResName = dxil::getResourceClassName(
- dxil::ResourceClass(to_underlying(Clause.Type)));
+ dxil::ResourceClass(Clause.Type));
assert(!ResName.empty() && "Provided an invalid Resource Class");
Metadata *Operands[] = {
MDString::get(Ctx, ResName),
More information about the llvm-commits
mailing list