Skip to content

Commit be07751

Browse files
authored
[SYCL][Driver] Improve fat static library support (#1319)
When processing libraries on the command line, take into account any thusly named static archive (*.a) file and consider that for offloading. We will also scan the appropriate linker options passed in so we can determine if the library should be considered as whole-archive. The static libraries found on the command line will be 'sniffed' to determine if the static library is fat. This effectively negates the need to use -foffload-static-lib and -foffload-whole-static-lib which we should consider deprecated now. Add a deprecated diagnostic when -foffload-static-lib is used Refactor to bring along common code for the device check. Narrows the focus of what is considered to be processed from the linker only arguments. Pulls in objects from -Wl, instead of only archives, but is only part of a potential partial link step and is not fully processed. Signed-off-by: Michael D Toguchi <[email protected]>
1 parent ca3bf4a commit be07751

File tree

13 files changed

+571
-171
lines changed

13 files changed

+571
-171
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ def warn_drv_object_size_disabled_O0 : Warning<
340340
InGroup<InvalidCommandLineArgument>, DefaultWarnNoWerror;
341341
def err_invalid_branch_protection: Error <
342342
"invalid branch protection option '%0' in '%1'">;
343+
def warn_drv_deprecated_option : Warning<
344+
"option '%0' is deprecated, use '%1' directly instead">, InGroup<Deprecated>;
343345

344346
def note_drv_command_failed_diag_msg : Note<
345347
"diagnostic msg: %0">;

clang/include/clang/Driver/Action.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class Action {
7676
SPIRVTranslatorJobClass,
7777
SPIRCheckJobClass,
7878
SYCLPostLinkJobClass,
79+
PartialLinkJobClass,
7980
BackendCompileJobClass,
8081

8182
JobClassFirst = PreprocessJobClass,
@@ -680,6 +681,18 @@ class SYCLPostLinkJobAction : public JobAction {
680681
}
681682
};
682683

684+
class PartialLinkJobAction : public JobAction {
685+
void anchor() override;
686+
687+
public:
688+
PartialLinkJobAction(Action *Input, types::ID OutputType);
689+
PartialLinkJobAction(ActionList &Input, types::ID OutputType);
690+
691+
static bool classof(const Action *A) {
692+
return A->getKind() == PartialLinkJobClass;
693+
}
694+
};
695+
683696
class BackendCompileJobAction : public JobAction {
684697
void anchor() override;
685698

clang/include/clang/Driver/Driver.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,15 @@ class Driver {
621621
&CachedResults,
622622
Action::OffloadKind TargetDeviceOffloadKind) const;
623623

624+
/// Static offload library seen.
625+
bool OffloadStaticLibSeen = false;
626+
627+
void setOffloadStaticLibSeen() { OffloadStaticLibSeen = true; }
628+
629+
/// Returns true if an offload static library is found.
630+
bool checkForOffloadStaticLib(Compilation &C,
631+
llvm::opt::DerivedArgList &Args) const;
632+
624633
public:
625634
/// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and
626635
/// return the grouped values as integers. Numbers which are not
@@ -642,6 +651,8 @@ class Driver {
642651
MutableArrayRef<unsigned> Digits);
643652
/// Compute the default -fmodule-cache-path.
644653
static void getDefaultModuleCachePath(SmallVectorImpl<char> &Result);
654+
655+
bool getOffloadStaticLibSeen() const { return OffloadStaticLibSeen; };
645656
};
646657

647658
/// \return True if the last defined optimization level is -Ofast.
@@ -651,6 +662,9 @@ bool isOptimizationLevelFast(const llvm::opt::ArgList &Args);
651662
/// \return True if the filename has a valid object file extension.
652663
bool isObjectFile(std::string FileName);
653664

665+
/// \return True if the filename has a static archive/lib extension.
666+
bool isStaticArchiveFile(const StringRef &FileName);
667+
654668
/// \return True if the argument combination will end up generating remarks.
655669
bool willEmitRemarks(const llvm::opt::ArgList &Args);
656670

clang/include/clang/Driver/ToolChain.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ class ToolChain {
145145
mutable std::unique_ptr<Tool> SPIRVTranslator;
146146
mutable std::unique_ptr<Tool> SPIRCheck;
147147
mutable std::unique_ptr<Tool> SYCLPostLink;
148+
mutable std::unique_ptr<Tool> PartialLink;
148149
mutable std::unique_ptr<Tool> BackendCompiler;
149150

150151
Tool *getClang() const;
@@ -158,6 +159,7 @@ class ToolChain {
158159
Tool *getSPIRVTranslator() const;
159160
Tool *getSPIRCheck() const;
160161
Tool *getSYCLPostLink() const;
162+
Tool *getPartialLink() const;
161163
Tool *getBackendCompiler() const;
162164

163165
mutable std::unique_ptr<SanitizerArgs> SanitizerArguments;

clang/lib/Driver/Action.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ const char *Action::getClassName(ActionClass AC) {
4949
return "llvm-no-spir-kernel";
5050
case SYCLPostLinkJobClass:
5151
return "sycl-post-link";
52+
case PartialLinkJobClass:
53+
return "partial-link";
5254
case BackendCompileJobClass:
5355
return "backend-compiler";
5456
}
@@ -454,6 +456,14 @@ void SYCLPostLinkJobAction::anchor() {}
454456
SYCLPostLinkJobAction::SYCLPostLinkJobAction(Action *Input, types::ID Type)
455457
: JobAction(SYCLPostLinkJobClass, Input, Type) {}
456458

459+
void PartialLinkJobAction::anchor() {}
460+
461+
PartialLinkJobAction::PartialLinkJobAction(Action *Input, types::ID Type)
462+
: JobAction(PartialLinkJobClass, Input, Type) {}
463+
464+
PartialLinkJobAction::PartialLinkJobAction(ActionList &Inputs, types::ID Type)
465+
: JobAction(PartialLinkJobClass, Inputs, Type) {}
466+
457467
void BackendCompileJobAction::anchor() {}
458468

459469
BackendCompileJobAction::BackendCompileJobAction(ActionList &Inputs,

0 commit comments

Comments
 (0)