Skip to content

Commit

Permalink
[SYCL][Driver] Improve fat static library support (#1319)
Browse files Browse the repository at this point in the history
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 <michael.d.toguchi@intel.com>
  • Loading branch information
mdtoguchi authored Mar 19, 2020
1 parent ca3bf4a commit be07751
Show file tree
Hide file tree
Showing 13 changed files with 571 additions and 171 deletions.
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ def warn_drv_object_size_disabled_O0 : Warning<
InGroup<InvalidCommandLineArgument>, DefaultWarnNoWerror;
def err_invalid_branch_protection: Error <
"invalid branch protection option '%0' in '%1'">;
def warn_drv_deprecated_option : Warning<
"option '%0' is deprecated, use '%1' directly instead">, InGroup<Deprecated>;

def note_drv_command_failed_diag_msg : Note<
"diagnostic msg: %0">;
Expand Down
13 changes: 13 additions & 0 deletions clang/include/clang/Driver/Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Action {
SPIRVTranslatorJobClass,
SPIRCheckJobClass,
SYCLPostLinkJobClass,
PartialLinkJobClass,
BackendCompileJobClass,

JobClassFirst = PreprocessJobClass,
Expand Down Expand Up @@ -680,6 +681,18 @@ class SYCLPostLinkJobAction : public JobAction {
}
};

class PartialLinkJobAction : public JobAction {
void anchor() override;

public:
PartialLinkJobAction(Action *Input, types::ID OutputType);
PartialLinkJobAction(ActionList &Input, types::ID OutputType);

static bool classof(const Action *A) {
return A->getKind() == PartialLinkJobClass;
}
};

class BackendCompileJobAction : public JobAction {
void anchor() override;

Expand Down
14 changes: 14 additions & 0 deletions clang/include/clang/Driver/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,15 @@ class Driver {
&CachedResults,
Action::OffloadKind TargetDeviceOffloadKind) const;

/// Static offload library seen.
bool OffloadStaticLibSeen = false;

void setOffloadStaticLibSeen() { OffloadStaticLibSeen = true; }

/// Returns true if an offload static library is found.
bool checkForOffloadStaticLib(Compilation &C,
llvm::opt::DerivedArgList &Args) const;

public:
/// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and
/// return the grouped values as integers. Numbers which are not
Expand All @@ -642,6 +651,8 @@ class Driver {
MutableArrayRef<unsigned> Digits);
/// Compute the default -fmodule-cache-path.
static void getDefaultModuleCachePath(SmallVectorImpl<char> &Result);

bool getOffloadStaticLibSeen() const { return OffloadStaticLibSeen; };
};

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

/// \return True if the filename has a static archive/lib extension.
bool isStaticArchiveFile(const StringRef &FileName);

/// \return True if the argument combination will end up generating remarks.
bool willEmitRemarks(const llvm::opt::ArgList &Args);

Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Driver/ToolChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class ToolChain {
mutable std::unique_ptr<Tool> SPIRVTranslator;
mutable std::unique_ptr<Tool> SPIRCheck;
mutable std::unique_ptr<Tool> SYCLPostLink;
mutable std::unique_ptr<Tool> PartialLink;
mutable std::unique_ptr<Tool> BackendCompiler;

Tool *getClang() const;
Expand All @@ -158,6 +159,7 @@ class ToolChain {
Tool *getSPIRVTranslator() const;
Tool *getSPIRCheck() const;
Tool *getSYCLPostLink() const;
Tool *getPartialLink() const;
Tool *getBackendCompiler() const;

mutable std::unique_ptr<SanitizerArgs> SanitizerArguments;
Expand Down
10 changes: 10 additions & 0 deletions clang/lib/Driver/Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const char *Action::getClassName(ActionClass AC) {
return "llvm-no-spir-kernel";
case SYCLPostLinkJobClass:
return "sycl-post-link";
case PartialLinkJobClass:
return "partial-link";
case BackendCompileJobClass:
return "backend-compiler";
}
Expand Down Expand Up @@ -454,6 +456,14 @@ void SYCLPostLinkJobAction::anchor() {}
SYCLPostLinkJobAction::SYCLPostLinkJobAction(Action *Input, types::ID Type)
: JobAction(SYCLPostLinkJobClass, Input, Type) {}

void PartialLinkJobAction::anchor() {}

PartialLinkJobAction::PartialLinkJobAction(Action *Input, types::ID Type)
: JobAction(PartialLinkJobClass, Input, Type) {}

PartialLinkJobAction::PartialLinkJobAction(ActionList &Inputs, types::ID Type)
: JobAction(PartialLinkJobClass, Inputs, Type) {}

void BackendCompileJobAction::anchor() {}

BackendCompileJobAction::BackendCompileJobAction(ActionList &Inputs,
Expand Down
Loading

0 comments on commit be07751

Please sign in to comment.