[clang] 15d78ce - [Clang][PowerPC] Support tune CPU in target attribute (#68681)

via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 10 19:39:02 PDT 2023


Author: Qiu Chaofan
Date: 2023-10-11T10:38:56+08:00
New Revision: 15d78cef3ddc9c2e00beaf7e6b1d4ba5dd232a89

URL: https://github.com/llvm/llvm-project/commit/15d78cef3ddc9c2e00beaf7e6b1d4ba5dd232a89
DIFF: https://github.com/llvm/llvm-project/commit/15d78cef3ddc9c2e00beaf7e6b1d4ba5dd232a89.diff

LOG: [Clang][PowerPC] Support tune CPU in target attribute (#68681)

Added: 
    

Modified: 
    clang/lib/Basic/Targets/PPC.h
    clang/test/Sema/attr-target.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index ef667b3d511f0e6..4d62673ba7fb8c5 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -198,6 +198,8 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
   void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
                          bool Enabled) const override;
 
+  bool supportsTargetAttributeTune() const override { return true; }
+
   ArrayRef<const char *> getGCCRegNames() const override;
 
   ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;

diff  --git a/clang/test/Sema/attr-target.c b/clang/test/Sema/attr-target.c
index 3416a3d0a6ba134..5328f056507a714 100644
--- a/clang/test/Sema/attr-target.c
+++ b/clang/test/Sema/attr-target.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu  -fsyntax-only -verify -std=c2x %s
 // RUN: %clang_cc1 -triple aarch64-linux-gnu  -fsyntax-only -verify -std=c2x %s
 // RUN: %clang_cc1 -triple arm-linux-gnu  -fsyntax-only -verify -std=c2x %s
+// RUN: %clang_cc1 -triple powerpc-linux-gnu  -fsyntax-only -verify -std=c2x %s
+// RUN: %clang_cc1 -triple ppc64le-linux-gnu  -fsyntax-only -verify -std=c2x %s
 
 #ifdef __x86_64__
 
@@ -61,6 +63,28 @@ int __attribute__((target("tune=cortex-a710,tune=neoverse-n2"))) pear_tree(void)
 // no warning - branch-protection should work on aarch64
 int __attribute__((target("branch-protection=none"))) birch_tree(void) { return 5; }
 
+#elifdef __powerpc__
+
+int __attribute__((target("float128,arch=pwr9"))) foo(void) { return 4; }
+//expected-error at +1 {{'target' attribute takes one argument}}
+int __attribute__((target())) bar(void) { return 4; }
+// no warning, tune is supported for PPC
+int __attribute__((target("tune=pwr8"))) baz(void) { return 4; }
+//expected-warning at +1 {{unsupported 'fpmath=' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("fpmath=387"))) walrus(void) { return 4; }
+//expected-warning at +1 {{unknown CPU 'hiss' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("float128,arch=hiss"))) meow(void) {  return 4; }
+// no warning, same as saying 'nothing'.
+int __attribute__((target("arch="))) turtle(void) { return 4; }
+//expected-warning at +1 {{unknown CPU 'hiss' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("arch=hiss,arch=woof"))) pine_tree(void) { return 4; }
+//expected-warning at +1 {{duplicate 'arch=' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("arch=pwr9,arch=pwr10"))) oak_tree(void) { return 4; }
+//expected-warning at +1 {{unsupported 'branch-protection' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("branch-protection=none"))) birch_tree(void) { return 5; }
+//expected-warning at +1 {{unknown tune CPU 'hiss' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("tune=hiss,tune=woof"))) apple_tree(void) { return 4; }
+
 #else
 
 // tune is not supported by other targets.


        


More information about the cfe-commits mailing list