diff options
Diffstat (limited to 'contrib/llvm/lib/Analysis/GlobalsModRef.cpp')
-rw-r--r-- | contrib/llvm/lib/Analysis/GlobalsModRef.cpp | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/contrib/llvm/lib/Analysis/GlobalsModRef.cpp b/contrib/llvm/lib/Analysis/GlobalsModRef.cpp index 1babb82..a7d1e04 100644 --- a/contrib/llvm/lib/Analysis/GlobalsModRef.cpp +++ b/contrib/llvm/lib/Analysis/GlobalsModRef.cpp @@ -243,13 +243,14 @@ FunctionModRefBehavior GlobalsAAResult::getModRefBehavior(ImmutableCallSite CS) { FunctionModRefBehavior Min = FMRB_UnknownModRefBehavior; - if (const Function *F = CS.getCalledFunction()) - if (FunctionInfo *FI = getFunctionInfo(F)) { - if (FI->getModRefInfo() == MRI_NoModRef) - Min = FMRB_DoesNotAccessMemory; - else if ((FI->getModRefInfo() & MRI_Mod) == 0) - Min = FMRB_OnlyReadsMemory; - } + if (!CS.hasOperandBundles()) + if (const Function *F = CS.getCalledFunction()) + if (FunctionInfo *FI = getFunctionInfo(F)) { + if (FI->getModRefInfo() == MRI_NoModRef) + Min = FMRB_DoesNotAccessMemory; + else if ((FI->getModRefInfo() & MRI_Mod) == 0) + Min = FMRB_OnlyReadsMemory; + } return FunctionModRefBehavior(AAResultBase::getModRefBehavior(CS) & Min); } @@ -269,7 +270,7 @@ GlobalsAAResult::getFunctionInfo(const Function *F) { /// (really, their address passed to something nontrivial), record this fact, /// and record the functions that they are used directly in. void GlobalsAAResult::AnalyzeGlobals(Module &M) { - SmallPtrSet<Function *, 64> TrackedFunctions; + SmallPtrSet<Function *, 32> TrackedFunctions; for (Function &F : M) if (F.hasLocalLinkage()) if (!AnalyzeUsesOfPointer(&F)) { @@ -281,7 +282,7 @@ void GlobalsAAResult::AnalyzeGlobals(Module &M) { ++NumNonAddrTakenFunctions; } - SmallPtrSet<Function *, 64> Readers, Writers; + SmallPtrSet<Function *, 16> Readers, Writers; for (GlobalVariable &GV : M.globals()) if (GV.hasLocalLinkage()) { if (!AnalyzeUsesOfPointer(&GV, &Readers, @@ -310,7 +311,7 @@ void GlobalsAAResult::AnalyzeGlobals(Module &M) { ++NumNonAddrTakenGlobalVars; // If this global holds a pointer type, see if it is an indirect global. - if (GV.getType()->getElementType()->isPointerTy() && + if (GV.getValueType()->isPointerTy() && AnalyzeIndirectGlobalMemory(&GV)) ++NumIndirectGlobalVars; } @@ -470,9 +471,10 @@ void GlobalsAAResult::AnalyzeCallGraph(CallGraph &CG, Module &M) { const std::vector<CallGraphNode *> &SCC = *I; assert(!SCC.empty() && "SCC with no functions?"); - if (!SCC[0]->getFunction() || SCC[0]->getFunction()->mayBeOverridden()) { - // Calls externally or is weak - can't say anything useful. Remove any existing - // function records (may have been created when scanning globals). + if (!SCC[0]->getFunction() || !SCC[0]->getFunction()->isDefinitionExact()) { + // Calls externally or not exact - can't say anything useful. Remove any + // existing function records (may have been created when scanning + // globals). for (auto *Node : SCC) FunctionInfos.erase(Node->getFunction()); continue; @@ -496,7 +498,7 @@ void GlobalsAAResult::AnalyzeCallGraph(CallGraph &CG, Module &M) { // Can't do better than that! } else if (F->onlyReadsMemory()) { FI.addModRefInfo(MRI_Ref); - if (!F->isIntrinsic()) + if (!F->isIntrinsic() && !F->onlyAccessesArgMemory()) // This function might call back into the module and read a global - // consider every global as possibly being read by this function. FI.setMayReadAnyGlobal(); @@ -698,7 +700,7 @@ bool GlobalsAAResult::isNonEscapingGlobalNoAlias(const GlobalValue *GV, auto *InputGVar = dyn_cast<GlobalVariable>(InputGV); if (GVar && InputGVar && !GVar->isDeclaration() && !InputGVar->isDeclaration() && - !GVar->mayBeOverridden() && !InputGVar->mayBeOverridden()) { + !GVar->isInterposable() && !InputGVar->isInterposable()) { Type *GVType = GVar->getInitializer()->getType(); Type *InputGVType = InputGVar->getInitializer()->getType(); if (GVType->isSized() && InputGVType->isSized() && @@ -863,7 +865,11 @@ ModRefInfo GlobalsAAResult::getModRefInfoForArgument(ImmutableCallSite CS, GetUnderlyingObjects(A, Objects, DL); // All objects must be identified. - if (!std::all_of(Objects.begin(), Objects.end(), isIdentifiedObject)) + if (!std::all_of(Objects.begin(), Objects.end(), isIdentifiedObject) && + // Try ::alias to see if all objects are known not to alias GV. + !std::all_of(Objects.begin(), Objects.end(), [&](Value *V) { + return this->alias(MemoryLocation(V), MemoryLocation(GV)) == NoAlias; + })) return ConservativeResult; if (std::find(Objects.begin(), Objects.end(), GV) != Objects.end()) @@ -896,10 +902,10 @@ ModRefInfo GlobalsAAResult::getModRefInfo(ImmutableCallSite CS, GlobalsAAResult::GlobalsAAResult(const DataLayout &DL, const TargetLibraryInfo &TLI) - : AAResultBase(TLI), DL(DL) {} + : AAResultBase(), DL(DL), TLI(TLI) {} GlobalsAAResult::GlobalsAAResult(GlobalsAAResult &&Arg) - : AAResultBase(std::move(Arg)), DL(Arg.DL), + : AAResultBase(std::move(Arg)), DL(Arg.DL), TLI(Arg.TLI), NonAddressTakenGlobals(std::move(Arg.NonAddressTakenGlobals)), IndirectGlobals(std::move(Arg.IndirectGlobals)), AllocsForIndirectGlobals(std::move(Arg.AllocsForIndirectGlobals)), @@ -912,6 +918,8 @@ GlobalsAAResult::GlobalsAAResult(GlobalsAAResult &&Arg) } } +GlobalsAAResult::~GlobalsAAResult() {} + /*static*/ GlobalsAAResult GlobalsAAResult::analyzeModule(Module &M, const TargetLibraryInfo &TLI, CallGraph &CG) { @@ -929,14 +937,14 @@ GlobalsAAResult::analyzeModule(Module &M, const TargetLibraryInfo &TLI, return Result; } -GlobalsAAResult GlobalsAA::run(Module &M, AnalysisManager<Module> *AM) { +char GlobalsAA::PassID; + +GlobalsAAResult GlobalsAA::run(Module &M, AnalysisManager<Module> &AM) { return GlobalsAAResult::analyzeModule(M, - AM->getResult<TargetLibraryAnalysis>(M), - AM->getResult<CallGraphAnalysis>(M)); + AM.getResult<TargetLibraryAnalysis>(M), + AM.getResult<CallGraphAnalysis>(M)); } -char GlobalsAA::PassID; - char GlobalsAAWrapperPass::ID = 0; INITIALIZE_PASS_BEGIN(GlobalsAAWrapperPass, "globals-aa", "Globals Alias Analysis", false, true) |