[llvm] r184641 - Revert "FunctionAttrs: Merge attributes once instead of doing it for every argument."

Benjamin Kramer benny.kra at googlemail.com
Sat Jun 22 09:56:32 PDT 2013


Author: d0k
Date: Sat Jun 22 11:56:32 2013
New Revision: 184641

URL: http://llvm.org/viewvc/llvm-project?rev=184641&view=rev
Log:
Revert "FunctionAttrs: Merge attributes once instead of doing it for every argument."

It doesn't work as I intended it to.  This reverts commit r184638.

Modified:
    llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp

Modified: llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp?rev=184641&r1=184640&r2=184641&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp Sat Jun 22 11:56:32 2013
@@ -410,6 +410,9 @@ bool FunctionAttrs::AddNoCaptureAttrs(co
 
   ArgumentGraph AG;
 
+  AttrBuilder B;
+  B.addAttribute(Attribute::NoCapture);
+
   // Check each function in turn, determining which pointer arguments are not
   // captured.
   for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) {
@@ -424,59 +427,43 @@ bool FunctionAttrs::AddNoCaptureAttrs(co
     if (F->isDeclaration() || F->mayBeOverridden())
       continue;
 
-    SmallVector<AttributeSet, 8> AttrSets;
-
     // Functions that are readonly (or readnone) and nounwind and don't return
     // a value can't capture arguments. Don't analyze them.
     if (F->onlyReadsMemory() && F->doesNotThrow() &&
         F->getReturnType()->isVoidTy()) {
-      for (Function::arg_iterator A = F->arg_begin(), E = F->arg_end(); A != E;
-           ++A) {
-        if (!A->getType()->isPointerTy() || A->hasNoCaptureAttr())
-          continue;
-
-        AttributeSet In =
-            F->getAttributes().getParamAttributes(A->getArgNo() + 1);
-        AttrSets.push_back(In.addAttribute(F->getContext(), A->getArgNo() + 1,
-                                           Attribute::NoCapture));
+      for (Function::arg_iterator A = F->arg_begin(), E = F->arg_end();
+           A != E; ++A) {
+        if (A->getType()->isPointerTy() && !A->hasNoCaptureAttr()) {
+          A->addAttr(AttributeSet::get(F->getContext(), A->getArgNo() + 1, B));
+          ++NumNoCapture;
+          Changed = true;
+        }
       }
-    } else {
-      for (Function::arg_iterator A = F->arg_begin(), E = F->arg_end(); A != E;
-           ++A) {
-        if (!A->getType()->isPointerTy() || A->hasNoCaptureAttr())
-          continue;
+      continue;
+    }
 
+    for (Function::arg_iterator A = F->arg_begin(), E = F->arg_end(); A!=E; ++A)
+      if (A->getType()->isPointerTy() && !A->hasNoCaptureAttr()) {
         ArgumentUsesTracker Tracker(SCCNodes);
         PointerMayBeCaptured(A, &Tracker);
-        if (Tracker.Captured)
-          continue; // It's captured. Don't bother doing SCC analysis on it.
-
-        if (Tracker.Uses.empty()) {
-          // If it's trivially not captured, mark it nocapture now.
-          AttributeSet In =
-              F->getAttributes().getParamAttributes(A->getArgNo() + 1);
-          AttrSets.push_back(In.addAttribute(F->getContext(), A->getArgNo() + 1,
-                                             Attribute::NoCapture));
-        } else {
-          // If it's not trivially captured and not trivially not captured,
-          // then it must be calling into another function in our SCC. Save
-          // its particulars for Argument-SCC analysis later.
-          ArgumentGraphNode *Node = AG[A];
-          for (SmallVectorImpl<Argument *>::iterator UI = Tracker.Uses.begin(),
-                                                     UE = Tracker.Uses.end();
-               UI != UE; ++UI)
-            Node->Uses.push_back(AG[*UI]);
+        if (!Tracker.Captured) {
+          if (Tracker.Uses.empty()) {
+            // If it's trivially not captured, mark it nocapture now.
+            A->addAttr(AttributeSet::get(F->getContext(), A->getArgNo()+1, B));
+            ++NumNoCapture;
+            Changed = true;
+          } else {
+            // If it's not trivially captured and not trivially not captured,
+            // then it must be calling into another function in our SCC. Save
+            // its particulars for Argument-SCC analysis later.
+            ArgumentGraphNode *Node = AG[A];
+            for (SmallVectorImpl<Argument*>::iterator UI = Tracker.Uses.begin(),
+                   UE = Tracker.Uses.end(); UI != UE; ++UI)
+              Node->Uses.push_back(AG[*UI]);
+          }
         }
+        // Otherwise, it's captured. Don't bother doing SCC analysis on it.
       }
-    }
-
-    // Merge all attribute sets into one in a single step.
-    if (!AttrSets.empty()) {
-      NumNoCapture += AttrSets.size();
-      AttrSets.push_back(F->getAttributes());
-      F->setAttributes(AttributeSet::get(F->getContext(), AttrSets));
-      Changed = true;
-    }
   }
 
   // The graph we've collected is partial because we stopped scanning for
@@ -499,7 +486,7 @@ bool FunctionAttrs::AddNoCaptureAttrs(co
           Definition->
           addAttr(AttributeSet::get(ArgumentSCC[0]->Definition->getContext(),
                                     ArgumentSCC[0]->Definition->getArgNo() + 1,
-                                    Attribute::NoCapture));
+                                    B));
         ++NumNoCapture;
         Changed = true;
       }
@@ -541,8 +528,7 @@ bool FunctionAttrs::AddNoCaptureAttrs(co
 
     for (unsigned i = 0, e = ArgumentSCC.size(); i != e; ++i) {
       Argument *A = ArgumentSCC[i]->Definition;
-      A->addAttr(AttributeSet::get(A->getContext(), A->getArgNo() + 1,
-                                   Attribute::NoCapture));
+      A->addAttr(AttributeSet::get(A->getContext(), A->getArgNo() + 1, B));
       ++NumNoCapture;
       Changed = true;
     }





More information about the llvm-commits mailing list