diff options
author | Alexander Shaposhnikov <ashaposhnikov@google.com> | 2025-03-19 10:11:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-19 10:11:18 -0700 |
commit | 297f0b3f4c05c6ef40183809eac5ccac9ca8c4ce (patch) | |
tree | 4e509319107ccce15dedb0b5203788f37a2bbc4d /clang/lib/CodeGen/CodeGenFunction.cpp | |
parent | d09ecb07c2894e3167b6cfb5761663fe0f01b905 (diff) | |
download | llvm-297f0b3f4c05c6ef40183809eac5ccac9ca8c4ce.zip llvm-297f0b3f4c05c6ef40183809eac5ccac9ca8c4ce.tar.gz llvm-297f0b3f4c05c6ef40183809eac5ccac9ca8c4ce.tar.bz2 |
[CudaSPIRV] Allow using integral non-type template parameters as attribute args (#131546)
Allow using integral non-type template parameters as attribute arguments
of
reqd_work_group_size and work_group_size_hint.
Test plan:
ninja check-all
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index a7fdfa6..dcf523f 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -649,18 +649,24 @@ void CodeGenFunction::EmitKernelMetadata(const FunctionDecl *FD, } if (const WorkGroupSizeHintAttr *A = FD->getAttr<WorkGroupSizeHintAttr>()) { + auto Eval = [&](Expr *E) { + return E->EvaluateKnownConstInt(FD->getASTContext()).getExtValue(); + }; llvm::Metadata *AttrMDArgs[] = { - llvm::ConstantAsMetadata::get(Builder.getInt32(A->getXDim())), - llvm::ConstantAsMetadata::get(Builder.getInt32(A->getYDim())), - llvm::ConstantAsMetadata::get(Builder.getInt32(A->getZDim()))}; + llvm::ConstantAsMetadata::get(Builder.getInt32(Eval(A->getXDim()))), + llvm::ConstantAsMetadata::get(Builder.getInt32(Eval(A->getYDim()))), + llvm::ConstantAsMetadata::get(Builder.getInt32(Eval(A->getZDim())))}; Fn->setMetadata("work_group_size_hint", llvm::MDNode::get(Context, AttrMDArgs)); } if (const ReqdWorkGroupSizeAttr *A = FD->getAttr<ReqdWorkGroupSizeAttr>()) { + auto Eval = [&](Expr *E) { + return E->EvaluateKnownConstInt(FD->getASTContext()).getExtValue(); + }; llvm::Metadata *AttrMDArgs[] = { - llvm::ConstantAsMetadata::get(Builder.getInt32(A->getXDim())), - llvm::ConstantAsMetadata::get(Builder.getInt32(A->getYDim())), - llvm::ConstantAsMetadata::get(Builder.getInt32(A->getZDim()))}; + llvm::ConstantAsMetadata::get(Builder.getInt32(Eval(A->getXDim()))), + llvm::ConstantAsMetadata::get(Builder.getInt32(Eval(A->getYDim()))), + llvm::ConstantAsMetadata::get(Builder.getInt32(Eval(A->getZDim())))}; Fn->setMetadata("reqd_work_group_size", llvm::MDNode::get(Context, AttrMDArgs)); } |