Revert "[LTO] Support LLVM level link time optimization on Darwin, Linux and Windows"

This commit is contained in:
Saleem Abdulrasool
2020-06-07 11:25:48 -07:00
committed by GitHub
parent cc84c7b740
commit 71309a8fa9
23 changed files with 35 additions and 255 deletions

View File

@@ -65,12 +65,6 @@ enum class IRGenDebugInfoFormat : unsigned {
CodeView CodeView
}; };
enum class IRGenLLVMLTOKind : unsigned {
None,
Thin,
Full
};
enum class IRGenEmbedMode : unsigned { enum class IRGenEmbedMode : unsigned {
None, None,
EmbedMarker, EmbedMarker,
@@ -223,8 +217,6 @@ public:
/// Whether we should embed the bitcode file. /// Whether we should embed the bitcode file.
IRGenEmbedMode EmbedMode : 2; IRGenEmbedMode EmbedMode : 2;
IRGenLLVMLTOKind LLVMLTOKind: 2;
/// Add names to LLVM values. /// Add names to LLVM values.
unsigned HasValueNamesSetting : 1; unsigned HasValueNamesSetting : 1;
unsigned ValueNames : 1; unsigned ValueNames : 1;
@@ -326,7 +318,6 @@ public:
DisableSwiftSpecificLLVMOptzns(false), DisableLLVMSLPVectorizer(false), DisableSwiftSpecificLLVMOptzns(false), DisableLLVMSLPVectorizer(false),
Playground(false), EmitStackPromotionChecks(false), Playground(false), EmitStackPromotionChecks(false),
FunctionSections(false), PrintInlineTree(false), EmbedMode(IRGenEmbedMode::None), FunctionSections(false), PrintInlineTree(false), EmbedMode(IRGenEmbedMode::None),
LLVMLTOKind(IRGenLLVMLTOKind::None),
HasValueNamesSetting(false), ValueNames(false), HasValueNamesSetting(false), ValueNames(false),
EnableReflectionMetadata(true), EnableReflectionNames(true), EnableReflectionMetadata(true), EnableReflectionNames(true),
EnableAnonymousContextMangledNames(false), ForcePublicLinkage(false), EnableAnonymousContextMangledNames(false), ForcePublicLinkage(false),

View File

@@ -328,19 +328,16 @@ public:
class DynamicLinkJobAction : public JobAction { class DynamicLinkJobAction : public JobAction {
virtual void anchor(); virtual void anchor();
LinkKind Kind; LinkKind Kind;
bool LTO;
public: public:
DynamicLinkJobAction(ArrayRef<const Action *> Inputs, LinkKind K, bool LTO) DynamicLinkJobAction(ArrayRef<const Action *> Inputs, LinkKind K)
: JobAction(Action::Kind::DynamicLinkJob, Inputs, file_types::TY_Image), : JobAction(Action::Kind::DynamicLinkJob, Inputs, file_types::TY_Image),
Kind(K), LTO(LTO) { Kind(K) {
assert(Kind != LinkKind::None && Kind != LinkKind::StaticLibrary); assert(Kind != LinkKind::None && Kind != LinkKind::StaticLibrary);
} }
LinkKind getKind() const { return Kind; } LinkKind getKind() const { return Kind; }
bool PerformLTO() const { return LTO; }
static bool classof(const Action *A) { static bool classof(const Action *A) {
return A->getKind() == Action::Kind::DynamicLinkJob; return A->getKind() == Action::Kind::DynamicLinkJob;
} }

View File

@@ -101,14 +101,6 @@ public:
/// The output type which should be used for compile actions. /// The output type which should be used for compile actions.
file_types::ID CompilerOutputType = file_types::ID::TY_INVALID; file_types::ID CompilerOutputType = file_types::ID::TY_INVALID;
enum class LTOKind {
None,
LLVMThin,
LLVMFull,
};
LTOKind LTOVariant = LTOKind::None;
/// Describes if and how the output of compile actions should be /// Describes if and how the output of compile actions should be
/// linked together. /// linked together.
LinkKind LinkAction = LinkKind::None; LinkKind LinkAction = LinkKind::None;

View File

@@ -515,10 +515,6 @@ def disable_bridging_pch : Flag<["-"], "disable-bridging-pch">,
Flags<[HelpHidden]>, Flags<[HelpHidden]>,
HelpText<"Disable automatic generation of bridging PCH files">; HelpText<"Disable automatic generation of bridging PCH files">;
def lto : Joined<["-"], "lto=">,
Flags<[FrontendOption, NoInteractiveOption]>,
HelpText<"Specify the LTO type to either 'llvm' or 'llvm-full'">;
// Experimental feature options // Experimental feature options
// Note: this flag will be removed when JVP/differential generation in the // Note: this flag will be removed when JVP/differential generation in the

View File

@@ -238,15 +238,12 @@ toolchains::Darwin::addLinkerInputArgs(InvocationInfo &II,
Arguments.push_back("-filelist"); Arguments.push_back("-filelist");
Arguments.push_back(context.getTemporaryFilePath("inputs", "LinkFileList")); Arguments.push_back(context.getTemporaryFilePath("inputs", "LinkFileList"));
II.FilelistInfos.push_back( II.FilelistInfos.push_back(
{Arguments.back(), context.OI.CompilerOutputType, {Arguments.back(), file_types::TY_Object,
FilelistInfo::WhichFiles::InputJobsAndSourceInputActions}); FilelistInfo::WhichFiles::InputJobsAndSourceInputActions});
} else { } else {
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args, addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
file_types::TY_Object); file_types::TY_Object);
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
file_types::TY_LLVM_BC);
addInputsOfType(Arguments, context.InputActions, file_types::TY_Object); addInputsOfType(Arguments, context.InputActions, file_types::TY_Object);
addInputsOfType(Arguments, context.InputActions, file_types::TY_LLVM_BC);
} }
@@ -309,20 +306,6 @@ toolchains::Darwin::addArgsToLinkARCLite(ArgStringList &Arguments,
} }
} }
void
toolchains::Darwin::addLTOLibArgs(ArgStringList &Arguments,
const JobContext &context) const {
llvm::SmallString<128> LTOLibPath;
if (findXcodeClangPath(LTOLibPath)) {
llvm::sys::path::remove_filename(LTOLibPath); // 'clang'
llvm::sys::path::remove_filename(LTOLibPath); // 'bin'
llvm::sys::path::append(LTOLibPath, "lib", "libLTO.dylib");
Arguments.push_back("-lto_library");
Arguments.push_back(context.Args.MakeArgString(LTOLibPath));
}
}
void void
toolchains::Darwin::addSanitizerArgs(ArgStringList &Arguments, toolchains::Darwin::addSanitizerArgs(ArgStringList &Arguments,
const DynamicLinkJobAction &job, const DynamicLinkJobAction &job,
@@ -740,10 +723,6 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job,
addArgsToLinkARCLite(Arguments, context); addArgsToLinkARCLite(Arguments, context);
if (job.PerformLTO()) {
addLTOLibArgs(Arguments, context);
}
for (const Arg *arg : for (const Arg *arg :
context.Args.filtered(options::OPT_F, options::OPT_Fsystem)) { context.Args.filtered(options::OPT_F, options::OPT_Fsystem)) {
Arguments.push_back("-F"); Arguments.push_back("-F");
@@ -811,17 +790,14 @@ toolchains::Darwin::constructInvocation(const StaticLinkJobAction &job,
if (context.shouldUseInputFileList()) { if (context.shouldUseInputFileList()) {
Arguments.push_back("-filelist"); Arguments.push_back("-filelist");
Arguments.push_back(context.getTemporaryFilePath("inputs", "LinkFileList")); Arguments.push_back(context.getTemporaryFilePath("inputs", "LinkFileList"));
II.FilelistInfos.push_back({Arguments.back(), context.OI.CompilerOutputType, II.FilelistInfos.push_back({Arguments.back(), file_types::TY_Object,
FilelistInfo::WhichFiles::InputJobs}); FilelistInfo::WhichFiles::InputJobs});
} else { } else {
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args, addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
file_types::TY_Object); file_types::TY_Object);
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
file_types::TY_LLVM_BC);
} }
addInputsOfType(Arguments, context.InputActions, file_types::TY_Object); addInputsOfType(Arguments, context.InputActions, file_types::TY_Object);
addInputsOfType(Arguments, context.InputActions, file_types::TY_LLVM_BC);
Arguments.push_back("-o"); Arguments.push_back("-o");

View File

@@ -1427,15 +1427,12 @@ static bool isSDKTooOld(StringRef sdkPath, const llvm::Triple &target) {
void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args, void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
const bool BatchMode, const InputFileList &Inputs, const bool BatchMode, const InputFileList &Inputs,
OutputInfo &OI) const { 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 // By default, the driver does not link its output; this will be updated
// appropriately below if linking is required. // appropriately below if linking is required.
OI.CompilerOutputType = driverKind == DriverKind::Interactive OI.CompilerOutputType = driverKind == DriverKind::Interactive
? file_types::TY_Nothing ? file_types::TY_Nothing
: LinkerInputType; : file_types::TY_Object;
if (const Arg *A = Args.getLastArg(options::OPT_num_threads)) { if (const Arg *A = Args.getLastArg(options::OPT_num_threads)) {
if (BatchMode) { if (BatchMode) {
@@ -1465,14 +1462,14 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
diag::error_static_emit_executable_disallowed); diag::error_static_emit_executable_disallowed);
OI.LinkAction = LinkKind::Executable; OI.LinkAction = LinkKind::Executable;
OI.CompilerOutputType = LinkerInputType; OI.CompilerOutputType = file_types::TY_Object;
break; break;
case options::OPT_emit_library: case options::OPT_emit_library:
OI.LinkAction = Args.hasArg(options::OPT_static) ? OI.LinkAction = Args.hasArg(options::OPT_static) ?
LinkKind::StaticLibrary : LinkKind::StaticLibrary :
LinkKind::DynamicLibrary; LinkKind::DynamicLibrary;
OI.CompilerOutputType = LinkerInputType; OI.CompilerOutputType = file_types::TY_Object;
break; break;
case options::OPT_static: case options::OPT_static:
@@ -1782,18 +1779,6 @@ 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)
.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 (TC.getTriple().isOSWindows()) {
if (const Arg *A = Args.getLastArg(options::OPT_libc)) { if (const Arg *A = Args.getLastArg(options::OPT_libc)) {
OI.RuntimeVariant = OI.RuntimeVariant =
@@ -2128,17 +2113,15 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
MergeModuleAction = C.createAction<MergeModuleJobAction>(AllModuleInputs); MergeModuleAction = C.createAction<MergeModuleJobAction>(AllModuleInputs);
} }
auto PerformLTO = Args.hasArg(options::OPT_lto);
if (OI.shouldLink() && !AllLinkerInputs.empty()) { if (OI.shouldLink() && !AllLinkerInputs.empty()) {
JobAction *LinkAction = nullptr; JobAction *LinkAction = nullptr;
if (OI.LinkAction == LinkKind::StaticLibrary) { if (OI.LinkAction == LinkKind::StaticLibrary) {
LinkAction = C.createAction<StaticLinkJobAction>(AllLinkerInputs, LinkAction = C.createAction<StaticLinkJobAction>(AllLinkerInputs,
OI.LinkAction); OI.LinkAction);
} else { } else {
LinkAction = C.createAction<DynamicLinkJobAction>(AllLinkerInputs, LinkAction = C.createAction<DynamicLinkJobAction>(AllLinkerInputs,
OI.LinkAction, OI.LinkAction);
PerformLTO);
} }
// On ELF platforms there's no built in autolinking mechanism, so we // On ELF platforms there's no built in autolinking mechanism, so we
@@ -2147,7 +2130,7 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
const auto &Triple = TC.getTriple(); const auto &Triple = TC.getTriple();
SmallVector<const Action *, 2> AutolinkExtractInputs; SmallVector<const Action *, 2> AutolinkExtractInputs;
for (const Action *A : AllLinkerInputs) for (const Action *A : AllLinkerInputs)
if (A->getType() == OI.CompilerOutputType) { if (A->getType() == file_types::TY_Object) {
// Shared objects on ELF platforms don't have a swift1_autolink_entries // 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 // section in them because the section in the .o files is marked as
// SHF_EXCLUDE. // SHF_EXCLUDE.
@@ -2163,7 +2146,7 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
(Triple.getObjectFormat() == llvm::Triple::ELF && !Triple.isPS4()) || (Triple.getObjectFormat() == llvm::Triple::ELF && !Triple.isPS4()) ||
Triple.getObjectFormat() == llvm::Triple::Wasm || Triple.getObjectFormat() == llvm::Triple::Wasm ||
Triple.isOSCygMing(); Triple.isOSCygMing();
if (!AutolinkExtractInputs.empty() && AutolinkExtractRequired && !PerformLTO) { if (!AutolinkExtractInputs.empty() && AutolinkExtractRequired) {
auto *AutolinkExtractAction = auto *AutolinkExtractAction =
C.createAction<AutolinkExtractJobAction>(AutolinkExtractInputs); C.createAction<AutolinkExtractJobAction>(AutolinkExtractInputs);
// Takes the same inputs as the linker... // Takes the same inputs as the linker...

View File

@@ -518,11 +518,6 @@ ToolChain::constructInvocation(const CompileJobAction &job,
Arguments.push_back("-track-system-dependencies"); Arguments.push_back("-track-system-dependencies");
} }
if (auto arg = context.Args.getLastArg(options::OPT_lto)) {
Arguments.push_back(context.Args.MakeArgString(
Twine("-lto=") + arg->getValue()));
}
context.Args.AddLastArg( context.Args.AddLastArg(
Arguments, Arguments,
options:: options::

View File

@@ -48,9 +48,6 @@ protected:
void addDeploymentTargetArgs(llvm::opt::ArgStringList &Arguments, void addDeploymentTargetArgs(llvm::opt::ArgStringList &Arguments,
const JobContext &context) const; const JobContext &context) const;
void addLTOLibArgs(llvm::opt::ArgStringList &Arguments,
const JobContext &context) const;
void addCommonFrontendArgs( void addCommonFrontendArgs(
const OutputInfo &OI, const CommandOutput &output, const OutputInfo &OI, const CommandOutput &output,
const llvm::opt::ArgList &inputArgs, const llvm::opt::ArgList &inputArgs,

View File

@@ -72,10 +72,7 @@ ToolChain::InvocationInfo toolchains::GenericUnix::constructInvocation(
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args, addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
file_types::TY_Object); file_types::TY_Object);
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
file_types::TY_LLVM_BC);
addInputsOfType(Arguments, context.InputActions, file_types::TY_Object); addInputsOfType(Arguments, context.InputActions, file_types::TY_Object);
addInputsOfType(Arguments, context.InputActions, file_types::TY_LLVM_BC);
Arguments.push_back("-o"); Arguments.push_back("-o");
Arguments.push_back( Arguments.push_back(
@@ -170,9 +167,6 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
std::string Linker; std::string Linker;
if (const Arg *A = context.Args.getLastArg(options::OPT_use_ld)) { if (const Arg *A = context.Args.getLastArg(options::OPT_use_ld)) {
Linker = A->getValue(); Linker = A->getValue();
} else if (context.OI.LTOVariant != OutputInfo::LTOKind::None) {
// Force to use lld for LTO
Linker = "lld";
} else { } else {
Linker = getDefaultLinker(); Linker = getDefaultLinker();
} }
@@ -224,16 +218,6 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
Arguments.push_back("-pie"); Arguments.push_back("-pie");
} }
switch (context.OI.LTOVariant) {
case OutputInfo::LTOKind::LLVMThin:
Arguments.push_back("-flto=thin");
break;
case OutputInfo::LTOKind::LLVMFull:
Arguments.push_back("-flto=full");
break;
case OutputInfo::LTOKind::None: break;
}
bool staticExecutable = false; bool staticExecutable = false;
bool staticStdlib = false; bool staticStdlib = false;
@@ -269,11 +253,7 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args, addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
file_types::TY_Object); file_types::TY_Object);
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
file_types::TY_LLVM_BC);
addInputsOfType(Arguments, context.InputActions, file_types::TY_Object); addInputsOfType(Arguments, context.InputActions, file_types::TY_Object);
addInputsOfType(Arguments, context.InputActions, file_types::TY_LLVM_BC);
for (const Arg *arg : for (const Arg *arg :
context.Args.filtered(options::OPT_F, options::OPT_Fsystem)) { context.Args.filtered(options::OPT_F, options::OPT_Fsystem)) {
@@ -388,7 +368,7 @@ toolchains::GenericUnix::constructInvocation(const StaticLinkJobAction &job,
ArgStringList Arguments; ArgStringList Arguments;
// Configure the toolchain. // Configure the toolchain.
const char *AR = "llvm-ar"; const char *AR = "ar";
Arguments.push_back("crs"); Arguments.push_back("crs");
Arguments.push_back( Arguments.push_back(
@@ -396,11 +376,7 @@ toolchains::GenericUnix::constructInvocation(const StaticLinkJobAction &job,
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args, addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
file_types::TY_Object); file_types::TY_Object);
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
file_types::TY_LLVM_BC);
addInputsOfType(Arguments, context.InputActions, file_types::TY_Object); addInputsOfType(Arguments, context.InputActions, file_types::TY_Object);
addInputsOfType(Arguments, context.InputActions, file_types::TY_LLVM_BC);
InvocationInfo II{AR, Arguments}; InvocationInfo II{AR, Arguments};

View File

@@ -143,11 +143,7 @@ toolchains::Windows::constructInvocation(const DynamicLinkJobAction &job,
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args, addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
file_types::TY_Object); file_types::TY_Object);
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
file_types::TY_LLVM_BC);
addInputsOfType(Arguments, context.InputActions, file_types::TY_Object); addInputsOfType(Arguments, context.InputActions, file_types::TY_Object);
addInputsOfType(Arguments, context.InputActions, file_types::TY_LLVM_BC);
for (const Arg *arg : for (const Arg *arg :
context.Args.filtered(options::OPT_F, options::OPT_Fsystem)) { context.Args.filtered(options::OPT_F, options::OPT_Fsystem)) {
@@ -190,21 +186,6 @@ toolchains::Windows::constructInvocation(const DynamicLinkJobAction &job,
context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group); context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group);
context.Args.AddAllArgValues(Arguments, options::OPT_Xclang_linker); context.Args.AddAllArgValues(Arguments, options::OPT_Xclang_linker);
switch (context.OI.LTOVariant) {
case OutputInfo::LTOKind::LLVMThin:
case OutputInfo::LTOKind::LLVMFull: {
if (Linker.empty())
Arguments.push_back("-fuse-ld=lld");
if (context.OI.LTOVariant == OutputInfo::LTOKind::LLVMThin) {
Arguments.push_back("-flto=thin");
} else {
Arguments.push_back("-flto=full");
}
break;
}
case OutputInfo::LTOKind::None: break;
}
// Run clang++ in verbose mode if "-v" is set // Run clang++ in verbose mode if "-v" is set
if (context.Args.hasArg(options::OPT_v)) { if (context.Args.hasArg(options::OPT_v)) {
Arguments.push_back("-v"); Arguments.push_back("-v");
@@ -229,46 +210,22 @@ toolchains::Windows::constructInvocation(const StaticLinkJobAction &job,
ArgStringList Arguments; ArgStringList Arguments;
switch (context.OI.LTOVariant) { const char *Linker = "link";
case OutputInfo::LTOKind::LLVMThin: if (const Arg *A = context.Args.getLastArg(options::OPT_use_ld))
case OutputInfo::LTOKind::LLVMFull: { Linker = context.Args.MakeArgString(A->getValue());
const char *AR = "llvm-ar";
Arguments.push_back("crs");
Arguments.push_back( Arguments.push_back("/lib");
context.Args.MakeArgString(context.Output.getPrimaryOutputFilename())); Arguments.push_back("-nologo");
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args, addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
file_types::TY_Object); file_types::TY_Object);
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args, addInputsOfType(Arguments, context.InputActions, file_types::TY_Object);
file_types::TY_LLVM_BC);
addInputsOfType(Arguments, context.InputActions, file_types::TY_Object);
addInputsOfType(Arguments, context.InputActions, file_types::TY_LLVM_BC);
InvocationInfo II{AR, Arguments}; StringRef OutputFile = context.Output.getPrimaryOutputFilename();
Arguments.push_back(context.Args.MakeArgString(Twine("/OUT:") + OutputFile));
return II; InvocationInfo II{Linker, Arguments};
} II.allowsResponseFiles = true;
case OutputInfo::LTOKind::None:
const char *Linker = "link";
if (const Arg *A = context.Args.getLastArg(options::OPT_use_ld))
Linker = context.Args.MakeArgString(A->getValue());
Arguments.push_back("/lib"); return II;
Arguments.push_back("-nologo");
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
file_types::TY_Object);
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
file_types::TY_LLVM_BC);
addInputsOfType(Arguments, context.InputActions, file_types::TY_Object);
addInputsOfType(Arguments, context.InputActions, file_types::TY_LLVM_BC);
StringRef OutputFile = context.Output.getPrimaryOutputFilename();
Arguments.push_back(context.Args.MakeArgString(Twine("/OUT:") + OutputFile));
InvocationInfo II{Linker, Arguments};
II.allowsResponseFiles = true;
return II;
}
} }

View File

@@ -1428,17 +1428,6 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
} }
} }
if (const Arg *A = Args.getLastArg(options::OPT_lto)) {
auto LLVMLTOKind = llvm::StringSwitch<Optional<IRGenLLVMLTOKind>>(A->getValue())
.Case("llvm", IRGenLLVMLTOKind::Thin)
.Case("llvm-full", IRGenLLVMLTOKind::Full)
.Default(llvm::None);
if (LLVMLTOKind)
Opts.LLVMLTOKind = LLVMLTOKind.getValue();
else
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
A->getAsString(Args), A->getValue());
}
if (const Arg *A = Args.getLastArg(options::OPT_sanitize_coverage_EQ)) { if (const Arg *A = Args.getLastArg(options::OPT_sanitize_coverage_EQ)) {
Opts.SanitizeCoverage = Opts.SanitizeCoverage =

View File

@@ -548,14 +548,9 @@ bool swift::performLLVM(const IRGenOptions &Opts,
case IRGenOutputKind::LLVMAssembly: case IRGenOutputKind::LLVMAssembly:
EmitPasses.add(createPrintModulePass(*RawOS)); EmitPasses.add(createPrintModulePass(*RawOS));
break; break;
case IRGenOutputKind::LLVMBitcode: { case IRGenOutputKind::LLVMBitcode:
if (Opts.LLVMLTOKind == IRGenLLVMLTOKind::Thin) { EmitPasses.add(createBitcodeWriterPass(*RawOS));
EmitPasses.add(createWriteThinLTOBitcodePass(*RawOS));
} else {
EmitPasses.add(createBitcodeWriterPass(*RawOS));
}
break; break;
}
case IRGenOutputKind::NativeAssembly: case IRGenOutputKind::NativeAssembly:
case IRGenOutputKind::ObjectFile: { case IRGenOutputKind::ObjectFile: {
CodeGenFileType FileType; CodeGenFileType FileType;

View File

@@ -1098,18 +1098,10 @@ void IRGenModule::addLinkLibrary(const LinkLibrary &linkLib) {
switch (linkLib.getKind()) { switch (linkLib.getKind()) {
case LibraryKind::Library: { case LibraryKind::Library: {
if (TargetInfo.OutputObjectFormat == llvm::Triple::ELF && IRGen.Opts.LLVMLTOKind != IRGenLLVMLTOKind::None) { llvm::SmallString<32> opt =
// When performing LTO, we always use lld that supports auto linking mechanism with ELF. getTargetDependentLibraryOption(Triple, linkLib.getName());
// So embed dependent libraries names in "llvm.dependent-libraries" instead of options AutolinkEntries.push_back(
// to avoid using swift-autolink-extract. llvm::MDNode::get(ctx, llvm::MDString::get(ctx, opt)));
AutolinkEntries.push_back(
llvm::MDNode::get(ctx, llvm::MDString::get(ctx, linkLib.getName())));
} else {
llvm::SmallString<32> opt =
getTargetDependentLibraryOption(Triple, linkLib.getName());
AutolinkEntries.push_back(
llvm::MDNode::get(ctx, llvm::MDString::get(ctx, opt)));
}
break; break;
} }
case LibraryKind::Framework: { case LibraryKind::Framework: {
@@ -1196,12 +1188,7 @@ static bool isFirstObjectFileInModule(IRGenModule &IGM) {
void IRGenModule::emitAutolinkInfo() { void IRGenModule::emitAutolinkInfo() {
// Collect the linker options already in the module (from ClangCodeGen). // Collect the linker options already in the module (from ClangCodeGen).
// FIXME: This constant should be vended by LLVM somewhere. // FIXME: This constant should be vended by LLVM somewhere.
// When performing LTO, we always use lld that supports auto linking mechanism with ELF. auto *Metadata = Module.getOrInsertNamedMetadata("llvm.linker.options");
// So embed dependent libraries names in "llvm.dependent-libraries" instead of "llvm.linker.options".
const StringRef AutolinkSectionName =
TargetInfo.OutputObjectFormat == llvm::Triple::ELF && IRGen.Opts.LLVMLTOKind != IRGenLLVMLTOKind::None
? "llvm.dependent-libraries" : "llvm.linker.options";
auto *Metadata = Module.getOrInsertNamedMetadata(AutolinkSectionName);
for (llvm::MDNode *LinkOption : Metadata->operands()) for (llvm::MDNode *LinkOption : Metadata->operands())
AutolinkEntries.push_back(LinkOption); AutolinkEntries.push_back(LinkOption);
@@ -1216,9 +1203,9 @@ void IRGenModule::emitAutolinkInfo() {
AutolinkEntries.end()); AutolinkEntries.end());
const bool AutolinkExtractRequired = const bool AutolinkExtractRequired =
((TargetInfo.OutputObjectFormat == llvm::Triple::ELF && !Triple.isPS4()) || (TargetInfo.OutputObjectFormat == llvm::Triple::ELF && !Triple.isPS4()) ||
TargetInfo.OutputObjectFormat == llvm::Triple::Wasm || TargetInfo.OutputObjectFormat == llvm::Triple::Wasm ||
Triple.isOSCygMing()) && IRGen.Opts.LLVMLTOKind == IRGenLLVMLTOKind::None; Triple.isOSCygMing();
if (!AutolinkExtractRequired) { if (!AutolinkExtractRequired) {
// On platforms that support autolinking, continue to use the metadata. // On platforms that support autolinking, continue to use the metadata.

View File

@@ -1 +0,0 @@
public func libraryFunction() {}

View File

@@ -1,3 +0,0 @@
import A
libraryFunction()

View File

@@ -1,3 +0,0 @@
func anotherFileFunction() {
print(#function)
}

View File

@@ -1 +0,0 @@
anotherFileFunction()

View File

@@ -1,12 +0,0 @@
// FIXME: ld64 in Xcode toolchain uses older version of LLVM than swiftc, so ld64 can't read module summary for LTO
// from bitcode file produced by compiler. This should be fixed before shipping Xcode toolchain by upgrading
// LLVM version used in ld64.
// XFAIL: OS=macosx
// XFAIL: OS=tvos
// XFAIL: OS=watchos
// XFAIL: OS=ios
// RUN: rm -rf %t
// RUN: %empty-directory(%t/thin)
// RUN: %target-swiftc_driver %S/Inputs/lto/lib.swift -lto=llvm -emit-library -emit-module -module-name A -working-directory %t/thin
// RUN: %target-swiftc_driver %S/Inputs/lto/main.swift -L. -I. -lA -lto=llvm -working-directory %t/thin

View File

@@ -1,5 +0,0 @@
// RUN: rm -rf %t
// RUN: %empty-directory(%t/full)
// RUN: %target-swiftc_driver %S/Inputs/lto/lib.swift -lto=llvm-full -emit-library -emit-module -module-name A -working-directory %t/full
// RUN: %target-swiftc_driver %S/Inputs/lto/main.swift -L. -I. -lA -lto=llvm-full -working-directory %t/full

View File

@@ -1,14 +0,0 @@
// UNSUPPORTED: OS=windows-msvc
// FIXME: ld64 in Xcode toolchain uses older version of LLVM than swiftc, so ld64 can't read module summary for LTO
// from bitcode file produced by compiler. This should be fixed before shipping Xcode toolchain by upgrading
// LLVM version used in ld64.
// XFAIL: OS=macosx
// XFAIL: OS=tvos
// XFAIL: OS=watchos
// XFAIL: OS=ios
// RUN: rm -rf %t
// RUN: %empty-directory(%t/thin-static)
// RUN: %target-swiftc_driver %S/Inputs/lto/lib.swift -static -lto=llvm -emit-library -emit-module -module-name A -working-directory %t/thin-static
// RUN: %target-swiftc_driver %S/Inputs/lto/main.swift -L. -I. -lA -lto=llvm -working-directory %t/thin-static

View File

@@ -1,6 +0,0 @@
// UNSUPPORTED: OS=windows-msvc
// RUN: rm -rf %t
// RUN: %empty-directory(%t/full-static)
// RUN: %target-swiftc_driver %S/Inputs/lto/lib.swift -static -lto=llvm-full -emit-library -emit-module -module-name A -working-directory %t/full-static
// RUN: %target-swiftc_driver %S/Inputs/lto/main.swift -L. -I. -lA -lto=llvm-full -working-directory %t/full-static

View File

@@ -1,5 +0,0 @@
// RUN: %target-swiftc_driver -driver-print-jobs %S/../Inputs/empty.swift -lto=llvm | %FileCheck %s --check-prefix=CHECK-%target-os --check-prefix=CHECK
// CHECK: swift{{(c\.exe")?}} -frontend -emit-bc
// CHECK-macosx-NEXT: bin/ld {{.+}} -lto_library {{.+}}/lib/libLTO.dylib
// CHECK-windows-msvc-NEXT: clang.exe" {{.+}} -fuse-ld=lld -flto=thin
// CHECK-linux-gnu-NEXT: bin/clang {{.+}} -flto=thin

View File

@@ -97,7 +97,6 @@ git clone --depth 1 --single-branch https://github.com/apple/swift-cmark cmark %
git clone --depth 1 --single-branch --branch swift/master https://github.com/apple/llvm-project llvm-project %exitOnError% git clone --depth 1 --single-branch --branch swift/master https://github.com/apple/llvm-project llvm-project %exitOnError%
mklink /D "%source_root%\clang" "%source_root%\llvm-project\clang" mklink /D "%source_root%\clang" "%source_root%\llvm-project\clang"
mklink /D "%source_root%\llvm" "%source_root%\llvm-project\llvm" mklink /D "%source_root%\llvm" "%source_root%\llvm-project\llvm"
mklink /D "%source_root%\lld" "%source_root%\llvm-project\lld"
mklink /D "%source_root%\lldb" "%source_root%\llvm-project\lldb" mklink /D "%source_root%\lldb" "%source_root%\llvm-project\lldb"
mklink /D "%source_root%\compiler-rt" "%source_root%\llvm-project\compiler-rt" mklink /D "%source_root%\compiler-rt" "%source_root%\llvm-project\compiler-rt"
mklink /D "%source_root%\libcxx" "%source_root%\llvm-project\libcxx" mklink /D "%source_root%\libcxx" "%source_root%\llvm-project\libcxx"
@@ -166,7 +165,7 @@ cmake^
-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-windows-msvc^ -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-windows-msvc^
-DLLVM_ENABLE_PDB:BOOL=YES^ -DLLVM_ENABLE_PDB:BOOL=YES^
-DLLVM_ENABLE_ASSERTIONS:BOOL=YES^ -DLLVM_ENABLE_ASSERTIONS:BOOL=YES^
-DLLVM_ENABLE_PROJECTS:STRING=lld;clang^ -DLLVM_ENABLE_PROJECTS:STRING=clang^
-DLLVM_TARGETS_TO_BUILD:STRING="AArch64;ARM;X86"^ -DLLVM_TARGETS_TO_BUILD:STRING="AArch64;ARM;X86"^
-DLLVM_INCLUDE_BENCHMARKS:BOOL=NO^ -DLLVM_INCLUDE_BENCHMARKS:BOOL=NO^
-DLLVM_INCLUDE_DOCS:BOOL=NO^ -DLLVM_INCLUDE_DOCS:BOOL=NO^