Skip to content

Commit 8557d1a

Browse files
committed
[OPENMP]Use host's long double when compiling the code for device.
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. llvm-svn: 363717
1 parent 5bef886 commit 8557d1a

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,8 +1915,15 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
19151915
Align = Target->getDoubleAlign();
19161916
break;
19171917
case BuiltinType::LongDouble:
1918-
Width = Target->getLongDoubleWidth();
1919-
Align = Target->getLongDoubleAlign();
1918+
if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&
1919+
(Target->getLongDoubleWidth() != AuxTarget->getLongDoubleWidth() ||
1920+
Target->getLongDoubleAlign() != AuxTarget->getLongDoubleAlign())) {
1921+
Width = AuxTarget->getLongDoubleWidth();
1922+
Align = AuxTarget->getLongDoubleAlign();
1923+
} else {
1924+
Width = Target->getLongDoubleWidth();
1925+
Align = Target->getLongDoubleAlign();
1926+
}
19201927
break;
19211928
case BuiltinType::Float128:
19221929
if (Target->hasFloat128Type() || !getLangOpts().OpenMP ||

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,9 @@ void Sema::checkOpenMPDeviceExpr(const Expr *E) {
15761576
"OpenMP device compilation mode is expected.");
15771577
QualType Ty = E->getType();
15781578
if ((Ty->isFloat16Type() && !Context.getTargetInfo().hasFloat16Type()) ||
1579-
(Ty->isFloat128Type() && !Context.getTargetInfo().hasFloat128Type()) ||
1579+
((Ty->isFloat128Type() ||
1580+
(Ty->isRealFloatingType() && Context.getTypeSize(Ty) == 128)) &&
1581+
!Context.getTargetInfo().hasFloat128Type()) ||
15801582
(Ty->isIntegerType() && Context.getTypeSize(Ty) == 128 &&
15811583
!Context.getTargetInfo().hasInt128Type()))
15821584
targetDiag(E->getExprLoc(), diag::err_type_unsupported)

clang/test/OpenMP/nvptx_unsupported_type_messages.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
// Test target codegen - host bc file has to be created first.
22
// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-linux -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-host.bc
3-
// 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
3+
// 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
4+
// RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-linux-gnu -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-host.bc
5+
// 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
46

57
struct T {
68
char a;
9+
#ifndef _ARCH_PPC
710
__float128 f;
11+
#else
12+
long double f;
13+
#endif
814
char c;
915
T() : a(12), f(15) {}
10-
T &operator+(T &b) { f += b.a; return *this;} // expected-error {{'__float128' is not supported on this target}}
16+
#ifndef _ARCH_PPC
17+
// expected-error@+4 {{'__float128' is not supported on this target}}
18+
#else
19+
// expected-error@+2 {{'long double' is not supported on this target}}
20+
#endif
21+
T &operator+(T &b) { f += b.a; return *this;}
1122
};
1223

1324
struct T1 {

0 commit comments

Comments
 (0)