[llvm] r203288 - [C++11] Convert sort predicates into lambdas.

Benjamin Kramer benny.kra at googlemail.com
Fri Mar 7 13:35:39 PST 2014


Author: d0k
Date: Fri Mar  7 15:35:39 2014
New Revision: 203288

URL: http://llvm.org/viewvc/llvm-project?rev=203288&view=rev
Log:
[C++11] Convert sort predicates into lambdas.

No functionality change.

Modified:
    llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.h
    llvm/trunk/lib/CodeGen/MachineScheduler.cpp
    llvm/trunk/lib/Support/TargetRegistry.cpp
    llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
    llvm/trunk/lib/Transforms/Scalar/ConstantHoisting.cpp

Modified: llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp?rev=203288&r1=203287&r2=203288&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp Fri Mar  7 15:35:39 2014
@@ -1674,15 +1674,6 @@ SCEVExpander::getOrInsertCanonicalInduct
   return V;
 }
 
-/// Sort values by integer width for replaceCongruentIVs.
-static bool width_descending(Value *lhs, Value *rhs) {
-  // Put pointers at the back and make sure pointer < pointer = false.
-  if (!lhs->getType()->isIntegerTy() || !rhs->getType()->isIntegerTy())
-    return rhs->getType()->isIntegerTy() && !lhs->getType()->isIntegerTy();
-  return rhs->getType()->getPrimitiveSizeInBits()
-    < lhs->getType()->getPrimitiveSizeInBits();
-}
-
 /// replaceCongruentIVs - Check for congruent phis in this loop header and
 /// replace them with their most canonical representative. Return the number of
 /// phis eliminated.
@@ -1699,7 +1690,13 @@ unsigned SCEVExpander::replaceCongruentI
     Phis.push_back(Phi);
   }
   if (TTI)
-    std::sort(Phis.begin(), Phis.end(), width_descending);
+    std::sort(Phis.begin(), Phis.end(), [](Value *LHS, Value *RHS) {
+      // Put pointers at the back and make sure pointer < pointer = false.
+      if (!LHS->getType()->isIntegerTy() || !RHS->getType()->isIntegerTy())
+        return RHS->getType()->isIntegerTy() && !LHS->getType()->isIntegerTy();
+      return RHS->getType()->getPrimitiveSizeInBits() <
+             LHS->getType()->getPrimitiveSizeInBits();
+    });
 
   unsigned NumElim = 0;
   DenseMap<const SCEV *, PHINode *> ExprToIVMap;

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp?rev=203288&r1=203287&r2=203288&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp Fri Mar  7 15:35:39 2014
@@ -58,19 +58,6 @@ unsigned DwarfException::SharedTypeIds(c
   return Count;
 }
 
-/// PadLT - Order landing pads lexicographically by type id.
-bool DwarfException::PadLT(const LandingPadInfo *L, const LandingPadInfo *R) {
-  const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds;
-  unsigned LSize = LIds.size(), RSize = RIds.size();
-  unsigned MinSize = LSize < RSize ? LSize : RSize;
-
-  for (unsigned i = 0; i != MinSize; ++i)
-    if (LIds[i] != RIds[i])
-      return LIds[i] < RIds[i];
-
-  return LSize < RSize;
-}
-
 /// ComputeActionsTable - Compute the actions table and gather the first action
 /// index for each landing pad site.
 unsigned DwarfException::
@@ -356,7 +343,10 @@ void DwarfException::EmitExceptionTable(
   for (unsigned i = 0, N = PadInfos.size(); i != N; ++i)
     LandingPads.push_back(&PadInfos[i]);
 
-  std::sort(LandingPads.begin(), LandingPads.end(), PadLT);
+  // Order landing pads lexicographically by type id.
+  std::sort(LandingPads.begin(), LandingPads.end(),
+            [](const LandingPadInfo *L,
+               const LandingPadInfo *R) { return L->TypeIds < R->TypeIds; });
 
   // Compute the actions table and gather the first action index for each
   // landing pad site.

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.h?rev=203288&r1=203287&r2=203288&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.h Fri Mar  7 15:35:39 2014
@@ -48,9 +48,6 @@ protected:
   static unsigned SharedTypeIds(const LandingPadInfo *L,
                                 const LandingPadInfo *R);
 
-  /// PadLT - Order landing pads lexicographically by type id.
-  static bool PadLT(const LandingPadInfo *L, const LandingPadInfo *R);
-
   /// PadRange - Structure holding a try-range and the associated landing pad.
   struct PadRange {
     // The index of the landing pad.

Modified: llvm/trunk/lib/CodeGen/MachineScheduler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineScheduler.cpp?rev=203288&r1=203287&r2=203288&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineScheduler.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineScheduler.cpp Fri Mar  7 15:35:39 2014
@@ -1205,9 +1205,11 @@ class LoadClusterMutation : public Sched
     unsigned Offset;
     LoadInfo(SUnit *su, unsigned reg, unsigned ofs)
       : SU(su), BaseReg(reg), Offset(ofs) {}
+
+    bool operator<(const LoadInfo &RHS) const {
+      return std::tie(BaseReg, Offset) < std::tie(RHS.BaseReg, RHS.Offset);
+    }
   };
-  static bool LoadInfoLess(const LoadClusterMutation::LoadInfo &LHS,
-                           const LoadClusterMutation::LoadInfo &RHS);
 
   const TargetInstrInfo *TII;
   const TargetRegisterInfo *TRI;
@@ -1222,14 +1224,6 @@ protected:
 };
 } // anonymous
 
