Skip to content

Commit e1d1ab5

Browse files
authored
[SYCL][Clang] Add ARM64_SPIRV64 and ARM64SPIR64 target info (#18859)
Add TargetInfo for MSVC ARM64 host with SPIR64 or SPIRV64 device target.
1 parent 754bb93 commit e1d1ab5

File tree

4 files changed

+114
-7
lines changed

4 files changed

+114
-7
lines changed

clang/lib/Basic/Targets.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,17 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
693693
switch (HT.getEnvironment()) {
694694
default: // Assume MSVC for unknown environments
695695
case llvm::Triple::MSVC:
696-
assert(HT.getArch() == llvm::Triple::x86_64 &&
697-
"Unsupported host architecture");
698-
return std::make_unique<MicrosoftX86_64_SPIR64TargetInfo>(Triple, Opts);
696+
switch (HT.getArch()) {
697+
case llvm::Triple::aarch64:
698+
return std::make_unique<MicrosoftARM64_SPIR64TargetInfo>(Triple,
699+
Opts);
700+
case llvm::Triple::x86_64:
701+
return std::make_unique<MicrosoftX86_64_SPIR64TargetInfo>(Triple,
702+
Opts);
703+
default:
704+
llvm::report_fatal_error(
705+
"Unsupported host architecture (not x86_64 or aarch64)");
706+
}
699707
}
700708
case llvm::Triple::Linux:
701709
if (IsFPGASubArch)
@@ -741,10 +749,17 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
741749
switch (HT.getEnvironment()) {
742750
default: // Assume MSVC for unknown environments
743751
case llvm::Triple::MSVC:
744-
assert(HT.getArch() == llvm::Triple::x86_64 &&
745-
"Unsupported host architecture");
746-
return std::make_unique<MicrosoftX86_64_SPIRV64TargetInfo>(Triple,
747-
Opts);
752+
switch (HT.getArch()) {
753+
case llvm::Triple::aarch64:
754+
return std::make_unique<MicrosoftARM64_SPIRV64TargetInfo>(Triple,
755+
Opts);
756+
case llvm::Triple::x86_64:
757+
return std::make_unique<MicrosoftX86_64_SPIRV64TargetInfo>(Triple,
758+
Opts);
759+
default:
760+
llvm::report_fatal_error(
761+
"Unsupported host architecture (not x86_64 or aarch64)");
762+
}
748763
}
749764
default:
750765
return std::make_unique<SPIRV64TargetInfo>(Triple, Opts);

clang/lib/Basic/Targets/SPIR.h

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,47 @@ class LLVM_LIBRARY_VISIBILITY MicrosoftX86_64_SPIR64TargetInfo
394394
}
395395
};
396396

397+
// ARM64 SPIR64 Windows target
398+
class LLVM_LIBRARY_VISIBILITY WindowsARM64_SPIR64TargetInfo
399+
: public WindowsTargetInfo<SPIR64TargetInfo> {
400+
public:
401+
WindowsARM64_SPIR64TargetInfo(const llvm::Triple &Triple,
402+
const TargetOptions &Opts)
403+
: WindowsTargetInfo<SPIR64TargetInfo>(Triple, Opts) {
404+
LongWidth = LongAlign = 32;
405+
DoubleAlign = LongLongAlign = 64;
406+
IntMaxType = SignedLongLong;
407+
Int64Type = SignedLongLong;
408+
SizeType = UnsignedLongLong;
409+
PtrDiffType = SignedLongLong;
410+
IntPtrType = SignedLongLong;
411+
WCharType = UnsignedShort;
412+
}
413+
414+
BuiltinVaListKind getBuiltinVaListKind() const override {
415+
return TargetInfo::CharPtrBuiltinVaList;
416+
}
417+
418+
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
419+
return (CC == CC_SpirFunction || CC == CC_OpenCLKernel) ? CCCR_OK
420+
: CCCR_Warning;
421+
}
422+
};
423+
424+
// ARM64 SPIR64 Windows Visual Studio target
425+
class LLVM_LIBRARY_VISIBILITY MicrosoftARM64_SPIR64TargetInfo
426+
: public WindowsARM64_SPIR64TargetInfo {
427+
public:
428+
MicrosoftARM64_SPIR64TargetInfo(const llvm::Triple &Triple,
429+
const TargetOptions &Opts)
430+
: WindowsARM64_SPIR64TargetInfo(Triple, Opts) {}
431+
432+
void getTargetDefines(const LangOptions &Opts,
433+
MacroBuilder &Builder) const override {
434+
WindowsARM64_SPIR64TargetInfo::getTargetDefines(Opts, Builder);
435+
}
436+
};
437+
397438
class LLVM_LIBRARY_VISIBILITY BaseSPIRVTargetInfo : public BaseSPIRTargetInfo {
398439
public:
399440
BaseSPIRVTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
@@ -591,6 +632,47 @@ class LLVM_LIBRARY_VISIBILITY MicrosoftX86_64_SPIRV64TargetInfo
591632
}
592633
};
593634

