Skip to content

Commit 152fab2

Browse files
authored
Revert "IRGen: Ensure that default witness thunks are emitted in the same thread as the protocol descriptor"
1 parent f771e4c commit 152fab2

File tree

7 files changed

+19
-48
lines changed

7 files changed

+19
-48
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ static bool hasCodeCoverageInstrumentation(SILFunction &f, SILModule &m) {
984984
return f.getProfiler() && m.getOptions().EmitProfileCoverageMapping;
985985
}
986986

987-
void IRGenerator::emitGlobalTopLevel() {
987+
void IRGenerator::emitGlobalTopLevel(bool emitForParallelEmission) {
988988
// Generate order numbers for the functions in the SIL module that
989989
// correspond to definitions in the LLVM module.
990990
unsigned nextOrderNumber = 0;
@@ -994,6 +994,13 @@ void IRGenerator::emitGlobalTopLevel() {
994994
FunctionOrder.insert(std::make_pair(&silFn, nextOrderNumber++));
995995
}
996996

997+
// Ensure that relative symbols are collocated in the same LLVM module.
998+
for (SILWitnessTable &wt : PrimaryIGM->getSILModule().getWitnessTableList()) {
999+
CurrentIGMPtr IGM = getGenModule(wt.getDeclContext());
1000+
if (emitForParallelEmission)
1001+
IGM->ensureRelativeSymbolCollocation(wt);
1002+
}
1003+
9971004
for (SILGlobalVariable &v : PrimaryIGM->getSILModule().getSILGlobals()) {
9981005
Decl *decl = v.getDecl();
9991006
CurrentIGMPtr IGM = getGenModule(decl ? decl->getDeclContext() : nullptr);

lib/IRGen/GenMeta.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4046,9 +4046,6 @@ void IRGenModule::emitProtocolDecl(ProtocolDecl *protocol) {
40464046
if (isResilient(protocol, ResilienceExpansion::Minimal))
40474047
defaultWitnesses = getSILModule().lookUpDefaultWitnessTable(protocol);
40484048

4049-
if (defaultWitnesses)
4050-
IRGen.ensureRelativeSymbolCollocation(*defaultWitnesses);
4051-
40524049
{
40534050
ProtocolDescriptorBuilder builder(*this, protocol, defaultWitnesses);
40544051
builder.emit();

lib/IRGen/GenProto.cpp

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@
3838
#include "swift/ClangImporter/ClangModule.h"
3939
#include "swift/IRGen/Linking.h"
4040
#include "swift/SIL/SILDeclRef.h"
41-
#include "swift/SIL/SILDefaultWitnessTable.h"
4241
#include "swift/SIL/SILModule.h"
4342
#include "swift/SIL/SILValue.h"
44-
#include "swift/SIL/SILWitnessTable.h"
4543
#include "swift/SIL/SILWitnessVisitor.h"
4644
#include "swift/SIL/TypeLowering.h"
4745
#include "llvm/ADT/SmallString.h"
@@ -2081,10 +2079,7 @@ void IRGenModule::emitProtocolConformance(
20812079
setTrueConstGlobal(var);
20822080
}
20832081

2084-
void IRGenerator::ensureRelativeSymbolCollocation(SILWitnessTable &wt) {
2085-
if (!CurrentIGM)
2086-
return;
2087-
2082+
void IRGenModule::ensureRelativeSymbolCollocation(SILWitnessTable &wt) {
20882083
// Only resilient conformances use relative pointers for witness methods.
20892084
if (wt.isDeclaration() || isAvailableExternally(wt.getLinkage()) ||
20902085
!isResilientConformance(wt.getConformance()))
@@ -2095,20 +2090,7 @@ void IRGenerator::ensureRelativeSymbolCollocation(SILWitnessTable &wt) {
20952090
continue;
20962091
auto *witness = entry.getMethodWitness().Witness;
20972092
if (witness)
2098-
forceLocalEmitOfLazyFunction(witness);
2099-
}
2100-
}
2101-
2102-
void IRGenerator::ensureRelativeSymbolCollocation(SILDefaultWitnessTable &wt) {
2103-
if (!CurrentIGM)
2104-
return;
2105-
2106-
for (auto &entry : wt.getEntries()) {
2107-
if (entry.getKind() != SILWitnessTable::Method)
2108-
continue;
2109-
auto *witness = entry.getMethodWitness().Witness;
2110-
if (witness)
2111-
forceLocalEmitOfLazyFunction(witness);
2093+
IRGen.forceLocalEmitOfLazyFunction(witness);
21122094
}
21132095
}
21142096

@@ -2252,10 +2234,6 @@ void IRGenModule::emitSILWitnessTable(SILWitnessTable *wt) {
22522234
if (isAvailableExternally(wt->getLinkage()))
22532235
return;
22542236

2255-
// Ensure that relatively-referenced symbols for witness thunks are collocated
2256-
// in the same LLVM module.
2257-
IRGen.ensureRelativeSymbolCollocation(*wt);
2258-
22592237
auto conf = wt->getConformance();
22602238
PrettyStackTraceConformance _st(Context, "emitting witness table for", conf);
22612239

lib/IRGen/IRGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,11 +964,11 @@ static void performParallelIRGeneration(
964964
}
965965

966966
// Emit the module contents.
967-
irgen.emitGlobalTopLevel();
967+
irgen.emitGlobalTopLevel(true /*emitForParallelEmission*/);
968968

969969
for (auto *File : M->getFiles()) {
970970
if (auto *SF = dyn_cast<SourceFile>(File)) {
971-
CurrentIGMPtr IGM = irgen.getGenModule(SF);
971+
IRGenModule *IGM = irgen.getGenModule(SF);
972972
IGM->emitSourceFile(*SF);
973973
} else {
974974
File->collectLinkLibraries([&](LinkLibrary LinkLib) {

lib/IRGen/IRGenModule.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ namespace swift {
9393
class ProtocolCompositionType;
9494
class RootProtocolConformance;
9595
struct SILDeclRef;
96-
class SILDefaultWitnessTable;
9796
class SILGlobalVariable;
9897
class SILModule;
9998
class SILProperty;
@@ -312,7 +311,11 @@ class IRGenerator {
312311

313312
/// Emit functions, variables and tables which are needed anyway, e.g. because
314313
/// they are externally visible.
315-
void emitGlobalTopLevel();
314+
/// If \p emitForParallelEmission is true ensures that symbols that are
315+
/// expressed as relative pointers are collocated in the same output module
316+
/// with their base symbol. For example, witness methods need to be collocated
317+
/// with the witness table in the same LLVM module.
318+
void emitGlobalTopLevel(bool emitForParallelEmission = false);
316319

317320
/// Emit references to each of the protocol descriptors defined in this
318321
/// IR module.
@@ -352,10 +355,6 @@ class IRGenerator {
352355
DefaultIGMForFunction[f] = CurrentIGM;
353356
}
354357

355-
void ensureRelativeSymbolCollocation(SILWitnessTable &wt);
356-
357-
void ensureRelativeSymbolCollocation(SILDefaultWitnessTable &wt);
358-
359358
void noteUseOfTypeMetadata(NominalTypeDecl *type) {
360359
noteUseOfTypeGlobals(type, true, RequireMetadata);
361360
}
@@ -1387,6 +1386,8 @@ private: \
13871386

13881387
void emitSharedContextDescriptor(DeclContext *dc);
13891388

1389+
void ensureRelativeSymbolCollocation(SILWitnessTable &wt);
1390+
13901391
llvm::GlobalVariable *
13911392
getGlobalForDynamicallyReplaceableThunk(LinkEntity &entity, llvm::Type *type,
13921393
ForDefinition_t forDefinition);

test/IRGen/Inputs/multithread_resilience_other.swift

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/IRGen/multithread_resilience.swift

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)