[llvm-commits] CVS: llvm/lib/Analysis/IPA/GlobalsModRef.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Mar 23 15:50:01 PST 2005



Changes in directory llvm/lib/Analysis/IPA:

GlobalsModRef.cpp updated: 1.11 -> 1.12
---
Log message:

If we are calling an external function, chain to another AA to potentially 
decide, don't just immediately give up.

This implements GlobalsModRef/chaining-analysis.ll


---
Diffs of the changes:  (+20 -8)

 GlobalsModRef.cpp |   28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)


Index: llvm/lib/Analysis/IPA/GlobalsModRef.cpp
diff -u llvm/lib/Analysis/IPA/GlobalsModRef.cpp:1.11 llvm/lib/Analysis/IPA/GlobalsModRef.cpp:1.12
--- llvm/lib/Analysis/IPA/GlobalsModRef.cpp:1.11	Mon Mar 14 22:54:18 2005
+++ llvm/lib/Analysis/IPA/GlobalsModRef.cpp	Wed Mar 23 17:49:47 2005
@@ -111,7 +111,7 @@
           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 @@
       // 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 @@
             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;






More information about the llvm-commits mailing list