Skip to content

[SYCL][Clang] Add ARM64_SPIRV64 and ARM64SPIR64 target info #18859

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

Open
wants to merge 4 commits into
base: sycl
Choose a base branch
from
Open
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
29 changes: 22 additions & 7 deletions clang/lib/Basic/Targets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,9 +693,17 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
switch (HT.getEnvironment()) {
default: // Assume MSVC for unknown environments
case llvm::Triple::MSVC:
assert(HT.getArch() == llvm::Triple::x86_64 &&
"Unsupported host architecture");
return std::make_unique<MicrosoftX86_64_SPIR64TargetInfo>(Triple, Opts);
switch (HT.getArch()) {
case llvm::Triple::aarch64:
return std::make_unique<MicrosoftARM64_SPIR64TargetInfo>(Triple,
Opts);
case llvm::Triple::x86_64:
return std::make_unique<MicrosoftX86_64_SPIR64TargetInfo>(Triple,
Opts);
default:
llvm::report_fatal_error(
"Unsupported host architecture (not x86_64 or aarch64)");
}
}
case llvm::Triple::Linux:
if (IsFPGASubArch)
Expand Down Expand Up @@ -741,10 +749,17 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
switch (HT.getEnvironment()) {
default: // Assume MSVC for unknown environments
case llvm::Triple::MSVC:
assert(HT.getArch() == llvm::Triple::x86_64 &&
"Unsupported host architecture");
return std::make_unique<MicrosoftX86_64_SPIRV64TargetInfo>(Triple,
Opts);
switch (HT.getArch()) {
case llvm::Triple::aarch64:
return std::make_unique<MicrosoftARM64_SPIRV64TargetInfo>(Triple,
Opts);
case llvm::Triple::x86_64:
return std::make_unique<MicrosoftX86_64_SPIRV64TargetInfo>(Triple,
Opts);
default:
llvm::report_fatal_error(
"Unsupported host architecture (not x86_64 or aarch64)");
}
}
default:
return std::make_unique<SPIRV64TargetInfo>(Triple, Opts);
Expand Down
86 changes: 86 additions & 0 deletions clang/lib/Basic/Targets/SPIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,49 @@ class LLVM_LIBRARY_VISIBILITY MicrosoftX86_64_SPIR64TargetInfo
}
};

// ARM64 SPIR64 Windows target
class LLVM_LIBRARY_VISIBILITY WindowsARM64_SPIR64TargetInfo
: public WindowsTargetInfo<SPIR64TargetInfo> {
public:
WindowsARM64_SPIR64TargetInfo(const llvm::Triple &Triple,
const TargetOptions &Opts)
: WindowsTargetInfo<SPIR64TargetInfo>(Triple, Opts) {
LongWidth = LongAlign = 32;
DoubleAlign = LongLongAlign = 64;
IntMaxType = SignedLongLong;
Int64Type = SignedLongLong;
SizeType = UnsignedLongLong;
PtrDiffType = SignedLongLong;
IntPtrType = SignedLongLong;
WCharType = UnsignedShort;
}

BuiltinVaListKind getBuiltinVaListKind() const override {
return TargetInfo::CharPtrBuiltinVaList;
}

CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
return (CC == CC_SpirFunction || CC == CC_OpenCLKernel) ? CCCR_OK
: CCCR_Warning;
}
};

// ARM64 SPIR64 Windows Visual Studio target
class LLVM_LIBRARY_VISIBILITY MicrosoftARM64_SPIR64TargetInfo
: public WindowsARM64_SPIR64TargetInfo {
public:
MicrosoftARM64_SPIR64TargetInfo(const llvm::Triple &Triple,
const TargetOptions &Opts)
: WindowsARM64_SPIR64TargetInfo(Triple, Opts) {}

void getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const override {
WindowsARM64_SPIR64TargetInfo::getTargetDefines(Opts, Builder);
// Device code doesn't need to have ARM64EC defines
Builder.defineMacro("_M_ARM64", "1");
}
};

class LLVM_LIBRARY_VISIBILITY BaseSPIRVTargetInfo : public BaseSPIRTargetInfo {
public:
BaseSPIRVTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Expand Down Expand Up @@ -591,6 +634,49 @@ class LLVM_LIBRARY_VISIBILITY MicrosoftX86_64_SPIRV64TargetInfo
}
};

// ARM64 SPIRV64 Windows target
class LLVM_LIBRARY_VISIBILITY WindowsARM64_SPIRV64TargetInfo
: public WindowsTargetInfo<SPIRV64TargetInfo> {
public:
WindowsARM64_SPIRV64TargetInfo(const llvm::Triple &Triple,
const TargetOptions &Opts)
: WindowsTargetInfo<SPIRV64TargetInfo>(Triple, Opts) {
LongWidth = LongAlign = 32;
DoubleAlign = LongLongAlign = 64;
IntMaxType = SignedLongLong;
Int64Type = SignedLongLong;
SizeType = UnsignedLongLong;
PtrDiffType = SignedLongLong;
IntPtrType = SignedLongLong;
WCharType = UnsignedShort;
}

BuiltinVaListKind getBuiltinVaListKind() const override {
return TargetInfo::CharPtrBuiltinVaList;
}

CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
return (CC == CC_SpirFunction || CC == CC_OpenCLKernel) ? CCCR_OK
: CCCR_Warning;
}
};

// ARM64 SPIRV64 Windows Visual Studio target
class LLVM_LIBRARY_VISIBILITY MicrosoftARM64_SPIRV64TargetInfo
: public WindowsARM64_SPIRV64TargetInfo {
public:
MicrosoftARM64_SPIRV64TargetInfo(const llvm::Triple &Triple,
const TargetOptions &Opts)
: WindowsARM64_SPIRV64TargetInfo(Triple, Opts) {}

void getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const override {
WindowsARM64_SPIRV64TargetInfo::getTargetDefines(Opts, Builder);
// Device code doesn't need to have ARM64EC defines
Builder.defineMacro("_M_ARM64", "1");
}
};

class LLVM_LIBRARY_VISIBILITY SPIRV64AMDGCNTargetInfo final
: public BaseSPIRVTargetInfo {
public:
Expand Down
4 changes: 4 additions & 0 deletions clang/test/CodeGenSYCL/kernel-arg-accessor-pointer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -triple spir64-unknown-unknown -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -aux-triple x86_64-pc-windows-msvc -fsycl-is-device -internal-isystem %S/Inputs -triple spir64-unknown-unknown -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -aux-triple x86_64-pc-windows-msvc -fsycl-is-device -internal-isystem %S/Inputs -triple spirv64-unknown-unknown -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -aux-triple aarch64-pc-windows-msvc -fsycl-is-device -internal-isystem %S/Inputs -triple spir64-unknown-unknown -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -aux-triple aarch64-pc-windows-msvc -fsycl-is-device -internal-isystem %S/Inputs -triple spirv64-unknown-unknown -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s

// This test checks if the metadata "kernel-arg-runtime-aligned" and "kernel_arg_exclusive_ptr"
// are generated if the kernel captures an accessor.
Expand Down