Skip to content

[SYCL][NativeCPU] Copy over more host/aux target data. #17999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 7 additions & 45 deletions clang/lib/Basic/Targets/NativeCPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,50 +60,12 @@ NativeCPUTargetInfo::NativeCPUTargetInfo(const llvm::Triple &,
}());
if (HostTriple.getArch() != llvm::Triple::UnknownArch) {
HostTarget = AllocateTarget(HostTriple, Opts);

// Copy properties from host target.
BoolWidth = HostTarget->getBoolWidth();
BoolAlign = HostTarget->getBoolAlign();
IntWidth = HostTarget->getIntWidth();
IntAlign = HostTarget->getIntAlign();
HalfWidth = HostTarget->getHalfWidth();
HalfAlign = HostTarget->getHalfAlign();
FloatWidth = HostTarget->getFloatWidth();
FloatAlign = HostTarget->getFloatAlign();
DoubleWidth = HostTarget->getDoubleWidth();
DoubleAlign = HostTarget->getDoubleAlign();
LongWidth = HostTarget->getLongWidth();
LongAlign = HostTarget->getLongAlign();
LongLongWidth = HostTarget->getLongLongWidth();
LongLongAlign = HostTarget->getLongLongAlign();
PointerWidth = HostTarget->getPointerWidth(LangAS::Default);
PointerAlign = HostTarget->getPointerAlign(LangAS::Default);
MinGlobalAlign = HostTarget->getMinGlobalAlign(/*TypeSize=*/0,
/*HasNonWeakDef=*/true);
NewAlign = HostTarget->getNewAlign();
DefaultAlignForAttributeAligned =
HostTarget->getDefaultAlignForAttributeAligned();
SizeType = HostTarget->getSizeType();
PtrDiffType = HostTarget->getPtrDiffType(LangAS::Default);
IntMaxType = HostTarget->getIntMaxType();
WCharType = HostTarget->getWCharType();
WIntType = HostTarget->getWIntType();
Char16Type = HostTarget->getChar16Type();
Char32Type = HostTarget->getChar32Type();
Int64Type = HostTarget->getInt64Type();
SigAtomicType = HostTarget->getSigAtomicType();
ProcessIDType = HostTarget->getProcessIDType();

UseBitFieldTypeAlignment = HostTarget->useBitFieldTypeAlignment();
UseZeroLengthBitfieldAlignment =
HostTarget->useZeroLengthBitfieldAlignment();
UseExplicitBitFieldAlignment = HostTarget->useExplicitBitFieldAlignment();
ZeroLengthBitfieldBoundary = HostTarget->getZeroLengthBitfieldBoundary();

// This is a bit of a lie, but it controls __GCC_ATOMIC_XXX_LOCK_FREE, and
// we need those macros to be identical on host and device, because (among
// other things) they affect which standard library classes are defined,
// and we need all classes to be defined on both the host and device.
MaxAtomicInlineWidth = HostTarget->getMaxAtomicInlineWidth();
copyAuxTarget(&*HostTarget);
}
}

void NativeCPUTargetInfo::setAuxTarget(const TargetInfo *Aux) {
assert(Aux && "Cannot invoke setAuxTarget without a valid auxiliary target!");
copyAuxTarget(Aux);
getTargetOpts() = Aux->getTargetOpts();
}
2 changes: 2 additions & 0 deletions clang/lib/Basic/Targets/NativeCPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class LLVM_LIBRARY_VISIBILITY NativeCPUTargetInfo final : public TargetInfo {
}

protected:
void setAuxTarget(const TargetInfo *Aux) override;

ArrayRef<const char *> getGCCRegNames() const override { return {}; }

ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
Expand Down
4 changes: 1 addition & 3 deletions clang/lib/Driver/Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//

#include "clang/Driver/Compilation.h"
#include "ToolChains/SYCL.h"
#include "clang/Basic/LLVM.h"
#include "clang/Driver/Action.h"
#include "clang/Driver/Driver.h"
Expand Down Expand Up @@ -128,8 +127,7 @@ Compilation::getArgsForToolChain(const ToolChain *TC, StringRef BoundArch,
if (DeviceOffloadKind == Action::OFK_OpenMP ||
DeviceOffloadKind == Action::OFK_SYCL) {
const ToolChain *HostTC = getSingleOffloadToolChain<Action::OFK_Host>();
bool SameTripleAsHost = (TC->getTriple() == HostTC->getTriple()) ||
isSYCLNativeCPU(TC->getTriple());
bool SameTripleAsHost = (TC->getTriple() == HostTC->getTriple());
OffloadArgs = TC->TranslateOffloadTargetArgs(
*TranslatedArgs, SameTripleAsHost, AllocatedArgs, DeviceOffloadKind);
}
Expand Down
17 changes: 17 additions & 0 deletions clang/test/CodeGenSYCL/native_cpu_target_features.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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
// 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
// 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

#include "Inputs/sycl.hpp"
using namespace sycl;

class Test;
int main() {
sycl::queue deviceQueue;
deviceQueue.submit([&](handler &h) { h.single_task<Test>([=] {}); });
}

// CHECK: void @_ZTS4Test() [[ATTRS:#[0-9]+]]
// CHECK: [[ATTRS]] = {
// NOAVX-NOT: "target-features"="{{[^"]*}}+avx{{[^"]*}}"
// AVX-SAME: "target-features"="{{[^"]*}}+avx{{[^"]*}}"
2 changes: 1 addition & 1 deletion clang/test/Driver/sycl-native-cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// CHECK-OPTS: clang{{.*}}"-triple" "[[TRIPLE]]"{{.*}}"-fsycl-is-device"
// CHECK-OPTS-NOT: -sycl-opt
// CHECK-OPTS-SAME: "-Wno-override-module" "-mllvm" "-sycl-native-cpu-backend"
// CHECK-OPTS-SAME: "-target-feature" "+v9.4a"
// CHECK-OPTS-SAME: "-aux-target-feature" "+v9.4a"

// RUN: %clangxx -fsycl -fsycl-targets=spir64 %s -### 2>&1 | FileCheck -check-prefix=CHECK-NONATIVECPU %s
// CHECK-NONATIVECPU-NOT: "-D" "__SYCL_NATIVE_CPU__"
Expand Down
7 changes: 6 additions & 1 deletion libclc/utils/prepare-builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ int main(int argc, char **argv) {
// functions were inlined prior to incompatible functions pass. Now that the
// inliner runs later in the pipeline we have to remove all of the target
// features, so libclc functions will not be earmarked for deletion.
if (M->getTargetTriple().str().find("amdgcn") != std::string::npos) {
//
// NativeCPU uses the same builtins for multiple host targets and should
// likewise not have features that limit the builtins to any particular
// target.
if (M->getTargetTriple().str().find("amdgcn") != std::string::npos ||
M->getTargetTriple().str() != "native_cpu") {
AttributeMask AM;
AM.addAttribute("target-features");
AM.addAttribute("target-cpu");
Expand Down