[llvm] r267614 - Reassociate: Simplify using lambdas. NFC

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 26 15:22:18 PDT 2016


Author: bogner
Date: Tue Apr 26 17:22:18 2016
New Revision: 267614

URL: http://llvm.org/viewvc/llvm-project?rev=267614&view=rev
Log:
Reassociate: Simplify using lambdas. NFC

Modified:
    llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp?rev=267614&r1=267613&r2=267614&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp Tue Apr 26 17:22:18 2016
@@ -81,22 +81,7 @@ namespace {
   struct Factor {
     Value *Base;
     unsigned Power;
-
     Factor(Value *Base, unsigned Power) : Base(Base), Power(Power) {}
-
-    /// \brief Sort factors in descending order by their power.
-    struct PowerDescendingSorter {
-      bool operator()(const Factor &LHS, const Factor &RHS) {
-        return LHS.Power > RHS.Power;
-      }
-    };
-
-    /// \brief Compare factors for equal powers.
-    struct PowerEqual {
-      bool operator()(const Factor &LHS, const Factor &RHS) {
-        return LHS.Power == RHS.Power;
-      }
-    };
   };
   
   /// Utility class representing a non-constant Xor-operand. We classify
@@ -1764,7 +1749,10 @@ bool Reassociate::collectMultiplyFactors
   // below our mininum of '4'.
   assert(FactorPowerSum >= 4);
 
-  std::stable_sort(Factors.begin(), Factors.end(), Factor::PowerDescendingSorter());
+  std::stable_sort(Factors.begin(), Factors.end(),
+                   [](const Factor &LHS, const Factor &RHS) {
+    return LHS.Power > RHS.Power;
+  });
   return true;
 }
 
@@ -1823,7 +1811,9 @@ Value *Reassociate::buildMinimalMultiply
   // Unique factors with equal powers -- we've folded them into the first one's
   // base.
   Factors.erase(std::unique(Factors.begin(), Factors.end(),
-                            Factor::PowerEqual()),
+                            [](const Factor &LHS, const Factor &RHS) {
+                              return LHS.Power == RHS.Power;
+                            }),
                 Factors.end());
 
   // Iteratively collect the base of each factor with an add power into the




More information about the llvm-commits mailing list