Skip to content

Commit 9b52f82

Browse files
committed
Remove InLTOMode flag.
Add a flag to differentiate between ExportSummary that is built locally and the external one.
1 parent 3f99a0b commit 9b52f82

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

llvm/include/llvm/Transforms/IPO/WholeProgramDevirt.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,15 @@ struct WholeProgramDevirtPass : public PassInfoMixin<WholeProgramDevirtPass> {
226226
ModuleSummaryIndex *ExportSummary;
227227
const ModuleSummaryIndex *ImportSummary;
228228
bool UseCommandLine = false;
229-
// Default value for LTO mode is true, as this is the default behavior for
230-
// whole program devirtualization unless explicitly disabled.
231-
const bool InLTOMode;
229+
// True if ExportSummary was built locally from the module rather than
230+
// provided externally to the pass (e.g., during LTO). Default value is false
231+
// unless explicitly set when the Summary is explicitly built.
232+
bool HasLocalSummary = false;
232233
WholeProgramDevirtPass()
233-
: ExportSummary(nullptr), ImportSummary(nullptr), UseCommandLine(true),
234-
InLTOMode(true) {}
234+
: ExportSummary(nullptr), ImportSummary(nullptr), UseCommandLine(true) {}
235235
WholeProgramDevirtPass(ModuleSummaryIndex *ExportSummary,
236-
const ModuleSummaryIndex *ImportSummary,
237-
bool InLTOMode = true)
238-
: ExportSummary(ExportSummary), ImportSummary(ImportSummary),
239-
InLTOMode(InLTOMode) {
236+
const ModuleSummaryIndex *ImportSummary)
237+
: ExportSummary(ExportSummary), ImportSummary(ImportSummary) {
240238
assert(!(ExportSummary && ImportSummary));
241239
}
242240
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &);

llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,9 @@ struct DevirtModule {
603603

604604
ModuleSummaryIndex *const ExportSummary;
605605
const ModuleSummaryIndex *const ImportSummary;
606-
607-
const bool InLTOMode;
606+
// True if ExportSummary was built locally from the module.
607+
// Default is false unless explicitly set.
608+
const bool HasLocalSummary;
608609

609610
IntegerType *const Int8Ty;
610611
PointerType *const Int8PtrTy;
@@ -642,11 +643,13 @@ struct DevirtModule {
642643

643644
DevirtModule(Module &M, ModuleAnalysisManager &MAM,
644645
ModuleSummaryIndex *ExportSummary,
645-
const ModuleSummaryIndex *ImportSummary, bool InLTOMode = true)
646+
const ModuleSummaryIndex *ImportSummary,
647+
bool HasLocalSummary = false)
646648
: M(M), MAM(MAM),
647649
FAM(MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager()),
648650
ExportSummary(ExportSummary), ImportSummary(ImportSummary),
649-
InLTOMode(InLTOMode), Int8Ty(Type::getInt8Ty(M.getContext())),
651+
HasLocalSummary(HasLocalSummary),
652+
Int8Ty(Type::getInt8Ty(M.getContext())),
650653
Int8PtrTy(PointerType::getUnqual(M.getContext())),
651654
Int32Ty(Type::getInt32Ty(M.getContext())),
652655
Int64Ty(Type::getInt64Ty(M.getContext())),
@@ -816,7 +819,8 @@ PreservedAnalyses WholeProgramDevirtPass::run(Module &M,
816819
return PreservedAnalyses::all();
817820
return PreservedAnalyses::none();
818821
}
819-
if (!DevirtModule(M, MAM, ExportSummary, ImportSummary, InLTOMode).run())
822+
if (!DevirtModule(M, MAM, ExportSummary, ImportSummary, HasLocalSummary)
823+
.run())
820824
return PreservedAnalyses::all();
821825
return PreservedAnalyses::none();
822826
}
@@ -1360,7 +1364,7 @@ bool DevirtModule::trySingleImplDevirt(
13601364
// If the only implementation has local linkage, we must promote
13611365
// to external to make it visible to thin LTO objects.
13621366
// This change should be safe only in LTO mode.
1363-
if (InLTOMode && TheFn->hasLocalLinkage()) {
1367+
if (!HasLocalSummary && TheFn->hasLocalLinkage()) {
13641368
std::string NewName = (TheFn->getName() + ".llvm.merged").str();
13651369

13661370
// Since we are renaming the function, any comdats with the same name must
@@ -2518,6 +2522,7 @@ bool DevirtModule::run() {
25182522
trySingleImplDevirt(ExportSummary, TargetsForSlot, S.second, Res);
25192523
// Out of speculative devirtualization mode, Try to apply virtual constant
25202524
// propagation or branch funneling.
2525+
// TODO: This should eventually be enabled for non-public type tests.
25212526
if (!SingleImplDevirt && !ClDevirtualizeSpeculatively) {
25222527
DidVirtualConstProp |=
25232528
tryVirtualConstProp(TargetsForSlot, S.second, Res, S.first);

0 commit comments

Comments
 (0)