r334613 - [PowerPC] The __float128 type should only be available on Power9

Stefan Pintilie via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 13 09:05:05 PDT 2018


Author: stefanp
Date: Wed Jun 13 09:05:05 2018
New Revision: 334613

URL: http://llvm.org/viewvc/llvm-project?rev=334613&view=rev
Log:
[PowerPC] The __float128 type should only be available on Power9

Diasble the use of the type __float128 for PPC machines older
than Power9.

The use of -mfloat128 for PPC machine older than Power9 will result
in an error.

Differential Revision: https://reviews.llvm.org/D48088

Added:
    cfe/trunk/test/Driver/ppc-f128-support-check.c
Modified:
    cfe/trunk/lib/Basic/Targets/PPC.cpp
    cfe/trunk/lib/Basic/Targets/PPC.h
    cfe/trunk/test/Preprocessor/init.c
    cfe/trunk/test/Sema/float128-ld-incompatibility.cpp

Modified: cfe/trunk/lib/Basic/Targets/PPC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/PPC.cpp?rev=334613&r1=334612&r2=334613&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets/PPC.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/PPC.cpp Wed Jun 13 09:05:05 2018
@@ -15,7 +15,6 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/MacroBuilder.h"
 #include "clang/Basic/TargetBuiltins.h"
-#include "llvm/ADT/StringSwitch.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -116,111 +115,37 @@ void PPCTargetInfo::getTargetDefines(con
       (getTriple().getOS() == llvm::Triple::Darwin && PointerWidth == 64))
     Builder.defineMacro("__STRUCT_PARM_ALIGN__", "16");
 
