Skip to content
Merged
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
55 changes: 17 additions & 38 deletions clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1061,44 +1061,23 @@ static Expected<StringRef> runLLVMToSPIRVTranslation(StringRef File,
return *TempFileOrErr;
}

/// Adds all AOT backend options required for SYCL AOT compilation step to
/// \p CmdArgs.
/// \p Args is passed to provide MakeArgString function for creating persistent
/// argument string storage.
/// \p IsCPU is a bool used to distinguish whether the target is an Intel GPU or
/// Intel CPU.
/// Adds ocloc options required for SYCL AOT compilation step to \p CmdArgs.
/// ocloc -options takes arguments in the form of '-options "-g
/// -cl-opt-disable"' where each argument is separated with spaces. split
/// function here returns a pair with everything before the separator
/// ("-options") in the first member of the pair, and everything after the
/// separator in the second part of the pair. The separator is not included in
/// any of them.
/// \p BackendOptions is a string containing backend compilation options. For
/// example, "-options -cl-opt-disable".
static void addSYCLBackendOptions(const ArgList &Args,
SmallVector<StringRef, 8> &CmdArgs,
bool IsCPU, StringRef BackendOptions) {
if (IsCPU) {
BackendOptions.split(CmdArgs, " ", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
} else {
// ocloc -options takes arguments in the form of '-options "-g
// -cl-opt-disable"' where each argument is separated with spaces.
// split function here returns a pair with everything before the separator
// ("-options") in the first member of the pair, and everything after the
// separator in the second part of the pair. The separator is not included
// in any of them.
auto [BeforeOptions, AfterOptions] = BackendOptions.split("-options ");
// Only add if not empty, an empty arg can lead to ocloc errors.
if (!BeforeOptions.empty()) {
SmallVector<StringRef, 8> BeforeArgs;
BeforeOptions.split(BeforeArgs, " ", /*MaxSplit=*/-1,
/*KeepEmpty=*/false);
for (const auto &string : BeforeArgs) {
CmdArgs.push_back(string);
}
}
if (!AfterOptions.empty()) {
CmdArgs.push_back("-options");
// Split the options string by spaces and rejoin to normalize whitespace
SmallVector<StringRef, 8> AfterArgs;
AfterOptions.split(AfterArgs, " ", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
std::string JoinedOptions = llvm::join(AfterArgs, " ");
CmdArgs.push_back(Args.MakeArgString(JoinedOptions));
}
static void addOclocOptions(StringRef BackendOptions,
SmallVector<StringRef, 8> &CmdArgs) {
auto [BeforeOptions, AfterOptions] = BackendOptions.split("-options ");
BeforeOptions.split(CmdArgs, " ", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
// Only add if not empty, an empty arg can lead to ocloc errors.
if (!AfterOptions.empty()) {
CmdArgs.push_back("-options");
CmdArgs.push_back(AfterOptions);
}
}

Expand All @@ -1121,7 +1100,7 @@ static Expected<StringRef> runAOTCompileIntelCPU(StringRef InputFile,

CmdArgs.push_back(*OpenCLAOTPath);
CmdArgs.push_back("--device=cpu");
addSYCLBackendOptions(Args, CmdArgs, /* IsCPU */ true, BackendOptions);
BackendOptions.split(CmdArgs, " ", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
// Create a new file to write the translated file to.
auto TempFileOrErr =
createOutputFile(sys::path::filename(ExecutableName), "out");
Expand Down Expand Up @@ -1161,7 +1140,7 @@ static Expected<StringRef> runAOTCompileIntelGPU(StringRef InputFile,
CmdArgs.push_back("-device");
CmdArgs.push_back(Arch);
}
addSYCLBackendOptions(Args, CmdArgs, /* IsCPU */ false, BackendOptions);
addOclocOptions(BackendOptions, CmdArgs);
// Create a new file to write the translated file to.
auto TempFileOrErr =
createOutputFile(sys::path::filename(ExecutableName), "out");
Expand Down
Loading