Skip to content

Commit 4fe0c69

Browse files
authored
Merge pull request #32235 from apple/revert-31146-katei/enable-lang-agnostic-lto
Revert "[LTO] Support LLVM level link time optimization on Darwin, Linux and Windows"
2 parents cc84c7b + 71309a8 commit 4fe0c69

23 files changed

+36
-256
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ enum class IRGenDebugInfoFormat : unsigned {
6565
CodeView
6666
};
6767

68-
enum class IRGenLLVMLTOKind : unsigned {
69-
None,
70-
Thin,
71-
Full
72-
};
73-
7468
enum class IRGenEmbedMode : unsigned {
7569
None,
7670
EmbedMarker,
@@ -223,8 +217,6 @@ class IRGenOptions {
223217
/// Whether we should embed the bitcode file.
224218
IRGenEmbedMode EmbedMode : 2;
225219

226-
IRGenLLVMLTOKind LLVMLTOKind: 2;
227-
228220
/// Add names to LLVM values.
229221
unsigned HasValueNamesSetting : 1;
230222
unsigned ValueNames : 1;
@@ -326,7 +318,6 @@ class IRGenOptions {
326318
DisableSwiftSpecificLLVMOptzns(false), DisableLLVMSLPVectorizer(false),
327319
Playground(false), EmitStackPromotionChecks(false),
328320
FunctionSections(false), PrintInlineTree(false), EmbedMode(IRGenEmbedMode::None),
329-
LLVMLTOKind(IRGenLLVMLTOKind::None),
330321
HasValueNamesSetting(false), ValueNames(false),
331322
EnableReflectionMetadata(true), EnableReflectionNames(true),
332323
EnableAnonymousContextMangledNames(false), ForcePublicLinkage(false),

include/swift/Driver/Action.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,19 +328,16 @@ class GeneratePCHJobAction : public JobAction {
328328
class DynamicLinkJobAction : public JobAction {
329329
virtual void anchor();
330330
LinkKind Kind;
331-
bool LTO;
332331

333332
public:
334-
DynamicLinkJobAction(ArrayRef<const Action *> Inputs, LinkKind K, bool LTO)
333+
DynamicLinkJobAction(ArrayRef<const Action *> Inputs, LinkKind K)
335334
: JobAction(Action::Kind::DynamicLinkJob, Inputs, file_types::TY_Image),
336-
Kind(K), LTO(LTO) {
335+
Kind(K) {
337336
assert(Kind != LinkKind::None && Kind != LinkKind::StaticLibrary);
338337
}
339338

340339
LinkKind getKind() const { return Kind; }
341340

342-
bool PerformLTO() const { return LTO; }
343-
344341
static bool classof(const Action *A) {
345342
return A->getKind() == Action::Kind::DynamicLinkJob;
346343
}

include/swift/Driver/Driver.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,6 @@ class OutputInfo {
101101
/// The output type which should be used for compile actions.
102102
file_types::ID CompilerOutputType = file_types::ID::TY_INVALID;
103103

104-
enum class LTOKind {
105-
None,
106-
LLVMThin,
107-
LLVMFull,
108-
};
109-
110-
LTOKind LTOVariant = LTOKind::None;
111-
112104
/// Describes if and how the output of compile actions should be
113105
/// linked together.
114106
LinkKind LinkAction = LinkKind::None;

include/swift/Option/Options.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -515,10 +515,6 @@ def disable_bridging_pch : Flag<["-"], "disable-bridging-pch">,
515515
Flags<[HelpHidden]>,
516516
HelpText<"Disable automatic generation of bridging PCH files">;
517517

518-
def lto : Joined<["-"], "lto=">,
519-
Flags<[FrontendOption, NoInteractiveOption]>,
520-
HelpText<"Specify the LTO type to either 'llvm' or 'llvm-full'">;
521-
522518
// Experimental feature options
523519

524520
// Note: this flag will be removed when JVP/differential generation in the

lib/Driver/DarwinToolChains.cpp

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,12 @@ toolchains::Darwin::addLinkerInputArgs(InvocationInfo &II,
238238
Arguments.push_back("-filelist");
239239
Arguments.push_back(context.getTemporaryFilePath("inputs", "LinkFileList"));
240240
II.FilelistInfos.push_back(
241-
{Arguments.back(), context.OI.CompilerOutputType,
241+
{Arguments.back(), file_types::TY_Object,
242242
FilelistInfo::WhichFiles::InputJobsAndSourceInputActions});
243243
} else {
244244
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
245245
file_types::TY_Object);
246-
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
247-
file_types::TY_LLVM_BC);
248246
addInputsOfType(Arguments, context.InputActions, file_types::TY_Object);
249-
addInputsOfType(Arguments, context.InputActions, file_types::TY_LLVM_BC);
250247
}
251248

252249

@@ -309,20 +306,6 @@ toolchains::Darwin::addArgsToLinkARCLite(ArgStringList &Arguments,
309306
}
310307
}
311308

312-
void
313-
toolchains::Darwin::addLTOLibArgs(ArgStringList &Arguments,
314-
const JobContext &context) const {
315-
llvm::SmallString<128> LTOLibPath;
316-
if (findXcodeClangPath(LTOLibPath)) {
317-
llvm::sys::path::remove_filename(LTOLibPath); // 'clang'
318-
llvm::sys::path::remove_filename(LTOLibPath); // 'bin'
319-
llvm::sys::path::append(LTOLibPath, "lib", "libLTO.dylib");
320-
321-
Arguments.push_back("-lto_library");
322-
Arguments.push_back(context.Args.MakeArgString(LTOLibPath));
323-
}
324-
}
325-
326309
void
327310
toolchains::Darwin::addSanitizerArgs(ArgStringList &Arguments,
328311
const DynamicLinkJobAction &job,
@@ -740,10 +723,6 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job,
740723

741724
addArgsToLinkARCLite(Arguments, context);
742725

743-
if (job.PerformLTO()) {
744-
addLTOLibArgs(Arguments, context);
745-
}
746-
747726
for (const Arg *arg :
748727
context.Args.filtered(options::OPT_F, options::OPT_Fsystem)) {
749728
Arguments.push_back("-F");
@@ -811,17 +790,14 @@ toolchains::Darwin::constructInvocation(const StaticLinkJobAction &job,
811790
if (context.shouldUseInputFileList()) {
812791
Arguments.push_back("-filelist");
813792
Arguments.push_back(context.getTemporaryFilePath("inputs", "LinkFileList"));
814-
II.FilelistInfos.push_back({Arguments.back(), context.OI.CompilerOutputType,
793+
II.FilelistInfos.push_back({Arguments.back(), file_types::TY_Object,
815794
FilelistInfo::WhichFiles::InputJobs});
816795
} else {
817796
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
818797
file_types::TY_Object);
819-
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
820-
file_types::TY_LLVM_BC);
821798
}
822799

823800
addInputsOfType(Arguments, context.InputActions, file_types::TY_Object);
824-
addInputsOfType(Arguments, context.InputActions, file_types::TY_LLVM_BC);
825801

826802
Arguments.push_back("-o");
827803

lib/Driver/Driver.cpp

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,15 +1427,12 @@ static bool isSDKTooOld(StringRef sdkPath, const llvm::Triple &target) {
14271427
void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
14281428
const bool BatchMode, const InputFileList &Inputs,
14291429
OutputInfo &OI) const {
1430-
auto LinkerInputType = Args.hasArg(options::OPT_lto)
1431-
? file_types::TY_LLVM_BC
1432-
: file_types::TY_Object;
14331430
// By default, the driver does not link its output; this will be updated
14341431
// appropriately below if linking is required.
14351432

14361433
OI.CompilerOutputType = driverKind == DriverKind::Interactive
14371434
? file_types::TY_Nothing
1438-
: LinkerInputType;
1435+
: file_types::TY_Object;
14391436

14401437
if (const Arg *A = Args.getLastArg(options::OPT_num_threads)) {
14411438
if (BatchMode) {
@@ -1465,14 +1462,14 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
14651462
diag::error_static_emit_executable_disallowed);
14661463

14671464
OI.LinkAction = LinkKind::Executable;
1468-
OI.CompilerOutputType = LinkerInputType;
1465+
OI.CompilerOutputType = file_types::TY_Object;
14691466
break;
14701467

14711468
case options::OPT_emit_library:
14721469
OI.LinkAction = Args.hasArg(options::OPT_static) ?
14731470
LinkKind::StaticLibrary :
14741471
LinkKind::DynamicLibrary;
1475-
OI.CompilerOutputType = LinkerInputType;
1472+
OI.CompilerOutputType = file_types::TY_Object;
14761473
break;
14771474

14781475
case options::OPT_static:
@@ -1782,18 +1779,6 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
17821779

17831780
}
17841781

1785-
if (const Arg *A = Args.getLastArg(options::OPT_lto)) {
1786-
auto LTOVariant = llvm::StringSwitch<Optional<OutputInfo::LTOKind>>(A->getValue())
1787-
.Case("llvm", OutputInfo::LTOKind::LLVMThin)
1788-
.Case("llvm-full", OutputInfo::LTOKind::LLVMFull)
1789-
.Default(llvm::None);
1790-
if (LTOVariant)
1791-
OI.LTOVariant = LTOVariant.getValue();
1792-
else
1793-
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
1794-
A->getAsString(Args), A->getValue());
1795-
}
1796-
17971782
if (TC.getTriple().isOSWindows()) {
17981783
if (const Arg *A = Args.getLastArg(options::OPT_libc)) {
17991784
OI.RuntimeVariant =
@@ -2128,17 +2113,15 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
21282113
MergeModuleAction = C.createAction<MergeModuleJobAction>(AllModuleInputs);
21292114
}
21302115

2131-
auto PerformLTO = Args.hasArg(options::OPT_lto);
21322116
if (OI.shouldLink() && !AllLinkerInputs.empty()) {
21332117
JobAction *LinkAction = nullptr;
21342118

21352119
if (OI.LinkAction == LinkKind::StaticLibrary) {
21362120
LinkAction = C.createAction<StaticLinkJobAction>(AllLinkerInputs,
2137-
OI.LinkAction);
2121+
OI.LinkAction);
21382122
} else {
21392123
LinkAction = C.createAction<DynamicLinkJobAction>(AllLinkerInputs,
2140-
OI.LinkAction,
2141-
PerformLTO);
2124+
OI.LinkAction);
21422125
}
21432126

21442127
// On ELF platforms there's no built in autolinking mechanism, so we
@@ -2147,7 +2130,7 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
21472130
const auto &Triple = TC.getTriple();
21482131
SmallVector<const Action *, 2> AutolinkExtractInputs;
21492132
for (const Action *A : AllLinkerInputs)
2150-
if (A->getType() == OI.CompilerOutputType) {
2133+
if (A->getType() == file_types::TY_Object) {
21512134
// Shared objects on ELF platforms don't have a swift1_autolink_entries
21522135
// section in them because the section in the .o files is marked as
21532136
// SHF_EXCLUDE.
@@ -2163,7 +2146,7 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
21632146
(Triple.getObjectFormat() == llvm::Triple::ELF && !Triple.isPS4()) ||
21642147
Triple.getObjectFormat() == llvm::Triple::Wasm ||
21652148
Triple.isOSCygMing();
2166-
if (!AutolinkExtractInputs.empty() && AutolinkExtractRequired && !PerformLTO) {
2149+
if (!AutolinkExtractInputs.empty() && AutolinkExtractRequired) {
21672150
auto *AutolinkExtractAction =
21682151
C.createAction<AutolinkExtractJobAction>(AutolinkExtractInputs);
21692152
// Takes the same inputs as the linker...

lib/Driver/ToolChains.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -518,11 +518,6 @@ ToolChain::constructInvocation(const CompileJobAction &job,
518518
Arguments.push_back("-track-system-dependencies");
519519
}
520520

521-
if (auto arg = context.Args.getLastArg(options::OPT_lto)) {
522-
Arguments.push_back(context.Args.MakeArgString(
523-
Twine("-lto=") + arg->getValue()));
524-
}
525-
526521
context.Args.AddLastArg(
527522
Arguments,
528523
options::

lib/Driver/ToolChains.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain {
4848
void addDeploymentTargetArgs(llvm::opt::ArgStringList &Arguments,
4949
const JobContext &context) const;
5050

51-
void addLTOLibArgs(llvm::opt::ArgStringList &Arguments,
52-
const JobContext &context) const;
53-
5451
void addCommonFrontendArgs(
5552
const OutputInfo &OI, const CommandOutput &output,
5653
const llvm::opt::ArgList &inputArgs,

lib/Driver/UnixToolChains.cpp

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ ToolChain::InvocationInfo toolchains::GenericUnix::constructInvocation(
7272

7373
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
7474
file_types::TY_Object);
75-
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
76-
file_types::TY_LLVM_BC);
7775
addInputsOfType(Arguments, context.InputActions, file_types::TY_Object);
78-
addInputsOfType(Arguments, context.InputActions, file_types::TY_LLVM_BC);
7976

8077
Arguments.push_back("-o");
8178
Arguments.push_back(
@@ -170,9 +167,6 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
170167
std::string Linker;
171168
if (const Arg *A = context.Args.getLastArg(options::OPT_use_ld)) {
172169
Linker = A->getValue();
173-
} else if (context.OI.LTOVariant != OutputInfo::LTOKind::None) {
174-
// Force to use lld for LTO
175-
Linker = "lld";
176170
} else {
177171
Linker = getDefaultLinker();
178172
}
@@ -224,16 +218,6 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
224218
Arguments.push_back("-pie");
225219
}
226220

227-
switch (context.OI.LTOVariant) {
228-
case OutputInfo::LTOKind::LLVMThin:
229-
Arguments.push_back("-flto=thin");
230-
break;
231-
case OutputInfo::LTOKind::LLVMFull:
232-
Arguments.push_back("-flto=full");
233-
break;
234-
case OutputInfo::LTOKind::None: break;
235-
}
236-
237221
bool staticExecutable = false;
238222
bool staticStdlib = false;
239223

@@ -269,11 +253,7 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
269253

270254
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
271255
file_types::TY_Object);
272-
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
273-
file_types::TY_LLVM_BC);
274256
addInputsOfType(Arguments, context.InputActions, file_types::TY_Object);
275-
addInputsOfType(Arguments, context.InputActions, file_types::TY_LLVM_BC);
276-
277257

278258
for (const Arg *arg :
279259
context.Args.filtered(options::OPT_F, options::OPT_Fsystem)) {
@@ -388,19 +368,15 @@ toolchains::GenericUnix::constructInvocation(const StaticLinkJobAction &job,
388368
ArgStringList Arguments;
389369

390370
// Configure the toolchain.
391-
const char *AR = "llvm-ar";
371+
const char *AR = "ar";
392372
Arguments.push_back("crs");
393373

394374
Arguments.push_back(
395375
context.Args.MakeArgString(context.Output.getPrimaryOutputFilename()));
396376

397377
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
398378
file_types::TY_Object);
399-
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
400-
file_types::TY_LLVM_BC);
401379
addInputsOfType(Arguments, context.InputActions, file_types::TY_Object);
402-
addInputsOfType(Arguments, context.InputActions, file_types::TY_LLVM_BC);
403-
404380

405381
InvocationInfo II{AR, Arguments};
406382

0 commit comments

Comments
 (0)