diff --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp --- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -31,8 +31,6 @@ #include "llvm/Transforms/IPO/ArgumentPromotion.h" #include "llvm/ADT/DepthFirstIterator.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/SmallPtrSet.h" @@ -41,13 +39,9 @@ #include "llvm/ADT/Twine.h" #include "llvm/Analysis/AssumptionCache.h" #include "llvm/Analysis/BasicAliasAnalysis.h" -#include "llvm/Analysis/CGSCCPassManager.h" #include "llvm/Analysis/CallGraph.h" -#include "llvm/Analysis/CallGraphSCCPass.h" -#include "llvm/Analysis/LazyCallGraph.h" #include "llvm/Analysis/Loads.h" #include "llvm/Analysis/MemoryLocation.h" -#include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/IR/Argument.h" @@ -64,19 +58,15 @@ #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Metadata.h" -#include "llvm/IR/Module.h" #include "llvm/IR/NoFolder.h" #include "llvm/IR/PassManager.h" #include "llvm/IR/Type.h" #include "llvm/IR/Use.h" #include "llvm/IR/User.h" #include "llvm/IR/Value.h" -#include "llvm/InitializePasses.h" -#include "llvm/Pass.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Transforms/IPO.h" #include "llvm/Transforms/Utils/PromoteMemToReg.h" #include #include @@ -155,12 +145,10 @@ /// DoPromotion - This method actually performs the promotion of the specified /// arguments, and returns the new function. At this point, we know that it's /// safe to do so. -static Function *doPromotion( - Function *F, function_ref DTGetter, - function_ref ACGetter, - const DenseMap> &ArgsToPromote, - Optional> - ReplaceCallSite) { +static Function * +doPromotion(Function *F, FunctionAnalysisManager &FAM, + const DenseMap> + &ArgsToPromote) { // Start by computing a new prototype for the function, which is the same as // the old function, but has modified arguments. FunctionType *FTy = F->getFunctionType(); @@ -228,9 +216,8 @@ F->getParent()->getFunctionList().insert(F->getIterator(), NF); NF->takeName(F); - // Loop over all of the callers of the function, transforming the call sites - // to pass in the loaded pointers. - // + // Loop over all the callers of the function, transforming the call sites to + // pass in the loaded pointers. SmallVector Args; const DataLayout &DL = F->getParent()->getDataLayout(); while (!F->use_empty()) { @@ -299,10 +286,6 @@ AttributeFuncs::updateMinLegalVectorWidthAttr(*CB.getCaller(), LargestVectorWidth); - // Update the callgraph to know that the callsite has been transformed. - if (ReplaceCallSite) - (*ReplaceCallSite)(CB, *NewCS); - if (!CB.use_empty()) { CB.replaceAllUsesWith(NewCS); NewCS->takeName(&CB); @@ -429,7 +412,9 @@ // And we are able to call the `promoteMemoryToRegister()` function. // Our earlier checks have ensured that PromoteMemToReg() will // succeed. - PromoteMemToReg(Allocas, DTGetter(*NF), ACGetter(*NF)); + auto &DT = FAM.getResult(*NF); + auto &AC = FAM.getResult(*NF); + PromoteMemToReg(Allocas, DT, &AC); } return NF; @@ -717,14 +702,8 @@ /// are any promotable arguments and if it is safe to promote the function (for /// example, all callers are direct). If safe to promote some arguments, it /// calls the DoPromotion method. -static Function * -promoteArguments(Function *F, function_ref AARGetter, - function_ref DTGetter, - function_ref ACGetter, - unsigned MaxElements, - Optional> - ReplaceCallSite, - const TargetTransformInfo &TTI, bool IsRecursive) { +static Function *promoteArguments(Function *F, FunctionAnalysisManager &FAM, + unsigned MaxElements, bool IsRecursive) { // Don't perform argument promotion for naked functions; otherwise we can end // up removing parameters that are seemingly 'not used' as they are referred // to in the assembly. @@ -781,8 +760,8 @@ return nullptr; const DataLayout &DL = F->getParent()->getDataLayout(); - - AAResults &AAR = AARGetter(*F); + auto &AAR = FAM.getResult(*F); + const auto &TTI = FAM.getResult(*F); // Check to see which arguments are promotable. If an argument is promotable, // add it to ArgsToPromote. @@ -819,7 +798,7 @@ if (ArgsToPromote.empty()) return nullptr; - return doPromotion(F, DTGetter, ACGetter, ArgsToPromote, ReplaceCallSite); + return doPromotion(F, FAM, ArgsToPromote); } PreservedAnalyses ArgumentPromotionPass::run(LazyCallGraph::SCC &C, @@ -838,27 +817,7 @@ bool IsRecursive = C.size() > 1; for (LazyCallGraph::Node &N : C) { Function &OldF = N.getFunction(); - - // FIXME: This lambda must only be used with this function. We should - // skip the lambda and just get the AA results directly. - auto AARGetter = [&](Function &F) -> AAResults & { - assert(&F == &OldF && "Called with an unexpected function!"); - return FAM.getResult(F); - }; - - auto DTGetter = [&](Function &F) -> DominatorTree & { - assert(&F != &OldF && "Called with the obsolete function!"); - return FAM.getResult(F); - }; - - auto ACGetter = [&](Function &F) -> AssumptionCache * { - assert(&F != &OldF && "Called with the obsolete function!"); - return &FAM.getResult(F); - }; - - const auto &TTI = FAM.getResult(OldF); - Function *NewF = promoteArguments(&OldF, AARGetter, DTGetter, ACGetter, - MaxElements, None, TTI, IsRecursive); + Function *NewF = promoteArguments(&OldF, FAM, MaxElements, IsRecursive); if (!NewF) continue; LocalChange = true;