]> granicus.if.org Git - clang/commitdiff
[OPENMP]Use host's long double when compiling the code for device.
authorAlexey Bataev <a.bataev@hotmail.com>
Tue, 18 Jun 2019 18:39:26 +0000 (18:39 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Tue, 18 Jun 2019 18:39:26 +0000 (18:39 +0000)
The device code must use the same long double type as the host.
Otherwise the code cannot be linked and executed properly. Patch adds
only basic support and checks for supporting of the host long double
double on the device.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@363717 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTContext.cpp
lib/Sema/SemaOpenMP.cpp
test/OpenMP/nvptx_unsupported_type_messages.cpp

index b3c9c20d2b33780833ea73f426daa56d1c428eab..7f73531a83befaa178976ea45f13442b808c74eb 100644 (file)
@@ -1915,8 +1915,15 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
       Align = Target->getDoubleAlign();
       break;
     case BuiltinType::LongDouble:
-      Width = Target->getLongDoubleWidth();
-      Align = Target->getLongDoubleAlign();
+      if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&
+          (Target->getLongDoubleWidth() != AuxTarget->getLongDoubleWidth() ||
+           Target->getLongDoubleAlign() != AuxTarget->getLongDoubleAlign())) {
+        Width = AuxTarget->getLongDoubleWidth();
+        Align = AuxTarget->getLongDoubleAlign();
+      } else {
+        Width = Target->getLongDoubleWidth();
+        Align = Target->getLongDoubleAlign();
+      }
       break;
     case BuiltinType::Float128:
       if (Target->hasFloat128Type() || !getLangOpts().OpenMP ||
index a4eafb180a18563dd92087a931e1edb24dbb149b..19057eb39863ab9a80d75e7739820fbabf810b06 100644 (file)
@@ -1576,7 +1576,9 @@ void Sema::checkOpenMPDeviceExpr(const Expr *E) {
          "OpenMP device compilation mode is expected.");
   QualType Ty = E->getType();
   if ((Ty->isFloat16Type() && !Context.getTargetInfo().hasFloat16Type()) ||
-      (Ty->isFloat128Type() && !Context.getTargetInfo().hasFloat128Type()) ||
+      ((Ty->isFloat128Type() ||
+        (Ty->isRealFloatingType() && Context.getTypeSize(Ty) == 128)) &&
+       !Context.getTargetInfo().hasFloat128Type()) ||
       (Ty->isIntegerType() && Context.getTypeSize(Ty) == 128 &&
        !Context.getTargetInfo().hasInt128Type()))
     targetDiag(E->getExprLoc(), diag::err_type_unsupported)
index 6e0fa3b1d5b441d8e34d415be876c683a30dc0c5..67f2e41ac4a96fb6f2bcb39aa94fe8c75dfbffe7 100644 (file)
@@ -1,13 +1,24 @@
 // Test target codegen - host bc file has to be created first.
 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-linux -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-host.bc
-// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -fsyntax-only
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -aux-triple x86_64-unknown-linux -fopenmp-targets=nvptx64-nvidia-cuda %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -fsyntax-only
+// RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-linux-gnu -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -aux-triple powerpc64le-unknown-linux-gnu -fopenmp-targets=nvptx64-nvidia-cuda %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -fsyntax-only
 
 struct T {
   char a;
+#ifndef _ARCH_PPC
   __float128 f;
+#else
+  long double f;
+#endif
   char c;
   T() : a(12), f(15) {}
-  T &operator+(T &b) { f += b.a; return *this;} // expected-error {{'__float128' is not supported on this target}}
+#ifndef _ARCH_PPC
+// expected-error@+4 {{'__float128' is not supported on this target}}
+#else
+// expected-error@+2 {{'long double' is not supported on this target}}
+#endif
+  T &operator+(T &b) { f += b.a; return *this;}
 };
 
 struct T1 {