635+
// ARM64 SPIRV64 Windows target
636+
class LLVM_LIBRARY_VISIBILITY WindowsARM64_SPIRV64TargetInfo
637+
: public WindowsTargetInfo<SPIRV64TargetInfo> {
638+
public:
639+
WindowsARM64_SPIRV64TargetInfo(const llvm::Triple &Triple,
640+
const TargetOptions &Opts)
641+
: WindowsTargetInfo<SPIRV64TargetInfo>(Triple, Opts) {
642+
LongWidth = LongAlign = 32;
643+
DoubleAlign = LongLongAlign = 64;
644+
IntMaxType = SignedLongLong;
645+
Int64Type = SignedLongLong;
646+
SizeType = UnsignedLongLong;
647+
PtrDiffType = SignedLongLong;
648+
IntPtrType = SignedLongLong;
649+
WCharType = UnsignedShort;
650+
}
651+
652+
BuiltinVaListKind getBuiltinVaListKind() const override {
653+
return TargetInfo::CharPtrBuiltinVaList;
654+
}
655+
656+
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
657+
return (CC == CC_SpirFunction || CC == CC_OpenCLKernel) ? CCCR_OK
658+
: CCCR_Warning;
659+
}
660+
};
661+
662+
// ARM64 SPIRV64 Windows Visual Studio target
663+
class LLVM_LIBRARY_VISIBILITY MicrosoftARM64_SPIRV64TargetInfo
664+
: public WindowsARM64_SPIRV64TargetInfo {
665+
public:
666+
MicrosoftARM64_SPIRV64TargetInfo(const llvm::Triple &Triple,
667+
const TargetOptions &Opts)
668+
: WindowsARM64_SPIRV64TargetInfo(Triple, Opts) {}
669+
670+
void getTargetDefines(const LangOptions &Opts,
671+
MacroBuilder &Builder) const override {
672+
WindowsARM64_SPIRV64TargetInfo::getTargetDefines(Opts, Builder);
673+
}
674+
};
675+
594676
class LLVM_LIBRARY_VISIBILITY SPIRV64AMDGCNTargetInfo final
595677
: public BaseSPIRVTargetInfo {
596678
public:

clang/test/CodeGenSYCL/kernel-arg-accessor-pointer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -triple spir64-unknown-unknown -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
2+
// 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
3+
// 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
4+
// 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
5+
// 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
26

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

clang/test/Preprocessor/sycl-macro-target-specific.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// RUN: | FileCheck --check-prefix=CHECK-NVPTX-NEG %s
1313
// RUN: %clang_cc1 %s -fsycl-is-device -triple amdgcn-amdhsa-amdhsa -E -dM \
1414
// RUN: | FileCheck --check-prefix=CHECK-NVPTX-NEG %s
15+
// RUN: %clang_cc1 %s -fsycl-is-device -triple spir64-unknown-unknown -aux-triple aarch64-pc-windows-msvc -E -dM \
16+
// RUN: | FileCheck --check-prefixes=CHECK-NVPTX-NEG,CHECK-ARM64 %s
1517
// CHECK-NVPTX: #define __NVPTX__
1618
// CHECK-NVPTX-NEG-NOT: #define __NVPTX__
1719

@@ -27,6 +29,8 @@
2729
// RUN: | FileCheck --check-prefix=CHECK-AMDGPU-NEG %s
2830
// RUN: %clang_cc1 %s -fsycl-is-device -triple spir64_fpga-unknown-unknown -E -dM \
2931
// RUN: | FileCheck --check-prefix=CHECK-AMDGPU-NEG %s
32+
// RUN: %clang_cc1 %s -fsycl-is-device -triple spir64-unknown-unknown -aux-triple aarch64-pc-windows-msvc -E -dM \
33+
// RUN: | FileCheck --check-prefixes=CHECK-AMDGPU-NEG,CHECK-ARM64 %s
3034
// CHECK-AMDGPU: #define __AMDGPU__
3135
// CHECK-AMDGPU-NEG-NOT: #define __AMDGPU__
3236

@@ -72,3 +76,5 @@
7276
// RUN: | FileCheck --check-prefix=CHECK-DISABLE-FALLBACK-ASSERT-NEG %s
7377
// CHECK-DISABLE-FALLBACK-ASSERT: #define SYCL_DISABLE_FALLBACK_ASSERT
7478
// CHECK-DISABLE-FALLBACK-ASSERT-NEG-NOT: #define SYCL_DISABLE_FALLBACK_ASSERT
79+
//
80+
// CHECK-ARM64: #define _M_ARM64

0 commit comments

Comments
 (0)