From e1362f1ebd3c10326e1d12514f3172201f91d832 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 7 Mar 2014 21:35:39 +0000 Subject: [PATCH] [C++11] Convert sort predicates into lambdas. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203288 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ScalarEvolutionExpander.cpp | 17 +++++++---------- lib/CodeGen/AsmPrinter/DwarfException.cpp | 18 ++++-------------- lib/CodeGen/AsmPrinter/DwarfException.h | 3 --- lib/CodeGen/MachineScheduler.cpp | 16 +++++----------- lib/Support/TargetRegistry.cpp | 11 +++++------ lib/Transforms/IPO/GlobalOpt.cpp | 9 ++++----- lib/Transforms/Scalar/ConstantHoisting.cpp | 21 ++++++++------------- 7 files changed, 33 insertions(+), 62 deletions(-) diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp index ed345ab115f..3602d1d4426 100644 --- a/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/lib/Analysis/ScalarEvolutionExpander.cpp @@ -1674,15 +1674,6 @@ SCEVExpander::getOrInsertCanonicalInductionVariable(const Loop *L, 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::replaceCongruentIVs(Loop *L, const DominatorTree *DT, 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 ExprToIVMap; diff --git a/lib/CodeGen/AsmPrinter/DwarfException.cpp b/lib/CodeGen/AsmPrinter/DwarfException.cpp index 42895300fc6..113a9e4cd4c 100644 --- a/lib/CodeGen/AsmPrinter/DwarfException.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfException.cpp @@ -58,19 +58,6 @@ unsigned DwarfException::SharedTypeIds(const LandingPadInfo *L, return Count; } -/// PadLT - Order landing pads lexicographically by type id. -bool DwarfException::PadLT(const LandingPadInfo *L, const LandingPadInfo *R) { - const std::vector &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. diff --git a/lib/CodeGen/AsmPrinter/DwarfException.h b/lib/CodeGen/AsmPrinter/DwarfException.h index a28eaf0c140..14357c6a367 100644 --- a/lib/CodeGen/AsmPrinter/DwarfException.h +++ b/lib/CodeGen/AsmPrinter/DwarfException.h @@ -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. diff --git a/lib/CodeGen/MachineScheduler.cpp b/lib/CodeGen/MachineScheduler.cpp index b57be0d16d3..a7b3d5e3376 100644 --- a/lib/CodeGen/MachineScheduler.cpp +++ b/lib/CodeGen/MachineScheduler.cpp @@ -1205,9 +1205,11 @@ class LoadClusterMutation : public ScheduleDAGMutation { 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 Loads, ScheduleDAGMI *DAG) { SmallVector LoadRecords; @@ -1242,7 +1236,7 @@ void LoadClusterMutation::clusterNeighboringLoads(ArrayRef Loads, } 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) { diff --git a/lib/Support/TargetRegistry.cpp b/lib/Support/TargetRegistry.cpp index 8d91a53c226..6e0e223ba70 100644 --- a/lib/Support/TargetRegistry.cpp +++ b/lib/Support/TargetRegistry.cpp @@ -127,11 +127,6 @@ const Target *TargetRegistry::getClosestTargetForJIT(std::string &Error) { return TheTarget; } -static int TargetArraySortFn(const std::pair *LHS, - const std::pair *RHS) { - return LHS->first.compare(RHS->first); -} - void TargetRegistry::printRegisteredTargetsForVersion() { std::vector > Targets; size_t Width = 0; @@ -141,7 +136,11 @@ void TargetRegistry::printRegisteredTargetsForVersion() { 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 *LHS, + const std::pair *RHS) { + return LHS->first.compare(RHS->first); + }); raw_ostream &OS = outs(); OS << " Registered Targets:\n"; diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index 0f97160eb6a..1ba9ac17688 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -2860,10 +2860,6 @@ bool GlobalOpt::OptimizeGlobalCtorsList(GlobalVariable *&GCL) { return true; } -static int compareNames(Constant *const *A, Constant *const *B) { - return (*A)->getName().compare((*B)->getName()); -} - static void setUsedInitializer(GlobalVariable &V, SmallPtrSet Init) { if (Init.empty()) { @@ -2882,7 +2878,10 @@ static void setUsedInitializer(GlobalVariable &V, 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(); diff --git a/lib/Transforms/Scalar/ConstantHoisting.cpp b/lib/Transforms/Scalar/ConstantHoisting.cpp index 4940424c123..b4419313b06 100644 --- a/lib/Transforms/Scalar/ConstantHoisting.cpp +++ b/lib/Transforms/Scalar/ConstantHoisting.cpp @@ -191,18 +191,6 @@ void ConstantHoisting::CollectConstants(Function &F) { 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 &LHS, - const std::pair &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::FindAndMakeBaseConstant(ConstantMapType::iterator S, /// 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 &LHS, + const std::pair &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.