Skip to content

[SYCL] Hide inline definitions of stdio functions #18174

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 1 commit into
base: sycl
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions clang/lib/Frontend/InitPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,13 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
Builder.defineMacro("__ENABLE_USM_ADDR_SPACE__");
Builder.defineMacro("SYCL_DISABLE_FALLBACK_ASSERT");
}

// Despite the name, DeviceTriple is not necessarily the device triple.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That comment can break a brain, could you please explain the whole situation here instead?
Also, should that only happen for native cpu?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also consider enabling this macro in SYCL headers instead? It is our library implementation can't deal with this, not any SYCL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That comment can break a brain, could you please explain the whole situation here instead?

This relates to

// FIXME: This will create multiple definitions for most of the predefined
// macros. This is not the right way to handle this.
if ((LangOpts.CUDA || LangOpts.OpenMPIsTargetDevice ||
LangOpts.SYCLIsDevice) &&
PP.getAuxTargetInfo())
InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts,
PP.getPreprocessorOpts(), Builder);
InitializePredefinedMacros(PP.getTargetInfo(), LangOpts, FEOpts,
PP.getPreprocessorOpts(), Builder);
, the way InitializePredefinedMacros called is not exactly ideal. It gets called twice, once for the host, once for the device, and the macros from both are used.

Also, should that only happen for native cpu?

This can simplify handling for all SYCL targets, not just NativeCPU.

Should we also consider enabling this macro in SYCL headers instead? It is our library implementation can't deal with this, not any SYCL.

We cannot enable this macro in SYCL headers since the MSVC system headers may be included before any SYCL header is included, so the macro would be defined too late.

Do we support any SYCL library other than our own?

if (DeviceTriple.isWindowsMSVCEnvironment()) {
// MSVC inline definitions of stdio functions should not be used for SYCL
// device code.
Builder.defineMacro("_NO_CRT_STDIO_INLINE");
}
} else if (LangOpts.SYCLIsHost && LangOpts.SYCLESIMDBuildHostCode) {
Builder.defineMacro("__ESIMD_BUILD_HOST_CODE");
}
Expand Down