Skip to content

Commit

Permalink
[SYCL][NFC] Added SPIRSYCLDevice target.
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Lazarev <[email protected]>
  • Loading branch information
vladimirlaz committed Jan 22, 2019
1 parent 03354a2 commit 1e60aa6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 10 deletions.
24 changes: 18 additions & 6 deletions clang/lib/Basic/Targets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,17 +558,29 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple,
}

case llvm::Triple::spir: {
if (Triple.getOS() != llvm::Triple::UnknownOS ||
Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
return nullptr;
if (Triple.getEnvironment() == llvm::Triple::SYCLDevice) {
switch (os) {
case llvm::Triple::Linux:
return new LinuxTargetInfo<SPIR32SYCLDeviceTargetInfo>(Triple, Opts);
default:
return new SPIR32SYCLDeviceTargetInfo(Triple, Opts);
}
}
return new SPIR32TargetInfo(Triple, Opts);
}

case llvm::Triple::spir64: {
if (Triple.getOS() != llvm::Triple::UnknownOS ||
Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
return nullptr;
if (Triple.getEnvironment() == llvm::Triple::SYCLDevice) {
switch (os) {
case llvm::Triple::Linux:
return new LinuxTargetInfo<SPIR64SYCLDeviceTargetInfo>(Triple, Opts);
default:
return new SPIR64SYCLDeviceTargetInfo(Triple, Opts);
}
}
return new SPIR64TargetInfo(Triple, Opts);
}

case llvm::Triple::wasm32:
if (Triple.getSubArch() != llvm::Triple::NoSubArch ||
Triple.getVendor() != llvm::Triple::UnknownVendor ||
Expand Down
41 changes: 37 additions & 4 deletions clang/lib/Basic/Targets/SPIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
public:
SPIRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
: TargetInfo(Triple) {
assert(getTriple().getOS() == llvm::Triple::UnknownOS &&
"SPIR target must use unknown OS");
assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
"SPIR target must use unknown environment type");
TLSSupported = false;
VLASupported = false;
LongWidth = LongAlign = 64;
Expand Down Expand Up @@ -127,6 +123,43 @@ class LLVM_LIBRARY_VISIBILITY SPIR64TargetInfo : public SPIRTargetInfo {
void getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const override;
};

class LLVM_LIBRARY_VISIBILITY SPIR32SYCLDeviceTargetInfo
: public SPIR32TargetInfo {
public:
SPIR32SYCLDeviceTargetInfo(const llvm::Triple &Triple,
const TargetOptions &Opts)
: SPIR32TargetInfo(Triple, Opts) {
// This is workaround for exception_ptr class.
// Exceptions is not allowed in sycl device code but we should be able
// to parse host code. So we allow compilation of exception_ptr but
// if exceptions are used in device code we should emit a diagnostic.
MaxAtomicInlineWidth = 32;
// This is workaround for mutex class.
// I'm not sure about this hack but I guess that mutex_class is same
// problem.
TLSSupported = true;
}
};

class LLVM_LIBRARY_VISIBILITY SPIR64SYCLDeviceTargetInfo
: public SPIR64TargetInfo {
public:
SPIR64SYCLDeviceTargetInfo(const llvm::Triple &Triple,
const TargetOptions &Opts)
: SPIR64TargetInfo(Triple, Opts) {
// This is workaround for exception_ptr class.
// Exceptions is not allowed in sycl device code but we should be able
// to parse host code. So we allow compilation of exception_ptr but
// if exceptions are used in device code we should emit a diagnostic.
MaxAtomicInlineWidth = 64;
// This is workaround for mutex class.
// I'm not sure about this hack but I guess that mutex_class is same
// problem.
TLSSupported = true;
}
};

} // namespace targets
} // namespace clang
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H

0 comments on commit 1e60aa6

Please sign in to comment.