summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2014-03-07 21:35:39 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2014-03-07 21:35:39 +0000
commite1362f1ebd3c10326e1d12514f3172201f91d832 (patch)
treeb3197de6c0c68500d1a51ef43ec86357fa07a77b
parent856eb29a6a62a73be41396aa695247656b95dea6 (diff)
downloadllvm-e1362f1ebd3c10326e1d12514f3172201f91d832.tar.gz
llvm-e1362f1ebd3c10326e1d12514f3172201f91d832.tar.bz2
llvm-e1362f1ebd3c10326e1d12514f3172201f91d832.tar.xz
[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
-rw-r--r--lib/Analysis/ScalarEvolutionExpander.cpp17
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfException.cpp18
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfException.h3
-rw-r--r--lib/CodeGen/MachineScheduler.cpp16
-rw-r--r--lib/Support/TargetRegistry.cpp11
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp9
-rw-r--r--lib/Transforms/Scalar/ConstantHoisting.cpp21
7 files changed, 33 insertions, 62 deletions
diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp
index ed345ab115..3602d1d442 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<const SCEV *, PHINode *> ExprToIVMap;
diff --git a/lib/CodeGen/AsmPrinter/DwarfException.cpp b/lib/CodeGen/AsmPrinter/DwarfException.cpp
index 42895300fc..113a9e4cd4 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<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.
diff --git a/lib/CodeGen/AsmPrinter/DwarfException.h b/lib/CodeGen/AsmPrinter/DwarfException.h
index a28eaf0c14..14357c6a36 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 b57be0d16d..a7b3d5e337 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<SUnit*> Loads,
ScheduleDAGMI *DAG) {
SmallVector<LoadClusterMutation::LoadInfo,32> LoadRecords;
@@ -1242,7 +1236,7 @@ void LoadClusterMutation::clusterNeighboringLoads(ArrayRef<SUnit*> 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 8d91a53c22..6e0e223ba7 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<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::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<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";
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index 0f97160eb6..1ba9ac1768 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<GlobalValue *, 8> 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 4940424c12..b4419313b0 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<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::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<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.