@@ -446,39 +446,52 @@ void llvm::thinLTOResolvePrevailingInIndex(
446
446
recordNewLinkage, GUIDPreservedSymbols);
447
447
}
448
448
449
- static bool isWeakObjectWithRWAccess (GlobalValueSummary *GVS) {
450
- if (auto *VarSummary = dyn_cast<GlobalVarSummary>(GVS->getBaseObject ()))
451
- return !VarSummary->maybeReadOnly () && !VarSummary->maybeWriteOnly () &&
452
- (VarSummary->linkage () == GlobalValue::WeakODRLinkage ||
453
- VarSummary->linkage () == GlobalValue::LinkOnceODRLinkage);
454
- return false ;
455
- }
456
-
457
449
static void thinLTOInternalizeAndPromoteGUID (
458
450
ValueInfo VI, function_ref<bool (StringRef, ValueInfo)> isExported,
459
451
function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
460
452
isPrevailing) {
461
453
for (auto &S : VI.getSummaryList ()) {
454
+ // First see if we need to promote an internal value because it is not
455
+ // exported.
462
456
if (isExported (S->modulePath (), VI)) {
463
457
if (GlobalValue::isLocalLinkage (S->linkage ()))
464
458
S->setLinkage (GlobalValue::ExternalLinkage);
465
- } else if (EnableLTOInternalization &&
466
- // Ignore local and appending linkage values since the linker
467
- // doesn't resolve them.
468
- !GlobalValue::isLocalLinkage (S->linkage ()) &&
469
- (!GlobalValue::isInterposableLinkage (S->linkage ()) ||
470
- isPrevailing (VI.getGUID (), S.get ())) &&
471
- S->linkage () != GlobalValue::AppendingLinkage &&
472
- // We can't internalize available_externally globals because this
473
- // can break function pointer equality.
474
- S->linkage () != GlobalValue::AvailableExternallyLinkage &&
475
- // Functions and read-only variables with linkonce_odr and
476
- // weak_odr linkage can be internalized. We can't internalize
477
- // linkonce_odr and weak_odr variables which are both modified
478
- // and read somewhere in the program because reads and writes
479
- // will become inconsistent.
480
- !isWeakObjectWithRWAccess (S.get ()))
481
- S->setLinkage (GlobalValue::InternalLinkage);
459
+ continue ;
460
+ }
461
+
462
+ // Otherwise, see if we can internalize.
463
+ if (!EnableLTOInternalization)
464
+ continue ;
465
+
466
+ // Ignore local and appending linkage values since the linker
467
+ // doesn't resolve them (and there is no need to internalize if this is
468
+ // already internal).
469
+ if (GlobalValue::isLocalLinkage (S->linkage ()) ||
470
+ S->linkage () == GlobalValue::AppendingLinkage)
471
+ continue ;
472
+
473
+ // We can't internalize available_externally globals because this
474
+ // can break function pointer equality.
475
+ if (S->linkage () == GlobalValue::AvailableExternallyLinkage)
476
+ continue ;
477
+
478
+ bool IsPrevailing = isPrevailing (VI.getGUID (), S.get ());
479
+
480
+ if (GlobalValue::isInterposableLinkage (S->linkage ()) && !IsPrevailing)
481
+ continue ;
482
+
483
+ // Functions and read-only variables with linkonce_odr and weak_odr linkage
484
+ // can be internalized. We can't internalize linkonce_odr and weak_odr
485
+ // variables which are both modified and read somewhere in the program
486
+ // because reads and writes will become inconsistent.
487
+ auto *VarSummary = dyn_cast<GlobalVarSummary>(S->getBaseObject ());
488
+ if (VarSummary && !VarSummary->maybeReadOnly () &&
489
+ !VarSummary->maybeWriteOnly () &&
490
+ (VarSummary->linkage () == GlobalValue::WeakODRLinkage ||
491
+ VarSummary->linkage () == GlobalValue::LinkOnceODRLinkage))
492
+ continue ;
493
+
494
+ S->setLinkage (GlobalValue::InternalLinkage);
482
495
}
483
496
}
484
497
0 commit comments