Skip to content

Commit d628f19

Browse files
committed
[C++11] Replace llvm::next and llvm::prior with std::next and std::prev.
Remove the old functions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202636 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent cb13d40 commit d628f19

File tree

136 files changed

+480
-548
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+480
-548
lines changed

include/llvm/ADT/MapVector.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
#ifndef LLVM_ADT_MAPVECTOR_H
1818
#define LLVM_ADT_MAPVECTOR_H
1919

20-
#include "llvm/ADT/ArrayRef.h"
2120
#include "llvm/ADT/DenseMap.h"
22-
#include "llvm/ADT/STLExtras.h"
2321
#include <vector>
2422

2523
namespace llvm {
@@ -97,7 +95,7 @@ class MapVector {
9795
if (Result.second) {
9896
Vector.push_back(std::make_pair(KV.first, KV.second));
9997
I = Vector.size() - 1;
100-
return std::make_pair(llvm::prior(end()), true);
98+
return std::make_pair(std::prev(end()), true);
10199
}
102100
return std::make_pair(begin() + I, false);
103101
}

include/llvm/ADT/STLExtras.h

-35
Original file line numberDiff line numberDiff line change
@@ -141,41 +141,6 @@ inline mapped_iterator<ItTy, FuncTy> map_iterator(const ItTy &I, FuncTy F) {
141141
return mapped_iterator<ItTy, FuncTy>(I, F);
142142
}
143143

144-
145-
// next/prior - These functions unlike std::advance do not modify the
146-
// passed iterator but return a copy.
147-
//
148-
// next(myIt) returns copy of myIt incremented once
149-
// next(myIt, n) returns copy of myIt incremented n times
150-
// prior(myIt) returns copy of myIt decremented once
151-
// prior(myIt, n) returns copy of myIt decremented n times
152-
153-
template <typename ItTy, typename Dist>
154-
inline ItTy next(ItTy it, Dist n)
155-
{
156-
std::advance(it, n);
157-
return it;
158-
}
159-
160-
template <typename ItTy>
161-
inline ItTy next(ItTy it)
162-
{
163-
return ++it;
164-
}
165-
166-
template <typename ItTy, typename Dist>
167-
inline ItTy prior(ItTy it, Dist n)
168-
{
169-
std::advance(it, -n);
170-
return it;
171-
}
172-
173-
template <typename ItTy>
174-
inline ItTy prior(ItTy it)
175-
{
176-
return --it;
177-
}
178-
179144
//===----------------------------------------------------------------------===//
180145
// Extra additions to <utility>
181146
//===----------------------------------------------------------------------===//

include/llvm/ADT/TinyPtrVector.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212

1313
#include "llvm/ADT/ArrayRef.h"
1414
#include "llvm/ADT/PointerUnion.h"
15-
#include "llvm/ADT/STLExtras.h"
1615
#include "llvm/ADT/SmallVector.h"
17-
#include "llvm/Support/Compiler.h"
1816

1917
namespace llvm {
2018

@@ -248,7 +246,7 @@ class TinyPtrVector {
248246
assert(I <= this->end() && "Inserting past the end of the vector.");
249247
if (I == end()) {
250248
push_back(Elt);
251-
return llvm::prior(end());
249+
return std::prev(end());
252250
}
253251
assert(!Val.isNull() && "Null value with non-end insert iterator.");
254252
if (EltTy V = Val.template dyn_cast<EltTy>()) {
@@ -271,7 +269,7 @@ class TinyPtrVector {
271269
// If we have a single value, convert to a vector.
272270
ptrdiff_t Offset = I - begin();
273271
if (Val.isNull()) {
274-
if (llvm::next(From) == To) {
272+
if (std::next(From) == To) {
275273
Val = *From;
276274
return begin();
277275
}

include/llvm/CodeGen/MachineBasicBlock.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ class MachineBasicBlock : public ilist_node<MachineBasicBlock> {
503503
///
504504
/// If I points to a bundle of instructions, they are all erased.
505505
iterator erase(iterator I) {
506-
return erase(I, llvm::next(I));
506+
return erase(I, std::next(I));
507507
}
508508

509509
/// Remove an instruction from the instruction list and delete it.
@@ -542,7 +542,7 @@ class MachineBasicBlock : public ilist_node<MachineBasicBlock> {
542542
void splice(iterator Where, MachineBasicBlock *Other, iterator From) {
543543
// The range splice() doesn't allow noop moves, but this one does.
544544
if (Where != From)
545-
splice(Where, Other, From, llvm::next(From));
545+
splice(Where, Other, From, std::next(From));
546546
}
547547

548548
/// Take a block of instructions from MBB 'Other' in the range [From, To),
@@ -750,11 +750,11 @@ class MachineInstrSpan {
750750
MachineInstrSpan(MachineBasicBlock::iterator I)
751751
: MBB(*I->getParent()),
752752
I(I),
753-
B(I == MBB.begin() ? MBB.end() : llvm::prior(I)),
754-
E(llvm::next(I)) {}
753+
B(I == MBB.begin() ? MBB.end() : std::prev(I)),
754+
E(std::next(I)) {}
755755

756756
MachineBasicBlock::iterator begin() {
757-
return B == MBB.end() ? MBB.begin() : llvm::next(B);
757+
return B == MBB.end() ? MBB.begin() : std::next(B);
758758
}
759759
MachineBasicBlock::iterator end() { return E; }
760760
bool empty() { return begin() == end(); }

include/llvm/CodeGen/SelectionDAGNodes.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
408408
/// hasOneUse - Return true if there is exactly one use of this node.
409409
///
410410
bool hasOneUse() const {
411-
return !use_empty() && llvm::next(use_begin()) == use_end();
411+
return !use_empty() && std::next(use_begin()) == use_end();
412412
}
413413

414414
/// use_size - Return the number of uses of this node. This method takes

include/llvm/CodeGen/SlotIndexes.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -545,15 +545,15 @@ namespace llvm {
545545
std::lower_bound(idx2MBBMap.begin(), idx2MBBMap.end(), start);
546546

547547
if (itr == idx2MBBMap.end()) {
548-
itr = prior(itr);
548+
itr = std::prev(itr);
549549
return itr->second;
550550
}
551551

552552
// Check that we don't cross the boundary into this block.
553553
if (itr->first < end)
554554
return 0;
555555

556-
itr = prior(itr);
556+
itr = std::prev(itr);
557557

558558
if (itr->first <= start)
559559
return itr->second;
@@ -581,11 +581,11 @@ namespace llvm {
581581
if (Late) {
582582
// Insert mi's index immediately before the following instruction.
583583
nextItr = getIndexAfter(mi).listEntry();
584-
prevItr = prior(nextItr);
584+
prevItr = std::prev(nextItr);
585585
} else {
586586
// Insert mi's index immediately after the preceding instruction.
587587
prevItr = getIndexBefore(mi).listEntry();
588-
nextItr = llvm::next(prevItr);
588+
nextItr = std::next(prevItr);
589589
}
590590

591591
// Get a number for the new instr, or 0 if there's no room currently.
@@ -638,7 +638,7 @@ namespace llvm {
638638
/// Add the given MachineBasicBlock into the maps.
639639
void insertMBBInMaps(MachineBasicBlock *mbb) {
640640
MachineFunction::iterator nextMBB =
641-
llvm::next(MachineFunction::iterator(mbb));
641+
std::next(MachineFunction::iterator(mbb));
642642

643643
IndexListEntry *startEntry = 0;
644644
IndexListEntry *endEntry = 0;

lib/Analysis/Lint.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ void Lint::visitInsertElementInst(InsertElementInst &I) {
603603
void Lint::visitUnreachableInst(UnreachableInst &I) {
604604
// This isn't undefined behavior, it's merely suspicious.
605605
Assert1(&I == I.getParent()->begin() ||
606-
prior(BasicBlock::iterator(&I))->mayHaveSideEffects(),
606+
std::prev(BasicBlock::iterator(&I))->mayHaveSideEffects(),
607607
"Unusual: unreachable immediately preceded by instruction without "
608608
"side effects", &I);
609609
}

lib/Analysis/LoopInfo.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,8 @@ void UnloopUpdater::removeBlocksFromAncestors() {
527527
/// nested within unloop.
528528
void UnloopUpdater::updateSubloopParents() {
529529
while (!Unloop->empty()) {
530-
Loop *Subloop = *llvm::prior(Unloop->end());
531-
Unloop->removeChildLoop(llvm::prior(Unloop->end()));
530+
Loop *Subloop = *std::prev(Unloop->end());
531+
Unloop->removeChildLoop(std::prev(Unloop->end()));
532532

533533
assert(SubloopParents.count(Subloop) && "DFS failed to visit subloop");
534534
if (Loop *Parent = SubloopParents[Subloop])
@@ -652,7 +652,7 @@ void LoopInfo::updateUnloop(Loop *Unloop) {
652652

653653
// Move all of the subloops to the top-level.
654654
while (!Unloop->empty())
655-
LI.addTopLevelLoop(Unloop->removeChildLoop(llvm::prior(Unloop->end())));
655+
LI.addTopLevelLoop(Unloop->removeChildLoop(std::prev(Unloop->end())));
656656

657657
return;
658658
}

lib/Analysis/MemoryDependenceAnalysis.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ MemoryDependenceAnalysis::getNonLocalCallDependency(CallSite QueryCS) {
693693
NonLocalDepInfo::iterator Entry =
694694
std::upper_bound(Cache.begin(), Cache.begin()+NumSortedEntries,
695695
NonLocalDepEntry(DirtyBB));
696-
if (Entry != Cache.begin() && prior(Entry)->getBB() == DirtyBB)
696+
if (Entry != Cache.begin() && std::prev(Entry)->getBB() == DirtyBB)
697697
--Entry;
698698

699699
NonLocalDepEntry *ExistingResult = 0;

lib/Analysis/ScalarEvolution.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void SCEV::print(raw_ostream &OS) const {
193193
for (SCEVNAryExpr::op_iterator I = NAry->op_begin(), E = NAry->op_end();
194194
I != E; ++I) {
195195
OS << **I;
196-
if (llvm::next(I) != E)
196+
if (std::next(I) != E)
197197
OS << OpStr;
198198
}
199199
OS << ")";
@@ -3258,7 +3258,7 @@ const SCEV *ScalarEvolution::createNodeForGEP(GEPOperator *GEP) {
32583258

32593259
const SCEV *TotalOffset = getConstant(IntPtrTy, 0);
32603260
gep_type_iterator GTI = gep_type_begin(GEP);
3261-
for (GetElementPtrInst::op_iterator I = llvm::next(GEP->op_begin()),
3261+
for (GetElementPtrInst::op_iterator I = std::next(GEP->op_begin()),
32623262
E = GEP->op_end();
32633263
I != E; ++I) {
32643264
Value *Index = *I;

lib/Analysis/ScalarEvolutionExpander.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
13911391
Value *V = expand(SE.getAddRecExpr(NewOps, S->getLoop(),
13921392
S->getNoWrapFlags(SCEV::FlagNW)));
13931393
BasicBlock::iterator NewInsertPt =
1394-
llvm::next(BasicBlock::iterator(cast<Instruction>(V)));
1394+
std::next(BasicBlock::iterator(cast<Instruction>(V)));
13951395
BuilderType::InsertPointGuard Guard(Builder);
13961396
while (isa<PHINode>(NewInsertPt) || isa<DbgInfoIntrinsic>(NewInsertPt) ||
13971397
isa<LandingPadInst>(NewInsertPt))
@@ -1619,7 +1619,7 @@ Value *SCEVExpander::expand(const SCEV *S) {
16191619
while (InsertPt != Builder.GetInsertPoint()
16201620
&& (isInsertedInstruction(InsertPt)
16211621
|| isa<DbgInfoIntrinsic>(InsertPt))) {
1622-
InsertPt = llvm::next(BasicBlock::iterator(InsertPt));
1622+
InsertPt = std::next(BasicBlock::iterator(InsertPt));
16231623
}
16241624
break;
16251625
}

lib/CodeGen/Analysis.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,7 @@ bool llvm::isInTailCallPosition(ImmutableCallSite CS,
498498
// chain interposes between I and the return.
499499
if (I->mayHaveSideEffects() || I->mayReadFromMemory() ||
500500
!isSafeToSpeculativelyExecute(I))
501-
for (BasicBlock::const_iterator BBI = prior(prior(ExitBB->end())); ;
502-
--BBI) {
501+
for (BasicBlock::const_iterator BBI = std::prev(ExitBB->end(), 2);; --BBI) {
503502
if (&*BBI == I)
504503
break;
505504
// Debug info intrinsics do not get in the way of tail call optimization.

lib/CodeGen/AsmPrinter/DwarfDebug.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
15921592

15931593
// Terminate old register assignments that don't reach MI;
15941594
MachineFunction::const_iterator PrevMBB = Prev->getParent();
1595-
if (PrevMBB != I && (!AtBlockEntry || llvm::next(PrevMBB) != I) &&
1595+
if (PrevMBB != I && (!AtBlockEntry || std::next(PrevMBB) != I) &&
15961596
isDbgValueInDefinedReg(Prev)) {
15971597
// Previous register assignment needs to terminate at the end of
15981598
// its basic block.
@@ -1603,7 +1603,7 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
16031603
DEBUG(dbgs() << "Dropping DBG_VALUE for empty range:\n"
16041604
<< "\t" << *Prev << "\n");
16051605
History.pop_back();
1606-
} else if (llvm::next(PrevMBB) != PrevMBB->getParent()->end())
1606+
} else if (std::next(PrevMBB) != PrevMBB->getParent()->end())
16071607
// Terminate after LastMI.
16081608
History.push_back(LastMI);
16091609
}

lib/CodeGen/BranchFolding.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ void BranchFolder::MaintainLiveIns(MachineBasicBlock *CurMBB,
383383
if (RS) {
384384
RS->enterBasicBlock(CurMBB);
385385
if (!CurMBB->empty())
386-
RS->forward(prior(CurMBB->end()));
386+
RS->forward(std::prev(CurMBB->end()));
387387
BitVector RegsLiveAtExit(TRI->getNumRegs());
388388
RS->getRegsUsed(RegsLiveAtExit, false);
389389
for (unsigned int i = 0, e = TRI->getNumRegs(); i != e; i++)
@@ -462,7 +462,7 @@ static unsigned EstimateRuntime(MachineBasicBlock::iterator I,
462462
static void FixTail(MachineBasicBlock *CurMBB, MachineBasicBlock *SuccBB,
463463
const TargetInstrInfo *TII) {
464464
MachineFunction *MF = CurMBB->getParent();
465-
MachineFunction::iterator I = llvm::next(MachineFunction::iterator(CurMBB));
465+
MachineFunction::iterator I = std::next(MachineFunction::iterator(CurMBB));
466466
MachineBasicBlock *TBB = 0, *FBB = 0;
467467
SmallVector<MachineOperand, 4> Cond;
468468
DebugLoc dl; // FIXME: this is nowhere
@@ -600,12 +600,11 @@ unsigned BranchFolder::ComputeSameTails(unsigned CurHash,
600600
unsigned maxCommonTailLength = 0U;
601601
SameTails.clear();
602602
MachineBasicBlock::iterator TrialBBI1, TrialBBI2;
603-
MPIterator HighestMPIter = prior(MergePotentials.end());
604-
for (MPIterator CurMPIter = prior(MergePotentials.end()),
603+
MPIterator HighestMPIter = std::prev(MergePotentials.end());
604+
for (MPIterator CurMPIter = std::prev(MergePotentials.end()),
605605
B = MergePotentials.begin();
606-
CurMPIter != B && CurMPIter->getHash() == CurHash;
607-
--CurMPIter) {
608-
for (MPIterator I = prior(CurMPIter); I->getHash() == CurHash ; --I) {
606+
CurMPIter != B && CurMPIter->getHash() == CurHash; --CurMPIter) {
607+
for (MPIterator I = std::prev(CurMPIter); I->getHash() == CurHash; --I) {
609608
unsigned CommonTailLen;
610609
if (ProfitableToMerge(CurMPIter->getBlock(), I->getBlock(),
611610
minCommonTailLength,
@@ -634,9 +633,9 @@ void BranchFolder::RemoveBlocksWithHash(unsigned CurHash,
634633
MachineBasicBlock *SuccBB,
635634
MachineBasicBlock *PredBB) {
636635
MPIterator CurMPIter, B;
637-
for (CurMPIter = prior(MergePotentials.end()), B = MergePotentials.begin();
638-
CurMPIter->getHash() == CurHash;
639-
--CurMPIter) {
636+
for (CurMPIter = std::prev(MergePotentials.end()),
637+
B = MergePotentials.begin();
638+
CurMPIter->getHash() == CurHash; --CurMPIter) {
640639
// Put the unconditional branch back, if we need one.
641640
MachineBasicBlock *CurMBB = CurMPIter->getBlock();
642641
if (SuccBB && CurMBB != PredBB)
@@ -868,12 +867,12 @@ bool BranchFolder::TailMergeBlocks(MachineFunction &MF) {
868867
// a compile-time infinite loop repeatedly doing and undoing the same
869868
// transformations.)
870869

871-
for (MachineFunction::iterator I = llvm::next(MF.begin()), E = MF.end();
870+
for (MachineFunction::iterator I = std::next(MF.begin()), E = MF.end();
872871
I != E; ++I) {
873872
if (I->pred_size() < 2) continue;
874873
SmallPtrSet<MachineBasicBlock *, 8> UniquePreds;
875874
MachineBasicBlock *IBB = I;
876-
MachineBasicBlock *PredBB = prior(I);
875+
MachineBasicBlock *PredBB = std::prev(I);
877876
MergePotentials.clear();
878877
for (MachineBasicBlock::pred_iterator P = I->pred_begin(),
879878
E2 = I->pred_end();
@@ -905,7 +904,7 @@ bool BranchFolder::TailMergeBlocks(MachineFunction &MF) {
905904
continue;
906905
// This is the QBB case described above
907906
if (!FBB)
908-
FBB = llvm::next(MachineFunction::iterator(PBB));
907+
FBB = std::next(MachineFunction::iterator(PBB));
909908
}
910909

911910
// Failing case: the only way IBB can be reached from PBB is via
@@ -955,7 +954,7 @@ bool BranchFolder::TailMergeBlocks(MachineFunction &MF) {
955954

956955
// Reinsert an unconditional branch if needed. The 1 below can occur as a
957956
// result of removing blocks in TryTailMergeBlocks.
958-
PredBB = prior(I); // this may have been changed in TryTailMergeBlocks
957+
PredBB = std::prev(I); // this may have been changed in TryTailMergeBlocks
959958
if (MergePotentials.size() == 1 &&
960959
MergePotentials.begin()->getBlock() != PredBB)
961960
FixTail(MergePotentials.begin()->getBlock(), IBB, TII);
@@ -974,7 +973,7 @@ bool BranchFolder::OptimizeBranches(MachineFunction &MF) {
974973
// Make sure blocks are numbered in order
975974
MF.RenumberBlocks();
976975

977-
for (MachineFunction::iterator I = llvm::next(MF.begin()), E = MF.end();
976+
for (MachineFunction::iterator I = std::next(MF.begin()), E = MF.end();
978977
I != E; ) {
979978
MachineBasicBlock *MBB = I++;
980979
MadeChange |= OptimizeBlock(MBB);
@@ -1095,7 +1094,7 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
10951094

10961095
// Check to see if we can simplify the terminator of the block before this
10971096
// one.
1098-
MachineBasicBlock &PrevBB = *prior(MachineFunction::iterator(MBB));
1097+
MachineBasicBlock &PrevBB = *std::prev(MachineFunction::iterator(MBB));
10991098

11001099
MachineBasicBlock *PriorTBB = 0, *PriorFBB = 0;
11011100
SmallVector<MachineOperand, 4> PriorCond;
@@ -1394,7 +1393,8 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
13941393
// B elsewhere
13951394
// next:
13961395
if (CurFallsThru) {
1397-
MachineBasicBlock *NextBB = llvm::next(MachineFunction::iterator(MBB));
1396+
MachineBasicBlock *NextBB =
1397+
std::next(MachineFunction::iterator(MBB));
13981398
CurCond.clear();
13991399
TII->InsertBranch(*MBB, NextBB, 0, CurCond, DebugLoc());
14001400
}

0 commit comments

Comments
 (0)