Skip to content

Commit

Permalink
Merge from 'sycl' to 'sycl-web' (#6)
Browse files Browse the repository at this point in the history
As part of the conflict resolution, reverted the following temporary commits
done to unblock the last llorg => sycl pulldown:
9399945 Revert "[Preprocessor] Implement -fminimize-whitespace."
fbdceb1 [hwasan] Change test-run line to check only NewPM pass behavior

  CONFLICT (modify/delete): clang/test/Preprocessor/minimize-whitespace.c deleted in 8da85f6 and modified in HEAD. Version HEAD of clang/test/Preprocessor/minimize-whitespace.c left in tree.
  CONFLICT (content): Merge conflict in clang/test/CodeGen/hwasan-stack-safety-analysis.c
  CONFLICT (content): Merge conflict in clang/lib/Frontend/PrintPreprocessedOutput.cpp
  • Loading branch information
abhinavgaba committed Aug 2, 2021
2 parents 6bd6acc + 8da85f6 commit bcfb6e7
Show file tree
Hide file tree
Showing 81 changed files with 2,357 additions and 959 deletions.
5 changes: 3 additions & 2 deletions buildbot/dependency.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ ocl_cpu_rt_ver_win=2021.12.6.0.19
# https://github.com/intel/compute-runtime/releases/tag/21.26.20194
ocl_gpu_rt_ver=21.26.20194
# Same GPU driver supports Level Zero and OpenCL
# https://downloadmirror.intel.com/30579/a08/igfx_win_100.9684.zip
# https://downloadmirror.intel.com/30381/a08/igfx_win10_100.9466.zip
ocl_gpu_rt_ver_win=27.20.100.9466
ocl_gpu_rt_ver_win=30.0.100.9684
intel_sycl_ver=build

# TBB binaries can be built from sources following instructions under
Expand All @@ -31,7 +32,7 @@ ocloc_ver_win=27.20.100.9168
cpu_driver_lin=2021.12.6.0.19
cpu_driver_win=2021.12.6.0.19
gpu_driver_lin=21.26.20194
gpu_driver_win=27.20.100.9466
gpu_driver_win=30.0.100.9684
fpga_driver_lin=2021.12.6.0.19
fpga_driver_win=2021.12.6.0.19
# NVidia CUDA driver
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Driver/Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ class SYCLPostLinkJobAction : public JobAction {
void anchor() override;

public:
// The tempfiletable management relies on a shadowing the main file type by
// The tempfiletable management relies on shadowing the main file type by
// types::TY_Tempfiletable. The problem of shadowing is it prevents its
// integration with clang tools that relies on the file type to properly set
// args.
Expand Down
19 changes: 19 additions & 0 deletions clang/include/clang/Driver/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,21 @@ class Driver {
FPGAEmulationMode = IsEmulation;
}

/// The inclusion of the default SYCL device triple is dependent on either
/// the discovery of an existing object/archive that contains the device code
/// or if a user explicitly turns this on with -fsycl-add-spirv.
/// We need to keep track of this so any use of any generic target option
/// setting is only applied to the user specified triples.
bool SYCLDefaultTripleImplied = false;
void setSYCLDefaultTriple(bool IsDefaultImplied) {
SYCLDefaultTripleImplied = IsDefaultImplied;
}

/// Returns true if an offload binary is found that contains the default
/// triple for SYCL (spir64)
bool checkForSYCLDefaultDevice(Compilation &C,
llvm::opt::DerivedArgList &Args) const;

/// Returns true if an offload static library is found.
bool checkForOffloadStaticLib(Compilation &C,
llvm::opt::DerivedArgList &Args) const;
Expand Down Expand Up @@ -708,6 +723,10 @@ class Driver {
/// FPGA Emulation. This is only used for SYCL offloading to FPGA device.
bool isFPGAEmulationMode() const { return FPGAEmulationMode; };

/// isSYCLDefaultTripleImplied - The default SYCL triple (spir64) has been
/// added or should be added given proper criteria.
bool isSYCLDefaultTripleImplied() const { return SYCLDefaultTripleImplied; };

/// addIntegrationFiles - Add the integration files that will be populated
/// by the device compilation and used by the host compile.
void addIntegrationFiles(StringRef IntHeaderName, StringRef IntFooterName,
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -2660,6 +2660,9 @@ def fno_sycl_use_footer : Flag<["-"], "fno-sycl-use-footer">, Flags<[CoreOption]
def fsycl_footer_path_EQ : Joined<["-"], "fsycl-footer-path=">,
Flags<[CoreOption]>, HelpText<"Specify the location of the temporary "
"source file with the included integration footer.">;
def fno_sycl_link_spirv : Flag<["-"], "fno-sycl-link-spirv">,
Flags<[CoreOption]>, HelpText<"Disable adding of the default (spir64) triple "
"when discovered in user specified objects and archives.">;
def fsyntax_only : Flag<["-"], "fsyntax-only">,
Flags<[NoXarchOption,CoreOption,CC1Option,FC1Option]>, Group<Action_Group>;
def ftabstop_EQ : Joined<["-"], "ftabstop=">, Group<f_Group>;
Expand Down
85 changes: 79 additions & 6 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,23 @@ static bool isValidSYCLTriple(llvm::Triple T) {
return true;
}

static void addSYCLDefaultTriple(Compilation &C,
SmallVectorImpl<llvm::Triple> &SYCLTriples) {
if (!C.getDriver().isSYCLDefaultTripleImplied())
return;
for (const auto &SYCLTriple : SYCLTriples) {
if (SYCLTriple.getSubArch() == llvm::Triple::NoSubArch &&
SYCLTriple.isSPIR())
return;
// If we encounter a known non-spir* target, do not add the default triple.
if (SYCLTriple.isNVPTX() || SYCLTriple.isAMDGCN())
return;
}
// Add the default triple as it was not found.
llvm::Triple DefaultTriple = C.getDriver().MakeSYCLDeviceTriple("spir64");
SYCLTriples.insert(SYCLTriples.begin(), DefaultTriple);
}

void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
InputList &Inputs) {

Expand Down Expand Up @@ -911,6 +928,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
FoundNormalizedTriples[NormalizedName] = Val;
UniqueSYCLTriplesVec.push_back(TT);
}
addSYCLDefaultTriple(C, UniqueSYCLTriplesVec);
} else
Diag(clang::diag::warn_drv_empty_joined_argument)
<< SYCLTargetsValues->getAsString(C.getInputArgs());
Expand Down Expand Up @@ -969,8 +987,10 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
else if (HasValidSYCLRuntime)
// Triple for -fintelfpga is spir64_fpga-unknown-unknown-sycldevice.
SYCLTargetArch = SYCLfpga ? "spir64_fpga" : "spir64";
if (!SYCLTargetArch.empty())
if (!SYCLTargetArch.empty()) {
UniqueSYCLTriplesVec.push_back(MakeSYCLDeviceTriple(SYCLTargetArch));
addSYCLDefaultTriple(C, UniqueSYCLTriplesVec);
}
}
// We'll need to use the SYCL and host triples as the key into
// getOffloadingDeviceToolChain, because the device toolchains we're
Expand Down Expand Up @@ -1403,6 +1423,11 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
if (checkForOffloadStaticLib(*C, *TranslatedArgs))
setOffloadStaticLibSeen();

// Check for any objects/archives that need to be compiled with the default
// triple.
if (checkForSYCLDefaultDevice(*C, *TranslatedArgs))
setSYCLDefaultTriple(true);

// Populate the tool chains for the offloading devices, if any.
CreateOffloadingDeviceToolChains(*C, Inputs);

Expand All @@ -1413,7 +1438,8 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
const ToolChain *TC = SYCLTCRange.first->second;
const toolchains::SYCLToolChain *SYCLTC =
static_cast<const toolchains::SYCLToolChain *>(TC);
SYCLTC->TranslateBackendTargetArgs(*TranslatedArgs, TargetArgs);
SYCLTC->TranslateBackendTargetArgs(SYCLTC->getTriple(), *TranslatedArgs,
TargetArgs);
for (StringRef ArgString : TargetArgs) {
if (ArgString.equals("-hardware") || ArgString.equals("-simulation")) {
setFPGAEmulationMode(false);
Expand Down Expand Up @@ -2747,6 +2773,30 @@ bool hasFPGABinary(Compilation &C, std::string Object, types::ID Type) {
return runBundler(BundlerArgs, C);
}

static bool hasSYCLDefaultSection(Compilation &C, const StringRef &File) {
// Do not do the check if the file doesn't exist
if (!llvm::sys::fs::exists(File))
return false;

bool IsArchive = isStaticArchiveFile(File);
if (!(IsArchive || isObjectFile(File.str())))
return false;

llvm::Triple TT(C.getDriver().MakeSYCLDeviceTriple("spir64"));
// Checking uses -check-section option with the input file, no output
// file and the target triple being looked for.
const char *Targets =
C.getArgs().MakeArgString(Twine("-targets=sycl-") + TT.str());
const char *Inputs =
C.getArgs().MakeArgString(Twine("-inputs=") + File.str());
// Always use -type=ao for bundle checking. The 'bundles' are
// actually archives.
SmallVector<StringRef, 6> BundlerArgs = {"clang-offload-bundler",
IsArchive ? "-type=ao" : "-type=o",
Targets, Inputs, "-check-section"};
return runBundler(BundlerArgs, C);
}

static bool hasOffloadSections(Compilation &C, const StringRef &Archive,
DerivedArgList &Args) {
// Do not do the check if the file doesn't exist
Expand Down Expand Up @@ -2777,14 +2827,15 @@ static bool optionMatches(const std::string &Option,
// Process linker inputs for use with offload static libraries. We are only
// handling options and explicitly named static archives as these need to be
// partially linked.
static SmallVector<const char *, 16> getLinkerArgs(Compilation &C,
DerivedArgList &Args) {
static SmallVector<const char *, 16>
getLinkerArgs(Compilation &C, DerivedArgList &Args, bool IncludeObj = false) {
SmallVector<const char *, 16> LibArgs;
for (const auto *A : Args) {
std::string FileName = A->getAsString(Args);
if (A->getOption().getKind() == Option::InputClass) {
StringRef Value(A->getValue());
if (isStaticArchiveFile(Value)) {
if (isStaticArchiveFile(Value) ||
(IncludeObj && isObjectFile(Value.str()))) {
LibArgs.push_back(Args.MakeArgString(FileName));
continue;
}
Expand All @@ -2803,7 +2854,7 @@ static SmallVector<const char *, 16> getLinkerArgs(Compilation &C,
// Only add named static libs objects and --whole-archive options.
if (optionMatches("-whole-archive", V.str()) ||
optionMatches("-no-whole-archive", V.str()) ||
isStaticArchiveFile(V)) {
isStaticArchiveFile(V) || (IncludeObj && isObjectFile(V.str()))) {
LibArgs.push_back(Args.MakeArgString(V));
return;
}
Expand Down Expand Up @@ -2869,6 +2920,26 @@ static bool IsSYCLDeviceLibObj(std::string ObjFilePath, bool isMSVCEnv) {
return Ret;
}

// Goes through all of the arguments, including inputs expected for the
// linker directly, to determine if we need to potentially add the SYCL
// default triple.
bool Driver::checkForSYCLDefaultDevice(Compilation &C,
DerivedArgList &Args) const {
// Check only if enabled with -fsycl
if (!Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false))
return false;

if (Args.hasArg(options::OPT_fno_sycl_link_spirv))
return false;

SmallVector<const char *, 16> AllArgs(getLinkerArgs(C, Args, true));
for (StringRef Arg : AllArgs) {
if (hasSYCLDefaultSection(C, Arg))
return true;
}
return false;
}

// Goes through all of the arguments, including inputs expected for the
// linker directly, to determine if we need to perform additional work for
// static offload libraries.
Expand Down Expand Up @@ -4639,6 +4710,7 @@ class OffloadingActionBuilder final {
if (TT.getSubArch() == llvm::Triple::SPIRSubArch_fpga)
SYCLfpgaTriple = true;
}
addSYCLDefaultTriple(C, SYCLTripleList);
}
if (SYCLAddTargets) {
for (StringRef Val : SYCLAddTargets->getValues()) {
Expand All @@ -4661,6 +4733,7 @@ class OffloadingActionBuilder final {
const char *SYCLTargetArch = SYCLfpga ? "spir64_fpga" : "spir64";
SYCLTripleList.push_back(
C.getDriver().MakeSYCLDeviceTriple(SYCLTargetArch));
addSYCLDefaultTriple(C, SYCLTripleList);
if (SYCLfpga)
SYCLfpgaTriple = true;
}
Expand Down
15 changes: 10 additions & 5 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1421,16 +1421,17 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,

// The file being compiled that contains the integration footer is not being
// compiled in the directory of the original source. Add that directory
// as a -I option so we can properly find potential headers there.
// as an -internal-isystem option so we can properly find potential headers
// there.
if (ContainsAppendFooterAction(&JA)) {
SmallString<128> SourcePath(Inputs[0].getBaseInput());
llvm::sys::path::remove_filename(SourcePath);
if (!SourcePath.empty()) {
CmdArgs.push_back("-I");
CmdArgs.push_back("-internal-isystem");
CmdArgs.push_back(Args.MakeArgString(SourcePath));
} else if (llvm::ErrorOr<std::string> CWD =
D.getVFS().getCurrentWorkingDirectory()) {
CmdArgs.push_back("-I");
CmdArgs.push_back("-internal-isystem");
CmdArgs.push_back(Args.MakeArgString(*CWD));
}
}
Expand Down Expand Up @@ -8314,6 +8315,8 @@ void OffloadBundler::ConstructJobMultipleOutputs(
if (getToolChain().getTriple().getSubArch() ==
llvm::Triple::SPIRSubArch_fpga &&
Dep.DependentOffloadKind == Action::OFK_SYCL) {
if (J++)
Triples += ',';
llvm::Triple TT;
TT.setArchName(types::getTypeName(InputType));
TT.setVendorName("intel");
Expand All @@ -8324,6 +8327,8 @@ void OffloadBundler::ConstructJobMultipleOutputs(
} else if (getToolChain().getTriple().getSubArch() !=
llvm::Triple::SPIRSubArch_fpga &&
Dep.DependentOffloadKind == Action::OFK_Host) {
if (J++)
Triples += ',';
Triples += Action::GetOffloadKindName(Dep.DependentOffloadKind);
Triples += '-';
Triples += Dep.DependentToolChain->getTriple().normalize();
Expand Down Expand Up @@ -8483,10 +8488,10 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
// Only store compile/link opts in the image descriptor for the SPIR-V
// target; AOT compilation has already been performed otherwise.
TC.AddImpliedTargetArgs(TT, TCArgs, BuildArgs);
TC.TranslateBackendTargetArgs(TCArgs, BuildArgs);
TC.TranslateBackendTargetArgs(TT, TCArgs, BuildArgs);
createArgString("-compile-opts=");
BuildArgs.clear();
TC.TranslateLinkerTargetArgs(TCArgs, BuildArgs);
TC.TranslateLinkerTargetArgs(TT, TCArgs, BuildArgs);
createArgString("-link-opts=");
}

Expand Down
41 changes: 30 additions & 11 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ void SYCL::fpga::BackendCompiler::constructOpenCLAOTCommand(
llvm::Triple CPUTriple("spir64_x86_64");
TC.AddImpliedTargetArgs(CPUTriple, Args, CmdArgs);
// Add the target args passed in
TC.TranslateBackendTargetArgs(Args, CmdArgs);
TC.TranslateLinkerTargetArgs(Args, CmdArgs);
TC.TranslateBackendTargetArgs(CPUTriple, Args, CmdArgs);
TC.TranslateLinkerTargetArgs(CPUTriple, Args, CmdArgs);

SmallString<128> ExecPath(
getToolChain().GetProgramPath(makeExeName(C, "opencl-aot")));
Expand All @@ -414,7 +414,7 @@ void SYCL::fpga::BackendCompiler::ConstructJob(
const toolchains::SYCLToolChain &TC =
static_cast<const toolchains::SYCLToolChain &>(getToolChain());
ArgStringList TargetArgs;
TC.TranslateBackendTargetArgs(Args, TargetArgs);
TC.TranslateBackendTargetArgs(TC.getTriple(), Args, TargetArgs);

// When performing emulation compilations for FPGA AOT, we want to use
// opencl-aot instead of aoc.
Expand Down Expand Up @@ -534,8 +534,8 @@ void SYCL::fpga::BackendCompiler::ConstructJob(
TC.AddImpliedTargetArgs(getToolChain().getTriple(), Args, CmdArgs);

// Add -Xsycl-target* options.
TC.TranslateBackendTargetArgs(Args, CmdArgs);
TC.TranslateLinkerTargetArgs(Args, CmdArgs);
TC.TranslateBackendTargetArgs(getToolChain().getTriple(), Args, CmdArgs);
TC.TranslateLinkerTargetArgs(getToolChain().getTriple(), Args, CmdArgs);

// Look for -reuse-exe=XX option
if (Arg *A = Args.getLastArg(options::OPT_reuse_exe_EQ)) {
Expand Down Expand Up @@ -581,8 +581,8 @@ void SYCL::gen::BackendCompiler::ConstructJob(Compilation &C,
const toolchains::SYCLToolChain &TC =
static_cast<const toolchains::SYCLToolChain &>(getToolChain());
TC.AddImpliedTargetArgs(getToolChain().getTriple(), Args, CmdArgs);
TC.TranslateBackendTargetArgs(Args, CmdArgs);
TC.TranslateLinkerTargetArgs(Args, CmdArgs);
TC.TranslateBackendTargetArgs(getToolChain().getTriple(), Args, CmdArgs);
TC.TranslateLinkerTargetArgs(getToolChain().getTriple(), Args, CmdArgs);
SmallString<128> ExecPath(
getToolChain().GetProgramPath(makeExeName(C, "ocloc")));
const char *Exec = C.getArgs().MakeArgString(ExecPath);
Expand Down Expand Up @@ -614,8 +614,8 @@ void SYCL::x86_64::BackendCompiler::ConstructJob(
static_cast<const toolchains::SYCLToolChain &>(getToolChain());

TC.AddImpliedTargetArgs(getToolChain().getTriple(), Args, CmdArgs);
TC.TranslateBackendTargetArgs(Args, CmdArgs);
TC.TranslateLinkerTargetArgs(Args, CmdArgs);
TC.TranslateBackendTargetArgs(getToolChain().getTriple(), Args, CmdArgs);
TC.TranslateLinkerTargetArgs(getToolChain().getTriple(), Args, CmdArgs);
SmallString<128> ExecPath(
getToolChain().GetProgramPath(makeExeName(C, "opencl-aot")));
const char *Exec = C.getArgs().MakeArgString(ExecPath);
Expand Down Expand Up @@ -765,7 +765,8 @@ void SYCLToolChain::AddImpliedTargetArgs(
}

void SYCLToolChain::TranslateBackendTargetArgs(
const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const {
const llvm::Triple &Triple, const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const {
// Handle -Xs flags.
for (auto *A : Args) {
// When parsing the target args, the -Xs<opt> type option applies to all
Expand All @@ -775,6 +776,15 @@ void SYCLToolChain::TranslateBackendTargetArgs(
// -Xs "-DFOO -DBAR"
// -XsDFOO -XsDBAR
// All of the above examples will pass -DFOO -DBAR to the backend compiler.

// Do not add the -Xs to the default SYCL triple (spir64) when we know we
// have implied the setting.
if ((A->getOption().matches(options::OPT_Xs) ||
A->getOption().matches(options::OPT_Xs_separate)) &&
Triple.getSubArch() == llvm::Triple::NoSubArch && Triple.isSPIR() &&
getDriver().isSYCLDefaultTripleImplied())
continue;

if (A->getOption().matches(options::OPT_Xs)) {
// Take the arg and create an option out of it.
CmdArgs.push_back(Args.MakeArgString(Twine("-") + A->getValue()));
Expand All @@ -788,13 +798,22 @@ void SYCLToolChain::TranslateBackendTargetArgs(
continue;
}
}
// Do not process -Xsycl-target-backend for implied spir64
if (Triple.getSubArch() == llvm::Triple::NoSubArch && Triple.isSPIR() &&
getDriver().isSYCLDefaultTripleImplied())
return;
// Handle -Xsycl-target-backend.
TranslateTargetOpt(Args, CmdArgs, options::OPT_Xsycl_backend,
options::OPT_Xsycl_backend_EQ);
}

void SYCLToolChain::TranslateLinkerTargetArgs(
const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const {
const llvm::Triple &Triple, const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const {
// Do not process -Xsycl-target-linker for implied spir64
if (Triple.getSubArch() == llvm::Triple::NoSubArch && Triple.isSPIR() &&
getDriver().isSYCLDefaultTripleImplied())
return;
// Handle -Xsycl-target-linker.
TranslateTargetOpt(Args, CmdArgs, options::OPT_Xsycl_linker,
options::OPT_Xsycl_linker_EQ);
Expand Down
Loading

0 comments on commit bcfb6e7

Please sign in to comment.