[clang] [clang][NVPTX] exclude feature attributes from target-features (PR #215451)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 10 20:28:16 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen
Author: Alex MacLean (AlexMaclean)
<details>
<summary>Changes</summary>
This info is already carried in `target-cpu` and the fact that these named features exist at all is something I hope to change.
---
Full diff: https://github.com/llvm/llvm-project/pull/215451.diff
3 Files Affected:
- (modified) clang/lib/Basic/Targets/NVPTX.cpp (+6)
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+5-3)
- (modified) clang/test/CodeGen/nvptx_attributes.c (+1-1)
``````````diff
diff --git a/clang/lib/Basic/Targets/NVPTX.cpp b/clang/lib/Basic/Targets/NVPTX.cpp
index 11577b75236a6..04b95dd19ed05 100644
--- a/clang/lib/Basic/Targets/NVPTX.cpp
+++ b/clang/lib/Basic/Targets/NVPTX.cpp
@@ -66,6 +66,12 @@ NVPTXTargetInfo::NVPTXTargetInfo(const llvm::Triple &Triple,
NoAsmVariants = true;
GPU = OffloadArch::getUnused();
+ // Architectures are in the feature map only to gate builtins; the backend
+ // takes the architecture from `target-cpu`.
+#define NVPTX_GPU(NAME, KIND, VIRTUAL, SM_ID, MIN_VER, MAX_VER, SUFFIX) \
+ ReadOnlyFeatures.insert(NAME);
+#include "llvm/TargetParser/NVPTXTargetParser.def"
+
// PTX supports f16 as a fundamental type.
HasFastHalfType = true;
HasFloat16 = true;
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 5ed5385c90f26..0c0d1c272b386 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3417,9 +3417,11 @@ bool CodeGenModule::GetCPUAndFeaturesAttributes(GlobalDecl GD,
llvm::erase_if(Features, [&](const std::string& F) {
return getTarget().isReadOnlyFeature(F.substr(1));
});
- llvm::sort(Features);
- Attrs.addAttribute("target-features", llvm::join(Features, ","));
- AddedAttr = true;
+ if (!Features.empty()) {
+ llvm::sort(Features);
+ Attrs.addAttribute("target-features", llvm::join(Features, ","));
+ AddedAttr = true;
+ }
}
// Add metadata for AArch64 Function Multi Versioning.
if (getTarget().getTriple().isAArch64()) {
diff --git a/clang/test/CodeGen/nvptx_attributes.c b/clang/test/CodeGen/nvptx_attributes.c
index c49a68b89bc64..fbba84ff05d5a 100644
--- a/clang/test/CodeGen/nvptx_attributes.c
+++ b/clang/test/CodeGen/nvptx_attributes.c
@@ -16,7 +16,7 @@ __attribute__((nvptx_kernel)) void foo(int *ret) {
}
//.
-// CHECK: attributes #[[ATTR0]] = { convergent noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="sm_61" "target-features"="+sm_61" }
+// CHECK: attributes #[[ATTR0]] = { convergent noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="sm_61" }
//.
// CHECK: [[META0:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"}
//.
``````````
</details>
https://github.com/llvm/llvm-project/pull/215451
More information about the cfe-commits
mailing list