Skip to content

Commit 1e60aa6

Browse files
committed
[SYCL][NFC] Added SPIRSYCLDevice target.
Signed-off-by: Vladimir Lazarev <[email protected]>
1 parent 03354a2 commit 1e60aa6

File tree

2 files changed

+55
-10
lines changed

2 files changed

+55
-10
lines changed

clang/lib/Basic/Targets.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -558,17 +558,29 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple,
558558
}
559559

560560
case llvm::Triple::spir: {
561-
if (Triple.getOS() != llvm::Triple::UnknownOS ||
562-
Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
563-
return nullptr;
561+
if (Triple.getEnvironment() == llvm::Triple::SYCLDevice) {
562+
switch (os) {
563+
case llvm::Triple::Linux:
564+
return new LinuxTargetInfo<SPIR32SYCLDeviceTargetInfo>(Triple, Opts);
565+
default:
566+
return new SPIR32SYCLDeviceTargetInfo(Triple, Opts);
567+
}
568+
}
564569
return new SPIR32TargetInfo(Triple, Opts);
565570
}
571+
566572
case llvm::Triple::spir64: {
567-
if (Triple.getOS() != llvm::Triple::UnknownOS ||
568-
Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
569-
return nullptr;
573+
if (Triple.getEnvironment() == llvm::Triple::SYCLDevice) {
574+
switch (os) {
575+
case llvm::Triple::Linux:
576+
return new LinuxTargetInfo<SPIR64SYCLDeviceTargetInfo>(Triple, Opts);
577+
default:
578+
return new SPIR64SYCLDeviceTargetInfo(Triple, Opts);
579+
}
580+
}
570581
return new SPIR64TargetInfo(Triple, Opts);
571582
}
583+
572584
case llvm::Triple::wasm32:
573585
if (Triple.getSubArch() != llvm::Triple::NoSubArch ||
574586
Triple.getVendor() != llvm::Triple::UnknownVendor ||

clang/lib/Basic/Targets/SPIR.h

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
3838
public:
3939
SPIRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
4040
: TargetInfo(Triple) {
41-
assert(getTriple().getOS() == llvm::Triple::UnknownOS &&
42-
"SPIR target must use unknown OS");
43-
assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
44-
"SPIR target must use unknown environment type");
4541
TLSSupported = false;
4642
VLASupported = false;
4743
LongWidth = LongAlign = 64;
@@ -127,6 +123,43 @@ class LLVM_LIBRARY_VISIBILITY SPIR64TargetInfo : public SPIRTargetInfo {
127123
void getTargetDefines(const LangOptions &Opts,
128124
MacroBuilder &Builder) const override;
129125
};
126+
127+
class LLVM_LIBRARY_VISIBILITY SPIR32SYCLDeviceTargetInfo
128+
: public SPIR32TargetInfo {
129+
public:
130+
SPIR32SYCLDeviceTargetInfo(const llvm::Triple &Triple,
131+
const TargetOptions &Opts)
132+
: SPIR32TargetInfo(Triple, Opts) {
133+
// This is workaround for exception_ptr class.
134+
// Exceptions is not allowed in sycl device code but we should be able
135+
// to parse host code. So we allow compilation of exception_ptr but
136+
// if exceptions are used in device code we should emit a diagnostic.
137+
MaxAtomicInlineWidth = 32;
138+
// This is workaround for mutex class.
139+
// I'm not sure about this hack but I guess that mutex_class is same
140+
// problem.
141+
TLSSupported = true;
142+
}
143+
};
144+
145+
class LLVM_LIBRARY_VISIBILITY SPIR64SYCLDeviceTargetInfo
146+
: public SPIR64TargetInfo {
147+
public:
148+
SPIR64SYCLDeviceTargetInfo(const llvm::Triple &Triple,
149+
const TargetOptions &Opts)
150+
: SPIR64TargetInfo(Triple, Opts) {
151+
// This is workaround for exception_ptr class.
152+
// Exceptions is not allowed in sycl device code but we should be able
153+
// to parse host code. So we allow compilation of exception_ptr but
154+
// if exceptions are used in device code we should emit a diagnostic.
155+
MaxAtomicInlineWidth = 64;
156+
// This is workaround for mutex class.
157+
// I'm not sure about this hack but I guess that mutex_class is same
158+
// problem.
159+
TLSSupported = true;
160+
}
161+
};
162+
130163
} // namespace targets
131164
} // namespace clang
132165
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H

0 commit comments

Comments
 (0)