If we are calling an external function, chain to another AA to potentially
authorChris Lattner <sabre@nondot.org>
Wed, 23 Mar 2005 23:49:47 +0000 (23:49 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 23 Mar 2005 23:49:47 +0000 (23:49 +0000)
decide, don't just immediately give up.

This implements GlobalsModRef/chaining-analysis.ll

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20796 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/IPA/GlobalsModRef.cpp

index 6bf2698988aaa263604611f58574b18c047694d4..47d7d518790313c769dbee3ee2543ec9e3d8a374 100644 (file)
@@ -111,7 +111,7 @@ namespace {
           return DoesNotAccessMemory;
        else if ((FR->FunctionEffect & Mod) == 0)
          return OnlyReadsMemory;
-      return AliasAnalysis::getModRefBehavior(F, CS);    
+      return AliasAnalysis::getModRefBehavior(F, CS, Info);    
     }
 
     virtual void deleteValue(Value *V);
@@ -198,11 +198,6 @@ bool GlobalsModRef::AnalyzeUsesOfGlobal(Value *V,
       // passing into the function.
       for (unsigned i = 1, e = CI->getNumOperands(); i != e; ++i)
         if (CI->getOperand(i) == V) return true;
-    } else if (CallInst *CI = dyn_cast<CallInst>(*UI)) {
-      // Make sure that this is just the function being called, not that it is
-      // passing into the function.
-      for (unsigned i = 1, e = CI->getNumOperands(); i != e; ++i)
-        if (CI->getOperand(i) == V) return true;
     } else if (InvokeInst *II = dyn_cast<InvokeInst>(*UI)) {
       // Make sure that this is just the function being called, not that it is
       // passing into the function.
@@ -279,8 +274,25 @@ void GlobalsModRef::AnalyzeSCC(std::vector<CallGraphNode *> &SCC) {
             FR.GlobalInfo[GI->first] |= GI->second;
 
         } else {
-          CallsExternal = true;
-          break;
+          // Okay, if we can't say anything about it, maybe some other alias
+          // analysis can.
+          ModRefBehavior MRB =
+            AliasAnalysis::getModRefBehavior(Callee, CallSite());
+          if (MRB != DoesNotAccessMemory) {
+            if (MRB == OnlyReadsMemory) {
+              // This reads memory, but we don't know what, just say that it
+              // reads all globals.
+              for (std::map<GlobalValue*, unsigned>::iterator
+                     GI = CalleeFR->GlobalInfo.begin(),
+                     E = CalleeFR->GlobalInfo.end();
+                   GI != E; ++GI)
+                FR.GlobalInfo[GI->first] |= Ref;
+
+            } else {
+              CallsExternal = true;
+              break;
+            }
+          }
         }
       } else {
         CallsExternal = true;