-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Revert "Revert "[LTO] Support LLVM level link time optimization on Darwin, Linux and Windows"" #32237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revert "Revert "[LTO] Support LLVM level link time optimization on Darwin, Linux and Windows"" #32237
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -328,16 +328,19 @@ class GeneratePCHJobAction : public JobAction { | |
class DynamicLinkJobAction : public JobAction { | ||
virtual void anchor(); | ||
LinkKind Kind; | ||
bool LTO; | ||
|
||
public: | ||
DynamicLinkJobAction(ArrayRef<const Action *> Inputs, LinkKind K) | ||
DynamicLinkJobAction(ArrayRef<const Action *> Inputs, LinkKind K, bool LTO) | ||
: JobAction(Action::Kind::DynamicLinkJob, Inputs, file_types::TY_Image), | ||
Kind(K) { | ||
Kind(K), LTO(LTO) { | ||
assert(Kind != LinkKind::None && Kind != LinkKind::StaticLibrary); | ||
} | ||
|
||
LinkKind getKind() const { return Kind; } | ||
|
||
bool PerformLTO() const { return LTO; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please follow naming guidelines! -> shouldPerformLTO(). Can you rename the flag to ShouldPerformLTO? What does bool LTO even mean? It is ambiguous. |
||
|
||
static bool classof(const Action *A) { | ||
return A->getKind() == Action::Kind::DynamicLinkJob; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1427,12 +1427,15 @@ static bool isSDKTooOld(StringRef sdkPath, const llvm::Triple &target) { | |
void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args, | ||
const bool BatchMode, const InputFileList &Inputs, | ||
OutputInfo &OI) const { | ||
auto LinkerInputType = Args.hasArg(options::OPT_lto) | ||
? file_types::TY_LLVM_BC | ||
: file_types::TY_Object; | ||
// By default, the driver does not link its output; this will be updated | ||
// appropriately below if linking is required. | ||
|
||
OI.CompilerOutputType = driverKind == DriverKind::Interactive | ||
? file_types::TY_Nothing | ||
: file_types::TY_Object; | ||
: LinkerInputType; | ||
|
||
if (const Arg *A = Args.getLastArg(options::OPT_num_threads)) { | ||
if (BatchMode) { | ||
|
@@ -1462,14 +1465,14 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args, | |
diag::error_static_emit_executable_disallowed); | ||
|
||
OI.LinkAction = LinkKind::Executable; | ||
OI.CompilerOutputType = file_types::TY_Object; | ||
OI.CompilerOutputType = LinkerInputType; | ||
break; | ||
|
||
case options::OPT_emit_library: | ||
OI.LinkAction = Args.hasArg(options::OPT_static) ? | ||
LinkKind::StaticLibrary : | ||
LinkKind::DynamicLibrary; | ||
OI.CompilerOutputType = file_types::TY_Object; | ||
OI.CompilerOutputType = LinkerInputType; | ||
break; | ||
|
||
case options::OPT_static: | ||
|
@@ -1779,6 +1782,18 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args, | |
|
||
} | ||
|
||
if (const Arg *A = Args.getLastArg(options::OPT_lto)) { | ||
auto LTOVariant = llvm::StringSwitch<Optional<OutputInfo::LTOKind>>(A->getValue()) | ||
.Case("llvm", OutputInfo::LTOKind::LLVMThin) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets be explicit here and be clear that it is llvm-thin. |
||
.Case("llvm-full", OutputInfo::LTOKind::LLVMFull) | ||
.Default(llvm::None); | ||
if (LTOVariant) | ||
OI.LTOVariant = LTOVariant.getValue(); | ||
else | ||
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value, | ||
A->getAsString(Args), A->getValue()); | ||
} | ||
|
||
if (TC.getTriple().isOSWindows()) { | ||
if (const Arg *A = Args.getLastArg(options::OPT_libc)) { | ||
OI.RuntimeVariant = | ||
|
@@ -2113,15 +2128,17 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions, | |
MergeModuleAction = C.createAction<MergeModuleJobAction>(AllModuleInputs); | ||
} | ||
|
||
auto PerformLTO = Args.hasArg(options::OPT_lto); | ||
if (OI.shouldLink() && !AllLinkerInputs.empty()) { | ||
JobAction *LinkAction = nullptr; | ||
|
||
if (OI.LinkAction == LinkKind::StaticLibrary) { | ||
LinkAction = C.createAction<StaticLinkJobAction>(AllLinkerInputs, | ||
OI.LinkAction); | ||
OI.LinkAction); | ||
} else { | ||
LinkAction = C.createAction<DynamicLinkJobAction>(AllLinkerInputs, | ||
OI.LinkAction); | ||
OI.LinkAction, | ||
PerformLTO); | ||
} | ||
|
||
// On ELF platforms there's no built in autolinking mechanism, so we | ||
|
@@ -2130,7 +2147,7 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions, | |
const auto &Triple = TC.getTriple(); | ||
SmallVector<const Action *, 2> AutolinkExtractInputs; | ||
for (const Action *A : AllLinkerInputs) | ||
if (A->getType() == file_types::TY_Object) { | ||
if (A->getType() == OI.CompilerOutputType) { | ||
// Shared objects on ELF platforms don't have a swift1_autolink_entries | ||
// section in them because the section in the .o files is marked as | ||
// SHF_EXCLUDE. | ||
|
@@ -2146,7 +2163,7 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions, | |
(Triple.getObjectFormat() == llvm::Triple::ELF && !Triple.isPS4()) || | ||
Triple.getObjectFormat() == llvm::Triple::Wasm || | ||
Triple.isOSCygMing(); | ||
if (!AutolinkExtractInputs.empty() && AutolinkExtractRequired) { | ||
if (!AutolinkExtractInputs.empty() && AutolinkExtractRequired && !PerformLTO) { | ||
auto *AutolinkExtractAction = | ||
C.createAction<AutolinkExtractJobAction>(AutolinkExtractInputs); | ||
// Takes the same inputs as the linker... | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code has not been run through git-clang-format. Please do so before this lands!