Skip to content

Commit 15d78ce

Browse files
authored
[Clang][PowerPC] Support tune CPU in target attribute (#68681)
1 parent 203ba23 commit 15d78ce

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

clang/lib/Basic/Targets/PPC.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
198198
void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
199199
bool Enabled) const override;
200200

201+
bool supportsTargetAttributeTune() const override { return true; }
202+
201203
ArrayRef<const char *> getGCCRegNames() const override;
202204

203205
ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;

clang/test/Sema/attr-target.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify -std=c2x %s
22
// RUN: %clang_cc1 -triple aarch64-linux-gnu -fsyntax-only -verify -std=c2x %s
33
// RUN: %clang_cc1 -triple arm-linux-gnu -fsyntax-only -verify -std=c2x %s
4+
// RUN: %clang_cc1 -triple powerpc-linux-gnu -fsyntax-only -verify -std=c2x %s
5+
// RUN: %clang_cc1 -triple ppc64le-linux-gnu -fsyntax-only -verify -std=c2x %s
46

57
#ifdef __x86_64__
68

@@ -61,6 +63,28 @@ int __attribute__((target("tune=cortex-a710,tune=neoverse-n2"))) pear_tree(void)
6163
// no warning - branch-protection should work on aarch64
6264
int __attribute__((target("branch-protection=none"))) birch_tree(void) { return 5; }
6365

66+
#elifdef __powerpc__
67+
68+
int __attribute__((target("float128,arch=pwr9"))) foo(void) { return 4; }
69+
//expected-error@+1 {{'target' attribute takes one argument}}
70+
int __attribute__((target())) bar(void) { return 4; }
71+
// no warning, tune is supported for PPC
72+
int __attribute__((target("tune=pwr8"))) baz(void) { return 4; }
73+
//expected-warning@+1 {{unsupported 'fpmath=' in the 'target' attribute string; 'target' attribute ignored}}
74+
int __attribute__((target("fpmath=387"))) walrus(void) { return 4; }
75+
//expected-warning@+1 {{unknown CPU 'hiss' in the 'target' attribute string; 'target' attribute ignored}}
76+
int __attribute__((target("float128,arch=hiss"))) meow(void) { return 4; }
77+
// no warning, same as saying 'nothing'.
78+
int __attribute__((target("arch="))) turtle(void) { return 4; }
79+
//expected-warning@+1 {{unknown CPU 'hiss' in the 'target' attribute string; 'target' attribute ignored}}
80+
int __attribute__((target("arch=hiss,arch=woof"))) pine_tree(void) { return 4; }
81+
//expected-warning@+1 {{duplicate 'arch=' in the 'target' attribute string; 'target' attribute ignored}}
82+
int __attribute__((target("arch=pwr9,arch=pwr10"))) oak_tree(void) { return 4; }
83+
//expected-warning@+1 {{unsupported 'branch-protection' in the 'target' attribute string; 'target' attribute ignored}}
84+
int __attribute__((target("branch-protection=none"))) birch_tree(void) { return 5; }
85+
//expected-warning@+1 {{unknown tune CPU 'hiss' in the 'target' attribute string; 'target' attribute ignored}}
86+
int __attribute__((target("tune=hiss,tune=woof"))) apple_tree(void) { return 4; }
87+
6488
#else
6589

6690
// tune is not supported by other targets.

0 commit comments

Comments
 (0)