Skip to content

Commit 8e43990

Browse files
committed
IRGen: Remove special handling of fragile entities in LinkEntity
Dead code now that SILGen enforces this. This patch was previously committed and reverted; the optimizer issues exposed by the original version should now be fixed.
1 parent 9a7a517 commit 8e43990

File tree

3 files changed

+18
-64
lines changed

3 files changed

+18
-64
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 14 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,33 +1208,11 @@ bool LinkEntity::isAvailableExternally(IRGenModule &IGM) const {
12081208
llvm_unreachable("bad link entity kind");
12091209
}
12101210

1211-
bool LinkEntity::isFragile(IRGenModule &IGM) const {
1212-
switch (getKind()) {
1213-
case Kind::SILFunction:
1214-
return getSILFunction()->isFragile();
1215-
1216-
case Kind::SILGlobalVariable:
1217-
return getSILGlobalVariable()->isFragile();
1218-
1219-
case Kind::DirectProtocolWitnessTable: {
1220-
if (auto wt = IGM.SILMod->lookUpWitnessTable(getProtocolConformance())) {
1221-
return wt->isFragile();
1222-
} else {
1223-
return false;
1224-
}
1225-
}
1226-
1227-
default:
1228-
break;
1229-
}
1230-
return false;
1231-
}
1232-
12331211

12341212
static std::pair<llvm::GlobalValue::LinkageTypes,
12351213
llvm::GlobalValue::VisibilityTypes>
12361214
getIRLinkage(IRGenModule &IGM,
1237-
SILLinkage linkage, bool isFragile, ForDefinition_t isDefinition,
1215+
SILLinkage linkage, ForDefinition_t isDefinition,
12381216
bool isWeakImported) {
12391217

12401218
#define RESULT(LINKAGE, VISIBILITY) \
@@ -1256,39 +1234,25 @@ llvm::GlobalValue::VISIBILITY##Visibility }
12561234
break;
12571235
}
12581236

