This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG911d2dc23035: [NFC] [HLSL] Move common metadata to 
LLVMFrontend (authored by beanz).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135110/new/

https://reviews.llvm.org/D135110

Files:
  clang/lib/CodeGen/CGHLSLRuntime.cpp
  clang/lib/CodeGen/CMakeLists.txt
  llvm/include/llvm/Frontend/HLSL/HLSLResource.h
  llvm/lib/Frontend/CMakeLists.txt
  llvm/lib/Frontend/HLSL/CMakeLists.txt
  llvm/lib/Frontend/HLSL/HLSLResource.cpp
  llvm/lib/Target/DirectX/CMakeLists.txt
  llvm/lib/Target/DirectX/DXILResource.cpp
  llvm/lib/Target/DirectX/DXILResource.h

Index: llvm/lib/Target/DirectX/DXILResource.h
===================================================================
--- llvm/lib/Target/DirectX/DXILResource.h
+++ llvm/lib/Target/DirectX/DXILResource.h
@@ -16,6 +16,7 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Frontend/HLSL/HLSLResource.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/Support/Compiler.h"
 #include <cstdint>
@@ -26,22 +27,6 @@
 
 namespace dxil {
 
-// FIXME: Ultimately this class and some of these utilities should be moved into
-// a new LLVMFrontendHLSL library so that they can be reused in Clang.
-// See issue https://github.com/llvm/llvm-project/issues/58000.
-class FrontendResource {
-  MDNode *Entry;
-
-public:
-  FrontendResource(MDNode *E) : Entry(E) {
-    assert(Entry->getNumOperands() == 3 && "Unexpected metadata shape");
-  }
-
-  GlobalVariable *getGlobalVariable();
-  StringRef getSourceType();
-  Constant *getID();
-};
-
 class ResourceBase {
 protected:
   uint32_t ID;
@@ -50,7 +35,7 @@
   uint32_t Space;
   uint32_t LowerBound;
   uint32_t RangeSize;
-  ResourceBase(uint32_t I, FrontendResource R);
+  ResourceBase(uint32_t I, hlsl::FrontendResource R);
 
   void write(LLVMContext &Ctx, MutableArrayRef<Metadata *> Entries) const;
 
@@ -142,7 +127,7 @@
   void parseSourceType(StringRef S);
 
 public:
-  UAVResource(uint32_t I, FrontendResource R);
+  UAVResource(uint32_t I, hlsl::FrontendResource R);
 
   MDNode *write() const;
   void print(raw_ostream &O) const;
Index: llvm/lib/Target/DirectX/DXILResource.cpp
===================================================================
--- llvm/lib/Target/DirectX/DXILResource.cpp
+++ llvm/lib/Target/DirectX/DXILResource.cpp
@@ -20,19 +20,7 @@
 
 using namespace llvm;
 using namespace llvm::dxil;
-
-GlobalVariable *FrontendResource::getGlobalVariable() {
-  return cast<GlobalVariable>(
-      cast<ConstantAsMetadata>(Entry->getOperand(0))->getValue());
-}
-
-StringRef FrontendResource::getSourceType() {
-  return cast<MDString>(Entry->getOperand(1))->getString();
-}
-
-Constant *FrontendResource::getID() {
-  return cast<ConstantAsMetadata>(Entry->getOperand(2))->getValue();
-}
+using namespace llvm::hlsl;
 
 void Resources::collectUAVs(Module &M) {
   NamedMDNode *Entry = M.getNamedMetadata("hlsl.uavs");
Index: llvm/lib/Target/DirectX/CMakeLists.txt
===================================================================
--- llvm/lib/Target/DirectX/CMakeLists.txt
+++ llvm/lib/Target/DirectX/CMakeLists.txt
@@ -35,6 +35,7 @@
   Support
   DirectXInfo
   DXILBitWriter
+  FrontendHLSL
 
   ADD_TO_COMPONENT
   DirectX
Index: llvm/lib/Frontend/HLSL/HLSLResource.cpp
===================================================================
--- /dev/null
+++ llvm/lib/Frontend/HLSL/HLSLResource.cpp
@@ -0,0 +1,41 @@
+//===- HLSLResource.cpp - HLSL Resource helper objects --------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file This file contains helper objects for working with HLSL Resources.
+///
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Frontend/HLSL/HLSLResource.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/Module.h"
+
+using namespace llvm;
+using namespace llvm::hlsl;
+
+GlobalVariable *FrontendResource::getGlobalVariable() {
+  return cast<GlobalVariable>(
+      cast<ConstantAsMetadata>(Entry->getOperand(0))->getValue());
+}
+
+StringRef FrontendResource::getSourceType() {
+  return cast<MDString>(Entry->getOperand(1))->getString();
+}
+
+Constant *FrontendResource::getID() {
+  return cast<ConstantAsMetadata>(Entry->getOperand(2))->getValue();
+}
+
+FrontendResource::FrontendResource(GlobalVariable *GV, StringRef TypeStr,
+                                   uint32_t Counter) {
+  auto &Ctx = GV->getContext();
+  IRBuilder<> B(Ctx);
+  Entry =
+      MDNode::get(Ctx, {ValueAsMetadata::get(GV), MDString::get(Ctx, TypeStr),
+                        ConstantAsMetadata::get(B.getInt32(Counter))});
+}
Index: llvm/lib/Frontend/HLSL/CMakeLists.txt
===================================================================
--- /dev/null
+++ llvm/lib/Frontend/HLSL/CMakeLists.txt
@@ -0,0 +1,14 @@
+add_llvm_component_library(LLVMFrontendHLSL
+  HLSLResource.cpp
+
+  ADDITIONAL_HEADER_DIRS
+  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend
+  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend/HLSL
+
+  DEPENDS
+  intrinsics_gen
+
+  LINK_COMPONENTS
+  Core
+  Support
+  )
Index: llvm/lib/Frontend/CMakeLists.txt
===================================================================
--- llvm/lib/Frontend/CMakeLists.txt
+++ llvm/lib/Frontend/CMakeLists.txt
@@ -1,2 +1,3 @@
+add_subdirectory(HLSL)
 add_subdirectory(OpenACC)
 add_subdirectory(OpenMP)
Index: llvm/include/llvm/Frontend/HLSL/HLSLResource.h
===================================================================
--- /dev/null
+++ llvm/include/llvm/Frontend/HLSL/HLSLResource.h
@@ -0,0 +1,43 @@
+//===- HLSLResource.h - HLSL Resource helper objects ----------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file This file contains helper objects for working with HLSL Resources.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_FRONTEND_HLSL_HLSLRESOURCE_H
+#define LLVM_FRONTEND_HLSL_HLSLRESOURCE_H
+
+#include "llvm/IR/Metadata.h"
+
+namespace llvm {
+class Module;
+class GlobalVariable;
+
+namespace hlsl {
+
+class FrontendResource {
+  MDNode *Entry;
+
+public:
+  FrontendResource(MDNode *E) : Entry(E) {
+    assert(Entry->getNumOperands() == 3 && "Unexpected metadata shape");
+  }
+
+  FrontendResource(GlobalVariable *GV, StringRef TypeStr, uint32_t Counter);
+
+  GlobalVariable *getGlobalVariable();
+  StringRef getSourceType();
+  Constant *getID();
+
+  MDNode *getMetadata() { return Entry; }
+};
+} // namespace hlsl
+} // namespace llvm
+
+#endif // LLVM_FRONTEND_HLSL_HLSLRESOURCE_H
Index: clang/lib/CodeGen/CMakeLists.txt
===================================================================
--- clang/lib/CodeGen/CMakeLists.txt
+++ clang/lib/CodeGen/CMakeLists.txt
@@ -7,6 +7,7 @@
   Coverage
   Demangle
   Extensions
+  FrontendHLSL
   FrontendOpenMP
   IPO
   IRReader
Index: clang/lib/CodeGen/CGHLSLRuntime.cpp
===================================================================
--- clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -17,6 +17,7 @@
 #include "CodeGenModule.h"
 #include "clang/AST/Decl.h"
 #include "clang/Basic/TargetOptions.h"
+#include "llvm/Frontend/HLSL/HLSLResource.h"
 #include "llvm/IR/IntrinsicsDirectX.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/Module.h"
@@ -227,9 +228,8 @@
   auto &Ctx = CGM.getModule().getContext();
   IRBuilder<> B(Ctx);
   QualType QT(Ty, 0);
-  ResourceMD->addOperand(MDNode::get(
-      Ctx, {ValueAsMetadata::get(GV), MDString::get(Ctx, QT.getAsString()),
-            ConstantAsMetadata::get(B.getInt32(Counter))}));
+  llvm::hlsl::FrontendResource Res(GV, QT.getAsString(), Counter);
+  ResourceMD->addOperand(Res.getMetadata());
 }
 
 void clang::CodeGen::CGHLSLRuntime::setHLSLEntryAttributes(
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to