diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 | 
| commit | 706b4fc47bbc608932d3b491ae19a3b9cde9497b (patch) | |
| tree | 4adf86a776049cbf7f69a1929c4babcbbef925eb /llvm/lib/Analysis/GlobalsModRef.cpp | |
| parent | 7cc9cf2bf09f069cb2dd947ead05d0b54301fb71 (diff) | |
Notes
Diffstat (limited to 'llvm/lib/Analysis/GlobalsModRef.cpp')
| -rw-r--r-- | llvm/lib/Analysis/GlobalsModRef.cpp | 20 | 
1 files changed, 14 insertions, 6 deletions
| diff --git a/llvm/lib/Analysis/GlobalsModRef.cpp b/llvm/lib/Analysis/GlobalsModRef.cpp index efdf9706ba3c..4361e0dc9bbd 100644 --- a/llvm/lib/Analysis/GlobalsModRef.cpp +++ b/llvm/lib/Analysis/GlobalsModRef.cpp @@ -25,6 +25,7 @@  #include "llvm/IR/Instructions.h"  #include "llvm/IR/IntrinsicInst.h"  #include "llvm/IR/Module.h" +#include "llvm/InitializePasses.h"  #include "llvm/Pass.h"  #include "llvm/Support/CommandLine.h"  using namespace llvm; @@ -286,7 +287,7 @@ GlobalsAAResult::getFunctionInfo(const Function *F) {  void GlobalsAAResult::AnalyzeGlobals(Module &M) {    SmallPtrSet<Function *, 32> TrackedFunctions;    for (Function &F : M) -    if (F.hasLocalLinkage()) +    if (F.hasLocalLinkage()) {        if (!AnalyzeUsesOfPointer(&F)) {          // Remember that we are tracking this global.          NonAddressTakenGlobals.insert(&F); @@ -294,7 +295,9 @@ void GlobalsAAResult::AnalyzeGlobals(Module &M) {          Handles.emplace_front(*this, &F);          Handles.front().I = Handles.begin();          ++NumNonAddrTakenFunctions; -      } +      } else +        UnknownFunctionsWithLocalLinkage = true; +    }    SmallPtrSet<Function *, 16> Readers, Writers;    for (GlobalVariable &GV : M.globals()) @@ -526,9 +529,12 @@ void GlobalsAAResult::AnalyzeCallGraph(CallGraph &CG, Module &M) {              FI.setMayReadAnyGlobal();          } else {            FI.addModRefInfo(ModRefInfo::ModRef); -          // Can't say anything useful unless it's an intrinsic - they don't -          // read or write global variables of the kind considered here. -          KnowNothing = !F->isIntrinsic(); +          if (!F->onlyAccessesArgMemory()) +            FI.setMayReadAnyGlobal(); +          if (!F->isIntrinsic()) { +            KnowNothing = true; +            break; +          }          }          continue;        } @@ -927,7 +933,9 @@ ModRefInfo GlobalsAAResult::getModRefInfo(const CallBase *Call,    // global we are tracking, return information if we have it.    if (const GlobalValue *GV =            dyn_cast<GlobalValue>(GetUnderlyingObject(Loc.Ptr, DL))) -    if (GV->hasLocalLinkage()) +    // If GV is internal to this IR and there is no function with local linkage +    // that has had their address taken, keep looking for a tighter ModRefInfo. +    if (GV->hasLocalLinkage() && !UnknownFunctionsWithLocalLinkage)        if (const Function *F = Call->getCalledFunction())          if (NonAddressTakenGlobals.count(GV))            if (const FunctionInfo *FI = getFunctionInfo(F)) | 
