Skip to content

[HLSL] Refactoring DXILABI.h to not depend on scope printer #153840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions llvm/include/llvm/Support/DXILABI.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#define LLVM_SUPPORT_DXILABI_H

#include "llvm/ADT/StringRef.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can also replace this StringRef.h include with a forward declaration.

#include "llvm/Support/ScopedPrinter.h"
#include <cstdint>

namespace llvm {
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good API to add - why would we want anything other than the strongly typed version of this function?


} // namespace dxil
} // namespace llvm
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
#include "llvm/Support/DXILABI.h"
#include "llvm/Support/ScopedPrinter.h"

namespace llvm {
Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 2 additions & 6 deletions llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,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[] = {
Expand Down Expand Up @@ -161,9 +159,7 @@ MDNode *MetadataBuilder::BuildDescriptorTable(const DescriptorTable &Table) {
MDNode *MetadataBuilder::BuildDescriptorTableClause(
const DescriptorTableClause &Clause) {
IRBuilder<> Builder(Ctx);
StringRef ResName =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the same enum @llvm-beanz

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using ClauseType = llvm::dxil::ResourceClass;

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),
Expand Down
6 changes: 5 additions & 1 deletion llvm/lib/Support/DXILABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,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());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using ScopedPrinter for this seems like overkill if we aren't using the EnumEntry thing for anything else. Would it be better to just implement dxil::getResourceClassName as a simple switch statement?


StringRef dxil::getResourceClassName(uint8_t RC) {
return enumToStringRef(ResourceClass(RC), getResourceClasses());
}
Loading