Skip to content

Commit e509af3

Browse files
committed
[OPENMP]Fix the float point semantics handling on the device.
The device should use the same float point representation as the host. Previous patch fixed the handling of the sizes of the float point types, but did not fixed the fp semantics. This patch makes target device to use the host fp semantics. this is required for the correct data transfer between host and device and correct codegen. llvm-svn: 365485
1 parent e6d10f9 commit e509af3

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,8 +1524,16 @@ const llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const {
15241524
return Target->getHalfFormat();
15251525
case BuiltinType::Float: return Target->getFloatFormat();
15261526
case BuiltinType::Double: return Target->getDoubleFormat();
1527-
case BuiltinType::LongDouble: return Target->getLongDoubleFormat();
1528-
case BuiltinType::Float128: return Target->getFloat128Format();
1527+
case BuiltinType::LongDouble:
1528+
if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&
1529+
&Target->getLongDoubleFormat() != &AuxTarget->getLongDoubleFormat())
1530+
return AuxTarget->getLongDoubleFormat();
1531+
return Target->getLongDoubleFormat();
1532+
case BuiltinType::Float128:
1533+
if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&
1534+
&Target->getFloat128Format() != &AuxTarget->getFloat128Format())
1535+
return AuxTarget->getFloat128Format();
1536+
return Target->getFloat128Format();
15291537
}
15301538
}
15311539

clang/test/OpenMP/nvptx_asm_delayed_diags.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %clang_cc1 -fopenmp -x c -triple i386-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm-bc %s -o %t-x86-host.bc
2-
// RUN: %clang_cc1 -verify -fopenmp -x c -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -fsyntax-only -Wuninitialized
3-
// RUN: %clang_cc1 -verify -DDIAGS -DIMMEDIATE -fopenmp -x c -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -fsyntax-only -Wuninitialized
4-
// RUN: %clang_cc1 -verify -DDIAGS -DDELAYED -fopenmp -x c -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -fsyntax-only -Wuninitialized
2+
// RUN: %clang_cc1 -verify -fopenmp -x c -triple nvptx-unknown-unknown -aux-triple i386-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -fsyntax-only -Wuninitialized
3+
// RUN: %clang_cc1 -verify -DDIAGS -DIMMEDIATE -fopenmp -x c -triple nvptx-unknown-unknown -aux-triple i386-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -fsyntax-only -Wuninitialized
4+
// RUN: %clang_cc1 -verify -DDIAGS -DDELAYED -fopenmp -x c -triple nvptx-unknown-unknown -aux-triple i386-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -fsyntax-only -Wuninitialized
55
// REQUIRES: x86-registered-target
66
// REQUIRES: nvptx-registered-target
77

clang/test/OpenMP/nvptx_unsupported_type_codegen.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Test target codegen - host bc file has to be created first.
22
// RUN: %clang_cc1 -verify -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 -aux-triple x86_64-unknown-linux -fopenmp-targets=nvptx64-nvidia-cuda -aux-triple x86_64-unknown-linux -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -o - | FileCheck %s
3+
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -aux-triple x86_64-unknown-linux -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -o - | FileCheck %s
44
// RUN: %clang_cc1 -verify -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 -aux-triple x86_64-unknown-linux -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -o - | FileCheck %s
5+
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -aux-triple powerpc64le-unknown-linux-gnu -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -o - | FileCheck %s
66
// expected-no-diagnostics
77

8-
// CHECK-DAG: [[T:%.+]] = type {{.+}}, fp128,
8+
// CHECK-DAG: [[T:%.+]] = type {{.+}}, {{fp128|ppc_fp128}},
99
// CHECK-DAG: [[T1:%.+]] = type {{.+}}, i128, i128,
1010

1111
#ifndef _ARCH_PPC
@@ -78,4 +78,4 @@ BIGTYPE foo(BIGTYPE f) {
7878
}
7979

8080
// CHECK: define weak void @__omp_offloading_{{.+}}foo{{.+}}_l75([[BIGTYPE:.+]]*
81-
// CHECK: store [[BIGTYPE]] 0xL00000000000000003FFF000000000000, [[BIGTYPE]]* %
81+
// CHECK: store [[BIGTYPE]] {{0xL00000000000000003FFF000000000000|0xM3FF00000000000000000000000000000}}, [[BIGTYPE]]* %

0 commit comments

Comments
 (0)