Skip to content

Revert "IRGen: Ensure that default witness thunks are emitted in the same thread as the protocol descriptor" #21870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ static bool hasCodeCoverageInstrumentation(SILFunction &f, SILModule &m) {
return f.getProfiler() && m.getOptions().EmitProfileCoverageMapping;
}

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

// Ensure that relative symbols are collocated in the same LLVM module.
for (SILWitnessTable &wt : PrimaryIGM->getSILModule().getWitnessTableList()) {
CurrentIGMPtr IGM = getGenModule(wt.getDeclContext());
if (emitForParallelEmission)
IGM->ensureRelativeSymbolCollocation(wt);
}

for (SILGlobalVariable &v : PrimaryIGM->getSILModule().getSILGlobals()) {
Decl *decl = v.getDecl();
CurrentIGMPtr IGM = getGenModule(decl ? decl->getDeclContext() : nullptr);
Expand Down
3 changes: 0 additions & 3 deletions lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4046,9 +4046,6 @@ void IRGenModule::emitProtocolDecl(ProtocolDecl *protocol) {
if (isResilient(protocol, ResilienceExpansion::Minimal))
defaultWitnesses = getSILModule().lookUpDefaultWitnessTable(protocol);

if (defaultWitnesses)
IRGen.ensureRelativeSymbolCollocation(*defaultWitnesses);

{
ProtocolDescriptorBuilder builder(*this, protocol, defaultWitnesses);
builder.emit();
Expand Down
26 changes: 2 additions & 24 deletions lib/IRGen/GenProto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@
#include "swift/ClangImporter/ClangModule.h"
#include "swift/IRGen/Linking.h"
#include "swift/SIL/SILDeclRef.h"
#include "swift/SIL/SILDefaultWitnessTable.h"
#include "swift/SIL/SILModule.h"
#include "swift/SIL/SILValue.h"
#include "swift/SIL/SILWitnessTable.h"
#include "swift/SIL/SILWitnessVisitor.h"
#include "swift/SIL/TypeLowering.h"
#include "llvm/ADT/SmallString.h"
Expand Down Expand Up @@ -2081,10 +2079,7 @@ void IRGenModule::emitProtocolConformance(
setTrueConstGlobal(var);
}

void IRGenerator::ensureRelativeSymbolCollocation(SILWitnessTable &wt) {
if (!CurrentIGM)
return;

void IRGenModule::ensureRelativeSymbolCollocation(SILWitnessTable &wt) {
// Only resilient conformances use relative pointers for witness methods.
if (wt.isDeclaration() || isAvailableExternally(wt.getLinkage()) ||
!isResilientConformance(wt.getConformance()))
Expand All @@ -2095,20 +2090,7 @@ void IRGenerator::ensureRelativeSymbolCollocation(SILWitnessTable &wt) {
continue;
auto *witness = entry.getMethodWitness().Witness;
if (witness)
forceLocalEmitOfLazyFunction(witness);
}
}

void IRGenerator::ensureRelativeSymbolCollocation(SILDefaultWitnessTable &wt) {
if (!CurrentIGM)
return;

for (auto &entry : wt.getEntries()) {
if (entry.getKind() != SILWitnessTable::Method)
continue;
auto *witness = entry.getMethodWitness().Witness;
if (witness)
forceLocalEmitOfLazyFunction(witness);
IRGen.forceLocalEmitOfLazyFunction(witness);
}
}

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

// Ensure that relatively-referenced symbols for witness thunks are collocated
// in the same LLVM module.
IRGen.ensureRelativeSymbolCollocation(*wt);

auto conf = wt->getConformance();
PrettyStackTraceConformance _st(Context, "emitting witness table for", conf);

Expand Down
4 changes: 2 additions & 2 deletions lib/IRGen/IRGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,11 +964,11 @@ static void performParallelIRGeneration(
}

// Emit the module contents.
irgen.emitGlobalTopLevel();
irgen.emitGlobalTopLevel(true /*emitForParallelEmission*/);

for (auto *File : M->getFiles()) {
if (auto *SF = dyn_cast<SourceFile>(File)) {
CurrentIGMPtr IGM = irgen.getGenModule(SF);
IRGenModule *IGM = irgen.getGenModule(SF);
IGM->emitSourceFile(*SF);
} else {
File->collectLinkLibraries([&](LinkLibrary LinkLib) {
Expand Down
13 changes: 7 additions & 6 deletions lib/IRGen/IRGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ namespace swift {
class ProtocolCompositionType;
class RootProtocolConformance;
struct SILDeclRef;
class SILDefaultWitnessTable;
class SILGlobalVariable;
class SILModule;
class SILProperty;
Expand Down Expand Up @@ -312,7 +311,11 @@ class IRGenerator {

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

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

void ensureRelativeSymbolCollocation(SILWitnessTable &wt);

void ensureRelativeSymbolCollocation(SILDefaultWitnessTable &wt);

void noteUseOfTypeMetadata(NominalTypeDecl *type) {
noteUseOfTypeGlobals(type, true, RequireMetadata);
}
Expand Down Expand Up @@ -1387,6 +1386,8 @@ private: \

void emitSharedContextDescriptor(DeclContext *dc);

void ensureRelativeSymbolCollocation(SILWitnessTable &wt);

llvm::GlobalVariable *
getGlobalForDynamicallyReplaceableThunk(LinkEntity &entity, llvm::Type *type,
ForDefinition_t forDefinition);
Expand Down
3 changes: 0 additions & 3 deletions test/IRGen/Inputs/multithread_resilience_other.swift

This file was deleted.

9 changes: 0 additions & 9 deletions test/IRGen/multithread_resilience.swift

This file was deleted.