1259-
if (isFragile) {
1260-
// Fragile functions/globals must be visible from outside, regardless of
1261-
// their accessibility. If a caller is also fragile and inlined into another
1262-
// module it must be able to access this (not-inlined) function/global.
1263-
switch (linkage) {
1264-
case SILLinkage::Hidden:
1265-
case SILLinkage::Private:
1266-
linkage = SILLinkage::Public;
1267-
break;
1268-
1269-
case SILLinkage::Public:
1270-
case SILLinkage::Shared:
1271-
case SILLinkage::HiddenExternal:
1272-
case SILLinkage::PrivateExternal:
1273-
case SILLinkage::PublicExternal:
1274-
case SILLinkage::SharedExternal:
1275-
break;
1276-
}
1277-
}
1278-
12791237
switch (linkage) {
12801238
case SILLinkage::Public:
12811239
return {llvm::GlobalValue::ExternalLinkage, PublicDefinitionVisibility};
1240+
12821241
case SILLinkage::Shared:
1283-
case SILLinkage::SharedExternal: return RESULT(LinkOnceODR, Hidden);
1284-
case SILLinkage::Hidden: return RESULT(External, Hidden);
1242+
case SILLinkage::SharedExternal:
1243+
return RESULT(LinkOnceODR, Hidden);
1244+
1245+
case SILLinkage::Hidden:
1246+
return RESULT(External, Hidden);
1247+
12851248
case SILLinkage::Private:
12861249
if (IGM.dispatcher.hasMultipleIGMs()) {
12871250
// In case of multiple llvm modules (in multi-threaded compilation) all
12881251
// private decls must be visible from other files.
12891252
return RESULT(External, Hidden);
12901253
}
12911254
return RESULT(Internal, Default);
1255+
12921256
case SILLinkage::PublicExternal:
12931257
if (isDefinition) {
12941258
return RESULT(AvailableExternally, Default);
@@ -1297,15 +1261,12 @@ llvm::GlobalValue::VISIBILITY##Visibility }
12971261
if (isWeakImported)
12981262
return RESULT(ExternalWeak, Default);
12991263
return RESULT(External, Default);
1264+
13001265
case SILLinkage::HiddenExternal:
1301-
case SILLinkage::PrivateExternal: {
1302-
auto visibility = isFragile ? llvm::GlobalValue::DefaultVisibility
1303-
: llvm::GlobalValue::HiddenVisibility;
1304-
if (isDefinition) {
1305-
return {llvm::GlobalValue::AvailableExternallyLinkage, visibility};
1306-
}
1307-
return {llvm::GlobalValue::ExternalLinkage, visibility};
1308-
}
1266+
case SILLinkage::PrivateExternal:
1267+
if (isDefinition)
1268+
return RESULT(AvailableExternally, Hidden);
1269+
return RESULT(External, Hidden);
13091270
}
13101271
llvm_unreachable("bad SIL linkage");
13111272
}
@@ -1320,7 +1281,6 @@ static void updateLinkageForDefinition(IRGenModule &IGM,
13201281
auto linkage = getIRLinkage(
13211282
IGM,
13221283
entity.getLinkage(IGM, ForDefinition),
1323-
entity.isFragile(IGM),
13241284
ForDefinition,
13251285
entity.isWeakImported(IGM.SILMod->getSwiftModule()));
13261286
global->setLinkage(linkage.first);
@@ -1346,7 +1306,6 @@ LinkInfo LinkInfo::get(IRGenModule &IGM, const LinkEntity &entity,
13461306

13471307
std::tie(result.Linkage, result.Visibility) =
13481308
getIRLinkage(IGM, entity.getLinkage(IGM, isDefinition),
1349-
entity.isFragile(IGM),
13501309
isDefinition,
13511310
entity.isWeakImported(IGM.SILMod->getSwiftModule()));
13521311

lib/IRGen/Linking.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,11 +505,6 @@ class LinkEntity {
505505
///
506506
bool isAvailableExternally(IRGenModule &IGM) const;
507507

508-
/// Returns true if this function or global variable may be inlined into
509-
/// another module.
510-
///
511-
bool isFragile(IRGenModule &IGM) const;
512-
513508
ValueDecl *getDecl() const {
514509
assert(isDeclKind(getKind()));
515510
return reinterpret_cast<ValueDecl*>(Pointer);

test/IRGen/sil_linkage.sil

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
sil_stage canonical
44

55
// CHECK: define{{( protected)?}} void @public_fragile_function_test() {{.*}} {
6-
// CHECK: define{{( protected)?}} void @hidden_fragile_function_test() {{.*}} {
6+
// CHECK: define hidden void @hidden_fragile_function_test() {{.*}} {
77
// CHECK: define linkonce_odr hidden void @shared_fragile_function_test() {{.*}} {
8-
// CHECK: define{{( protected)?}} void @private_fragile_function_test() {{.*}} {
8+
// CHECK: define internal void @private_fragile_function_test() {{.*}} {
99
// CHECK: define linkonce_odr hidden void @public_external_fragile_function_def_test() {{.*}} {
10-
// CHECK: define{{( protected)?}} available_externally void @hidden_external_fragile_function_def_test() {{.*}} {
10+
// CHECK: define available_externally hidden void @hidden_external_fragile_function_def_test() {{.*}} {
1111
// CHECK: define linkonce_odr hidden void @shared_external_fragile_function_def_test() {{.*}} {
12-
// CHECK: define{{( protected)?}} available_externally void @private_external_fragile_function_def_test() {{.*}} {
12+
// CHECK: define available_externally hidden void @private_external_fragile_function_def_test() {{.*}} {
1313
// CHECK: define{{( protected)?}} void @public_resilient_function_test() {{.*}} {
1414
// CHECK: define hidden void @hidden_resilient_function_test() {{.*}} {
1515
// CHECK: define linkonce_odr hidden void @shared_resilient_function_test() {{.*}} {

0 commit comments

Comments
 (0)