[clang] [llvm] [HLSL] Add handle initialization for simple resource declarations (PR #111207)

Helena Kotas via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 15 21:48:01 PDT 2024


================
@@ -489,3 +494,100 @@ void CGHLSLRuntime::generateGlobalCtorDtorCalls() {
       GV->eraseFromParent();
   }
 }
+
+// Returns handle type of a resource, if the type is a resource
+// or an array of resources
+static const HLSLAttributedResourceType *findHandleTypeOnResource(QualType QT) {
+  // If the type is a resource class, the first field must
+  // be the resource handle of type HLSLAttributedResourceType
+  const clang::Type *Ty = QT->getUnqualifiedDesugaredType();
+  if (RecordDecl *RD = Ty->getAsCXXRecordDecl()) {
+    if (!RD->fields().empty()) {
+      const auto &FirstFD = RD->fields().begin();
+      return dyn_cast<HLSLAttributedResourceType>(
+          FirstFD->getType().getTypePtr());
+    }
+  }
+  return nullptr;
+}
----------------
hekota wrote:

It would be nice to share this logic, but Sema and CodeGen currently do not have any dependencies between them. Maybe a static method on `HLSLAttributedResourceType`?

https://github.com/llvm/llvm-project/pull/111207


More information about the cfe-commits mailing list