Skip to content

Commit d653b20

Browse files
authored
[SYCL][NativeCPU] Copy over more host/aux target data. (#17999)
* Use copyAuxTarget instead of copying over each field. * Copy over TargetOpts as well. * Prevent recording the target flags for builtins.
1 parent a9db584 commit d653b20

File tree

6 files changed

+34
-50
lines changed

6 files changed

+34
-50
lines changed

clang/lib/Basic/Targets/NativeCPU.cpp

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -60,50 +60,12 @@ NativeCPUTargetInfo::NativeCPUTargetInfo(const llvm::Triple &,
6060
}());
6161
if (HostTriple.getArch() != llvm::Triple::UnknownArch) {
6262
HostTarget = AllocateTarget(HostTriple, Opts);
63-
64-
// Copy properties from host target.
65-
BoolWidth = HostTarget->getBoolWidth();
66-
BoolAlign = HostTarget->getBoolAlign();
67-
IntWidth = HostTarget->getIntWidth();
68-
IntAlign = HostTarget->getIntAlign();
69-
HalfWidth = HostTarget->getHalfWidth();
70-
HalfAlign = HostTarget->getHalfAlign();
71-
FloatWidth = HostTarget->getFloatWidth();
72-
FloatAlign = HostTarget->getFloatAlign();
73-
DoubleWidth = HostTarget->getDoubleWidth();
74-
DoubleAlign = HostTarget->getDoubleAlign();
75-
LongWidth = HostTarget->getLongWidth();
76-
LongAlign = HostTarget->getLongAlign();
77-
LongLongWidth = HostTarget->getLongLongWidth();
78-
LongLongAlign = HostTarget->getLongLongAlign();
79-
PointerWidth = HostTarget->getPointerWidth(LangAS::Default);
80-
PointerAlign = HostTarget->getPointerAlign(LangAS::Default);
81-
MinGlobalAlign = HostTarget->getMinGlobalAlign(/*TypeSize=*/0,
82-
/*HasNonWeakDef=*/true);
83-
NewAlign = HostTarget->getNewAlign();
84-
DefaultAlignForAttributeAligned =
85-
HostTarget->getDefaultAlignForAttributeAligned();
86-
SizeType = HostTarget->getSizeType();
87-
PtrDiffType = HostTarget->getPtrDiffType(LangAS::Default);
88-
IntMaxType = HostTarget->getIntMaxType();
89-
WCharType = HostTarget->getWCharType();
90-
WIntType = HostTarget->getWIntType();
91-
Char16Type = HostTarget->getChar16Type();
92-
Char32Type = HostTarget->getChar32Type();
93-
Int64Type = HostTarget->getInt64Type();
94-
SigAtomicType = HostTarget->getSigAtomicType();
95-
ProcessIDType = HostTarget->getProcessIDType();
96-
97-
UseBitFieldTypeAlignment = HostTarget->useBitFieldTypeAlignment();
98-
UseZeroLengthBitfieldAlignment =
99-
HostTarget->useZeroLengthBitfieldAlignment();
100-
UseExplicitBitFieldAlignment = HostTarget->useExplicitBitFieldAlignment();
101-
ZeroLengthBitfieldBoundary = HostTarget->getZeroLengthBitfieldBoundary();
102-
103-
// This is a bit of a lie, but it controls __GCC_ATOMIC_XXX_LOCK_FREE, and
104-
// we need those macros to be identical on host and device, because (among
105-
// other things) they affect which standard library classes are defined,
106-
// and we need all classes to be defined on both the host and device.
107-
MaxAtomicInlineWidth = HostTarget->getMaxAtomicInlineWidth();
63+
copyAuxTarget(&*HostTarget);
10864
}
10965
}
66+
67+
void NativeCPUTargetInfo::setAuxTarget(const TargetInfo *Aux) {
68+
assert(Aux && "Cannot invoke setAuxTarget without a valid auxiliary target!");
69+
copyAuxTarget(Aux);
70+
getTargetOpts() = Aux->getTargetOpts();
71+
}

