[clang] [FMV][AIX] Implement target_clones (cpu-only) (PR #177428)
Wael Yehia via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 16 13:51:01 PDT 2026
================
@@ -3053,9 +3008,11 @@ bool CodeGenModule::GetCPUAndFeaturesAttributes(GlobalDecl GD,
// While we populated the feature map above, we still need to
// get and parse the target attribute so we can get the cpu for
// the function.
- if (TD) {
- ParsedTargetAttr ParsedAttr =
- Target.parseTargetAttr(TD->getFeaturesStr());
+ StringRef FeatureStr =
+ TD ? TD->getFeaturesStr()
+ : (TC ? TC->getFeatureStr(GD.getMultiVersionIndex()) : StringRef());
+ if (!FeatureStr.empty()) {
----------------
w2yehia wrote:
You're correct;
- in Clang, only RISCV [1] and x86 [2] seem to use `parseTargetAttr` on `target_clones`.
- latest GCC states:
> For the x86 and PowerPC targets, the supported options and restrictions are the same as for the target attribute.
- official RISCV documentation has slightly different grammar for `target` [3] and `target_clones`[4].
so I think it should be safe to reuse `parseTargetAttr` for x86 and PPC here, but not RISCV and others. Ideally, we would have a `parseTargetClonesAttr` function... but that would be substantial rework if want to use it for parsing target_clones on all FMV-supporting targets. I've updated the PR to only use parseTargetAttr on AIX (PowerPC) and x86.
[1] https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/ASTContext.cpp#L15255
[2] https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/ABIInfo.cpp#L213 used by x86
[3] https://github.com/riscv-non-isa/riscv-c-api-doc/blob/main/src/c-api.adoc#__attribute__targetattr-string
[4] https://github.com/riscv-non-isa/riscv-c-api-doc/blob/main/src/c-api.adoc#__attribute__target_clonestarget-clones-attr-string-
https://github.com/llvm/llvm-project/pull/177428
More information about the cfe-commits
mailing list