Skip to content

Commit

Permalink
[C++11] Replace llvm::next and llvm::prior with std::next and std::prev.
Browse files Browse the repository at this point in the history
Remove the old functions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202636 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
d0k committed Mar 2, 2014
1 parent cb13d40 commit d628f19
Show file tree
Hide file tree
Showing 136 changed files with 480 additions and 548 deletions.
4 changes: 1 addition & 3 deletions include/llvm/ADT/MapVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
#ifndef LLVM_ADT_MAPVECTOR_H
#define LLVM_ADT_MAPVECTOR_H

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include <vector>

namespace llvm {
Expand Down Expand Up @@ -97,7 +95,7 @@ class MapVector {
if (Result.second) {
Vector.push_back(std::make_pair(KV.first, KV.second));
I = Vector.size() - 1;
return std::make_pair(llvm::prior(end()), true);
return std::make_pair(std::prev(end()), true);
}
return std::make_pair(begin() + I, false);
}
Expand Down
35 changes: 0 additions & 35 deletions include/llvm/ADT/STLExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,41 +141,6 @@ inline mapped_iterator<ItTy, FuncTy> map_iterator(const ItTy &I, FuncTy F) {
return mapped_iterator<ItTy, FuncTy>(I, F);
}


// next/prior - These functions unlike std::advance do not modify the
// passed iterator but return a copy.
//
// next(myIt) returns copy of myIt incremented once
// next(myIt, n) returns copy of myIt incremented n times
// prior(myIt) returns copy of myIt decremented once
// prior(myIt, n) returns copy of myIt decremented n times

template <typename ItTy, typename Dist>
inline ItTy next(ItTy it, Dist n)
{
std::advance(it, n);
return it;
}

template <typename ItTy>
inline ItTy next(ItTy it)
{
return ++it;
}

template <typename ItTy, typename Dist>
inline ItTy prior(ItTy it, Dist n)
{
std::advance(it, -n);
return it;
}

template <typename ItTy>
inline ItTy prior(ItTy it)
{
return --it;
}

//===----------------------------------------------------------------------===//
// Extra additions to <utility>
//===----------------------------------------------------------------------===//
Expand Down
6 changes: 2 additions & 4 deletions include/llvm/ADT/TinyPtrVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Compiler.h"

namespace llvm {

Expand Down Expand Up @@ -248,7 +246,7 @@ class TinyPtrVector {
assert(I <= this->end() && "Inserting past the end of the vector.");
if (I == end()) {
push_back(Elt);
return llvm::prior(end());
return std::prev(end());
}
assert(!Val.isNull() && "Null value with non-end insert iterator.");
if (EltTy V = Val.template dyn_cast<EltTy>()) {
Expand All @@ -271,7 +269,7 @@ class TinyPtrVector {
// If we have a single value, convert to a vector.
ptrdiff_t Offset = I - begin();
if (Val.isNull()) {
if (llvm::next(From) == To) {
if (std::next(From) == To) {
Val = *From;
return begin();
}
Expand Down
10 changes: 5 additions & 5 deletions include/llvm/CodeGen/MachineBasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ class MachineBasicBlock : public ilist_node<MachineBasicBlock> {
///
/// If I points to a bundle of instructions, they are all erased.
iterator erase(iterator I) {
return erase(I, llvm::next(I));
return erase(I, std::next(I));
}

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

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

MachineBasicBlock::iterator begin() {
return B == MBB.end() ? MBB.begin() : llvm::next(B);
return B == MBB.end() ? MBB.begin() : std::next(B);
}
MachineBasicBlock::iterator end() { return E; }
bool empty() { return begin() == end(); }
Expand Down
2 changes: 1 addition & 1 deletion include/llvm/CodeGen/SelectionDAGNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
/// hasOneUse - Return true if there is exactly one use of this node.
///
bool hasOneUse() const {
return !use_empty() && llvm::next(use_begin()) == use_end();
return !use_empty() && std::next(use_begin()) == use_end();
}

/// use_size - Return the number of uses of this node. This method takes
Expand Down
10 changes: 5 additions & 5 deletions include/llvm/CodeGen/SlotIndexes.h
Original file line number Diff line number Diff line change
Expand Up @@ -545,15 +545,15 @@ namespace llvm {
std::lower_bound(idx2MBBMap.begin(), idx2MBBMap.end(), start);

if (itr == idx2MBBMap.end()) {
itr = prior(itr);
itr = std::prev(itr);
return itr->second;
}

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

itr = prior(itr);
itr = std::prev(itr);

if (itr->first <= start)
return itr->second;
Expand Down Expand Up @@ -581,11 +581,11 @@ namespace llvm {
if (Late) {
// Insert mi's index immediately before the following instruction.
nextItr = getIndexAfter(mi).listEntry();
prevItr = prior(nextItr);
prevItr = std::prev(nextItr);
} else {
// Insert mi's index immediately after the preceding instruction.
prevItr = getIndexBefore(mi).listEntry();
nextItr = llvm::next(prevItr);
nextItr = std::next(prevItr);
}

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

IndexListEntry *startEntry = 0;
IndexListEntry *endEntry = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/Analysis/Lint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ void Lint::visitInsertElementInst(InsertElementInst &I) {
void Lint::visitUnreachableInst(UnreachableInst &I) {
// This isn't undefined behavior, it's merely suspicious.
Assert1(&I == I.getParent()->begin() ||
prior(BasicBlock::iterator(&I))->mayHaveSideEffects(),
std::prev(BasicBlock::iterator(&I))->mayHaveSideEffects(),
"Unusual: unreachable immediately preceded by instruction without "
"side effects", &I);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Analysis/LoopInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,8 @@ void UnloopUpdater::removeBlocksFromAncestors() {
/// nested within unloop.
void UnloopUpdater::updateSubloopParents() {
while (!Unloop->empty()) {
Loop *Subloop = *llvm::prior(Unloop->end());
Unloop->removeChildLoop(llvm::prior(Unloop->end()));
Loop *Subloop = *std::prev(Unloop->end());
Unloop->removeChildLoop(std::prev(Unloop->end()));

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

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

return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Analysis/MemoryDependenceAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ MemoryDependenceAnalysis::getNonLocalCallDependency(CallSite QueryCS) {
NonLocalDepInfo::iterator Entry =
std::upper_bound(Cache.begin(), Cache.begin()+NumSortedEntries,
NonLocalDepEntry(DirtyBB));
if (Entry != Cache.begin() && prior(Entry)->getBB() == DirtyBB)
if (Entry != Cache.begin() && std::prev(Entry)->getBB() == DirtyBB)
--Entry;

NonLocalDepEntry *ExistingResult = 0;
Expand Down
4 changes: 2 additions & 2 deletions lib/Analysis/ScalarEvolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void SCEV::print(raw_ostream &OS) const {
for (SCEVNAryExpr::op_iterator I = NAry->op_begin(), E = NAry->op_end();
I != E; ++I) {
OS << **I;
if (llvm::next(I) != E)
if (std::next(I) != E)
OS << OpStr;
}
OS << ")";
Expand Down Expand Up @@ -3258,7 +3258,7 @@ const SCEV *ScalarEvolution::createNodeForGEP(GEPOperator *GEP) {

const SCEV *TotalOffset = getConstant(IntPtrTy, 0);
gep_type_iterator GTI = gep_type_begin(GEP);
for (GetElementPtrInst::op_iterator I = llvm::next(GEP->op_begin()),
for (GetElementPtrInst::op_iterator I = std::next(GEP->op_begin()),
E = GEP->op_end();
I != E; ++I) {
Value *Index = *I;
Expand Down
4 changes: 2 additions & 2 deletions lib/Analysis/ScalarEvolutionExpander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
Value *V = expand(SE.getAddRecExpr(NewOps, S->getLoop(),
S->getNoWrapFlags(SCEV::FlagNW)));
BasicBlock::iterator NewInsertPt =
llvm::next(BasicBlock::iterator(cast<Instruction>(V)));
std::next(BasicBlock::iterator(cast<Instruction>(V)));
BuilderType::InsertPointGuard Guard(Builder);
while (isa<PHINode>(NewInsertPt) || isa<DbgInfoIntrinsic>(NewInsertPt) ||
isa<LandingPadInst>(NewInsertPt))
Expand Down Expand Up @@ -1619,7 +1619,7 @@ Value *SCEVExpander::expand(const SCEV *S) {
while (InsertPt != Builder.GetInsertPoint()
&& (isInsertedInstruction(InsertPt)
|| isa<DbgInfoIntrinsic>(InsertPt))) {
InsertPt = llvm::next(BasicBlock::iterator(InsertPt));
InsertPt = std::next(BasicBlock::iterator(InsertPt));
}
break;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/CodeGen/Analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,7 @@ bool llvm::isInTailCallPosition(ImmutableCallSite CS,
// chain interposes between I and the return.
if (I->mayHaveSideEffects() || I->mayReadFromMemory() ||
!isSafeToSpeculativelyExecute(I))
for (BasicBlock::const_iterator BBI = prior(prior(ExitBB->end())); ;
--BBI) {
for (BasicBlock::const_iterator BBI = std::prev(ExitBB->end(), 2);; --BBI) {
if (&*BBI == I)
break;
// Debug info intrinsics do not get in the way of tail call optimization.
Expand Down
4 changes: 2 additions & 2 deletions lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {

// Terminate old register assignments that don't reach MI;
MachineFunction::const_iterator PrevMBB = Prev->getParent();
if (PrevMBB != I && (!AtBlockEntry || llvm::next(PrevMBB) != I) &&
if (PrevMBB != I && (!AtBlockEntry || std::next(PrevMBB) != I) &&
isDbgValueInDefinedReg(Prev)) {
// Previous register assignment needs to terminate at the end of
// its basic block.
Expand All @@ -1603,7 +1603,7 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
DEBUG(dbgs() << "Dropping DBG_VALUE for empty range:\n"
<< "\t" << *Prev << "\n");
History.pop_back();
} else if (llvm::next(PrevMBB) != PrevMBB->getParent()->end())
} else if (std::next(PrevMBB) != PrevMBB->getParent()->end())
// Terminate after LastMI.
History.push_back(LastMI);
}
Expand Down
34 changes: 17 additions & 17 deletions lib/CodeGen/BranchFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ void BranchFolder::MaintainLiveIns(MachineBasicBlock *CurMBB,
if (RS) {
RS->enterBasicBlock(CurMBB);
if (!CurMBB->empty())
RS->forward(prior(CurMBB->end()));
RS->forward(std::prev(CurMBB->end()));
BitVector RegsLiveAtExit(TRI->getNumRegs());
RS->getRegsUsed(RegsLiveAtExit, false);
for (unsigned int i = 0, e = TRI->getNumRegs(); i != e; i++)
Expand Down Expand Up @@ -462,7 +462,7 @@ static unsigned EstimateRuntime(MachineBasicBlock::iterator I,
static void FixTail(MachineBasicBlock *CurMBB, MachineBasicBlock *SuccBB,
const TargetInstrInfo *TII) {
MachineFunction *MF = CurMBB->getParent();
MachineFunction::iterator I = llvm::next(MachineFunction::iterator(CurMBB));
MachineFunction::iterator I = std::next(MachineFunction::iterator(CurMBB));
MachineBasicBlock *TBB = 0, *FBB = 0;
SmallVector<MachineOperand, 4> Cond;
DebugLoc dl; // FIXME: this is nowhere
Expand Down Expand Up @@ -600,12 +600,11 @@ unsigned BranchFolder::ComputeSameTails(unsigned CurHash,
unsigned maxCommonTailLength = 0U;
SameTails.clear();
MachineBasicBlock::iterator TrialBBI1, TrialBBI2;
MPIterator HighestMPIter = prior(MergePotentials.end());
for (MPIterator CurMPIter = prior(MergePotentials.end()),
MPIterator HighestMPIter = std::prev(MergePotentials.end());
for (MPIterator CurMPIter = std::prev(MergePotentials.end()),
B = MergePotentials.begin();
CurMPIter != B && CurMPIter->getHash() == CurHash;
--CurMPIter) {
for (MPIterator I = prior(CurMPIter); I->getHash() == CurHash ; --I) {
CurMPIter != B && CurMPIter->getHash() == CurHash; --CurMPIter) {
for (MPIterator I = std::prev(CurMPIter); I->getHash() == CurHash; --I) {
unsigned CommonTailLen;
if (ProfitableToMerge(CurMPIter->getBlock(), I->getBlock(),
minCommonTailLength,
Expand Down Expand Up @@ -634,9 +633,9 @@ void BranchFolder::RemoveBlocksWithHash(unsigned CurHash,
MachineBasicBlock *SuccBB,
MachineBasicBlock *PredBB) {
MPIterator CurMPIter, B;
for (CurMPIter = prior(MergePotentials.end()), B = MergePotentials.begin();
CurMPIter->getHash() == CurHash;
--CurMPIter) {
for (CurMPIter = std::prev(MergePotentials.end()),
B = MergePotentials.begin();
CurMPIter->getHash() == CurHash; --CurMPIter) {
// Put the unconditional branch back, if we need one.
MachineBasicBlock *CurMBB = CurMPIter->getBlock();
if (SuccBB && CurMBB != PredBB)
Expand Down Expand Up @@ -868,12 +867,12 @@ bool BranchFolder::TailMergeBlocks(MachineFunction &MF) {
// a compile-time infinite loop repeatedly doing and undoing the same
// transformations.)

for (MachineFunction::iterator I = llvm::next(MF.begin()), E = MF.end();
for (MachineFunction::iterator I = std::next(MF.begin()), E = MF.end();
I != E; ++I) {
if (I->pred_size() < 2) continue;
SmallPtrSet<MachineBasicBlock *, 8> UniquePreds;
MachineBasicBlock *IBB = I;
MachineBasicBlock *PredBB = prior(I);
MachineBasicBlock *PredBB = std::prev(I);
MergePotentials.clear();
for (MachineBasicBlock::pred_iterator P = I->pred_begin(),
E2 = I->pred_end();
Expand Down Expand Up @@ -905,7 +904,7 @@ bool BranchFolder::TailMergeBlocks(MachineFunction &MF) {
continue;
// This is the QBB case described above
if (!FBB)
FBB = llvm::next(MachineFunction::iterator(PBB));
FBB = std::next(MachineFunction::iterator(PBB));
}

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

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

for (MachineFunction::iterator I = llvm::next(MF.begin()), E = MF.end();
for (MachineFunction::iterator I = std::next(MF.begin()), E = MF.end();
I != E; ) {
MachineBasicBlock *MBB = I++;
MadeChange |= OptimizeBlock(MBB);
Expand Down Expand Up @@ -1095,7 +1094,7 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {

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

MachineBasicBlock *PriorTBB = 0, *PriorFBB = 0;
SmallVector<MachineOperand, 4> PriorCond;
Expand Down Expand Up @@ -1394,7 +1393,8 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
// B elsewhere
// next:
if (CurFallsThru) {
MachineBasicBlock *NextBB = llvm::next(MachineFunction::iterator(MBB));
MachineBasicBlock *NextBB =
std::next(MachineFunction::iterator(MBB));
CurCond.clear();
TII->InsertBranch(*MBB, NextBB, 0, CurCond, DebugLoc());
}
Expand Down
Loading

0 comments on commit d628f19

Please sign in to comment.