Skip to content

Commit 706c08c

Browse files
authored
Merge pull request swiftlang#12549 from swiftix/sil-serialization-before-optimizations5
Enable the serialization of sil_vtables by default and completely remove the -sil-serialize-vtables option
2 parents e05f7c9 + c3bc08e commit 706c08c

File tree

66 files changed

+102
-137
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+102
-137
lines changed

CMakeLists.txt

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,6 @@ option(SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS
251251
"Overwrite memory for deallocated Swift objects"
252252
"${SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS_default}")
253253

254-
option(SWIFT_SERIALIZE_STDLIB_UNITTEST
255-
"Compile the StdlibUnittest module with -sil-serialize-all to increase the test coverage for the optimizer"
256-
FALSE)
257-
258254
option(SWIFT_STDLIB_SIL_DEBUGGING
259255
"Compile the Swift standard library with -gsil to enable debugging and profiling on SIL level"
260256
FALSE)
@@ -296,20 +292,6 @@ option(SWIFT_STDLIB_ENABLE_SIL_OWNERSHIP
296292
"Build the standard libraries and overlays with sil ownership enabled."
297293
FALSE)
298294

299-
option(SWIFT_STDLIB_SIL_SERIALIZE_ALL
300-
"Build the standard libraries and overlays serializing all method bodies"
301-
TRUE)
302-
303-
if(SWIFT_SERIALIZE_STDLIB_UNITTEST AND SWIFT_STDLIB_ENABLE_RESILIENCE)
304-
message(WARNING "Ignoring SWIFT_SERIALIZE_STDLIB_UNITTEST because SWIFT_STDLIB_ENABLE_RESILIENCE is set")
305-
set(SWIFT_SERIALIZE_STDLIB_UNITTEST FALSE)
306-
endif()
307-
308-
if(SWIFT_STDLIB_SIL_SERIALIZE_ALL AND SWIFT_STDLIB_ENABLE_RESILIENCE)
309-
message(WARNING "Ignoring SWIFT_STDLIB_SIL_SERIALIZE_ALL because SWIFT_STDLIB_ENABLE_RESILIENCE is set")
310-
set(SWIFT_STDLIB_SIL_SERIALIZE_ALL FALSE)
311-
endif()
312-
313295
#
314296
# End of user-configurable options.
315297
#

cmake/modules/SwiftSource.cmake

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,6 @@ function(_compile_swift_files
254254
"-nostdimport" "-parse-stdlib" "-module-name" "Swift")
255255
list(APPEND swift_flags "-Xfrontend" "-group-info-path"
256256
"-Xfrontend" "${GROUP_INFO_JSON_FILE}")
257-
if (NOT SWIFT_STDLIB_ENABLE_RESILIENCE)
258-
if (SWIFT_STDLIB_SIL_SERIALIZE_ALL)
259-
list(APPEND swift_flags "-Xfrontend" "-sil-serialize-vtables")
260-
endif()
261-
endif()
262257
endif()
263258

264259
# Force swift 3 compatibility mode for Standard Library and overlay.