-bool LoadClusterMutation::LoadInfoLess(
-  const LoadClusterMutation::LoadInfo &LHS,
-  const LoadClusterMutation::LoadInfo &RHS) {
-  if (LHS.BaseReg != RHS.BaseReg)
-    return LHS.BaseReg < RHS.BaseReg;
-  return LHS.Offset < RHS.Offset;
-}
-
 void LoadClusterMutation::clusterNeighboringLoads(ArrayRef<SUnit*> Loads,
                                                   ScheduleDAGMI *DAG) {
   SmallVector<LoadClusterMutation::LoadInfo,32> LoadRecords;
@@ -1242,7 +1236,7 @@ void LoadClusterMutation::clusterNeighbo
   }
   if (LoadRecords.size() < 2)
     return;
-  std::sort(LoadRecords.begin(), LoadRecords.end(), LoadInfoLess);
+  std::sort(LoadRecords.begin(), LoadRecords.end());
   unsigned ClusterLength = 1;
   for (unsigned Idx = 0, End = LoadRecords.size(); Idx < (End - 1); ++Idx) {
     if (LoadRecords[Idx].BaseReg != LoadRecords[Idx+1].BaseReg) {

Modified: llvm/trunk/lib/Support/TargetRegistry.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/TargetRegistry.cpp?rev=203288&r1=203287&r2=203288&view=diff
==============================================================================
--- llvm/trunk/lib/Support/TargetRegistry.cpp (original)
+++ llvm/trunk/lib/Support/TargetRegistry.cpp Fri Mar  7 15:35:39 2014
@@ -127,11 +127,6 @@ const Target *TargetRegistry::getClosest
   return TheTarget;
 }
 
-static int TargetArraySortFn(const std::pair<StringRef, const Target *> *LHS,
-                             const std::pair<StringRef, const Target *> *RHS) {
-  return LHS->first.compare(RHS->first);
-}
-
 void TargetRegistry::printRegisteredTargetsForVersion() {
   std::vector<std::pair<StringRef, const Target*> > Targets;
   size_t Width = 0;
@@ -141,7 +136,11 @@ void TargetRegistry::printRegisteredTarg
     Targets.push_back(std::make_pair(I->getName(), &*I));
     Width = std::max(Width, Targets.back().first.size());
   }
-  array_pod_sort(Targets.begin(), Targets.end(), TargetArraySortFn);
+  array_pod_sort(Targets.begin(), Targets.end(),
+                 [](const std::pair<StringRef, const Target *> *LHS,
+                    const std::pair<StringRef, const Target *> *RHS) {
+    return LHS->first.compare(RHS->first);
+  });
 
   raw_ostream &OS = outs();
   OS << "  Registered Targets:\n";

Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=203288&r1=203287&r2=203288&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Fri Mar  7 15:35:39 2014
@@ -2860,10 +2860,6 @@ bool GlobalOpt::OptimizeGlobalCtorsList(
   return true;
 }
 
-static int compareNames(Constant *const *A, Constant *const *B) {
-  return (*A)->getName().compare((*B)->getName());
-}
-
 static void setUsedInitializer(GlobalVariable &V,
                                SmallPtrSet<GlobalValue *, 8> Init) {
   if (Init.empty()) {
@@ -2882,7 +2878,10 @@ static void setUsedInitializer(GlobalVar
     UsedArray.push_back(Cast);
   }
   // Sort to get deterministic order.
-  array_pod_sort(UsedArray.begin(), UsedArray.end(), compareNames);
+  array_pod_sort(UsedArray.begin(), UsedArray.end(),
+                 [](Constant *const *A, Constant *const *B) {
+    return (*A)->getName().compare((*B)->getName());
+  });
   ArrayType *ATy = ArrayType::get(Int8PtrTy, UsedArray.size());
 
   Module *M = V.getParent();

Modified: llvm/trunk/lib/Transforms/Scalar/ConstantHoisting.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/ConstantHoisting.cpp?rev=203288&r1=203287&r2=203288&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/ConstantHoisting.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/ConstantHoisting.cpp Fri Mar  7 15:35:39 2014
@@ -191,18 +191,6 @@ void ConstantHoisting::CollectConstants(
       CollectConstants(I);
 }
 
-/// \brief Compare function for sorting integer constants by type and by value
-/// within a type in ConstantMaps.
-static bool
-ConstantMapLessThan(const std::pair<ConstantInt *, ConstantCandidate> &LHS,
-                    const std::pair<ConstantInt *, ConstantCandidate> &RHS) {
-  if (LHS.first->getType() == RHS.first->getType())
-    return LHS.first->getValue().ult(RHS.first->getValue());
-  else
-    return LHS.first->getType()->getBitWidth() <
-           RHS.first->getType()->getBitWidth();
-}
-
 /// \brief Find the base constant within the given range and rebase all other
 /// constants with respect to the base constant.
 void ConstantHoisting::FindAndMakeBaseConstant(ConstantMapType::iterator S,
@@ -239,7 +227,14 @@ void ConstantHoisting::FindAndMakeBaseCo
 /// an add from a common base constant.
 void ConstantHoisting::FindBaseConstants() {
   // Sort the constants by value and type. This invalidates the mapping.
-  std::sort(ConstantMap.begin(), ConstantMap.end(), ConstantMapLessThan);
+  std::sort(ConstantMap.begin(), ConstantMap.end(),
+            [](const std::pair<ConstantInt *, ConstantCandidate> &LHS,
+               const std::pair<ConstantInt *, ConstantCandidate> &RHS) {
+    if (LHS.first->getType() != RHS.first->getType())
+      return LHS.first->getType()->getBitWidth() <
+             RHS.first->getType()->getBitWidth();
+    return LHS.first->getValue().ult(RHS.first->getValue());
+  });
 
   // Simple linear scan through the sorted constant map for viable merge
   // candidates.





More information about the llvm-commits mailing list