clang/lib/Basic/Targets/NativeCPU.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class LLVM_LIBRARY_VISIBILITY NativeCPUTargetInfo final : public TargetInfo {
5757
}
5858

5959
protected:
60+
void setAuxTarget(const TargetInfo *Aux) override;
61+
6062
ArrayRef<const char *> getGCCRegNames() const override { return {}; }
6163

6264
ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {

clang/lib/Driver/Compilation.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "clang/Driver/Compilation.h"
10-
#include "ToolChains/SYCL.h"
1110
#include "clang/Basic/LLVM.h"
1211
#include "clang/Driver/Action.h"
1312
#include "clang/Driver/Driver.h"
@@ -128,8 +127,7 @@ Compilation::getArgsForToolChain(const ToolChain *TC, StringRef BoundArch,
128127
if (DeviceOffloadKind == Action::OFK_OpenMP ||
129128
DeviceOffloadKind == Action::OFK_SYCL) {
130129
const ToolChain *HostTC = getSingleOffloadToolChain<Action::OFK_Host>();
131-
bool SameTripleAsHost = (TC->getTriple() == HostTC->getTriple()) ||
132-
isSYCLNativeCPU(TC->getTriple());
130+
bool SameTripleAsHost = (TC->getTriple() == HostTC->getTriple());
133131
OffloadArgs = TC->TranslateOffloadTargetArgs(
134132
*TranslatedArgs, SameTripleAsHost, AllocatedArgs, DeviceOffloadKind);
135133
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clang_cc1 -triple native_cpu -aux-triple x86_64-unknown-linux-gnu -fsycl-is-device -emit-llvm -fsycl-is-native-cpu -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 -fsycl-is-native-cpu -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 -fsycl-is-native-cpu -o - %s | FileCheck %s --check-prefixes=CHECK,AVX
4+
5+
#include "Inputs/sycl.hpp"
6+
using namespace sycl;
7+
8+
class Test;
9+
int main() {
10+
sycl::queue deviceQueue;
11+
deviceQueue.submit([&](handler &h) { h.single_task<Test>([=] {}); });
12+
}
13+
14+
// CHECK: void @_ZTS4Test() [[ATTRS:#[0-9]+]]
15+
// CHECK: [[ATTRS]] = {
16+
// NOAVX-NOT: "target-features"="{{[^"]*}}+avx{{[^"]*}}"
17+
// AVX-SAME: "target-features"="{{[^"]*}}+avx{{[^"]*}}"

clang/test/Driver/sycl-native-cpu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// CHECK-OPTS: clang{{.*}}"-triple" "[[TRIPLE]]"{{.*}}"-fsycl-is-device"
2626
// CHECK-OPTS-NOT: -sycl-opt
2727
// CHECK-OPTS-SAME: "-Wno-override-module" "-mllvm" "-sycl-native-cpu-backend"
28-
// CHECK-OPTS-SAME: "-target-feature" "+v9.4a"
28+
// CHECK-OPTS-SAME: "-aux-target-feature" "+v9.4a"
2929

3030
// RUN: %clangxx -fsycl -fsycl-targets=spir64 %s -### 2>&1 | FileCheck -check-prefix=CHECK-NONATIVECPU %s
3131
// CHECK-NONATIVECPU-NOT: "-D" "__SYCL_NATIVE_CPU__"

libclc/utils/prepare-builtins.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ int main(int argc, char **argv) {
116116
// functions were inlined prior to incompatible functions pass. Now that the
117117
// inliner runs later in the pipeline we have to remove all of the target
118118
// features, so libclc functions will not be earmarked for deletion.
119-
if (M->getTargetTriple().str().find("amdgcn") != std::string::npos) {
119+
//
120+
// NativeCPU uses the same builtins for multiple host targets and should
121+
// likewise not have features that limit the builtins to any particular
122+
// target.
123+
if (M->getTargetTriple().str().find("amdgcn") != std::string::npos ||
124+
M->getTargetTriple().str() != "native_cpu") {
120125
AttributeMask AM;
121126
AM.addAttribute("target-features");
122127
AM.addAttribute("target-cpu");

0 commit comments

Comments
 (0)