@@ -572,8 +572,8 @@ void VTableSlotInfo::addCallSite(Value *VTable, CallBase &CB,
572
572
573
573
struct DevirtModule {
574
574
Module &M;
575
- function_ref<AAResults &(Function &)> AARGetter ;
576
- function_ref<DominatorTree &(Function &)> LookupDomTree ;
575
+ ModuleAnalysisManager &MAM ;
576
+ FunctionAnalysisManager &FAM ;
577
577
578
578
ModuleSummaryIndex *const ExportSummary;
579
579
const ModuleSummaryIndex *const ImportSummary;
@@ -589,7 +589,7 @@ struct DevirtModule {
589
589
ArrayType *const Int8Arr0Ty;
590
590
591
591
const bool RemarksEnabled;
592
- function_ref <OptimizationRemarkEmitter &(Function &)> OREGetter;
592
+ std::function <OptimizationRemarkEmitter &(Function &)> OREGetter;
593
593
MapVector<VTableSlot, VTableSlotInfo> CallSlots;
594
594
595
595
// Calls that have already been optimized. We may add a call to multiple
@@ -612,20 +612,22 @@ struct DevirtModule {
612
612
std::map<CallInst *, unsigned > NumUnsafeUsesForTypeTest;
613
613
PatternList FunctionsToSkip;
614
614
615
- DevirtModule (Module &M, function_ref<AAResults &(Function &)> AARGetter,
616
- function_ref<OptimizationRemarkEmitter &(Function &)> OREGetter,
617
- function_ref<DominatorTree &(Function &)> LookupDomTree,
615
+ DevirtModule (Module &M, ModuleAnalysisManager &MAM,
618
616
ModuleSummaryIndex *ExportSummary,
619
617
const ModuleSummaryIndex *ImportSummary)
620
- : M(M), AARGetter(AARGetter), LookupDomTree(LookupDomTree),
618
+ : M(M), MAM(MAM),
619
+ FAM (MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager()),
621
620
ExportSummary(ExportSummary), ImportSummary(ImportSummary),
622
621
Int8Ty(Type::getInt8Ty(M.getContext())),
623
622
Int8PtrTy(PointerType::getUnqual(M.getContext())),
624
623
Int32Ty(Type::getInt32Ty(M.getContext())),
625
624
Int64Ty(Type::getInt64Ty(M.getContext())),
626
625
IntPtrTy(M.getDataLayout().getIntPtrType(M.getContext(), 0)),
627
626
Int8Arr0Ty(ArrayType::get(Type::getInt8Ty(M.getContext()), 0)),
628
- RemarksEnabled(areRemarksEnabled()), OREGetter(OREGetter) {
627
+ RemarksEnabled(areRemarksEnabled()),
628
+ OREGetter([&](Function &F) -> OptimizationRemarkEmitter & {
629
+ return FAM.getResult <OptimizationRemarkEmitterAnalysis>(F);
630
+ }) {
629
631
assert (!(ExportSummary && ImportSummary));
630
632
FunctionsToSkip.init (SkipFunctionNames);
631
633
}
@@ -739,10 +741,7 @@ struct DevirtModule {
739
741
740
742
// Lower the module using the action and summary passed as command line
741
743
// arguments. For testing purposes only.
742
- static bool
743
- runForTesting (Module &M, function_ref<AAResults &(Function &)> AARGetter,
744
- function_ref<OptimizationRemarkEmitter &(Function &)> OREGetter,
745
- function_ref<DominatorTree &(Function &)> LookupDomTree);
744
+ static bool runForTesting (Module &M, ModuleAnalysisManager &MAM);
746
745
};
747
746
748
747
struct DevirtIndex {
@@ -783,25 +782,13 @@ struct DevirtIndex {
783
782
} // end anonymous namespace
784
783
785
784
PreservedAnalyses WholeProgramDevirtPass::run (Module &M,
786
- ModuleAnalysisManager &AM) {
787
- auto &FAM = AM.getResult <FunctionAnalysisManagerModuleProxy>(M).getManager ();
788
- auto AARGetter = [&](Function &F) -> AAResults & {
789
- return FAM.getResult <AAManager>(F);
790
- };
791
- auto OREGetter = [&](Function &F) -> OptimizationRemarkEmitter & {
792
- return FAM.getResult <OptimizationRemarkEmitterAnalysis>(F);
793
- };
794
- auto LookupDomTree = [&FAM](Function &F) -> DominatorTree & {
795
- return FAM.getResult <DominatorTreeAnalysis>(F);
796
- };
785
+ ModuleAnalysisManager &MAM) {
797
786
if (UseCommandLine) {
798
- if (!DevirtModule::runForTesting (M, AARGetter, OREGetter, LookupDomTree ))
787
+ if (!DevirtModule::runForTesting (M, MAM ))
799
788
return PreservedAnalyses::all ();
800
789
return PreservedAnalyses::none ();
801
790
}
802
- if (!DevirtModule (M, AARGetter, OREGetter, LookupDomTree, ExportSummary,
803
- ImportSummary)
804
- .run ())
791
+ if (!DevirtModule (M, MAM, ExportSummary, ImportSummary).run ())
805
792
return PreservedAnalyses::all ();
806
793
return PreservedAnalyses::none ();
807
794
}
@@ -996,10 +983,7 @@ static Error checkCombinedSummaryForTesting(ModuleSummaryIndex *Summary) {
996
983
return ErrorSuccess ();
997
984
}
998
985
999
- bool DevirtModule::runForTesting (
1000
- Module &M, function_ref<AAResults &(Function &)> AARGetter,
1001
- function_ref<OptimizationRemarkEmitter &(Function &)> OREGetter,
1002
- function_ref<DominatorTree &(Function &)> LookupDomTree) {
986
+ bool DevirtModule::runForTesting (Module &M, ModuleAnalysisManager &MAM) {
1003
987
std::unique_ptr<ModuleSummaryIndex> Summary =
1004
988
std::make_unique<ModuleSummaryIndex>(/* HaveGVs=*/ false );
1005
989
@@ -1024,7 +1008,7 @@ bool DevirtModule::runForTesting(
1024
1008
}
1025
1009
1026
1010
bool Changed =
1027
- DevirtModule (M, AARGetter, OREGetter, LookupDomTree ,
1011
+ DevirtModule (M, MAM ,
1028
1012
ClSummaryAction == PassSummaryAction::Export ? Summary.get ()
1029
1013
: nullptr ,
1030
1014
ClSummaryAction == PassSummaryAction::Import ? Summary.get ()
@@ -1877,7 +1861,7 @@ bool DevirtModule::tryVirtualConstProp(
1877
1861
return false ;
1878
1862
1879
1863
if (Fn->isDeclaration () ||
1880
- !computeFunctionBodyMemoryAccess (*Fn, AARGetter (*Fn))
1864
+ !computeFunctionBodyMemoryAccess (*Fn, FAM. getResult <AAManager> (*Fn))
1881
1865
.doesNotAccessMemory () ||
1882
1866
Fn->arg_empty () || !Fn->arg_begin ()->use_empty () ||
1883
1867
Fn->getReturnType () != RetType)
@@ -2051,7 +2035,7 @@ void DevirtModule::scanTypeTestUsers(
2051
2035
// Search for virtual calls based on %p and add them to DevirtCalls.
2052
2036
SmallVector<DevirtCallSite, 1 > DevirtCalls;
2053
2037
SmallVector<CallInst *, 1 > Assumes;
2054
- auto &DT = LookupDomTree (*CI->getFunction ());
2038
+ auto &DT = FAM. getResult <DominatorTreeAnalysis> (*CI->getFunction ());
2055
2039
findDevirtualizableCallsForTypeTest (DevirtCalls, Assumes, CI, DT);
2056
2040
2057
2041
Metadata *TypeId =
@@ -2128,7 +2112,7 @@ void DevirtModule::scanTypeCheckedLoadUsers(Function *TypeCheckedLoadFunc) {
2128
2112
SmallVector<Instruction *, 1 > LoadedPtrs;
2129
2113
SmallVector<Instruction *, 1 > Preds;
2130
2114
bool HasNonCallUses = false ;
2131
- auto &DT = LookupDomTree (*CI->getFunction ());
2115
+ auto &DT = FAM. getResult <DominatorTreeAnalysis> (*CI->getFunction ());
2132
2116
findDevirtualizableCallsForTypeCheckedLoad (DevirtCalls, LoadedPtrs, Preds,
2133
2117
HasNonCallUses, CI, DT);
2134
2118
0 commit comments