[llvm-commits] [llvm] r118410 - in /llvm/trunk: lib/Transforms/IPO/FunctionAttrs.cpp test/Transforms/FunctionAttrs/2008-10-04-LocalMemory.ll

Dan Gohman gohman at apple.com
Mon Nov 8 08:10:15 PST 2010


Author: djg
Date: Mon Nov  8 10:10:15 2010
New Revision: 118410

URL: http://llvm.org/viewvc/llvm-project?rev=118410&view=rev
Log:
Make FunctionAttrs use AliasAnalysis::getModRefBehavior, now that it
knows about intrinsic functions.

Modified:
    llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp
    llvm/trunk/test/Transforms/FunctionAttrs/2008-10-04-LocalMemory.ll

Modified: llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp?rev=118410&r1=118409&r2=118410&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp Mon Nov  8 10:10:15 2010
@@ -40,7 +40,7 @@
 namespace {
   struct FunctionAttrs : public CallGraphSCCPass {
     static char ID; // Pass identification, replacement for typeid
-    FunctionAttrs() : CallGraphSCCPass(ID) {
+    FunctionAttrs() : CallGraphSCCPass(ID), AA(0) {
       initializeFunctionAttrsPass(*PassRegistry::getPassRegistry());
     }
 
@@ -62,10 +62,14 @@
 
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
       AU.setPreservesCFG();
+      AU.addRequired<AliasAnalysis>();
       CallGraphSCCPass::getAnalysisUsage(AU);
     }
 
     bool PointsToLocalOrConstantMemory(Value *V);
+
+  private:
+    AliasAnalysis *AA;
   };
 }
 
@@ -167,26 +171,35 @@
       // Some instructions can be ignored even if they read or write memory.
       // Detect these now, skipping to the next instruction if one is found.
       CallSite CS(cast<Value>(I));
-      if (CS && CS.getCalledFunction()) {
+      if (CS) {
         // Ignore calls to functions in the same SCC.
-        if (SCCNodes.count(CS.getCalledFunction()))
+        if (CS.getCalledFunction() && SCCNodes.count(CS.getCalledFunction()))
+          continue;
+        switch (AA->getModRefBehavior(CS)) {
+        case AliasAnalysis::DoesNotAccessMemory:
+          // Ignore calls that don't access memory.
           continue;
-        // Ignore intrinsics that only access local memory.
-        if (unsigned id = CS.getCalledFunction()->getIntrinsicID())
-          if (AliasAnalysis::getIntrinsicModRefBehavior(id) ==
-              AliasAnalysis::AccessesArguments) {
-            // Check that all pointer arguments point to local memory.
-            for (CallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end();
-                 CI != CE; ++CI) {
-              Value *Arg = *CI;
-              if (Arg->getType()->isPointerTy() &&
-                  !PointsToLocalOrConstantMemory(Arg))
-                // Writes memory.  Just give up.
-                return false;
-            }
-            // Only reads and writes local memory.
-            continue;
+        case AliasAnalysis::OnlyReadsMemory:
+          // Handle calls that only read from memory.
+          ReadsMemory = true;
+          continue;
+        case AliasAnalysis::AccessesArguments:
+          // Check whether all pointer arguments point to local memory, and
+          // ignore calls that only access local memory.
+          for (CallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end();
+               CI != CE; ++CI) {
+            Value *Arg = *CI;
+            if (Arg->getType()->isPointerTy() &&
+                !PointsToLocalOrConstantMemory(Arg))
+              // Writes memory.  Just give up.
+              return false;
           }
+          // Only reads and writes local memory.
+          continue;
+        default:
+          // Otherwise, be conservative.
+          break;
+        }
       } else if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
         // Ignore non-volatile loads from local memory.
         if (!LI->isVolatile() &&
@@ -387,6 +400,8 @@
 }
 
 bool FunctionAttrs::runOnSCC(CallGraphSCC &SCC) {
+  AA = &getAnalysis<AliasAnalysis>();
+
   bool Changed = AddReadAttrs(SCC);
   Changed |= AddNoCaptureAttrs(SCC);
   Changed |= AddNoAliasAttrs(SCC);

Modified: llvm/trunk/test/Transforms/FunctionAttrs/2008-10-04-LocalMemory.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/2008-10-04-LocalMemory.ll?rev=118410&r1=118409&r2=118410&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/FunctionAttrs/2008-10-04-LocalMemory.ll (original)
+++ llvm/trunk/test/Transforms/FunctionAttrs/2008-10-04-LocalMemory.ll Mon Nov  8 10:10:15 2010
@@ -1,4 +1,4 @@
-; RUN: opt < %s -functionattrs -S | FileCheck %s
+; RUN: opt < %s -basicaa -functionattrs -S | FileCheck %s
 
 %struct.X = type { i32*, i32* }
 





More information about the llvm-commits mailing list