summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/GlobalsModRef.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2019-09-07 03:09:36 +0000
committerTeresa Johnson <tejohnson@google.com>2019-09-07 03:09:36 +0000
commit9c27b59cec76abea4f3f9261f3ffa73450f239c6 (patch)
treecbd262430eaef3d65d5ab2ae6f948c7befa9698f /llvm/lib/Analysis/GlobalsModRef.cpp
parentdd507867efdc04a9d117cfe10bd291aa4b44ebbb (diff)
downloadbcm5719-llvm-9c27b59cec76abea4f3f9261f3ffa73450f239c6.tar.gz
bcm5719-llvm-9c27b59cec76abea4f3f9261f3ffa73450f239c6.zip
Change TargetLibraryInfo analysis passes to always require Function
Summary: This is the first change to enable the TLI to be built per-function so that -fno-builtin* handling can be migrated to use function attributes. See discussion on D61634 for background. This is an enabler for fixing handling of these options for LTO, for example. This change should not affect behavior, as the provided function is not yet used to build a specifically per-function TLI, but rather enables that migration. Most of the changes were very mechanical, e.g. passing a Function to the legacy analysis pass's getTLI interface, or in Module level cases, adding a callback. This is similar to the way the per-function TTI analysis works. There was one place where we were looking for builtins but not in the context of a specific function. See FindCXAAtExit in lib/Transforms/IPO/GlobalOpt.cpp. I'm somewhat concerned my workaround could provide the wrong behavior in some corner cases. Suggestions welcome. Reviewers: chandlerc, hfinkel Subscribers: arsenm, dschuff, jvesely, nhaehnle, mehdi_amini, javed.absar, sbc100, jgravelle-google, eraman, aheejin, steven_wu, george.burgess.iv, dexonsmith, jfb, asbirlea, gchatelet, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66428 llvm-svn: 371284
Diffstat (limited to 'llvm/lib/Analysis/GlobalsModRef.cpp')
-rw-r--r--llvm/lib/Analysis/GlobalsModRef.cpp37
1 files changed, 23 insertions, 14 deletions
diff --git a/llvm/lib/Analysis/GlobalsModRef.cpp b/llvm/lib/Analysis/GlobalsModRef.cpp
index 0d6c0ffb18a..efdf9706ba3 100644
--- a/llvm/lib/Analysis/GlobalsModRef.cpp
+++ b/llvm/lib/Analysis/GlobalsModRef.cpp
@@ -370,7 +370,8 @@ bool GlobalsAAResult::AnalyzeUsesOfPointer(Value *V,
// passing into the function.
if (Call->isDataOperand(&U)) {
// Detect calls to free.
- if (Call->isArgOperand(&U) && isFreeCall(I, &TLI)) {
+ if (Call->isArgOperand(&U) &&
+ isFreeCall(I, &GetTLI(*Call->getFunction()))) {
if (Writers)
Writers->insert(Call->getParent()->getParent());
} else {
@@ -432,7 +433,7 @@ bool GlobalsAAResult::AnalyzeIndirectGlobalMemory(GlobalVariable *GV) {
Value *Ptr = GetUnderlyingObject(SI->getOperand(0),
GV->getParent()->getDataLayout());
- if (!isAllocLikeFn(Ptr, &TLI))
+ if (!isAllocLikeFn(Ptr, &GetTLI(*SI->getFunction())))
return false; // Too hard to analyze.
// Analyze all uses of the allocation. If any of them are used in a
@@ -576,6 +577,7 @@ void GlobalsAAResult::AnalyzeCallGraph(CallGraph &CG, Module &M) {
// We handle calls specially because the graph-relevant aspects are
// handled above.
if (auto *Call = dyn_cast<CallBase>(&I)) {
+ auto &TLI = GetTLI(*Node->getFunction());
if (isAllocationFn(Call, &TLI) || isFreeCall(Call, &TLI)) {
// FIXME: It is completely unclear why this is necessary and not
// handled by the above graph code.
@@ -937,12 +939,13 @@ ModRefInfo GlobalsAAResult::getModRefInfo(const CallBase *Call,
return intersectModRef(Known, AAResultBase::getModRefInfo(Call, Loc, AAQI));
}
-GlobalsAAResult::GlobalsAAResult(const DataLayout &DL,
- const TargetLibraryInfo &TLI)
- : AAResultBase(), DL(DL), TLI(TLI) {}
+GlobalsAAResult::GlobalsAAResult(
+ const DataLayout &DL,
+ std::function<const TargetLibraryInfo &(Function &F)> GetTLI)
+ : AAResultBase(), DL(DL), GetTLI(std::move(GetTLI)) {}
GlobalsAAResult::GlobalsAAResult(GlobalsAAResult &&Arg)
- : AAResultBase(std::move(Arg)), DL(Arg.DL), TLI(Arg.TLI),
+ : AAResultBase(std::move(Arg)), DL(Arg.DL), GetTLI(std::move(Arg.GetTLI)),
NonAddressTakenGlobals(std::move(Arg.NonAddressTakenGlobals)),
IndirectGlobals(std::move(Arg.IndirectGlobals)),
AllocsForIndirectGlobals(std::move(Arg.AllocsForIndirectGlobals)),
@@ -957,10 +960,10 @@ GlobalsAAResult::GlobalsAAResult(GlobalsAAResult &&Arg)
GlobalsAAResult::~GlobalsAAResult() {}
-/*static*/ GlobalsAAResult
-GlobalsAAResult::analyzeModule(Module &M, const TargetLibraryInfo &TLI,
- CallGraph &CG) {
- GlobalsAAResult Result(M.getDataLayout(), TLI);
+/*static*/ GlobalsAAResult GlobalsAAResult::analyzeModule(
+ Module &M, std::function<const TargetLibraryInfo &(Function &F)> GetTLI,
+ CallGraph &CG) {
+ GlobalsAAResult Result(M.getDataLayout(), GetTLI);
// Discover which functions aren't recursive, to feed into AnalyzeGlobals.
Result.CollectSCCMembership(CG);
@@ -977,8 +980,12 @@ GlobalsAAResult::analyzeModule(Module &M, const TargetLibraryInfo &TLI,
AnalysisKey GlobalsAA::Key;
GlobalsAAResult GlobalsAA::run(Module &M, ModuleAnalysisManager &AM) {
- return GlobalsAAResult::analyzeModule(M,
- AM.getResult<TargetLibraryAnalysis>(M),
+ FunctionAnalysisManager &FAM =
+ AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
+ auto GetTLI = [&FAM](Function &F) -> TargetLibraryInfo & {
+ return FAM.getResult<TargetLibraryAnalysis>(F);
+ };
+ return GlobalsAAResult::analyzeModule(M, GetTLI,
AM.getResult<CallGraphAnalysis>(M));
}
@@ -999,9 +1006,11 @@ GlobalsAAWrapperPass::GlobalsAAWrapperPass() : ModulePass(ID) {
}
bool GlobalsAAWrapperPass::runOnModule(Module &M) {
+ auto GetTLI = [this](Function &F) -> TargetLibraryInfo & {
+ return this->getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
+ };
Result.reset(new GlobalsAAResult(GlobalsAAResult::analyzeModule(
- M, getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(),
- getAnalysis<CallGraphWrapperPass>().getCallGraph())));
+ M, GetTLI, getAnalysis<CallGraphWrapperPass>().getCallGraph())));
return false;
}
OpenPOWER on IntegriCloud