Skip to content

[SYCL][Driver] Fix issue that sycl is not able to print internal defi… #2188

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

Merged
merged 7 commits into from
Aug 3, 2020
Merged
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
20 changes: 18 additions & 2 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5740,6 +5740,7 @@ InputInfo Driver::BuildJobsForActionNoCache(

// Only use pipes when there is exactly one input.
InputInfoList InputInfos;
bool JobForPreprocessToStdout = false;
for (const Action *Input : Inputs) {
// Treat dsymutil and verify sub-jobs as being at the top-level too, they
// shouldn't get temporary output names.
Expand All @@ -5750,6 +5751,11 @@ InputInfo Driver::BuildJobsForActionNoCache(
C, Input, TC, BoundArch, SubJobAtTopLevel, MultipleArchs, LinkingOutput,
CachedResults, A->getOffloadingDeviceKind()));
}
// Check if we are in sub-work for preprocessing for host side. If so we will
// add another job to print information to terminal later.
if (!AtTopLevel && A->getKind() == Action::PreprocessJobClass &&
C.getJobs().size() == 1)
JobForPreprocessToStdout = true;

// Always use the first input as the base input.
const char *BaseInput = InputInfos[0].getBaseInput();
Expand Down Expand Up @@ -5784,6 +5790,7 @@ InputInfo Driver::BuildJobsForActionNoCache(

// Determine the place to write output to, if any.
InputInfo Result;
InputInfo ResultForPreprocessToStdout;
InputInfoList UnbundlingResults;
if (auto *UA = dyn_cast<OffloadUnbundlingJobAction>(JA)) {
// If we have an unbundling job, we need to create results for all the
Expand Down Expand Up @@ -5945,6 +5952,8 @@ InputInfo Driver::BuildJobsForActionNoCache(
AtTopLevel, MultipleArchs,
OffloadingPrefix),
BaseInput);
if (JobForPreprocessToStdout)
ResultForPreprocessToStdout = InputInfo(A, "-", BaseInput);
}

if (CCCPrintBindings && !CCGenDiagnostics) {
Expand All @@ -5967,12 +5976,19 @@ InputInfo Driver::BuildJobsForActionNoCache(
llvm::errs() << "] \n";
}
} else {
if (UnbundlingResults.empty())
if (UnbundlingResults.empty()) {
T->ConstructJob(
C, *JA, Result, InputInfos,
C.getArgsForToolChain(TC, BoundArch, JA->getOffloadingDeviceKind()),
LinkingOutput);
else
// Add another job to print information to terminal for host side.
if (JobForPreprocessToStdout) {
T->ConstructJob(
C, *JA, ResultForPreprocessToStdout, InputInfos,
C.getArgsForToolChain(TC, BoundArch, JA->getOffloadingDeviceKind()),
LinkingOutput);
}
} else
T->ConstructJobMultipleOutputs(
C, *JA, UnbundlingResults, InputInfos,
C.getArgsForToolChain(TC, BoundArch, JA->getOffloadingDeviceKind()),
Expand Down
5 changes: 5 additions & 0 deletions clang/test/Driver/print-internal-defines-for-sycl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Test if clang is able to print internal defines in SYCL mode
//
// RUN: %clangxx -fsycl -dM -E -x c++ %s 2>&1 \
// RUN: | FileCheck --check-prefix CHECK-PRINT-INTERNAL-DEFINES %s
// CHECK-PRINT-INTERNAL-DEFINES: #define