Skip to content

Commit 45acb91

Browse files
committed
Revert "Add a mechanism to let cross-module-optimization add additional TBD symbols."
This reverts commit c55f040. It's not needed anymore because CMO does not introduce public symbols when a TBD file is emitted.
1 parent 0cdbd3e commit 45acb91

File tree

14 files changed

+48
-121
lines changed

14 files changed

+48
-121
lines changed

include/swift/AST/TBDGenRequests.h

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,8 @@ class TBDGenDescriptor final {
5050
FileOrModule Input;
5151
TBDGenOptions Opts;
5252

53-
/// Symbols (e.g. function names) which are made public by the
54-
/// CrossModuleOptimization pass and therefore must be included in the TBD file.
55-
TBDSymbolSetPtr publicCMOSymbols;
56-
57-
TBDGenDescriptor(FileOrModule input, const TBDGenOptions &opts,
58-
TBDSymbolSetPtr publicCMOSymbols)
59-
: Input(input), Opts(opts), publicCMOSymbols(publicCMOSymbols) {
53+
TBDGenDescriptor(FileOrModule input, const TBDGenOptions &opts)
54+
: Input(input), Opts(opts) {
6055
assert(input);
6156
}
6257

@@ -78,21 +73,17 @@ class TBDGenDescriptor final {
7873
const StringRef getDataLayoutString() const;
7974
const llvm::Triple &getTarget() const;
8075

81-
TBDSymbolSetPtr getPublicCMOSymbols() const { return publicCMOSymbols; }
82-
8376
bool operator==(const TBDGenDescriptor &other) const;
8477
bool operator!=(const TBDGenDescriptor &other) const {
8578
return !(*this == other);
8679
}
8780

88-
static TBDGenDescriptor forFile(FileUnit *file, const TBDGenOptions &opts,
89-
TBDSymbolSetPtr publicCMOSymbols) {
90-
return TBDGenDescriptor(file, opts, publicCMOSymbols);
81+
static TBDGenDescriptor forFile(FileUnit *file, const TBDGenOptions &opts) {
82+
return TBDGenDescriptor(file, opts);
9183
}
9284

93-
static TBDGenDescriptor forModule(ModuleDecl *M, const TBDGenOptions &opts,
94-
TBDSymbolSetPtr publicCMOSymbols) {
95-
return TBDGenDescriptor(M, opts, publicCMOSymbols);
85+
static TBDGenDescriptor forModule(ModuleDecl *M, const TBDGenOptions &opts) {
86+
return TBDGenDescriptor(M, opts);
9687
}
9788
};
9889

@@ -163,9 +154,6 @@ class SymbolSource {
163154
/// A symbol used to customize linker behavior, introduced by TBDGen.
164155
LinkerDirective,
165156

166-
/// A symbol which was made public by the CrossModuleOptimization pass.
167-
CrossModuleOptimization,
168-
169157
/// A symbol with an unknown origin.
170158
// FIXME: This should be eliminated.
171159
Unknown
@@ -185,8 +173,7 @@ class SymbolSource {
185173
irEntity = entity;
186174
}
187175
explicit SymbolSource(Kind kind) : kind(kind) {
188-
assert(kind == Kind::LinkerDirective || kind == Kind::Unknown ||
189-
kind == Kind::CrossModuleOptimization);
176+
assert(kind == Kind::LinkerDirective || kind == Kind::Unknown);
190177
}
191178

192179
public:
@@ -199,9 +186,6 @@ class SymbolSource {
199186
static SymbolSource forLinkerDirective() {
200187
return SymbolSource{Kind::LinkerDirective};
201188
}
202-
static SymbolSource forCrossModuleOptimization() {
203-
return SymbolSource{Kind::CrossModuleOptimization};
204-
}
205189
static SymbolSource forUnknown() {
206190
return SymbolSource{Kind::Unknown};
207191
}
@@ -210,10 +194,6 @@ class SymbolSource {
210194
return kind == Kind::LinkerDirective;
211195
}
212196

213-
bool isFromCrossModuleOptimization() const {
214-
return kind == Kind::CrossModuleOptimization;
215-
}
216-
217197
SILDeclRef getSILDeclRef() const {
218198
assert(kind == Kind::SIL);
219199
return silDeclRef;

include/swift/Frontend/Frontend.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,6 @@ class CompilerInstance {
436436
std::unique_ptr<ASTContext> Context;
437437
std::unique_ptr<Lowering::TypeConverter> TheSILTypes;
438438
std::unique_ptr<DiagnosticVerifier> DiagVerifier;
439-
TBDSymbolSetPtr publicCMOSymbols;
440439

441440
/// A cache describing the set of inter-module dependencies that have been queried.
442441
/// Null if not present.
@@ -588,10 +587,6 @@ class CompilerInstance {
588587
/// file.
589588
SourceFile *getCodeCompletionFile() const;
590589

591-
/// Return the symbols (e.g. function names) which are made public by the
592-
/// CrossModuleOptimization pass and therefore must be included in the TBD file.
593-
TBDSymbolSetPtr getPublicCMOSymbols() const { return publicCMOSymbols; }
594-
595590
private:
596591
/// Set up the file system by loading and validating all VFS overlay YAML
597592
/// files. If the process of validating VFS files failed, or the overlay

include/swift/SIL/SILModule.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include "swift/SIL/SILVTable.h"
3939
#include "swift/SIL/SILWitnessTable.h"
4040
#include "swift/SIL/TypeLowering.h"
41-
#include "swift/TBDGen/TBDGen.h"
4241
#include "llvm/ADT/ArrayRef.h"
4342
#include "llvm/ADT/FoldingSet.h"
4443
#include "llvm/ADT/MapVector.h"
@@ -387,10 +386,6 @@ class SILModule {
387386

388387
/// Folding set for key path patterns.
389388
llvm::FoldingSet<KeyPathPattern> KeyPathPatterns;
390-
391-
/// Symbols (e.g. function names) which are made public by the
392-
/// CrossModuleOptimization pass and therefore must be included in the TBD file.
393-
TBDSymbolSetPtr publicCMOSymbols;
394389

395390
public:
396391
~SILModule();
@@ -560,12 +555,6 @@ class SILModule {
560555

561556
const SILOptions &getOptions() const { return Options; }
562557

563-
/// Return the symbols (e.g. function names) which are made public by the
564-
/// CrossModuleOptimization pass and therefore must be included in the TBD file.
565-
TBDSymbolSetPtr getPublicCMOSymbols() { return publicCMOSymbols; }
566-
567-
void addPublicCMOSymbol(StringRef symbol);
568-
569558
using iterator = FunctionListType::iterator;
570559
using const_iterator = FunctionListType::const_iterator;
571560
FunctionListType &getFunctionList() { return functions; }

include/swift/TBDGen/TBDGen.h

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
#include "llvm/ADT/StringSet.h"
1717
#include "swift/Basic/Version.h"
1818
#include <vector>
19-
#include <set>
20-
#include <string>
21-
#include <memory>
2219

2320
namespace llvm {
2421
class raw_ostream;
@@ -107,26 +104,12 @@ struct TBDGenOptions {
107104
}
108105
};
109106

110-
/// Used for symbols which are made public by the CrossModuleOptimization pass
111-
/// and therefore must be included in the TBD file.
112-
///
113-
/// We cannot use llvm::StringSet, because we need deterministic iteration order.
114-
using TBDSymbolSet = std::set<std::string>;
115-
116-
/// A pointer to TBDSymbolSet.
117-
///
118-
/// Do reference counting for memory management.
119-
/// This set is created in the optimizer and primarily stored in the SILModule.
120-
/// But then they need to be kept alive beyond the lifetime of the SILModule.
121-
using TBDSymbolSetPtr = std::shared_ptr<TBDSymbolSet>;
122-
123107
std::vector<std::string> getPublicSymbols(TBDGenDescriptor desc);
124108

125109
void writeTBDFile(ModuleDecl *M, llvm::raw_ostream &os,
126-
const TBDGenOptions &opts, TBDSymbolSetPtr publicCMOSymbols);
110+
const TBDGenOptions &opts);
127111

128-
void writeAPIJSONFile(ModuleDecl *M, llvm::raw_ostream &os, bool PrettyPrint,
129-
TBDSymbolSetPtr publicCMOSymbols);
112+
void writeAPIJSONFile(ModuleDecl *M, llvm::raw_ostream &os, bool PrettyPrint);
130113

131114
} // end namespace swift
132115

lib/DriverTool/swift_api_extract_main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class SwiftAPIExtractInvocation {
215215
return 1;
216216

217217
if (OutputFilename == "-") {
218-
writeAPIJSONFile(M, llvm::outs(), PrettyPrint, nullptr);
218+
writeAPIJSONFile(M, llvm::outs(), PrettyPrint);
219219
return 0;
220220
}
221221

@@ -227,7 +227,7 @@ class SwiftAPIExtractInvocation {
227227
return 1;
228228
}
229229

230-
writeAPIJSONFile(M, OS, PrettyPrint, nullptr);
230+
writeAPIJSONFile(M, OS, PrettyPrint);
231231
return 0;
232232
}
233233
};

lib/Frontend/Frontend.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,8 +1330,6 @@ bool CompilerInstance::performSILProcessing(SILModule *silModule) {
13301330

13311331
performSILOptimizations(Invocation, silModule);
13321332

1333-
publicCMOSymbols = silModule->getPublicCMOSymbols();
1334-
13351333
if (auto *stats = getStatsReporter())
13361334
countStatsPostSILOpt(*stats, *silModule);
13371335

lib/FrontendTool/FrontendTool.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,15 @@ static bool writeTBDIfNeeded(CompilerInstance &Instance) {
702702
return false;
703703
}
704704

705+
if (Invocation.getSILOptions().CrossModuleOptimization) {
706+
Instance.getDiags().diagnose(SourceLoc(),
707+
diag::tbd_not_supported_with_cmo);
708+
return false;
709+
}
710+
705711
const std::string &TBDPath = Invocation.getTBDPathForWholeModule();
706712

707-
return writeTBD(Instance.getMainModule(), TBDPath, tbdOpts,
708-
Instance.getPublicCMOSymbols());
713+
return writeTBD(Instance.getMainModule(), TBDPath, tbdOpts);
709714
}
710715

711716
static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
@@ -1392,19 +1397,19 @@ static bool processCommandLineAndRunImmediately(CompilerInstance &Instance,
13921397

13931398
static bool validateTBDIfNeeded(const CompilerInvocation &Invocation,
13941399
ModuleOrSourceFile MSF,
1395-
const llvm::Module &IRModule,
1396-
TBDSymbolSetPtr publicCMOSymbols) {
1397-
auto mode = Invocation.getFrontendOptions().ValidateTBDAgainstIR;
1398-
if (mode == FrontendOptions::TBDValidationMode::All &&
1399-
Invocation.getSILOptions().CrossModuleOptimization)
1400-
mode = FrontendOptions::TBDValidationMode::MissingFromTBD;
1401-
1400+
const llvm::Module &IRModule) {
1401+
const auto mode = Invocation.getFrontendOptions().ValidateTBDAgainstIR;
14021402
const bool canPerformTBDValidation = [&]() {
14031403
// If the user has requested we skip validation, honor it.
14041404
if (mode == FrontendOptions::TBDValidationMode::None) {
14051405
return false;
14061406
}
14071407

1408+
// Cross-module optimization does not support TBD.
1409+
if (Invocation.getSILOptions().CrossModuleOptimization) {
1410+
return false;
1411+
}
1412+
14081413
// If we can't validate the given input file, bail early. This covers cases
14091414
// like passing raw SIL as a primary file.
14101415
const auto &IO = Invocation.getFrontendOptions().InputsAndOutputs;
@@ -1465,10 +1470,9 @@ static bool validateTBDIfNeeded(const CompilerInvocation &Invocation,
14651470
// noise from e.g. statically-linked libraries.
14661471
Opts.embedSymbolsFromModules.clear();
14671472
if (auto *SF = MSF.dyn_cast<SourceFile *>()) {
1468-
return validateTBD(SF, IRModule, Opts, publicCMOSymbols,
1469-
diagnoseExtraSymbolsInTBD);
1473+
return validateTBD(SF, IRModule, Opts, diagnoseExtraSymbolsInTBD);
14701474
} else {
1471-
return validateTBD(MSF.get<ModuleDecl *>(), IRModule, Opts, publicCMOSymbols,
1475+
return validateTBD(MSF.get<ModuleDecl *>(), IRModule, Opts,
14721476
diagnoseExtraSymbolsInTBD);
14731477
}
14741478
}
@@ -1681,8 +1685,6 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
16811685
return processCommandLineAndRunImmediately(
16821686
Instance, std::move(SM), MSF, observer, ReturnValue);
16831687

1684-
TBDSymbolSetPtr publicCMOSymbols = SM->getPublicCMOSymbols();
1685-
16861688
StringRef OutputFilename = PSPs.OutputFilename;
16871689
std::vector<std::string> ParallelOutputFilenames =
16881690
opts.InputsAndOutputs.copyOutputFilenames();
@@ -1701,8 +1703,7 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
17011703
if (!IRModule)
17021704
return Instance.getDiags().hadAnyError();
17031705

1704-
if (validateTBDIfNeeded(Invocation, MSF, *IRModule.getModule(),
1705-
publicCMOSymbols))
1706+
if (validateTBDIfNeeded(Invocation, MSF, *IRModule.getModule()))
17061707
return true;
17071708

17081709
return generateCode(Instance, OutputFilename, IRModule.getModule(),

lib/FrontendTool/TBD.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static std::vector<StringRef> sortSymbols(llvm::StringSet<> &symbols) {
4242
}
4343

4444
bool swift::writeTBD(ModuleDecl *M, StringRef OutputFilename,
45-
const TBDGenOptions &Opts, TBDSymbolSetPtr publicCMOSymbols) {
45+
const TBDGenOptions &Opts) {
4646
std::error_code EC;
4747
llvm::raw_fd_ostream OS(OutputFilename, EC, llvm::sys::fs::OF_None);
4848
if (EC) {
@@ -51,7 +51,7 @@ bool swift::writeTBD(ModuleDecl *M, StringRef OutputFilename,
5151
return true;
5252
}
5353

54-
writeTBDFile(M, OS, Opts, publicCMOSymbols);
54+
writeTBDFile(M, OS, Opts);
5555

5656
return false;
5757
}
@@ -152,21 +152,17 @@ static bool validateSymbols(DiagnosticEngine &diags,
152152
bool swift::validateTBD(ModuleDecl *M,
153153
const llvm::Module &IRModule,
154154
const TBDGenOptions &opts,
155-
TBDSymbolSetPtr publicCMOSymbols,
156155
bool diagnoseExtraSymbolsInTBD) {
157-
auto symbols = getPublicSymbols(TBDGenDescriptor::forModule(M, opts,
158-
publicCMOSymbols));
156+
auto symbols = getPublicSymbols(TBDGenDescriptor::forModule(M, opts));
159157
return validateSymbols(M->getASTContext().Diags, symbols, IRModule,
160158
diagnoseExtraSymbolsInTBD);
161159
}
162160

163161
bool swift::validateTBD(FileUnit *file,
164162
const llvm::Module &IRModule,
165163
const TBDGenOptions &opts,
166-
TBDSymbolSetPtr publicCMOSymbols,
167164
bool diagnoseExtraSymbolsInTBD) {
168-
auto symbols = getPublicSymbols(TBDGenDescriptor::forFile(file, opts,
169-
publicCMOSymbols));
165+
auto symbols = getPublicSymbols(TBDGenDescriptor::forFile(file, opts));
170166
return validateSymbols(file->getParentModule()->getASTContext().Diags,
171167
symbols, IRModule, diagnoseExtraSymbolsInTBD);
172168
}

lib/FrontendTool/TBD.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define SWIFT_FRONTENDTOOL_TBD_H
1515

1616
#include "swift/Frontend/FrontendOptions.h"
17-
#include "swift/TBDGen/TBDGen.h"
1817

1918
namespace llvm {
2019
class StringRef;
@@ -27,16 +26,14 @@ class FrontendOptions;
2726
struct TBDGenOptions;
2827

2928
bool writeTBD(ModuleDecl *M, StringRef OutputFilename,
30-
const TBDGenOptions &Opts, TBDSymbolSetPtr publicCMOSymbols);
29+
const TBDGenOptions &Opts);
3130
bool validateTBD(ModuleDecl *M,
3231
const llvm::Module &IRModule,
3332
const TBDGenOptions &opts,
34-
TBDSymbolSetPtr publicCMOSymbols,
3533
bool diagnoseExtraSymbolsInTBD);
3634
bool validateTBD(FileUnit *M,
3735
const llvm::Module &IRModule,
3836
const TBDGenOptions &opts,
39-
TBDSymbolSetPtr publicCMOSymbols,
4037
bool diagnoseExtraSymbolsInTBD);
4138
}
4239

lib/IRGen/IRGen.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,6 @@ getSymbolSourcesToEmit(const IRGenDescriptor &desc) {
10321032
irEntitiesToEmit.push_back(source->getIRLinkEntity());
10331033
break;
10341034
case SymbolSource::Kind::LinkerDirective:
1035-
case SymbolSource::Kind::CrossModuleOptimization:
10361035
case SymbolSource::Kind::Unknown:
10371036
llvm_unreachable("Not supported");
10381037
}

0 commit comments

Comments
 (0)