Mercurial > hg > Members > tobaru > cbc > CbC_llvm
diff lib/Analysis/GlobalsModRef.cpp @ 120:1172e4bd9c6f
update 4.0.0
author | mir3636 |
---|---|
date | Fri, 25 Nov 2016 19:14:25 +0900 |
parents | 7d135dc70f03 |
children | 803732b1fca8 |
line wrap: on
line diff
--- a/lib/Analysis/GlobalsModRef.cpp Tue Jan 26 22:56:36 2016 +0900 +++ b/lib/Analysis/GlobalsModRef.cpp Fri Nov 25 19:14:25 2016 +0900 @@ -78,7 +78,7 @@ return (AlignedMap *)P; } enum { NumLowBitsAvailable = 3 }; - static_assert(AlignOf<AlignedMap>::Alignment >= (1 << NumLowBitsAvailable), + static_assert(alignof(AlignedMap) >= (1 << NumLowBitsAvailable), "AlignedMap insufficiently aligned to have enough low bits."); }; @@ -243,13 +243,14 @@ 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 @@ /// (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 @@ ++NumNonAddrTakenFunctions; } - SmallPtrSet<Function *, 64> Readers, Writers; + SmallPtrSet<Function *, 16> Readers, Writers; for (GlobalVariable &GV : M.globals()) if (GV.hasLocalLinkage()) { if (!AnalyzeUsesOfPointer(&GV, &Readers, @@ -365,6 +366,10 @@ } else if (ICmpInst *ICI = dyn_cast<ICmpInst>(I)) { if (!isa<ConstantPointerNull>(ICI->getOperand(1))) return true; // Allow comparison against null. + } else if (Constant *C = dyn_cast<Constant>(I)) { + // Ignore constants which don't have any live uses. + if (isa<GlobalValue>(C) || C->isConstantUsed()) + return true; } else { return true; } @@ -470,9 +475,10 @@ 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 +502,7 @@ // 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(); @@ -519,7 +525,7 @@ // Can't say anything about it. However, if it is inside our SCC, // then nothing needs to be done. CallGraphNode *CalleeNode = CG[Callee]; - if (std::find(SCC.begin(), SCC.end(), CalleeNode) == SCC.end()) + if (!is_contained(SCC, CalleeNode)) KnowNothing = true; } } else { @@ -698,7 +704,7 @@ 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() && @@ -855,22 +861,22 @@ if (CS.doesNotAccessMemory()) return MRI_NoModRef; ModRefInfo ConservativeResult = CS.onlyReadsMemory() ? MRI_Ref : MRI_ModRef; - + // Iterate through all the arguments to the called function. If any argument // is based on GV, return the conservative result. for (auto &A : CS.args()) { SmallVector<Value*, 4> Objects; GetUnderlyingObjects(A, Objects, DL); - + // All objects must be identified. - if (!std::all_of(Objects.begin(), Objects.end(), isIdentifiedObject) && + if (!all_of(Objects, isIdentifiedObject) && // Try ::alias to see if all objects are known not to alias GV. - !std::all_of(Objects.begin(), Objects.end(), [&](Value *V) { + !all_of(Objects, [&](Value *V) { return this->alias(MemoryLocation(V), MemoryLocation(GV)) == NoAlias; - })) + })) return ConservativeResult; - if (std::find(Objects.begin(), Objects.end(), GV) != Objects.end()) + if (is_contained(Objects, GV)) return ConservativeResult; } @@ -900,10 +906,10 @@ 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)), @@ -916,6 +922,8 @@ } } +GlobalsAAResult::~GlobalsAAResult() {} + /*static*/ GlobalsAAResult GlobalsAAResult::analyzeModule(Module &M, const TargetLibraryInfo &TLI, CallGraph &CG) { @@ -933,14 +941,14 @@ return Result; } -GlobalsAAResult GlobalsAA::run(Module &M, AnalysisManager<Module> *AM) { +AnalysisKey GlobalsAA::Key; + +GlobalsAAResult GlobalsAA::run(Module &M, ModuleAnalysisManager &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)