[clang] [HLSL] Implement `SpirvType` and `SpirvOpaqueType` (PR #134034)
Cassandra Beckley via cfe-commits
cfe-commits at lists.llvm.org
Tue May 6 16:37:38 PDT 2025
================
@@ -3228,6 +3228,62 @@ static QualType builtinCommonTypeImpl(Sema &S, TemplateName BaseTemplate,
}
}
+static bool isInVkNamespace(const RecordType *RT) {
+ DeclContext *DC = RT->getDecl()->getDeclContext();
+ if (!DC)
+ return false;
+
+ NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC);
+ if (!ND)
+ return false;
+
+ return ND->getQualifiedNameAsString() == "hlsl::vk";
+}
+
+static SpirvOperand checkHLSLSpirvTypeOperand(Sema &SemaRef,
+ QualType OperandArg,
+ SourceLocation Loc) {
+ if (auto *RT = OperandArg->getAs<RecordType>()) {
+ bool Literal = false;
+ SourceLocation LiteralLoc;
+ if (isInVkNamespace(RT) && RT->getDecl()->getName() == "Literal") {
+ auto SpecDecl = dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl());
+ assert(SpecDecl);
+
+ const TemplateArgumentList &LiteralArgs = SpecDecl->getTemplateArgs();
+ QualType ConstantType = LiteralArgs[0].getAsType();
+ RT = ConstantType->getAs<RecordType>();
+ Literal = true;
+ LiteralLoc = SpecDecl->getSourceRange().getBegin();
+ }
+
+ if (RT && isInVkNamespace(RT) &&
+ RT->getDecl()->getName() == "integral_constant") {
+ auto SpecDecl = dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl());
+ assert(SpecDecl);
+
+ const TemplateArgumentList &ConstantArgs = SpecDecl->getTemplateArgs();
+
+ QualType ConstantType = ConstantArgs[0].getAsType();
+ llvm::APInt Value = ConstantArgs[1].getAsIntegral();
+
+ if (Literal) {
+ return SpirvOperand::createLiteral(Value);
+ } else {
+ return SpirvOperand::createConstant(ConstantType, Value);
+ }
----------------
cassiebeckley wrote:
Done.
https://github.com/llvm/llvm-project/pull/134034
More information about the cfe-commits
mailing list