[llvm] r202588 - Now that we have C++11, turn simple functors into lambdas and remove a ton of boilerplate.
Benjamin Kramer
benny.kra at gmail.com
Mon Mar 3 09:16:02 PST 2014
On Mon, Mar 3, 2014 at 6:02 PM, David Blaikie <dblaikie at gmail.com> wrote:
>
>
>
> On Sat, Mar 1, 2014 at 3:47 AM, Benjamin Kramer <benny.kra at googlemail.com>
> wrote:
>>
>> Author: d0k
>> Date: Sat Mar 1 05:47:00 2014
>> New Revision: 202588
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=202588&view=rev
>> Log:
>> Now that we have C++11, turn simple functors into lambdas and remove a ton
>> of boilerplate.
>>
>> No intended functionality change.
>>
>> Modified:
>> llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp
>> llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp
>> llvm/trunk/lib/CodeGen/MachineSink.cpp
>> llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
>> llvm/trunk/lib/CodeGen/StackColoring.cpp
>> llvm/trunk/lib/Support/CommandLine.cpp
>> llvm/trunk/lib/Support/Statistic.cpp
>> llvm/trunk/lib/Target/ARM/ARMLoadStoreOptimizer.cpp
>> llvm/trunk/lib/Target/Mips/MipsDelaySlotFiller.cpp
>> llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp
>> llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp
>> llvm/trunk/lib/Transforms/Scalar/GlobalMerge.cpp
>> llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
>> llvm/trunk/lib/Transforms/Scalar/SROA.cpp
>> llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp
>> llvm/trunk/tools/llvm-ar/llvm-ar.cpp
>> llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp
>> llvm/trunk/utils/TableGen/CodeGenRegisters.cpp
>> llvm/trunk/utils/TableGen/CodeGenTarget.cpp
>> llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp
>>
>> Modified: llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp (original)
>> +++ llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp Sat Mar 1 05:47:00
>> 2014
>> @@ -173,29 +173,19 @@ void ValueEnumerator::print(raw_ostream
>> }
>> }
>>
>> -// Optimize constant ordering.
>> -namespace {
>> - struct CstSortPredicate {
>> - ValueEnumerator &VE;
>> - explicit CstSortPredicate(ValueEnumerator &ve) : VE(ve) {}
>> - bool operator()(const std::pair<const Value*, unsigned> &LHS,
>> - const std::pair<const Value*, unsigned> &RHS) {
>> - // Sort by plane.
>> - if (LHS.first->getType() != RHS.first->getType())
>> - return VE.getTypeID(LHS.first->getType()) <
>> - VE.getTypeID(RHS.first->getType());
>> - // Then by frequency.
>> - return LHS.second > RHS.second;
>> - }
>> - };
>> -}
>> -
>> /// OptimizeConstants - Reorder constant pool for denser encoding.
>> void ValueEnumerator::OptimizeConstants(unsigned CstStart, unsigned
>> CstEnd) {
>> if (CstStart == CstEnd || CstStart+1 == CstEnd) return;
>>
>> - CstSortPredicate P(*this);
>> - std::stable_sort(Values.begin()+CstStart, Values.begin()+CstEnd, P);
>> + std::stable_sort(Values.begin() + CstStart, Values.begin() + CstEnd,
>> + [this](const std::pair<const Value *, unsigned> &LHS,
>> + const std::pair<const Value *, unsigned> &RHS)
>> {
>> + // Sort by plane.
>> + if (LHS.first->getType() != RHS.first->getType())
>> + return getTypeID(LHS.first->getType()) <
>> getTypeID(RHS.first->getType());
>> + // Then by frequency.
>> + return LHS.second > RHS.second;
>
>
> I think I mentioned this off-list (by accident, replying on my phone) & not
> sure if it's already been addressed, but should we implement these sort of
> sorts via std::tie and tuple's op<?
>
> return std::tie(getTypeID(LHS.first->getType()), LHS.second) <
> std::tie(getTypeID(RHS.first->getType()), RHS.second);
I think using std::tie makes a lot of sense for comparators. This one
is asymmetric though so it's not a good candidate. I guess I'll do a
cleanup sweep over the others.
- Ben
>
>>
>> + });
>>
>> // Ensure that integer and vector of integer constants are at the start
>> of the
>> // constant pool. This is important so that GEP structure indices come
>> before
>>
>> Modified: llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp Sat Mar 1 05:47:00
>> 2014
>> @@ -409,23 +409,6 @@ MachineBasicBlock *MachineBlockPlacement
>> return BestSucc;
>> }
>>
>> -namespace {
>> -/// \brief Predicate struct to detect blocks already placed.
>> -class IsBlockPlaced {
>> - const BlockChain &PlacedChain;
>> - const BlockToChainMapType &BlockToChain;
>> -
>> -public:
>> - IsBlockPlaced(const BlockChain &PlacedChain,
>> - const BlockToChainMapType &BlockToChain)
>> - : PlacedChain(PlacedChain), BlockToChain(BlockToChain) {}
>> -
>> - bool operator()(MachineBasicBlock *BB) const {
>> - return BlockToChain.lookup(BB) == &PlacedChain;
>> - }
>> -};
>> -}
>> -
>> /// \brief Select the best block from a worklist.
>> ///
>> /// This looks through the provided worklist as a list of candidate basic
>> @@ -444,7 +427,9 @@ MachineBasicBlock *MachineBlockPlacement
>> // FIXME: If this shows up on profiles, it could be folded (at the cost
>> of
>> // some code complexity) into the loop below.
>> WorkList.erase(std::remove_if(WorkList.begin(), WorkList.end(),
>> - IsBlockPlaced(Chain, BlockToChain)),
>> + [&](MachineBasicBlock *BB) {
>> + return BlockToChain.lookup(BB) == &Chain;
>> + }),
>> WorkList.end());
>>
>> MachineBasicBlock *BestBlock = 0;
>>
>> Modified: llvm/trunk/lib/CodeGen/MachineSink.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineSink.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/MachineSink.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/MachineSink.cpp Sat Mar 1 05:47:00 2014
>> @@ -98,16 +98,6 @@ namespace {
>> bool PerformTrivialForwardCoalescing(MachineInstr *MI,
>> MachineBasicBlock *MBB);
>> };
>> -
>> - // SuccessorSorter - Sort Successors according to their loop depth.
>> - struct SuccessorSorter {
>> - SuccessorSorter(MachineLoopInfo *LoopInfo) : LI(LoopInfo) {}
>> - bool operator()(const MachineBasicBlock *LHS,
>> - const MachineBasicBlock *RHS) const {
>> - return LI->getLoopDepth(LHS) < LI->getLoopDepth(RHS);
>> - }
>> - MachineLoopInfo *LI;
>> - };
>> } // end anonymous namespace
>>
>> char MachineSinking::ID = 0;
>> @@ -553,7 +543,12 @@ MachineBasicBlock *MachineSinking::FindS
>> // we should sink to.
>> // We give successors with smaller loop depth higher priority.
>> SmallVector<MachineBasicBlock*, 4> Succs(MBB->succ_begin(),
>> MBB->succ_end());
>> - std::stable_sort(Succs.begin(), Succs.end(), SuccessorSorter(LI));
>> + // Sort Successors according to their loop depth.
>> + std::stable_sort(
>> + Succs.begin(), Succs.end(),
>> + [this](const MachineBasicBlock *LHS, const MachineBasicBlock
>> *RHS) {
>> + return LI->getLoopDepth(LHS) < LI->getLoopDepth(RHS);
>> + });
>> for (SmallVectorImpl<MachineBasicBlock *>::iterator SI =
>> Succs.begin(),
>> E = Succs.end(); SI != E; ++SI) {
>> MachineBasicBlock *SuccBlock = *SI;
>>
>> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Sat Mar 1
>> 05:47:00 2014
>> @@ -8197,14 +8197,6 @@ struct LoadedSlice {
>> };
>> }
>>
>> -/// \brief Sorts LoadedSlice according to their offset.
>> -struct LoadedSliceSorter {
>> - bool operator()(const LoadedSlice &LHS, const LoadedSlice &RHS) {
>> - assert(LHS.Origin == RHS.Origin && "Different bases not
>> implemented.");
>> - return LHS.getOffsetFromBase() < RHS.getOffsetFromBase();
>> - }
>> -};
>> -
>> /// \brief Check that all bits set in \p UsedBits form a dense region,
>> i.e.,
>> /// \p UsedBits looks like 0..0 1..1 0..0.
>> static bool areUsedBitsDense(const APInt &UsedBits) {
>> @@ -8248,7 +8240,11 @@ static void adjustCostForPairing(SmallVe
>>
>> // Sort the slices so that elements that are likely to be next to each
>> // other in memory are next to each other in the list.
>> - std::sort(LoadedSlices.begin(), LoadedSlices.end(),
>> LoadedSliceSorter());
>> + std::sort(LoadedSlices.begin(), LoadedSlices.end(),
>> + [](const LoadedSlice &LHS, const LoadedSlice &RHS) {
>> + assert(LHS.Origin == RHS.Origin && "Different bases not
>> implemented.");
>> + return LHS.getOffsetFromBase() < RHS.getOffsetFromBase();
>> + });
>> const TargetLowering &TLI =
>> LoadedSlices[0].DAG->getTargetLoweringInfo();
>> // First (resp. Second) is the first (resp. Second) potentially
>> candidate
>> // to be placed in a paired load.
>> @@ -8852,17 +8848,6 @@ struct MemOpLink {
>> unsigned SequenceNum;
>> };
>>
>> -/// Sorts store nodes in a link according to their offset from a shared
>> -// base ptr.
>> -struct ConsecutiveMemoryChainSorter {
>> - bool operator()(MemOpLink LHS, MemOpLink RHS) {
>> - return
>> - LHS.OffsetFromBase < RHS.OffsetFromBase ||
>> - (LHS.OffsetFromBase == RHS.OffsetFromBase &&
>> - LHS.SequenceNum > RHS.SequenceNum);
>> - }
>> -};
>> -
>> bool DAGCombiner::MergeConsecutiveStores(StoreSDNode* St) {
>> EVT MemVT = St->getMemoryVT();
>> int64_t ElementSizeBytes = MemVT.getSizeInBits()/8;
>> @@ -8981,7 +8966,11 @@ bool DAGCombiner::MergeConsecutiveStores
>>
>> // Sort the memory operands according to their distance from the base
>> pointer.
>> std::sort(StoreNodes.begin(), StoreNodes.end(),
>> - ConsecutiveMemoryChainSorter());
>> + [](MemOpLink LHS, MemOpLink RHS) {
>> + return LHS.OffsetFromBase < RHS.OffsetFromBase ||
>> + (LHS.OffsetFromBase == RHS.OffsetFromBase &&
>> + LHS.SequenceNum > RHS.SequenceNum);
>> + });
>>
>> // Scan the memory operations on the chain and find the first
>> non-consecutive
>> // store memory address.
>>
>> Modified: llvm/trunk/lib/CodeGen/StackColoring.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/StackColoring.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/StackColoring.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/StackColoring.cpp Sat Mar 1 05:47:00 2014
>> @@ -125,20 +125,6 @@ class StackColoring : public MachineFunc
>> /// once the coloring is done.
>> SmallVector<MachineInstr*, 8> Markers;
>>
>> - /// SlotSizeSorter - A Sort utility for arranging stack slots according
>> - /// to their size.
>> - struct SlotSizeSorter {
>> - MachineFrameInfo *MFI;
>> - SlotSizeSorter(MachineFrameInfo *mfi) : MFI(mfi) { }
>> - bool operator()(int LHS, int RHS) {
>> - // We use -1 to denote a uninteresting slot. Place these slots at
>> the end.
>> - if (LHS == -1) return false;
>> - if (RHS == -1) return true;
>> - // Sort according to size.
>> - return MFI->getObjectSize(LHS) > MFI->getObjectSize(RHS);
>> - }
>> -};
>> -
>> public:
>> static char ID;
>> StackColoring() : MachineFunctionPass(ID) {
>> @@ -767,7 +753,13 @@ bool StackColoring::runOnMachineFunction
>> // Sort the slots according to their size. Place unused slots at the
>> end.
>> // Use stable sort to guarantee deterministic code generation.
>> std::stable_sort(SortedSlots.begin(), SortedSlots.end(),
>> - SlotSizeSorter(MFI));
>> + [this](int LHS, int RHS) {
>> + // We use -1 to denote a uninteresting slot. Place these slots at the
>> end.
>> + if (LHS == -1) return false;
>> + if (RHS == -1) return true;
>> + // Sort according to size.
>> + return MFI->getObjectSize(LHS) > MFI->getObjectSize(RHS);
>> + });
>>
>> bool Changed = true;
>> while (Changed) {
>>
>> Modified: llvm/trunk/lib/Support/CommandLine.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CommandLine.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Support/CommandLine.cpp (original)
>> +++ llvm/trunk/lib/Support/CommandLine.cpp Sat Mar 1 05:47:00 2014
>> @@ -125,20 +125,12 @@ static ManagedStatic<OptionCatSet> Regis
>> // Initialise the general option category.
>> OptionCategory llvm::cl::GeneralCategory("General options");
>>
>> -struct HasName {
>> - HasName(StringRef Name) : Name(Name) {}
>> - bool operator()(const OptionCategory *Category) const {
>> - return Name == Category->getName();
>> - }
>> - StringRef Name;
>> -};
>> -
>> -void OptionCategory::registerCategory()
>> -{
>> +void OptionCategory::registerCategory() {
>> assert(std::count_if(RegisteredOptionCategories->begin(),
>> RegisteredOptionCategories->end(),
>> - HasName(getName())) == 0 &&
>> - "Duplicate option categories");
>> + [this](const OptionCategory *Category) {
>> + return getName() == Category->getName();
>> + }) == 0 && "Duplicate option categories");
>>
>> RegisteredOptionCategories->insert(this);
>> }
>>
>> Modified: llvm/trunk/lib/Support/Statistic.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Statistic.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Support/Statistic.cpp (original)
>> +++ llvm/trunk/lib/Support/Statistic.cpp Sat Mar 1 05:47:00 2014
>> @@ -84,20 +84,6 @@ void Statistic::RegisterStatistic() {
>> }
>> }
>>
>> -namespace {
>> -
>> -struct NameCompare {
>> - bool operator()(const Statistic *LHS, const Statistic *RHS) const {
>> - int Cmp = std::strcmp(LHS->getName(), RHS->getName());
>> - if (Cmp != 0) return Cmp < 0;
>> -
>> - // Secondary key is the description.
>> - return std::strcmp(LHS->getDesc(), RHS->getDesc()) < 0;
>> - }
>> -};
>> -
>> -}
>> -
>> // Print information when destroyed, iff command line option is
>> specified.
>> StatisticInfo::~StatisticInfo() {
>> llvm::PrintStatistics();
>> @@ -124,7 +110,14 @@ void llvm::PrintStatistics(raw_ostream &
>> }
>>
>> // Sort the fields by name.
>> - std::stable_sort(Stats.Stats.begin(), Stats.Stats.end(),
>> NameCompare());
>> + std::stable_sort(Stats.Stats.begin(), Stats.Stats.end(),
>> + [](const Statistic *LHS, const Statistic *RHS) {
>> + if (int Cmp = std::strcmp(LHS->getName(), RHS->getName()))
>> + return Cmp < 0;
>> +
>> + // Secondary key is the description.
>> + return std::strcmp(LHS->getDesc(), RHS->getDesc()) < 0;
>> + });
>>
>> // Print out the statistics header...
>> OS << "===" << std::string(73, '-') << "===\n"
>>
>> Modified: llvm/trunk/lib/Target/ARM/ARMLoadStoreOptimizer.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMLoadStoreOptimizer.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Target/ARM/ARMLoadStoreOptimizer.cpp (original)
>> +++ llvm/trunk/lib/Target/ARM/ARMLoadStoreOptimizer.cpp Sat Mar 1
>> 05:47:00 2014
>> @@ -1724,17 +1724,6 @@ ARMPreAllocLoadStoreOpt::CanFormLdStDWor
>> return true;
>> }
>>
>> -namespace {
>> - struct OffsetCompare {
>> - bool operator()(const MachineInstr *LHS, const MachineInstr *RHS)
>> const {
>> - int LOffset = getMemoryOpOffset(LHS);
>> - int ROffset = getMemoryOpOffset(RHS);
>> - assert(LHS == RHS || LOffset != ROffset);
>> - return LOffset > ROffset;
>> - }
>> - };
>> -}
>> -
>> bool ARMPreAllocLoadStoreOpt::RescheduleOps(MachineBasicBlock *MBB,
>> SmallVectorImpl<MachineInstr *> &Ops,
>> unsigned Base, bool isLd,
>> @@ -1742,7 +1731,13 @@ bool ARMPreAllocLoadStoreOpt::Reschedule
>> bool RetVal = false;
>>
>> // Sort by offset (in reverse order).
>> - std::sort(Ops.begin(), Ops.end(), OffsetCompare());
>> + std::sort(Ops.begin(), Ops.end(),
>> + [](const MachineInstr *LHS, const MachineInstr *RHS) {
>> + int LOffset = getMemoryOpOffset(LHS);
>> + int ROffset = getMemoryOpOffset(RHS);
>> + assert(LHS == RHS || LOffset != ROffset);
>> + return LOffset > ROffset;
>> + });
>>
>> // The loads / stores of the same base are in order. Scan them from
>> first to
>> // last and check for the following:
>>
>> Modified: llvm/trunk/lib/Target/Mips/MipsDelaySlotFiller.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsDelaySlotFiller.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Target/Mips/MipsDelaySlotFiller.cpp (original)
>> +++ llvm/trunk/lib/Target/Mips/MipsDelaySlotFiller.cpp Sat Mar 1 05:47:00
>> 2014
>> @@ -65,20 +65,6 @@ namespace {
>> typedef MachineBasicBlock::reverse_iterator ReverseIter;
>> typedef SmallDenseMap<MachineBasicBlock*, MachineInstr*, 2> BB2BrMap;
>>
>> - /// \brief A functor comparing edge weight of two blocks.
>> - struct CmpWeight {
>> - CmpWeight(const MachineBasicBlock &S,
>> - const MachineBranchProbabilityInfo &P) : Src(S), Prob(P) {}
>> -
>> - bool operator()(const MachineBasicBlock *Dst0,
>> - const MachineBasicBlock *Dst1) const {
>> - return Prob.getEdgeWeight(&Src, Dst0) < Prob.getEdgeWeight(&Src,
>> Dst1);
>> - }
>> -
>> - const MachineBasicBlock &Src;
>> - const MachineBranchProbabilityInfo &Prob;
>> - };
>> -
>> class RegDefsUses {
>> public:
>> RegDefsUses(TargetMachine &TM);
>> @@ -640,8 +626,12 @@ MachineBasicBlock *Filler::selectSuccBB(
>> return NULL;
>>
>> // Select the successor with the larget edge weight.
>> - CmpWeight Cmp(B, getAnalysis<MachineBranchProbabilityInfo>());
>> - MachineBasicBlock *S = *std::max_element(B.succ_begin(), B.succ_end(),
>> Cmp);
>> + auto &Prob = getAnalysis<MachineBranchProbabilityInfo>();
>> + MachineBasicBlock *S = *std::max_element(B.succ_begin(), B.succ_end(),
>> + [&](const MachineBasicBlock
>> *Dst0,
>> + const MachineBasicBlock
>> *Dst1) {
>> + return Prob.getEdgeWeight(&B, Dst0) < Prob.getEdgeWeight(&B, Dst1);
>> + });
>> return S->isLandingPad() ? NULL : S;
>> }
>>
>>
>> Modified: llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp (original)
>> +++ llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp Sat Mar 1
>> 05:47:00 2014
>> @@ -239,14 +239,6 @@ namespace {
>> };
>>
>>
>> - // Sorting function for deterministic behaviour in GCOVBlock::writeOut.
>> - struct StringKeySort {
>> - bool operator()(StringMapEntry<GCOVLines *> *LHS,
>> - StringMapEntry<GCOVLines *> *RHS) const {
>> - return LHS->getKey() < RHS->getKey();
>> - }
>> - };
>> -
>> // Represent a basic block in GCOV. Each block has a unique number in
>> the
>> // function, number of lines belonging to each block, and a set of
>> edges to
>> // other blocks.
>> @@ -277,8 +269,11 @@ namespace {
>> write(Len);
>> write(Number);
>>
>> - StringKeySort Sorter;
>> - std::sort(SortedLinesByFile.begin(), SortedLinesByFile.end(),
>> Sorter);
>> + std::sort(SortedLinesByFile.begin(), SortedLinesByFile.end(),
>> + [](StringMapEntry<GCOVLines *> *LHS,
>> + StringMapEntry<GCOVLines *> *RHS) {
>> + return LHS->getKey() < RHS->getKey();
>> + });
>> for (SmallVectorImpl<StringMapEntry<GCOVLines *> *>::iterator
>> I = SortedLinesByFile.begin(), E =
>> SortedLinesByFile.end();
>> I != E; ++I)
>>
>> Modified: llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp (original)
>> +++ llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp Sat Mar 1
>> 05:47:00 2014
>> @@ -702,22 +702,6 @@ bool DSE::HandleFree(CallInst *F) {
>> return MadeChange;
>> }
>>
>> -namespace {
>> - struct CouldRef {
>> - typedef Value *argument_type;
>> - const CallSite CS;
>> - AliasAnalysis *AA;
>> -
>> - bool operator()(Value *I) {
>> - // See if the call site touches the value.
>> - AliasAnalysis::ModRefResult A =
>> - AA->getModRefInfo(CS, I, getPointerSize(I, *AA));
>> -
>> - return A == AliasAnalysis::ModRef || A == AliasAnalysis::Ref;
>> - }
>> - };
>> -}
>> -
>> /// handleEndBlock - Remove dead stores to stack-allocated locations in
>> the
>> /// function end block. Ex:
>> /// %A = alloca i32
>> @@ -819,7 +803,13 @@ bool DSE::handleEndBlock(BasicBlock &BB)
>>
>> // If the call might load from any of our allocas, then any store
>> above
>> // the call is live.
>> - CouldRef Pred = { CS, AA };
>> + std::function<bool(Value *)> Pred = [&](Value *I) {
>> + // See if the call site touches the value.
>> + AliasAnalysis::ModRefResult A =
>> + AA->getModRefInfo(CS, I, getPointerSize(I, *AA));
>> +
>> + return A == AliasAnalysis::ModRef || A == AliasAnalysis::Ref;
>> + };
>> DeadStackObjects.remove_if(Pred);
>>
>> // If all of the allocas were clobbered by the call then we're not
>> going
>> @@ -863,20 +853,6 @@ bool DSE::handleEndBlock(BasicBlock &BB)
>> return MadeChange;
>> }
>>
>> -namespace {
>> - struct CouldAlias {
>> - typedef Value *argument_type;
>> - const AliasAnalysis::Location &LoadedLoc;
>> - AliasAnalysis *AA;
>> -
>> - bool operator()(Value *I) {
>> - // See if the loaded location could alias the stack location.
>> - AliasAnalysis::Location StackLoc(I, getPointerSize(I, *AA));
>> - return !AA->isNoAlias(StackLoc, LoadedLoc);
>> - }
>> - };
>> -}
>> -
>> /// RemoveAccessedObjects - Check to see if the specified location may
>> alias any
>> /// of the stack objects in the DeadStackObjects set. If so, they become
>> live
>> /// because the location is being loaded.
>> @@ -896,6 +872,10 @@ void DSE::RemoveAccessedObjects(const Al
>> }
>>
>> // Remove objects that could alias LoadedLoc.
>> - CouldAlias Pred = { LoadedLoc, AA };
>> + std::function<bool(Value *)> Pred = [&](Value *I) {
>> + // See if the loaded location could alias the stack location.
>> + AliasAnalysis::Location StackLoc(I, getPointerSize(I, *AA));
>> + return !AA->isNoAlias(StackLoc, LoadedLoc);
>> + };
>> DeadStackObjects.remove_if(Pred);
>> }
>>
>> Modified: llvm/trunk/lib/Transforms/Scalar/GlobalMerge.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GlobalMerge.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Transforms/Scalar/GlobalMerge.cpp (original)
>> +++ llvm/trunk/lib/Transforms/Scalar/GlobalMerge.cpp Sat Mar 1 05:47:00
>> 2014
>> @@ -124,19 +124,6 @@ namespace {
>> AU.setPreservesCFG();
>> FunctionPass::getAnalysisUsage(AU);
>> }
>> -
>> - struct GlobalCmp {
>> - const DataLayout *DL;
>> -
>> - GlobalCmp(const DataLayout *DL) : DL(DL) { }
>> -
>> - bool operator()(const GlobalVariable *GV1, const GlobalVariable
>> *GV2) {
>> - Type *Ty1 = cast<PointerType>(GV1->getType())->getElementType();
>> - Type *Ty2 = cast<PointerType>(GV2->getType())->getElementType();
>> -
>> - return (DL->getTypeAllocSize(Ty1) < DL->getTypeAllocSize(Ty2));
>> - }
>> - };
>> };
>> } // end anonymous namespace
>>
>> @@ -156,7 +143,13 @@ bool GlobalMerge::doMerge(SmallVectorImp
>> unsigned MaxOffset = TLI->getMaximalGlobalOffset();
>>
>> // FIXME: Find better heuristics
>> - std::stable_sort(Globals.begin(), Globals.end(), GlobalCmp(DL));
>> + std::stable_sort(Globals.begin(), Globals.end(),
>> + [DL](const GlobalVariable *GV1, const GlobalVariable
>> *GV2) {
>> + Type *Ty1 = cast<PointerType>(GV1->getType())->getElementType();
>> + Type *Ty2 = cast<PointerType>(GV2->getType())->getElementType();
>> +
>> + return (DL->getTypeAllocSize(Ty1) < DL->getTypeAllocSize(Ty2));
>> + });
>>
>> Type *Int32Ty = Type::getInt32Ty(M.getContext());
>>
>>
>> Modified: llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp (original)
>> +++ llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp Sat Mar 1 05:47:00
>> 2014
>> @@ -1547,19 +1547,6 @@ Value *Reassociate::OptimizeAdd(Instruct
>> return 0;
>> }
>>
>> -namespace {
>> - /// \brief Predicate tests whether a ValueEntry's op is in a map.
>> - struct IsValueInMap {
>> - const DenseMap<Value *, unsigned> ⤅
>> -
>> - IsValueInMap(const DenseMap<Value *, unsigned> &Map) : Map(Map) {}
>> -
>> - bool operator()(const ValueEntry &Entry) {
>> - return Map.find(Entry.Op) != Map.end();
>> - }
>> - };
>> -}
>> -
>> /// \brief Build up a vector of value/power pairs factoring a product.
>> ///
>> /// Given a series of multiplication operands, build a vector of factors
>> and
>>
>> Modified: llvm/trunk/lib/Transforms/Scalar/SROA.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SROA.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Transforms/Scalar/SROA.cpp (original)
>> +++ llvm/trunk/lib/Transforms/Scalar/SROA.cpp Sat Mar 1 05:47:00 2014
>> @@ -3255,18 +3255,6 @@ bool SROA::rewritePartition(AllocaInst &
>> return true;
>> }
>>
>> -namespace {
>> -struct IsSliceEndLessOrEqualTo {
>> - uint64_t UpperBound;
>> -
>> - IsSliceEndLessOrEqualTo(uint64_t UpperBound) : UpperBound(UpperBound)
>> {}
>> -
>> - bool operator()(const AllocaSlices::iterator &I) {
>> - return I->endOffset() <= UpperBound;
>> - }
>> -};
>> -}
>> -
>> static void
>> removeFinishedSplitUses(SmallVectorImpl<AllocaSlices::iterator>
>> &SplitUses,
>> uint64_t &MaxSplitUseEndOffset, uint64_t Offset)
>> {
>> @@ -3278,7 +3266,9 @@ removeFinishedSplitUses(SmallVectorImpl<
>>
>> size_t SplitUsesOldSize = SplitUses.size();
>> SplitUses.erase(std::remove_if(SplitUses.begin(), SplitUses.end(),
>> - IsSliceEndLessOrEqualTo(Offset)),
>> + [Offset](const AllocaSlices::iterator
>> &I) {
>> + return I->endOffset() <= Offset;
>> + }),
>> SplitUses.end());
>> if (SplitUsesOldSize == SplitUses.size())
>> return;
>> @@ -3616,20 +3606,6 @@ bool SROA::promoteAllocas(Function &F) {
>> return true;
>> }
>>
>> -namespace {
>> - /// \brief A predicate to test whether an alloca belongs to a set.
>> - class IsAllocaInSet {
>> - typedef SmallPtrSet<AllocaInst *, 4> SetType;
>> - const SetType &Set;
>> -
>> - public:
>> - typedef AllocaInst *argument_type;
>> -
>> - IsAllocaInSet(const SetType &Set) : Set(Set) {}
>> - bool operator()(AllocaInst *AI) const { return Set.count(AI); }
>> - };
>> -}
>> -
>> bool SROA::runOnFunction(Function &F) {
>> if (skipOptnoneFunction(F))
>> return false;
>> @@ -3665,11 +3641,14 @@ bool SROA::runOnFunction(Function &F) {
>> // Remove the deleted allocas from various lists so that we don't
>> try to
>> // continue processing them.
>> if (!DeletedAllocas.empty()) {
>> - Worklist.remove_if(IsAllocaInSet(DeletedAllocas));
>> - PostPromotionWorklist.remove_if(IsAllocaInSet(DeletedAllocas));
>> + std::function<bool(AllocaInst *)> IsInSet = [&](AllocaInst *AI) {
>> + return DeletedAllocas.count(AI);
>> + };
>> + Worklist.remove_if(IsInSet);
>> + PostPromotionWorklist.remove_if(IsInSet);
>> PromotableAllocas.erase(std::remove_if(PromotableAllocas.begin(),
>> PromotableAllocas.end(),
>> -
>> IsAllocaInSet(DeletedAllocas)),
>> + IsInSet),
>> PromotableAllocas.end());
>> DeletedAllocas.clear();
>> }
>>
>> Modified: llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp (original)
>> +++ llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp Sat Mar 1
>> 05:47:00 2014
>> @@ -1682,16 +1682,6 @@ Value *BoUpSLP::vectorizeTree() {
>> return VectorizableTree[0].VectorizedValue;
>> }
>>
>> -class DTCmp {
>> - const DominatorTree *DT;
>> -
>> -public:
>> - DTCmp(const DominatorTree *DT) : DT(DT) {}
>> - bool operator()(const BasicBlock *A, const BasicBlock *B) const {
>> - return DT->properlyDominates(A, B);
>> - }
>> -};
>> -
>> void BoUpSLP::optimizeGatherSequence() {
>> DEBUG(dbgs() << "SLP: Optimizing " << GatherSeq.size()
>> << " gather sequences instructions.\n");
>> @@ -1730,7 +1720,10 @@ void BoUpSLP::optimizeGatherSequence() {
>> // Sort blocks by domination. This ensures we visit a block after all
>> blocks
>> // dominating it are visited.
>> SmallVector<BasicBlock *, 8> CSEWorkList(CSEBlocks.begin(),
>> CSEBlocks.end());
>> - std::stable_sort(CSEWorkList.begin(), CSEWorkList.end(), DTCmp(DT));
>> + std::stable_sort(CSEWorkList.begin(), CSEWorkList.end(),
>> + [this](const BasicBlock *A, const BasicBlock *B) {
>> + return DT->properlyDominates(A, B);
>> + });
>>
>> // Perform O(N^2) search over the gather sequences and merge identical
>> // instructions. TODO: We can further optimize this scan if we split
>> the
>>
>> Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
>> +++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Sat Mar 1 05:47:00 2014
>> @@ -475,16 +475,6 @@ void addMember(std::vector<NewArchiveIte
>> Members[Pos] = NI;
>> }
>>
>> -namespace {
>> -class HasName {
>> - StringRef Name;
>> -
>> -public:
>> - HasName(StringRef Name) : Name(Name) {}
>> - bool operator()(StringRef Path) { return Name ==
>> sys::path::filename(Path); }
>> -};
>> -}
>> -
>> enum InsertAction {
>> IA_AddOldMember,
>> IA_AddNewMeber,
>> @@ -500,8 +490,9 @@ computeInsertAction(ArchiveOperation Ope
>> if (Operation == QuickAppend || Members.empty())
>> return IA_AddOldMember;
>>
>> - std::vector<std::string>::iterator MI =
>> - std::find_if(Members.begin(), Members.end(), HasName(Name));
>> + std::vector<std::string>::iterator MI = std::find_if(
>> + Members.begin(), Members.end(),
>> + [Name](StringRef Path) { return Name == sys::path::filename(Path);
>> });
>>
>> if (MI == Members.end())
>> return IA_AddOldMember;
>>
>> Modified: llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp (original)
>> +++ llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp Sat Mar 1 05:47:00
>> 2014
>> @@ -288,15 +288,6 @@ public:
>> }
>> };
>>
>> -namespace {
>> -/// Sort ClassInfo pointers independently of pointer value.
>> -struct LessClassInfoPtr {
>> - bool operator()(const ClassInfo *LHS, const ClassInfo *RHS) const {
>> - return *LHS < *RHS;
>> - }
>> -};
>> -}
>> -
>> /// MatchableInfo - Helper class for storing the necessary information
>> for an
>> /// instruction or alias which is capable of being matched.
>> struct MatchableInfo {
>> @@ -1288,7 +1279,7 @@ void AsmMatcherInfo::buildOperandMatchIn
>>
>> /// Map containing a mask with all operands indices that can be found
>> for
>> /// that class inside a instruction.
>> - typedef std::map<ClassInfo*, unsigned, LessClassInfoPtr> OpClassMaskTy;
>> + typedef std::map<ClassInfo *, unsigned, less_ptr<ClassInfo>>
>> OpClassMaskTy;
>> OpClassMaskTy OpClassMask;
>>
>> for (std::vector<MatchableInfo*>::const_iterator it =
>>
>> Modified: llvm/trunk/utils/TableGen/CodeGenRegisters.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenRegisters.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/utils/TableGen/CodeGenRegisters.cpp (original)
>> +++ llvm/trunk/utils/TableGen/CodeGenRegisters.cpp Sat Mar 1 05:47:00
>> 2014
>> @@ -1705,16 +1705,6 @@ void CodeGenRegBank::computeRegUnitSets(
>> }
>> }
>>
>> -struct LessUnits {
>> - const CodeGenRegBank &RegBank;
>> - LessUnits(const CodeGenRegBank &RB): RegBank(RB) {}
>> -
>> - bool operator()(unsigned ID1, unsigned ID2) {
>> - return RegBank.getRegPressureSet(ID1).Units.size()
>> - < RegBank.getRegPressureSet(ID2).Units.size();
>> - }
>> -};
>> -
>> void CodeGenRegBank::computeDerivedInfo() {
>> computeComposites();
>> computeSubRegIndexLaneMasks();
>> @@ -1737,7 +1727,10 @@ void CodeGenRegBank::computeDerivedInfo(
>> RegUnitSetOrder.push_back(Idx);
>>
>> std::stable_sort(RegUnitSetOrder.begin(), RegUnitSetOrder.end(),
>> - LessUnits(*this));
>> + [this](unsigned ID1, unsigned ID2) {
>> + return getRegPressureSet(ID1).Units.size() <
>> + getRegPressureSet(ID2).Units.size();
>> + });
>> for (unsigned Idx = 0, EndIdx = RegUnitSets.size(); Idx != EndIdx;
>> ++Idx) {
>> RegUnitSets[RegUnitSetOrder[Idx]].Order = Idx;
>> }
>>
>> Modified: llvm/trunk/utils/TableGen/CodeGenTarget.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenTarget.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/utils/TableGen/CodeGenTarget.cpp (original)
>> +++ llvm/trunk/utils/TableGen/CodeGenTarget.cpp Sat Mar 1 05:47:00 2014
>> @@ -289,17 +289,6 @@ GetInstByName(const char *Name,
>> return I->second;
>> }
>>
>> -namespace {
>> -/// SortInstByName - Sorting predicate to sort instructions by name.
>> -///
>> -struct SortInstByName {
>> - bool operator()(const CodeGenInstruction *Rec1,
>> - const CodeGenInstruction *Rec2) const {
>> - return Rec1->TheDef->getName() < Rec2->TheDef->getName();
>> - }
>> -};
>> -}
>> -
>> /// \brief Return all of the instructions defined by the target, ordered
>> by
>> /// their enum value.
>> void CodeGenTarget::ComputeInstrsByEnum() const {
>> @@ -346,8 +335,10 @@ void CodeGenTarget::ComputeInstrsByEnum(
>>
>> // All of the instructions are now in random order based on the map
>> iteration.
>> // Sort them by name.
>> - std::sort(InstrsByEnum.begin()+EndOfPredefines, InstrsByEnum.end(),
>> - SortInstByName());
>> + std::sort(InstrsByEnum.begin() + EndOfPredefines, InstrsByEnum.end(),
>> + [](const CodeGenInstruction *Rec1, const CodeGenInstruction
>> *Rec2) {
>> + return Rec1->TheDef->getName() < Rec2->TheDef->getName();
>> + });
>> }
>>
>>
>>
>> Modified: llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp?rev=202588&r1=202587&r2=202588&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp (original)
>> +++ llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp Sat Mar 1 05:47:00
>> 2014
>> @@ -131,20 +131,6 @@ void IntrinsicEmitter::EmitEnumInfo(cons
>> OS << "#endif\n\n";
>> }
>>
>> -struct IntrinsicNameSorter {
>> - IntrinsicNameSorter(const std::vector<CodeGenIntrinsic> &I)
>> - : Ints(I) {}
>> -
>> - // Sort in reverse order of intrinsic name so "abc.def" appears after
>> - // "abd.def.ghi" in the overridden name matcher
>> - bool operator()(unsigned i, unsigned j) {
>> - return Ints[i].Name > Ints[j].Name;
>> - }
>> -
>> -private:
>> - const std::vector<CodeGenIntrinsic> &Ints;
>> -};
>> -
>> void IntrinsicEmitter::
>> EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
>> raw_ostream &OS) {
>> @@ -158,15 +144,17 @@ EmitFnNameRecognizer(const std::vector<C
>> OS << " StringRef NameR(Name+6, Len-6); // Skip over 'llvm.'\n";
>> OS << " switch (Name[5]) { // Dispatch on first
>> letter.\n";
>> OS << " default: break;\n";
>> - IntrinsicNameSorter Sorter(Ints);
>> // Emit the intrinsic matching stuff by first letter.
>> for (std::map<char, std::vector<unsigned> >::iterator I =
>> IntMapping.begin(),
>> E = IntMapping.end(); I != E; ++I) {
>> OS << " case '" << I->first << "':\n";
>> std::vector<unsigned> &IntList = I->second;
>>
>> - // Sort intrinsics in reverse order of their names
>> - std::sort(IntList.begin(), IntList.end(), Sorter);
>> + // Sort in reverse order of intrinsic name so "abc.def" appears after
>> + // "abd.def.ghi" in the overridden name matcher
>> + std::sort(IntList.begin(), IntList.end(), [&](unsigned i, unsigned j)
>> {
>> + return Ints[i].Name > Ints[j].Name;
>> + });
>>
>> // Emit all the overloaded intrinsics first, build a table of the
>> // non-overloaded ones.
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
More information about the llvm-commits
mailing list