include/swift/AST/SILOptions.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,6 @@ class SILOptions {
150150
/// \brief Enable large loadable types IRGen pass.
151151
bool EnableLargeLoadableTypes = true;
152152

153-
/// If set, SIL vtables will be serialized.
154-
///
155-
/// It is supposed to be used only for compiling overlays.
156-
/// User code should never be compiled with this flag set.
157-
bool SILSerializeVTables = false;
158-
159153
SILOptions() {}
160154

161155
/// Return a hash code of any components from these options that should

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,6 @@ def sil_merge_partial_modules : Flag<["-"], "sil-merge-partial-modules">,
372372
def sil_link_all : Flag<["-"], "sil-link-all">,
373373
HelpText<"Link all SIL functions">;
374374

375-
def sil_serialize_vtables : Flag<["-"], "sil-serialize-vtables">,
376-
HelpText<"Serialize eligible SIL vtables">;
377-
378375
def sil_verify_all : Flag<["-"], "sil-verify-all">,
379376
HelpText<"Verify SIL after each transform">;
380377

include/swift/SIL/SILVTable.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
namespace swift {
3333

3434
class ClassDecl;
35+
enum IsSerialized_t : unsigned char;
3536
class SILFunction;
3637
class SILModule;
3738

@@ -93,14 +94,18 @@ class SILVTable : public llvm::ilist_node<SILVTable>,
9394
/// The ClassDecl mapped to this VTable.
9495
ClassDecl *Class;
9596

97+
/// Whether or not this vtable is serialized, which allows
98+
/// devirtualization from another module.
99+
bool Serialized : 1;
100+
96101
/// The number of SILVTables entries.
97-
unsigned NumEntries;
102+
unsigned NumEntries : 31;
98103

99104
/// Tail-allocated SILVTable entries.
100105
Entry Entries[1];
101106

102107
/// Private constructor. Create SILVTables by calling SILVTable::create.
103-
SILVTable(ClassDecl *c, ArrayRef<Entry> entries);
108+
SILVTable(ClassDecl *c, IsSerialized_t serialized, ArrayRef<Entry> entries);
104109

105110
public:
106111
~SILVTable();
@@ -109,11 +114,15 @@ class SILVTable : public llvm::ilist_node<SILVTable>,
109114
/// The SILDeclRef keys should reference the most-overridden members available
110115
/// through the class.
111116
static SILVTable *create(SILModule &M, ClassDecl *Class,
117+
IsSerialized_t Serialized,
112118
ArrayRef<Entry> Entries);
113119

114120
/// Return the class that the vtable represents.
115121
ClassDecl *getClass() const { return Class; }
116122

123+
/// Returns true if this vtable is going to be (or was) serialized.
124+
IsSerialized_t isSerialized() const;
125+
117126
/// Return all of the method entries.
118127
ArrayRef<Entry> getEntries() const { return {Entries, NumEntries}; }
119128

include/swift/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const uint16_t VERSION_MAJOR = 0;
5454
/// in source control, you should also update the comment to briefly
5555
/// describe what change you made. The content of this comment isn't important;
5656
/// it just ensures a conflict if two people change the module format.
57-
const uint16_t VERSION_MINOR = 371; // Last change: SILFunctionType.noescape
57+
const uint16_t VERSION_MINOR = 372; // Last change: VTable serialized
5858

5959
using DeclID = PointerEmbeddedInt<unsigned, 31>;
6060
using DeclIDField = BCFixed<31>;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,9 +1208,6 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
12081208
if (Args.hasArg(OPT_sil_merge_partial_modules))
12091209
Opts.MergePartialModules = true;
12101210

1211-
Opts.SILSerializeVTables |=
1212-
Args.hasArg(OPT_sil_serialize_vtables);
1213-
12141211
// Parse the optimization level.
12151212
// Default to Onone settings if no option is passed.
12161213
IRGenOpts.Optimize = false;

lib/ParseSIL/ParseSIL.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5108,6 +5108,12 @@ bool SILParserTUState::parseSILVTable(Parser &P) {
51085108
P.consumeToken(tok::kw_sil_vtable);
51095109
SILParser VTableState(P);
51105110

5111+
IsSerialized_t Serialized = IsNotSerialized;
5112+
if (parseDeclSILOptional(nullptr, &Serialized, nullptr, nullptr,
5113+
nullptr, nullptr, nullptr, nullptr, nullptr,
5114+
nullptr, VTableState))
5115+
return true;
5116+
51115117
// Parse the class name.
51125118
Identifier Name;
51135119
SourceLoc Loc;
@@ -5195,7 +5201,7 @@ bool SILParserTUState::parseSILVTable(Parser &P) {
51955201
P.parseMatchingToken(tok::r_brace, RBraceLoc, diag::expected_sil_rbrace,
51965202
LBraceLoc);
51975203

5198-
SILVTable::create(M, theClass, vtableEntries);
5204+
SILVTable::create(M, theClass, Serialized, vtableEntries);
51995205
return false;
52005206
}
52015207

lib/SIL/SILPrinter.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2536,7 +2536,11 @@ void SILInstruction::printInContext(llvm::raw_ostream &OS) const {
25362536
}
25372537

25382538
void SILVTable::print(llvm::raw_ostream &OS, bool Verbose) const {
2539-
OS << "sil_vtable " << getClass()->getName() << " {\n";
2539+
OS << "sil_vtable ";
2540+
if (isSerialized())
2541+
OS << "[serialized] ";
2542+
OS << getClass()->getName() << " {\n";
2543+
25402544
PrintOptions QualifiedSILTypeOptions = PrintOptions::printQualifiedSILType();
25412545
for (auto &entry : getEntries()) {
25422546
OS << " ";

lib/SIL/SILVTable.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
using namespace swift;
2525

2626
SILVTable *SILVTable::create(SILModule &M, ClassDecl *Class,
27+
IsSerialized_t Serialized,
2728
ArrayRef<Entry> Entries) {
2829
// SILVTable contains one element declared in Entries. We must allocate
2930
// space for it, because its default ctor will write to it.
3031
unsigned NumTailElements = std::max((unsigned)Entries.size(), 1U)-1;
3132
void *buf = M.allocate(sizeof(SILVTable) + sizeof(Entry) * NumTailElements,
3233
alignof(SILVTable));
33-
SILVTable *vt = ::new (buf) SILVTable(Class, Entries);
34+
SILVTable *vt = ::new (buf) SILVTable(Class, Serialized, Entries);
3435
M.vtables.push_back(vt);
3536
M.VTableMap[Class] = vt;
3637
// Update the Module's cache with new vtable + vtable entries:
@@ -57,9 +58,13 @@ void SILVTable::removeFromVTableCache(Entry &entry) {
5758
M.VTableEntryCache.erase({this, entry.Method});
5859
}
5960

60-
SILVTable::SILVTable(ClassDecl *c, ArrayRef<Entry> entries)
61-
: Class(c), NumEntries(entries.size())
62-
{
61+
IsSerialized_t SILVTable::isSerialized() const {
62+
return Serialized ? IsSerialized : IsNotSerialized;
63+
}
64+
65+
SILVTable::SILVTable(ClassDecl *c, IsSerialized_t serialized,
66+
ArrayRef<Entry> entries)
67+
: Class(c), Serialized(serialized), NumEntries(entries.size()) {
6368
memcpy(Entries, entries.begin(), sizeof(Entry) * NumEntries);
6469

6570
// Bump the reference count of functions referenced by this table.

0 commit comments

Comments
 (0)