[llvm-commits] [llvm] r64300 - in /llvm/trunk: lib/Analysis/IPA/CallGraphSCCPass.cpp test/Transforms/SimplifyLibCalls/2009-02-11-NotInitialized.ll

Duncan Sands baldrick at free.fr
Wed Feb 11 01:58:43 PST 2009


Author: baldrick
Date: Wed Feb 11 03:58:43 2009
New Revision: 64300

URL: http://llvm.org/viewvc/llvm-project?rev=64300&view=rev
Log:
Make sure the SCC pass manager initializes any contained
function pass managers.  Without this, simplify-libcalls
would add nocapture attributes when run on its own, but
not when run as part of -std-compile-opts or similar.

Added:
    llvm/trunk/test/Transforms/SimplifyLibCalls/2009-02-11-NotInitialized.ll
Modified:
    llvm/trunk/lib/Analysis/IPA/CallGraphSCCPass.cpp

Modified: llvm/trunk/lib/Analysis/IPA/CallGraphSCCPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IPA/CallGraphSCCPass.cpp?rev=64300&r1=64299&r2=64300&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/IPA/CallGraphSCCPass.cpp (original)
+++ llvm/trunk/lib/Analysis/IPA/CallGraphSCCPass.cpp Wed Feb 11 03:58:43 2009
@@ -40,8 +40,8 @@
   /// whether any of the passes modifies the module, and if so, return true.
   bool runOnModule(Module &M);
 
-  bool doInitialization(CallGraph &CG);
-  bool doFinalization(CallGraph &CG);
+  bool doInitialization(CallGraph &CG, Module &M);
+  bool doFinalization(CallGraph &CG, Module &M);
 
   /// Pass Manager itself does not invalidate any analysis info.
   void getAnalysisUsage(AnalysisUsage &Info) const {
@@ -82,7 +82,7 @@
 /// whether any of the passes modifies the module, and if so, return true.
 bool CGPassManager::runOnModule(Module &M) {
   CallGraph &CG = getAnalysis<CallGraph>();
-  bool Changed = doInitialization(CG);
+  bool Changed = doInitialization(CG, M);
 
   // Walk SCC
   for (scc_iterator<CallGraph*> I = scc_begin(&CG), E = scc_end(&CG);
@@ -126,28 +126,38 @@
       removeDeadPasses(P, "", ON_CG_MSG);
     }
   }
-  Changed |= doFinalization(CG);
+  Changed |= doFinalization(CG, M);
   return Changed;
 }
 
 /// Initialize CG
-bool CGPassManager::doInitialization(CallGraph &CG) {
+bool CGPassManager::doInitialization(CallGraph &CG, Module &M) {
   bool Changed = false;
   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {  
     Pass *P = getContainedPass(Index);
-    if (CallGraphSCCPass *CGSP = dynamic_cast<CallGraphSCCPass *>(P)) 
+    if (CallGraphSCCPass *CGSP = dynamic_cast<CallGraphSCCPass *>(P)) {
       Changed |= CGSP->doInitialization(CG);
+    } else {
+      FPPassManager *FP = dynamic_cast<FPPassManager *>(P);
+      assert (FP && "Invalid CGPassManager member");
+      Changed |= FP->doInitialization(M);
+    }
   }
   return Changed;
 }
 
 /// Finalize CG
-bool CGPassManager::doFinalization(CallGraph &CG) {
+bool CGPassManager::doFinalization(CallGraph &CG, Module &M) {
   bool Changed = false;
   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {  
     Pass *P = getContainedPass(Index);
-    if (CallGraphSCCPass *CGSP = dynamic_cast<CallGraphSCCPass *>(P)) 
+    if (CallGraphSCCPass *CGSP = dynamic_cast<CallGraphSCCPass *>(P)) {
       Changed |= CGSP->doFinalization(CG);
+    } else {
+      FPPassManager *FP = dynamic_cast<FPPassManager *>(P);
+      assert (FP && "Invalid CGPassManager member");
+      Changed |= FP->doFinalization(M);
+    }
   }
   return Changed;
 }

Added: llvm/trunk/test/Transforms/SimplifyLibCalls/2009-02-11-NotInitialized.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyLibCalls/2009-02-11-NotInitialized.ll?rev=64300&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/SimplifyLibCalls/2009-02-11-NotInitialized.ll (added)
+++ llvm/trunk/test/Transforms/SimplifyLibCalls/2009-02-11-NotInitialized.ll Wed Feb 11 03:58:43 2009
@@ -0,0 +1,12 @@
+; RUN: llvm-as < %s | opt -std-compile-opts | llvm-dis | grep nocapture | count 2
+; Check that nocapture attributes are added when run after an SCC pass.
+; PR3520
+
+define i32 @use(i8* %x) nounwind readonly {
+entry:
+	%0 = tail call i64 @strlen(i8* %x) nounwind readonly		; <i64> [#uses=1]
+	%1 = trunc i64 %0 to i32		; <i32> [#uses=1]
+	ret i32 %1
+}
+
+declare i64 @strlen(i8*) nounwind readonly





More information about the llvm-commits mailing list