diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index e31e5b40c06be..3caf5db2cd56c 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -2793,10 +2793,8 @@ bool Driver::checkForOffloadStaticLib(Compilation &C, if (isStaticArchiveFile(OLArg) && hasOffloadSections(C, OLArg, Args)) { // FPGA binaries with AOCX or AOCR sections are not considered fat // static archives. - if (Args.hasArg(options::OPT_fintelfpga)) - return !(hasFPGABinary(C, OLArg.str(), types::TY_FPGA_AOCR) || - hasFPGABinary(C, OLArg.str(), types::TY_FPGA_AOCX)); - return true; + return !(hasFPGABinary(C, OLArg.str(), types::TY_FPGA_AOCR) || + hasFPGABinary(C, OLArg.str(), types::TY_FPGA_AOCX)); } return false; } @@ -3814,11 +3812,12 @@ class OffloadingActionBuilder final { ActionList FullSYCLLinkBinaryList; bool SYCLDeviceLibLinked = false; FullSYCLLinkBinaryList.push_back(DeviceLinkAction); - // If used without -fintelfpga, -fsycl-link is used to wrap device - // objects for future host link. Device libraries should be linked - // by default to resolve any undefined reference. - if (!Args.hasArg(options::OPT_fintelfpga)) { - const auto *TC = ToolChains.front(); + // If used without the FPGA target, -fsycl-link is used to wrap + // device objects for future host link. Device libraries should + // be linked by default to resolve any undefined reference. + const auto *TC = ToolChains.front(); + if (TC->getTriple().getSubArch() != + llvm::Triple::SPIRSubArch_fpga) { SYCLDeviceLibLinked = addSYCLDeviceLibs(TC, FullSYCLLinkBinaryList, true, C.getDefaultToolChain() @@ -3921,8 +3920,9 @@ class OffloadingActionBuilder final { return ABRT_Inactive; // For SYCL device libraries, don't need to add them to // FPGAObjectInputs as there is no FPGA dep files inside. - - if (Args.hasArg(options::OPT_fintelfpga) && + const auto *TC = ToolChains.front(); + if (TC->getTriple().getSubArch() == + llvm::Triple::SPIRSubArch_fpga && !IsSYCLDeviceLibObj(FileName, C.getDefaultToolChain() .getTriple() .isWindowsMSVCEnvironment())) @@ -4269,7 +4269,7 @@ class OffloadingActionBuilder final { BEInputs.push_back(UnbundleAction); }; // Send any known objects/archives through the unbundler to grab the - // dependency file associated. + // dependency file associated. This is only done for -fintelfpga. for (Action *A : FPGAObjectInputs) unbundleAdd(A, types::TY_FPGA_Dependencies); for (Action *A : FPGAArchiveInputs) @@ -4397,11 +4397,6 @@ class OffloadingActionBuilder final { // -fsycl-device-code-split=per_source DeviceCodeSplit = DeviceCodeSplitArg && DeviceCodeSplitArg->getValue() != StringRef("off"); - // Device only compilation for -fsycl-link (no FPGA) and - // -fsycl-link-targets - CompileDeviceOnly = - (SYCLLinkTargets || - (WrapDeviceOnlyBinary && !Args.hasArg(options::OPT_fintelfpga))); // Gather information about the SYCL Ahead of Time targets. The targets // are determined on the SubArch values passed along in the triple. Arg *SYCLTargets = @@ -4456,6 +4451,11 @@ class OffloadingActionBuilder final { SYCLfpgaTriple = true; } + // Device only compilation for -fsycl-link (no FPGA) and + // -fsycl-link-targets + CompileDeviceOnly = + (SYCLLinkTargets || (WrapDeviceOnlyBinary && !SYCLfpgaTriple)); + // Set the FPGA output type based on command line (-fsycl-link). if (auto * A = C.getInputArgs().getLastArg(options::OPT_fsycl_link_EQ)) FPGAOutType = (A->getValue() == StringRef("early")) @@ -4463,7 +4463,7 @@ class OffloadingActionBuilder final { // Populate FPGA static archives that could contain dep files to be // incorporated into the aoc compilation - if (SYCLfpgaTriple) { + if (SYCLfpgaTriple && Args.hasArg(options::OPT_fintelfpga)) { SmallVector LinkArgs(getLinkerArgs(C, Args)); for (StringRef LA : LinkArgs) { if (isStaticArchiveFile(LA) && hasOffloadSections(C, LA, Args)) { @@ -4622,6 +4622,7 @@ class OffloadingActionBuilder final { // is a bundle or not and if the input is not a bundle it assumes it is a // host file. Therefore it is safe to create an unbundling action even if // the input is not a bundle. + bool HasFPGATarget = false; if (CanUseBundler && isa(HostAction) && InputArg->getOption().getKind() == llvm::opt::Option::InputClass && !InputArg->getOption().hasFlag(options::LinkerInput) && @@ -4631,9 +4632,12 @@ class OffloadingActionBuilder final { ActionList HostActionList; Action *A(HostAction); // Only check for FPGA device information when using fpga SubArch. - if (Args.hasArg(options::OPT_fintelfpga) && - !(HostAction->getType() == types::TY_Object && - isObjectFile(InputName))) { + auto SYCLTCRange = C.getOffloadToolChains(); + for (auto TI = SYCLTCRange.first, TE = SYCLTCRange.second; TI != TE; ++TI) + HasFPGATarget |= TI->second->getTriple().getSubArch() == + llvm::Triple::SPIRSubArch_fpga; + if (HasFPGATarget && !(HostAction->getType() == types::TY_Object && + isObjectFile(InputName))) { // Type FPGA aoco is a special case for -foffload-static-lib. if (HostAction->getType() == types::TY_FPGA_AOCO) { if (!hasFPGABinary(C, InputName, types::TY_FPGA_AOCO)) @@ -4678,10 +4682,9 @@ class OffloadingActionBuilder final { // For unbundling of an FPGA AOCX binary, we want to link with the original // FPGA device archive. if ((OffloadKind == Action::OFK_None && CanUseBundler) || - (Args.hasArg(options::OPT_fintelfpga) && - ((Args.hasArg(options::OPT_fsycl_link_EQ) && - HostAction->getType() == types::TY_Object) || - HostAction->getType() == types::TY_FPGA_AOCX))) + (HasFPGATarget && ((Args.hasArg(options::OPT_fsycl_link_EQ) && + HostAction->getType() == types::TY_Object) || + HostAction->getType() == types::TY_FPGA_AOCX))) if (auto *UA = dyn_cast(HostAction)) HostAction = UA->getInputs().back(); @@ -5124,13 +5127,13 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args, // are then added to the appropriate device link actions and host list is // ignored since we are adding offload-static-libs as normal libraries to // the host link command. - if (hasOffloadSections(C, LA, Args)) + if (hasOffloadSections(C, LA, Args)) { unbundleStaticLib(types::TY_Archive, LA); - // Pass along the static libraries to check if we need to add them for - // unbundling for FPGA AOT static lib usage. Uses FPGA aoco type to - // differentiate if aoco unbundling is needed. - if (Args.hasArg(options::OPT_fintelfpga)) + // Pass along the static libraries to check if we need to add them for + // unbundling for FPGA AOT static lib usage. Uses FPGA aoco type to + // differentiate if aoco unbundling is needed. unbundleStaticLib(types::TY_FPGA_AOCO, LA); + } } // For an FPGA archive, we add the unbundling step above to take care of @@ -6089,16 +6092,17 @@ InputInfo Driver::BuildJobsForActionNoCache( // unbundling action does not change the type of the output which can // cause a overwrite. InputInfo CurI; - bool IsFPGAObjLink = (JA->getType() == types::TY_Object && - C.getInputArgs().hasArg(options::OPT_fintelfpga) && - C.getInputArgs().hasArg(options::OPT_fsycl_link_EQ)); + bool IsFPGAObjLink = + (JA->getType() == types::TY_Object && + EffectiveTriple.getSubArch() == llvm::Triple::SPIRSubArch_fpga && + C.getInputArgs().hasArg(options::OPT_fsycl_link_EQ)); if (C.getDriver().getOffloadStaticLibSeen() && JA->getType() == types::TY_Archive) { // Host part of the unbundled static archive is not used. if (UI.DependentOffloadKind == Action::OFK_Host) continue; - // Host part of the unbundled object when -fintelfpga -fsycl-link is - // enabled is not used + // Host part of the unbundled object is not used when using the + // FPGA target and -fsycl-link is enabled. if (UI.DependentOffloadKind == Action::OFK_Host && IsFPGAObjLink) continue; std::string TmpFileName = C.getDriver().GetTemporaryPath( @@ -6140,8 +6144,8 @@ InputInfo Driver::BuildJobsForActionNoCache( C.addTempFile(C.getArgs().MakeArgString(TmpFileName)); CurI = InputInfo(TI, TmpFile, TmpFile); } else { - // Host part of the unbundled object is not used when -fintelfpga - // -fsycl-link is enabled + // Host part of the unbundled object is not used when -fsycl-link is + // enabled with FPGA target if (UI.DependentOffloadKind == Action::OFK_Host && IsFPGAObjLink) continue; std::string OffloadingPrefix = Action::GetOffloadingFileNamePrefix( diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 4d6df22b1be6c..c89dc27d2698e 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1105,6 +1105,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs) const { const bool IsIAMCU = getToolChain().getTriple().isOSIAMCU(); + const bool IsIntelFPGA = Args.hasArg(options::OPT_fintelfpga); CheckPreprocessingOptions(D, Args); @@ -1143,16 +1144,14 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, C.addFailureResultFile(DepFile, &JA); // Populate the named dependency file to be used in the bundle // or passed to the offline compilation. - if (Args.hasArg(options::OPT_fintelfpga) && - JA.isDeviceOffloading(Action::OFK_SYCL)) + if (IsIntelFPGA && JA.isDeviceOffloading(Action::OFK_SYCL)) C.getDriver().addFPGATempDepFile( DepFile, Clang::getBaseInputName(Args, Inputs[0])); } else if (Output.getType() == types::TY_Dependencies) { DepFile = Output.getFilename(); } else if (!ArgMD) { DepFile = "-"; - } else if (Args.hasArg(options::OPT_fintelfpga) && - JA.isDeviceOffloading(Action::OFK_SYCL)) { + } else if (IsIntelFPGA && JA.isDeviceOffloading(Action::OFK_SYCL)) { createFPGATempDepFile(DepFile); } else { DepFile = getDependencyFileName(Args, Inputs); @@ -1208,8 +1207,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, CmdArgs.push_back("-module-file-deps"); } - if (!ArgM && Args.hasArg(options::OPT_fintelfpga) && - JA.isDeviceOffloading(Action::OFK_SYCL)) { + if (!ArgM && IsIntelFPGA && JA.isDeviceOffloading(Action::OFK_SYCL)) { // No dep generation option was provided, add all of the needed options // to ensure a successful dep generation. const char *DepFile; @@ -7668,9 +7666,12 @@ void OffloadBundler::ConstructJob(Compilation &C, const JobAction &JA, Triples += CurDep->getOffloadingArch(); } } - bool IsFPGADepBundle = (TCArgs.hasArg(options::OPT_fintelfpga) && - Output.getType() == types::TY_Object); - // For -fintelfpga, when bundling objects we also want to bundle up the + // If we see we are bundling for FPGA using -fintelfpga, add the + // dependency bundle + bool IsFPGADepBundle = TCArgs.hasArg(options::OPT_fintelfpga) && + Output.getType() == types::TY_Object; + + // For spir64_fpga target, when bundling objects we also want to bundle up the // named dependency file. // TODO - We are currently using the target triple inputs to slot a location // of the dependency information into the bundle. It would be good to diff --git a/clang/test/Driver/sycl-intelfpga-static-lib-win.cpp b/clang/test/Driver/sycl-intelfpga-static-lib-win.cpp index 4aebb9d896fc8..2667844caa0fa 100644 --- a/clang/test/Driver/sycl-intelfpga-static-lib-win.cpp +++ b/clang/test/Driver/sycl-intelfpga-static-lib-win.cpp @@ -33,3 +33,9 @@ // RUN: | FileCheck -check-prefix=CHECK_UNBUNDLE %s // CHECK_UNBUNDLE: clang-offload-bundler" "-type=aoo" "-targets=sycl-fpga_dep" "-inputs={{.*}}" "-outputs=[[DEPFILES:.+\.txt]]" "-unbundle" // CHECK_UNBUNDLE: aoc{{.*}} "-dep-files=@[[DEPFILES]]" + +/// Check for no unbundle and use of deps in static lib when using triple +// RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -fno-sycl-device-lib=all -fsycl-targets=spir64_fpga-unknown-unknown-sycldevice %t.lib -### 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK_NO_UNBUNDLE %s +// CHECK_NO_UNBUNDLE-NOT: clang-offload-bundler" "-type=aoo" "-targets=sycl-fpga_dep" +// CHECK_NO_UNBUNDLE-NOT: aoc{{.*}} "-dep-files={{.*}}" diff --git a/clang/test/Driver/sycl-intelfpga-static-lib.cpp b/clang/test/Driver/sycl-intelfpga-static-lib.cpp index 8918aa0d6069d..5e6ec1fb0e97d 100644 --- a/clang/test/Driver/sycl-intelfpga-static-lib.cpp +++ b/clang/test/Driver/sycl-intelfpga-static-lib.cpp @@ -32,3 +32,9 @@ // RUN: | FileCheck -check-prefix=CHECK_UNBUNDLE %s // CHECK_UNBUNDLE: clang-offload-bundler" "-type=aoo" "-targets=sycl-fpga_dep" "-inputs={{.*}}" "-outputs=[[DEPFILES:.+\.txt]]" "-unbundle" // CHECK_UNBUNDLE: aoc{{.*}} "-dep-files=@[[DEPFILES]]" + +/// Check for no unbundle and use of deps in static lib when using triple +// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -fno-sycl-device-lib=all -fsycl-targets=spir64_fpga-unknown-unknown-sycldevice %t.a -### 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK_NO_UNBUNDLE %s +// CHECK_NO_UNBUNDLE-NOT: clang-offload-bundler" "-type=aoo" "-targets=sycl-fpga_dep" +// CHECK_NO_UNBUNDLE-NOT: aoc{{.*}} "-dep-files={{.*}}" diff --git a/clang/test/Driver/sycl-offload-intelfpga.cpp b/clang/test/Driver/sycl-offload-intelfpga.cpp index 5dd5914198aa1..e49df9f57120b 100644 --- a/clang/test/Driver/sycl-offload-intelfpga.cpp +++ b/clang/test/Driver/sycl-offload-intelfpga.cpp @@ -5,6 +5,7 @@ /// Check SYCL headers path // RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga %s 2>&1 \ +// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fsycl-targets=spir64_fpga-unknown-unknown-sycldevice %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHK-HEADERS-INTELFPGA %s // CHK-HEADERS-INTELFPGA: clang{{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl" diff --git a/clang/test/Driver/sycl-offload-with-split.c b/clang/test/Driver/sycl-offload-with-split.c index e44c173fbb334..9bc40055d5448 100644 --- a/clang/test/Driver/sycl-offload-with-split.c +++ b/clang/test/Driver/sycl-offload-with-split.c @@ -313,6 +313,7 @@ // RUN: %clang -### -fsycl -fno-sycl-device-code-split-esimd %s 2>&1 | FileCheck %s -check-prefixes=CHK-NO-ESIMD-SPLIT // RUN: %clang_cl -### -fsycl -fno-sycl-device-code-split-esimd %s 2>&1 | FileCheck %s -check-prefixes=CHK-NO-ESIMD-SPLIT // RUN: %clang -### -fsycl -fintelfpga %s 2>&1 | FileCheck %s -check-prefixes=CHK-NO-ESIMD-SPLIT +// RUN: %clang -### -fsycl -fsycl-targets=spir64_fpga-unknown-unknown-sycldevice %s 2>&1 | FileCheck %s -check-prefixes=CHK-NO-ESIMD-SPLIT // RUN: %clang_cl -### -fsycl -fintelfpga %s 2>&1 | FileCheck %s -check-prefixes=CHK-NO-ESIMD-SPLIT // CHK-ESIMD-SPLIT: sycl-post-link{{.*}} "-split-esimd" // CHK-NO-ESIMD-SPLIT-NOT: sycl-post-link{{.*}} "-split-esimd" @@ -325,6 +326,7 @@ // RUN: %clang -### -fsycl -fno-sycl-device-code-lower-esimd %s 2>&1 | FileCheck %s -check-prefixes=CHK-NO-ESIMD-LOWER // RUN: %clang_cl -### -fsycl -fno-sycl-device-code-lower-esimd %s 2>&1 | FileCheck %s -check-prefixes=CHK-NO-ESIMD-LOWER // RUN: %clang -### -fsycl -fintelfpga %s 2>&1 | FileCheck %s -check-prefixes=CHK-NO-ESIMD-LOWER +// RUN: %clang -### -fsycl -fsycl-targets=spir64_fpga-unknown-unknown-sycldevice %s 2>&1 | FileCheck %s -check-prefixes=CHK-NO-ESIMD-LOWER // RUN: %clang_cl -### -fsycl -fintelfpga %s 2>&1 | FileCheck %s -check-prefixes=CHK-NO-ESIMD-LOWER // CHK-ESIMD-LOWER: sycl-post-link{{.*}} "-lower-esimd" // CHK-NO-ESIMD-LOWER-NOT: sycl-post-link{{.*}} "-lower-esimd"