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

Chris Lattner lattner at cs.uiuc.edu
Tue Jul 27 00:46:37 PDT 2004



Changes in directory llvm/lib/Analysis/IPA:

GlobalsModRef.cpp updated: 1.3 -> 1.4

---
Log message:

Fix conservative assumption, which was quite broken.  Also, notice that 
functions known to not access memory (like sin/cos) don't access memory! :)


---
Diffs of the changes:  (+22 -2)

Index: llvm/lib/Analysis/IPA/GlobalsModRef.cpp
diff -u llvm/lib/Analysis/IPA/GlobalsModRef.cpp:1.3 llvm/lib/Analysis/IPA/GlobalsModRef.cpp:1.4
--- llvm/lib/Analysis/IPA/GlobalsModRef.cpp:1.3	Tue Jul 27 01:40:37 2004
+++ llvm/lib/Analysis/IPA/GlobalsModRef.cpp	Tue Jul 27 02:46:26 2004
@@ -64,6 +64,8 @@
     /// FunctionEffect - Capture whether or not this function reads or writes to
     /// ANY memory.  If not, we can do a lot of aggressive analysis on it.
     unsigned FunctionEffect;
+
+    FunctionRecord() : FunctionEffect(0) {}
   };
 
   /// GlobalsModRef - The actual analysis pass.
@@ -232,9 +234,27 @@
   // We do a bottom-up SCC traversal of the call graph.  In other words, we
   // visit all callees before callers (leaf-first).
   for (scc_iterator<CallGraph*> I = scc_begin(&CG), E = scc_end(&CG); I!=E; ++I)
-    // Do not call AnalyzeSCC on the external function node.
-    if ((*I).size() != 1 || (*I)[0]->getFunction())
+    if ((*I).size() != 1) {
       AnalyzeSCC(*I);
+    } else if (Function *F = (*I)[0]->getFunction()) {
+      if (!F->isExternal()) {
+        // Nonexternal function.
+        AnalyzeSCC(*I);
+      } else {
+        // Otherwise external function.  Handle intrinsics and other special
+        // cases here.
+        if (getAnalysis<AliasAnalysis>().doesNotAccessMemory(F))
+          // If it does not access memory, process the function, causing us to
+          // realize it doesn't do anything (the body is empty).
+          AnalyzeSCC(*I);
+        else {
+          // Otherwise, don't process it.  This will cause us to conservatively
+          // assume the worst.
+        }
+      }
+    } else {
+      // Do not process the external node, assume the worst.
+    }
 }
 
 void GlobalsModRef::AnalyzeSCC(std::vector<CallGraphNode *> &SCC) {





More information about the llvm-commits mailing list