Skip to content

Commit a97650c

Browse files
authored
[NativeCPU] Use host data layout. (#19544)
For compilations without an aux target, the data layout string is not used by us because it only appears in device libs where it will be overwritten when the device lib gets merged in. For compilations with an aux target, the data layout string should be set to that of the aux target, the aux target may be relying on that.
1 parent 72bb2e4 commit a97650c

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

clang/lib/Basic/Targets/NativeCPU.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ NativeCPUTargetInfo::NativeCPUTargetInfo(const llvm::Triple &Triple,
4848
UseAddrSpaceMapMangling = true;
4949
HasLegalHalfType = true;
5050
HasFloat16 = true;
51-
resetDataLayout("e");
5251

5352
llvm::Triple HostTriple([&] {
5453
// Take the default target triple if no other host triple is specified so
@@ -58,14 +57,19 @@ NativeCPUTargetInfo::NativeCPUTargetInfo(const llvm::Triple &Triple,
5857

5958
return llvm::Triple(Opts.HostTriple);
6059
}());
61-
if (!HostTriple.isNativeCPU()) {
60+
if (HostTriple.isNativeCPU()) {
61+
// This should never happen, just make sure we do not crash.
62+
resetDataLayout("e");
63+
} else {
6264
HostTarget = AllocateTarget(HostTriple, Opts);
6365
copyAuxTarget(&*HostTarget);
66+
resetDataLayout(HostTarget->getDataLayoutString());
6467
}
6568
}
6669

6770
void NativeCPUTargetInfo::setAuxTarget(const TargetInfo *Aux) {
6871
assert(Aux && "Cannot invoke setAuxTarget without a valid auxiliary target!");
6972
copyAuxTarget(Aux);
7073
getTargetOpts() = Aux->getTargetOpts();
74+
resetDataLayout(Aux->getDataLayoutString());
7175
}

clang/test/CodeGenSYCL/native_cpu_target_features.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// RUN: %clang_cc1 -triple native_cpu -aux-triple x86_64-unknown-linux-gnu -fsycl-is-device -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,NOAVX
2-
// RUN: %clang_cc1 -triple native_cpu -aux-triple x86_64-unknown-linux-gnu -aux-target-cpu skylake -fsycl-is-device -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,AVX
3-
// RUN: %clang_cc1 -triple native_cpu -aux-triple x86_64-unknown-linux-gnu -aux-target-feature +avx -fsycl-is-device -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,AVX
1+
// RUN: %clang_cc1 -triple native_cpu -aux-triple x86_64-unknown-linux-gnu -fsycl-is-device -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,X86,NOAVX
2+
// RUN: %clang_cc1 -triple native_cpu -aux-triple x86_64-unknown-linux-gnu -aux-target-cpu skylake -fsycl-is-device -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,X86,AVX
3+
// RUN: %clang_cc1 -triple native_cpu -aux-triple x86_64-unknown-linux-gnu -aux-target-feature +avx -fsycl-is-device -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,X86,AVX
44
//
55
// This is not sensible but check that we do not crash.
6-
// RUN: %clang_cc1 -triple native_cpu -aux-triple native_cpu -fsycl-is-device -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,NOAVX
6+
// RUN: %clang_cc1 -triple native_cpu -aux-triple native_cpu -fsycl-is-device -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,NOX86,NOAVX
77

88
#include "Inputs/sycl.hpp"
99
using namespace sycl;
@@ -14,6 +14,9 @@ int main() {
1414
deviceQueue.submit([&](handler &h) { h.single_task<Test>([=] {}); });
1515
}
1616

17+
// X86: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
18+
// NOX86: target datalayout = "e"
19+
1720
// CHECK: void @_ZTS4Test() [[ATTRS:#[0-9]+]]
1821
// CHECK: [[ATTRS]] = {
1922
// NOAVX-NOT: "target-features"="{{[^"]*}}+avx{{[^"]*}}"

0 commit comments

Comments
 (0)