Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -7266,6 +7266,8 @@ defm sycl_allow_device_image_dependencies: BoolOptionWithoutMarshalling<"f", "sy
def fsycl_dump_device_code_EQ : Joined<["-"], "fsycl-dump-device-code=">,
Flags<[NoXarchOption]>,
HelpText<"Dump device code into the user provided directory.">;
def fsyclbin : Flag<["-"], "fsyclbin">,
HelpText<"Create a SYCLBIN file">;
} // let Group = sycl_Group

// FIXME: -fsycl-explicit-simd is deprecated. remove it when support is dropped.
Expand Down
31 changes: 31 additions & 0 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8414,6 +8414,19 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
C.MakeAction<LinkJobAction>(OffloadActions, types::TY_HIP_FATBIN);
DDep.add(*FatbinAction, *C.getSingleOffloadToolChain<Action::OFK_HIP>(),
nullptr, Action::OFK_HIP);
} else if (C.isOffloadingHostKind(Action::OFK_SYCL) &&
Args.hasArg(options::OPT_fsyclbin)) {
// With '-fsyclbin', package all the offloading actions into a single output
// that is sent to the clang-linker-wrapper.
Action *PackagerAction =
C.MakeAction<OffloadPackagerJobAction>(OffloadActions, types::TY_Image);
ActionList PackagerActions;
PackagerActions.push_back(PackagerAction);
Action *LinkAction = C.MakeAction<LinkerWrapperJobAction>(
PackagerActions, types::TY_Image);
DDep.add(*LinkAction, *C.getSingleOffloadToolChain<Action::OFK_Host>(),
nullptr, C.getActiveOffloadKinds());
return C.MakeAction<OffloadAction>(DDep, types::TY_Nothing);
} else {
// Package all the offloading actions into a single output that can be
// embedded in the host and linked.
Expand Down Expand Up @@ -10037,6 +10050,24 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
else
BaseName = llvm::sys::path::filename(BasePath);

// When compiling with -fsyclbin, maintain a simple output file name for the
// resulting image. A '.syclbin' extension is intended to be added during
// the linking step with the clang-linker-wrapper.
if (JA.getOffloadingDeviceKind() == Action::OFK_SYCL &&
C.getArgs().hasArgNoClaim(options::OPT_fsyclbin) &&
JA.getType() == types::TY_Image) {
const char *SYCLBinOutput;
if (IsCLMode()) {
// clang-cl uses BaseName for the executable name.
SYCLBinOutput =
MakeCLOutputFilename(C.getArgs(), "", BaseName, types::TY_Image);
} else {
SmallString<128> Output(getDefaultImageName());
SYCLBinOutput = C.getArgs().MakeArgString(Output.c_str());
}
return C.addResultFile(SYCLBinOutput, &JA);
}

// Determine what the derived output name should be.
const char *NamedOutput;

Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11733,6 +11733,9 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back(
Args.MakeArgString("--sycl-target-link-options=" + LinkOptString));
}
// Add option to enable creating of the .syclbin file
if (Args.hasArg(options::OPT_fsyclbin))
CmdArgs.push_back(Args.MakeArgString("--syclbin"));
}

// Construct the link job so we can wrap around it.
Expand Down
30 changes: 30 additions & 0 deletions clang/test/Driver/fsyclbin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/// Tests behaviors of -fsyclbin

/// -fsyclbin is only used with the new offloading model.
// RUN: %clangxx -fsycl -fsyclbin --no-offload-new-driver %s -### 2>&1 \
// RUN: | FileCheck %s --check-prefix=UNUSED
// UNUSED: warning: argument unused during compilation: '-fsyclbin'

/// Check tool invocation contents.
// RUN: %clangxx -fsycl -fsyclbin --offload-new-driver %s -### 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK_TOOLS
// RUN: %clang_cl -fsycl -fsyclbin --offload-new-driver %s -### 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK_TOOLS
// CHECK_TOOLS: clang-offload-packager
// CHECK_TOOLS-SAME: --image=file={{.*}}.bc,triple=spir64-unknown-unknown
// CHECK_TOOLS-SAME: kind=sycl
// CHECK_TOOLS: clang-linker-wrapper
// CHECK_TOOLS-SAME: --syclbin

/// Check compilation phases, only device compile should be performed
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl -fsyclbin \
// RUN: --offload-new-driver %s -ccc-print-phases 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK_PHASES
// CHECK_PHASES: 0: input, "{{.*}}", c++, (device-sycl)
// CHECK_PHASES: 1: preprocessor, {0}, c++-cpp-output, (device-sycl)
// CHECK_PHASES: 2: compiler, {1}, ir, (device-sycl)
// CHECK_PHASES: 3: backend, {2}, ir, (device-sycl)
// CHECK_PHASES: 4: offload, "device-sycl (spir64-unknown-unknown)" {3}, ir
// CHECK_PHASES: 5: clang-offload-packager, {4}, image, (device-sycl)
// CHECK_PHASES: 6: clang-linker-wrapper, {5}, image, (device-sycl)
// CHECK_PHASES: 7: offload, "device-sycl (x86_64-unknown-linux-gnu)" {6}, none
Loading