-  // CPU identification.
-  ArchDefineTypes defs =
-      (ArchDefineTypes)llvm::StringSwitch<int>(CPU)
-          .Case("440", ArchDefineName)
-          .Case("450", ArchDefineName | ArchDefine440)
-          .Case("601", ArchDefineName)
-          .Case("602", ArchDefineName | ArchDefinePpcgr)
-          .Case("603", ArchDefineName | ArchDefinePpcgr)
-          .Case("603e", ArchDefineName | ArchDefine603 | ArchDefinePpcgr)
-          .Case("603ev", ArchDefineName | ArchDefine603 | ArchDefinePpcgr)
-          .Case("604", ArchDefineName | ArchDefinePpcgr)
-          .Case("604e", ArchDefineName | ArchDefine604 | ArchDefinePpcgr)
-          .Case("620", ArchDefineName | ArchDefinePpcgr)
-          .Case("630", ArchDefineName | ArchDefinePpcgr)
-          .Case("7400", ArchDefineName | ArchDefinePpcgr)
-          .Case("7450", ArchDefineName | ArchDefinePpcgr)
-          .Case("750", ArchDefineName | ArchDefinePpcgr)
-          .Case("970", ArchDefineName | ArchDefinePwr4 | ArchDefinePpcgr |
-                           ArchDefinePpcsq)
-          .Case("a2", ArchDefineA2)
-          .Case("a2q", ArchDefineName | ArchDefineA2 | ArchDefineA2q)
-          .Case("pwr3", ArchDefinePpcgr)
-          .Case("pwr4", ArchDefineName | ArchDefinePpcgr | ArchDefinePpcsq)
-          .Case("pwr5", ArchDefineName | ArchDefinePwr4 | ArchDefinePpcgr |
-                            ArchDefinePpcsq)
-          .Case("pwr5x", ArchDefineName | ArchDefinePwr5 | ArchDefinePwr4 |
-                             ArchDefinePpcgr | ArchDefinePpcsq)
-          .Case("pwr6", ArchDefineName | ArchDefinePwr5x | ArchDefinePwr5 |
-                            ArchDefinePwr4 | ArchDefinePpcgr | ArchDefinePpcsq)
-          .Case("pwr6x", ArchDefineName | ArchDefinePwr6 | ArchDefinePwr5x |
-                             ArchDefinePwr5 | ArchDefinePwr4 | ArchDefinePpcgr |
-                             ArchDefinePpcsq)
-          .Case("pwr7", ArchDefineName | ArchDefinePwr6x | ArchDefinePwr6 |
-                            ArchDefinePwr5x | ArchDefinePwr5 | ArchDefinePwr4 |
-                            ArchDefinePpcgr | ArchDefinePpcsq)
-          .Case("pwr8", ArchDefineName | ArchDefinePwr7 | ArchDefinePwr6x |
-                            ArchDefinePwr6 | ArchDefinePwr5x | ArchDefinePwr5 |
-                            ArchDefinePwr4 | ArchDefinePpcgr | ArchDefinePpcsq)
-          .Case("pwr9", ArchDefineName | ArchDefinePwr8 | ArchDefinePwr7 |
-                            ArchDefinePwr6x | ArchDefinePwr6 | ArchDefinePwr5x |
-                            ArchDefinePwr5 | ArchDefinePwr4 | ArchDefinePpcgr |
-                            ArchDefinePpcsq)
-          .Case("power3", ArchDefinePpcgr)
-          .Case("power4", ArchDefinePwr4 | ArchDefinePpcgr | ArchDefinePpcsq)
-          .Case("power5", ArchDefinePwr5 | ArchDefinePwr4 | ArchDefinePpcgr |
-                              ArchDefinePpcsq)
-          .Case("power5x", ArchDefinePwr5x | ArchDefinePwr5 | ArchDefinePwr4 |
-                               ArchDefinePpcgr | ArchDefinePpcsq)
-          .Case("power6", ArchDefinePwr6 | ArchDefinePwr5x | ArchDefinePwr5 |
-                              ArchDefinePwr4 | ArchDefinePpcgr |
-                              ArchDefinePpcsq)
-          .Case("power6x", ArchDefinePwr6x | ArchDefinePwr6 | ArchDefinePwr5x |
-                               ArchDefinePwr5 | ArchDefinePwr4 |
-                               ArchDefinePpcgr | ArchDefinePpcsq)
-          .Case("power7", ArchDefinePwr7 | ArchDefinePwr6x | ArchDefinePwr6 |
-                              ArchDefinePwr5x | ArchDefinePwr5 |
-                              ArchDefinePwr4 | ArchDefinePpcgr |
-                              ArchDefinePpcsq)
-          .Case("power8", ArchDefinePwr8 | ArchDefinePwr7 | ArchDefinePwr6x |
-                              ArchDefinePwr6 | ArchDefinePwr5x |
-                              ArchDefinePwr5 | ArchDefinePwr4 |
-                              ArchDefinePpcgr | ArchDefinePpcsq)
-          .Case("power9", ArchDefinePwr9 | ArchDefinePwr8 | ArchDefinePwr7 |
-                              ArchDefinePwr6x | ArchDefinePwr6 |
-                              ArchDefinePwr5x | ArchDefinePwr5 |
-                              ArchDefinePwr4 | ArchDefinePpcgr |
-                              ArchDefinePpcsq)
-          // powerpc64le automatically defaults to at least power8.
-          .Case("ppc64le", ArchDefinePwr8 | ArchDefinePwr7 | ArchDefinePwr6x |
-                               ArchDefinePwr6 | ArchDefinePwr5x |
-                               ArchDefinePwr5 | ArchDefinePwr4 |
-                               ArchDefinePpcgr | ArchDefinePpcsq)
-          .Default(ArchDefineNone);
-
-  if (defs & ArchDefineName)
+  if (ArchDefs & ArchDefineName)
     Builder.defineMacro(Twine("_ARCH_", StringRef(CPU).upper()));
-  if (defs & ArchDefinePpcgr)
+  if (ArchDefs & ArchDefinePpcgr)
     Builder.defineMacro("_ARCH_PPCGR");
-  if (defs & ArchDefinePpcsq)
+  if (ArchDefs & ArchDefinePpcsq)
     Builder.defineMacro("_ARCH_PPCSQ");
-  if (defs & ArchDefine440)
+  if (ArchDefs & ArchDefine440)
     Builder.defineMacro("_ARCH_440");
-  if (defs & ArchDefine603)
+  if (ArchDefs & ArchDefine603)
     Builder.defineMacro("_ARCH_603");
-  if (defs & ArchDefine604)
+  if (ArchDefs & ArchDefine604)
     Builder.defineMacro("_ARCH_604");
-  if (defs & ArchDefinePwr4)
+  if (ArchDefs & ArchDefinePwr4)
     Builder.defineMacro("_ARCH_PWR4");
