[clang] a7183a1 - [NFC] [DirectX backend] move ResourceClass into llvm.
Xiang Li via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 20 13:27:04 PDT 2022
Author: Xiang Li
Date: 2022-10-20T13:26:56-07:00
New Revision: a7183a158d68d97902aeb2015a5cac5e36ae84c5
URL: https://github.com/llvm/llvm-project/commit/a7183a158d68d97902aeb2015a5cac5e36ae84c5
DIFF: https://github.com/llvm/llvm-project/commit/a7183a158d68d97902aeb2015a5cac5e36ae84c5.diff
LOG: [NFC] [DirectX backend] move ResourceClass into llvm.
Move ResourceClass into llvm/Frontend/HLSL/HLSLResource.h so it could be shared between clang and DirectX backend.
Reviewed By: beanz
Differential Revision: https://reviews.llvm.org/D136134
Added:
Modified:
clang/include/clang/Basic/HLSLRuntime.h
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/lib/CodeGen/CGHLSLRuntime.h
clang/lib/Sema/CMakeLists.txt
clang/lib/Sema/HLSLExternalSemaSource.cpp
llvm/include/llvm/Frontend/HLSL/HLSLResource.h
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/HLSLRuntime.h b/clang/include/clang/Basic/HLSLRuntime.h
index d3d2306faf302..03166805daa6a 100644
--- a/clang/include/clang/Basic/HLSLRuntime.h
+++ b/clang/include/clang/Basic/HLSLRuntime.h
@@ -20,14 +20,6 @@
namespace clang {
namespace hlsl {
-enum class ResourceClass : uint8_t {
- SRV = 0,
- UAV,
- CBuffer,
- Sampler,
- NumClasses
-};
-
constexpr ShaderStage
getStageFromEnvironment(const llvm::Triple::EnvironmentType &E) {
uint32_t Pipeline =
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 59fab7b69c20b..f64fdfade9f4f 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -24,7 +24,7 @@
using namespace clang;
using namespace CodeGen;
-using namespace hlsl;
+using namespace clang::hlsl;
using namespace llvm;
namespace {
@@ -176,8 +176,9 @@ void CGHLSLRuntime::finishCodeGen() {
layoutBuffer(Buf, DL);
GlobalVariable *GV = replaceBuffer(Buf);
M.getGlobalList().push_back(GV);
- hlsl::ResourceClass RC =
- Buf.IsCBuffer ? hlsl::ResourceClass::CBuffer : hlsl::ResourceClass::SRV;
+ llvm::hlsl::ResourceClass RC = Buf.IsCBuffer
+ ? llvm::hlsl::ResourceClass::CBuffer
+ : llvm::hlsl::ResourceClass::SRV;
llvm::hlsl::ResourceKind RK = Buf.IsCBuffer
? llvm::hlsl::ResourceKind::CBuffer
: llvm::hlsl::ResourceKind::TBuffer;
@@ -193,7 +194,7 @@ CGHLSLRuntime::Buffer::Buffer(const HLSLBufferDecl *D)
void CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
llvm::StringRef TyName,
- hlsl::ResourceClass RC,
+ llvm::hlsl::ResourceClass RC,
llvm::hlsl::ResourceKind RK,
BufferResBinding &Binding) {
uint32_t Counter = ResourceCounters[static_cast<uint32_t>(RC)]++;
@@ -201,13 +202,13 @@ void CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
NamedMDNode *ResourceMD = nullptr;
switch (RC) {
- case hlsl::ResourceClass::UAV:
+ case llvm::hlsl::ResourceClass::UAV:
ResourceMD = M.getOrInsertNamedMetadata("hlsl.uavs");
break;
- case hlsl::ResourceClass::SRV:
+ case llvm::hlsl::ResourceClass::SRV:
ResourceMD = M.getOrInsertNamedMetadata("hlsl.srvs");
break;
- case hlsl::ResourceClass::CBuffer:
+ case llvm::hlsl::ResourceClass::CBuffer:
ResourceMD = M.getOrInsertNamedMetadata("hlsl.cbufs");
break;
default:
@@ -290,8 +291,9 @@ void CGHLSLRuntime::annotateHLSLResource(const VarDecl *D, GlobalVariable *GV) {
QualType QT(Ty, 0);
BufferResBinding Binding(D->getAttr<HLSLResourceBindingAttr>());
- addBufferResourceAnnotation(
- GV, QT.getAsString(), static_cast<hlsl::ResourceClass>(RC), RK, Binding);
+ addBufferResourceAnnotation(GV, QT.getAsString(),
+ static_cast<llvm::hlsl::ResourceClass>(RC), RK,
+ Binding);
}
CGHLSLRuntime::BufferResBinding::BufferResBinding(
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h
index 922ef59dca37a..107b0d6d12854 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -71,7 +71,7 @@ class CGHLSLRuntime {
protected:
CodeGenModule &CGM;
uint32_t ResourceCounters[static_cast<uint32_t>(
- hlsl::ResourceClass::NumClasses)] = {0};
+ llvm::hlsl::ResourceClass::NumClasses)] = {0};
llvm::Value *emitInputSemantic(llvm::IRBuilder<> &B, const ParmVarDecl &D,
llvm::Type *Ty);
@@ -94,7 +94,7 @@ class CGHLSLRuntime {
private:
void addBufferResourceAnnotation(llvm::GlobalVariable *GV,
llvm::StringRef TyName,
- hlsl::ResourceClass RC,
+ llvm::hlsl::ResourceClass RC,
llvm::hlsl::ResourceKind RK,
BufferResBinding &Binding);
void addConstant(VarDecl *D, Buffer &CB);
diff --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index a7a97a1c53e77..696e403c51d77 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -1,5 +1,6 @@
set(LLVM_LINK_COMPONENTS
Core
+ FrontendHLSL
FrontendOpenMP
MC
Support
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index 3794a989be11a..f1b90fa971866 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -17,11 +17,12 @@
#include "clang/Basic/HLSLRuntime.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/Sema.h"
+#include "llvm/Frontend/HLSL/HLSLResource.h"
#include <functional>
using namespace clang;
-using namespace hlsl;
+using namespace llvm::hlsl;
namespace {
diff --git a/llvm/include/llvm/Frontend/HLSL/HLSLResource.h b/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
index eb1ba4623219d..09a566ae4f318 100644
--- a/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
+++ b/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
@@ -21,6 +21,15 @@ class GlobalVariable;
namespace hlsl {
+enum class ResourceClass : uint8_t {
+ SRV = 0,
+ UAV,
+ CBuffer,
+ Sampler,
+ Invalid,
+ NumClasses = Invalid,
+};
+
// The value ordering of this enumeration is part of the DXIL ABI. Elements
// can only be added to the end, and not removed.
enum class ResourceKind : uint32_t {
More information about the cfe-commits
mailing list