Skip to content

[SYCL] Enable programs that include system headers on Windows #369

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

Closed
wants to merge 1 commit into from
Closed
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
24 changes: 21 additions & 3 deletions clang/lib/Basic/Targets/SPIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ static const unsigned SYCLAddrSpaceMap[] = {
};

class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
private:
bool IsWindowsSYCL;
public:
SPIRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
: TargetInfo(Triple) {
IsWindowsSYCL = false;
TLSSupported = false;
VLASupported = false;
LongWidth = LongAlign = 64;
Expand Down Expand Up @@ -103,12 +106,17 @@ class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
}

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

CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
if (CC == CC_X86VectorCall && isWindows_SYCL())
// Permit CC_X86VectorCall which is used in Microsoft headers
return CCCR_OK;
return (CC == CC_SpirFunction || CC == CC_OpenCLKernel) ? CCCR_OK
: CCCR_Warning;
: CCCR_Warning;
}

CallingConv getDefaultCallingConv(CallingConvMethodType MT) const override {
Expand All @@ -120,6 +128,9 @@ class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
// for SPIR since it is a generic target.
getSupportedOpenCLOpts().supportAll();
}
void setWindows_SYCL(bool Value) { IsWindowsSYCL = Value; }
bool isWindows_SYCL(void) const { return IsWindowsSYCL; }

};
class LLVM_LIBRARY_VISIBILITY SPIR32TargetInfo : public SPIRTargetInfo {
public:
Expand All @@ -141,8 +152,15 @@ class LLVM_LIBRARY_VISIBILITY SPIR64TargetInfo : public SPIRTargetInfo {
SPIR64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
: SPIRTargetInfo(Triple, Opts) {
PointerWidth = PointerAlign = 64;
SizeType = TargetInfo::UnsignedLong;
PtrDiffType = IntPtrType = TargetInfo::SignedLong;
SizeType = TargetInfo::UnsignedLongLong;
Int64Type = TargetInfo::SignedLongLong;
PtrDiffType = IntPtrType = IntMaxType = Int64Type;
llvm::Triple HT(Opts.HostTriple);
if (HT.isWindowsMSVCEnvironment() && Triple.isSYCLDeviceEnvironment()) {
setWindows_SYCL(true);
WCharType = UnsignedShort;
LongWidth = LongAlign = 32;
}
resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-"
"v96:128-v192:256-v256:256-v512:512-v1024:1024");
}
Expand Down
24 changes: 20 additions & 4 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3550,14 +3550,30 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,

if (UseSYCLTriple) {
// We want to compile sycl kernels.
if (types::isCXX(Input.getType()))
CmdArgs.push_back("-std=c++11");
CmdArgs.push_back("-fsycl-is-device");
// Pass the triple of host when doing SYCL
std::string NormalizedTriple =
llvm::Triple(llvm::sys::getProcessTriple()).normalize();
auto AuxT = llvm::Triple(llvm::sys::getProcessTriple());
std::string NormalizedTriple = AuxT.normalize();
CmdArgs.push_back("-aux-triple");
CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));

bool IsMSVC = AuxT.isWindowsMSVCEnvironment();
if (types::isCXX(Input.getType()))
CmdArgs.push_back(IsMSVC ? "-std=c++14" : "-std=c++11");
if (IsMSVC) {
CmdArgs.push_back("-fms-extensions");
VersionTuple MSVT = TC.computeMSVCVersion(&D, Args);
if (!MSVT.empty())
CmdArgs.push_back(Args.MakeArgString("-fms-compatibility-version=" +
MSVT.getAsString()));
else {
const char *LowestMSVCSupported =
"191025017"; // VS2017 v15.0 (initial release)
CmdArgs.push_back(Args.MakeArgString(
Twine("-fms-compatibility-version=") + LowestMSVCSupported));
}
}

CmdArgs.push_back("-disable-llvm-passes");
if (Args.hasFlag(options::OPT_fsycl_allow_func_ptr,
options::OPT_fno_sycl_allow_func_ptr, false)) {
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3414,6 +3414,10 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
if (LangOpts.OpenMPIsDevice)
Res.getTargetOpts().HostTriple = Res.getFrontendOpts().AuxTriple;

// Set the triple of the host for SYCL device compile.
if (LangOpts.SYCLIsDevice)
Res.getTargetOpts().HostTriple = Res.getFrontendOpts().AuxTriple;

// FIXME: Override value name discarding when asan or msan is used because the
// backend passes depend on the name of the alloca in order to print out
// names.
Expand Down
2 changes: 1 addition & 1 deletion clang/test/SemaSYCL/mangle-kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ int main() {

// CHECK: _ZTS10SimpleVaddIiE
// CHECK: _ZTS10SimpleVaddIdE
// CHECK-64: _ZTS10SimpleVaddImE
// CHECK-64: _ZTS10SimpleVaddIyE
// CHECK-32: _ZTS10SimpleVaddIjE
7 changes: 7 additions & 0 deletions clang/test/SemaSYCL/msvc-fixes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %clang_cc1 -triple spir64-unknown-windows-sycldevice -fsycl-is-device -aux-triple x86_64-pc-windows-msvc -fsyntax-only -verify %s
// expected-no-diagnostics

void foo(__builtin_va_list bvl) {
char * VaList = bvl;
static_assert(sizeof(wchar_t) == 2, "sizeof wchar is 2 on Windows");
}