-  if (defs & ArchDefinePwr5)
+  if (ArchDefs & ArchDefinePwr5)
     Builder.defineMacro("_ARCH_PWR5");
-  if (defs & ArchDefinePwr5x)
+  if (ArchDefs & ArchDefinePwr5x)
     Builder.defineMacro("_ARCH_PWR5X");
-  if (defs & ArchDefinePwr6)
+  if (ArchDefs & ArchDefinePwr6)
     Builder.defineMacro("_ARCH_PWR6");
-  if (defs & ArchDefinePwr6x)
+  if (ArchDefs & ArchDefinePwr6x)
     Builder.defineMacro("_ARCH_PWR6X");
-  if (defs & ArchDefinePwr7)
+  if (ArchDefs & ArchDefinePwr7)
     Builder.defineMacro("_ARCH_PWR7");
-  if (defs & ArchDefinePwr8)
+  if (ArchDefs & ArchDefinePwr8)
     Builder.defineMacro("_ARCH_PWR8");
-  if (defs & ArchDefinePwr9)
+  if (ArchDefs & ArchDefinePwr9)
     Builder.defineMacro("_ARCH_PWR9");
-  if (defs & ArchDefineA2)
+  if (ArchDefs & ArchDefineA2)
     Builder.defineMacro("_ARCH_A2");
-  if (defs & ArchDefineA2q) {
+  if (ArchDefs & ArchDefineA2q) {
     Builder.defineMacro("_ARCH_A2Q");
     Builder.defineMacro("_ARCH_QP");
   }
@@ -384,6 +309,14 @@ bool PPCTargetInfo::initFeatureMap(
   if (!ppcUserFeaturesCheck(Diags, FeaturesVec))
     return false;
 
+  if (!(ArchDefs & ArchDefinePwr9) && (ArchDefs & ArchDefinePpcgr) &&
+      std::find(FeaturesVec.begin(), FeaturesVec.end(), "+float128") !=
+          FeaturesVec.end()) {
+    // We have __float128 on PPC but not power 9 and above.
+    Diags.Report(diag::err_opt_not_valid_with_opt) << "-mfloat128" << CPU;
+    return false;
+  }
+
   return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
 }
 

Modified: cfe/trunk/lib/Basic/Targets/PPC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/PPC.h?rev=334613&r1=334612&r2=334613&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets/PPC.h (original)
+++ cfe/trunk/lib/Basic/Targets/PPC.h Wed Jun 13 09:05:05 2018
@@ -18,6 +18,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/ADT/Triple.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/Compiler.h"
 
 namespace clang {
@@ -25,6 +26,30 @@ namespace targets {
 
 // PPC abstract base class
 class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
+
+  /// Flags for architecture specific defines.
+  typedef enum {
+    ArchDefineNone = 0,
+    ArchDefineName = 1 << 0, // <name> is substituted for arch name.
+    ArchDefinePpcgr = 1 << 1,
+    ArchDefinePpcsq = 1 << 2,
+    ArchDefine440 = 1 << 3,
+    ArchDefine603 = 1 << 4,
+    ArchDefine604 = 1 << 5,
+    ArchDefinePwr4 = 1 << 6,
+    ArchDefinePwr5 = 1 << 7,
+    ArchDefinePwr5x = 1 << 8,
+    ArchDefinePwr6 = 1 << 9,
+    ArchDefinePwr6x = 1 << 10,
+    ArchDefinePwr7 = 1 << 11,
+    ArchDefinePwr8 = 1 << 12,
+    ArchDefinePwr9 = 1 << 13,
+    ArchDefineA2 = 1 << 14,
+    ArchDefineA2q = 1 << 15
+  } ArchDefineTypes;
+
+
+  ArchDefineTypes ArchDefs;
   static const Builtin::Info BuiltinInfo[];
   static const char *const GCCRegNames[];
   static const TargetInfo::GCCRegAlias GCCRegAliases[];
@@ -50,34 +75,13 @@ public:
       : TargetInfo(Triple), HasAltivec(false), HasVSX(false),
         HasP8Vector(false), HasP8Crypto(false), HasDirectMove(false),
         HasQPX(false), HasHTM(false), HasBPERMD(false), HasExtDiv(false),
-        HasP9Vector(false) {
+        HasP9Vector(false), ArchDefs(ArchDefineNone) {
     SuitableAlign = 128;
     SimdDefaultAlign = 128;
     LongDoubleWidth = LongDoubleAlign = 128;
     LongDoubleFormat = &llvm::APFloat::PPCDoubleDouble();
   }
 
-  /// Flags for architecture specific defines.
-  typedef enum {
-    ArchDefineNone = 0,
-    ArchDefineName = 1 << 0, // <name> is substituted for arch name.
-    ArchDefinePpcgr = 1 << 1,
-    ArchDefinePpcsq = 1 << 2,
-    ArchDefine440 = 1 << 3,
-    ArchDefine603 = 1 << 4,
-    ArchDefine604 = 1 << 5,
-    ArchDefinePwr4 = 1 << 6,
-    ArchDefinePwr5 = 1 << 7,
-    ArchDefinePwr5x = 1 << 8,
-    ArchDefinePwr6 = 1 << 9,
-    ArchDefinePwr6x = 1 << 10,
-    ArchDefinePwr7 = 1 << 11,
-    ArchDefinePwr8 = 1 << 12,
-    ArchDefinePwr9 = 1 << 13,
-    ArchDefineA2 = 1 << 14,
-    ArchDefineA2q = 1 << 15
-  } ArchDefineTypes;
-
   // Set the language option for altivec based on our value.
   void adjust(LangOptions &Opts) override;
 
@@ -90,8 +94,62 @@ public:
 
   bool setCPU(const std::string &Name) override {
     bool CPUKnown = isValidCPUName(Name);
-    if (CPUKnown)
+    if (CPUKnown) {
       CPU = Name;
+
+      // CPU identification.
+      ArchDefs =
+          (ArchDefineTypes)llvm::StringSwitch<int>(CPU)
+              .Case("440", ArchDefineName)
+              .Case("450", ArchDefineName | ArchDefine440)
+              .Case("601", ArchDefineName)
+              .Case("602", ArchDefineName | ArchDefinePpcgr)
+              .Case("603", ArchDefineName | ArchDefinePpcgr)
+              .Case("603e", ArchDefineName | ArchDefine603 | ArchDefinePpcgr)
+              .Case("603ev", ArchDefineName | ArchDefine603 | ArchDefinePpcgr)
+              .Case("604", ArchDefineName | ArchDefinePpcgr)
+              .Case("604e", ArchDefineName | ArchDefine604 | ArchDefinePpcgr)
+              .Case("620", ArchDefineName | ArchDefinePpcgr)
+              .Case("630", ArchDefineName | ArchDefinePpcgr)
+              .Case("7400", ArchDefineName | ArchDefinePpcgr)
+              .Case("7450", ArchDefineName | ArchDefinePpcgr)
+              .Case("750", ArchDefineName | ArchDefinePpcgr)
+              .Case("970", ArchDefineName | ArchDefinePwr4 | ArchDefinePpcgr |
+                               ArchDefinePpcsq)
+              .Case("a2", ArchDefineA2)
+              .Case("a2q", ArchDefineName | ArchDefineA2 | ArchDefineA2q)
+              .Cases("power3", "pwr3", ArchDefinePpcgr)
+              .Cases("power4", "pwr4",
+                    ArchDefinePwr4 | ArchDefinePpcgr | ArchDefinePpcsq)
+              .Cases("power5", "pwr5",
+                    ArchDefinePwr5 | ArchDefinePwr4 | ArchDefinePpcgr |
+                        ArchDefinePpcsq)
+              .Cases("power5x", "pwr5x",
+                    ArchDefinePwr5x | ArchDefinePwr5 | ArchDefinePwr4 |
+                        ArchDefinePpcgr | ArchDefinePpcsq)
+              .Cases("power6", "pwr6",
+                    ArchDefinePwr6 | ArchDefinePwr5x | ArchDefinePwr5 |
+                        ArchDefinePwr4 | ArchDefinePpcgr | ArchDefinePpcsq)
+              .Cases("power6x", "pwr6x",
+                    ArchDefinePwr6x | ArchDefinePwr6 | ArchDefinePwr5x |
+                        ArchDefinePwr5 | ArchDefinePwr4 | ArchDefinePpcgr |
+                        ArchDefinePpcsq)
+              .Cases("power7", "pwr7",
+                    ArchDefinePwr7 | ArchDefinePwr6x | ArchDefinePwr6 |
+                        ArchDefinePwr5x | ArchDefinePwr5 | ArchDefinePwr4 |
+                        ArchDefinePpcgr | ArchDefinePpcsq)
+              // powerpc64le automatically defaults to at least power8.
+              .Cases("power8", "pwr8", "ppc64le",
+                    ArchDefinePwr8 | ArchDefinePwr7 | ArchDefinePwr6x |
+                        ArchDefinePwr6 | ArchDefinePwr5x | ArchDefinePwr5 |
+                        ArchDefinePwr4 | ArchDefinePpcgr | ArchDefinePpcsq)
+              .Cases("power9", "pwr9",
+                    ArchDefinePwr9 | ArchDefinePwr8 | ArchDefinePwr7 |
+                        ArchDefinePwr6x | ArchDefinePwr6 | ArchDefinePwr5x |
+                        ArchDefinePwr5 | ArchDefinePwr4 | ArchDefinePpcgr |
+                        ArchDefinePpcsq)
+              .Default(ArchDefineNone);
+    }
     return CPUKnown;
   }
 

Added: cfe/trunk/test/Driver/ppc-f128-support-check.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/ppc-f128-support-check.c?rev=334613&view=auto
==============================================================================
--- cfe/trunk/test/Driver/ppc-f128-support-check.c (added)
+++ cfe/trunk/test/Driver/ppc-f128-support-check.c Wed Jun 13 09:05:05 2018
@@ -0,0 +1,20 @@
+// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
+// RUN:   -mcpu=pwr9 -mfloat128 %s 2>&1 | FileCheck %s --check-prefix=HASF128
+// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
+// RUN:   -mcpu=power9 -mfloat128 %s 2>&1 | FileCheck %s --check-prefix=HASF128
+
+// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
+// RUN:   -mcpu=pwr8 -mfloat128 %s 2>&1 | FileCheck %s --check-prefix=NOF128
+// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
+// RUN:   -mcpu=pwr7 -mfloat128 %s 2>&1 | FileCheck %s --check-prefix=NOF128
+// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
+// RUN:   -mfloat128 %s 2>&1 | FileCheck %s --check-prefix=NOF128
+
+#ifdef __FLOAT128__
+static_assert(false, "__float128 enabled");
+#endif
+
+// HASF128: __float128 enabled
+// HASF128-NOT: option '-mfloat128' cannot be specified with
+// NOF128: option '-mfloat128' cannot be specified with
+

Modified: cfe/trunk/test/Preprocessor/init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=334613&r1=334612&r2=334613&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/init.c (original)
+++ cfe/trunk/test/Preprocessor/init.c Wed Jun 13 09:05:05 2018
@@ -6370,7 +6370,7 @@
 // PPCPOWER9:#define _ARCH_PWR7 1
 // PPCPOWER9:#define _ARCH_PWR9 1
 //
-// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-feature +float128 -target-cpu power8 -fno-signed-char < /dev/null | FileCheck -check-prefix PPC-FLOAT128 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-feature +float128 -target-cpu power9 -fno-signed-char < /dev/null | FileCheck -check-prefix PPC-FLOAT128 %s
 // PPC-FLOAT128:#define __FLOAT128__ 1
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-linux-gnu -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-LINUX %s

Modified: cfe/trunk/test/Sema/float128-ld-incompatibility.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/float128-ld-incompatibility.cpp?rev=334613&r1=334612&r2=334613&view=diff
==============================================================================
--- cfe/trunk/test/Sema/float128-ld-incompatibility.cpp (original)
+++ cfe/trunk/test/Sema/float128-ld-incompatibility.cpp Wed Jun 13 09:05:05 2018
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 \
-// RUN: -triple powerpc64le-unknown-linux-gnu -target-cpu pwr8 \
+// RUN: -triple powerpc64le-unknown-linux-gnu -target-cpu pwr9 \
 // RUN: -target-feature +float128 %s
 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -triple x86_64-unknown-linux-gnu -Wno-unused-value -Wno-parentheses %s
 




More information about the cfe-commits mailing list