Skip to content

Commit

Permalink
Use the range variant of find instead of unpacking begin/end
Browse files Browse the repository at this point in the history
If the result of the find is only used to compare against end(), just
use is_contained instead.

No functionality change is intended.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278433 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
majnemer committed Aug 11, 2016
1 parent fb2a7f9 commit 975248e
Show file tree
Hide file tree
Showing 78 changed files with 142 additions and 205 deletions.
3 changes: 1 addition & 2 deletions examples/Kaleidoscope/include/KaleidoscopeJIT.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ class KaleidoscopeJIT {
}

void removeModule(ModuleHandleT H) {
ModuleHandles.erase(
std::find(ModuleHandles.begin(), ModuleHandles.end(), H));
ModuleHandles.erase(find(ModuleHandles, H));
CompileLayer.removeModuleSet(H);
}

Expand Down
3 changes: 1 addition & 2 deletions include/llvm/ADT/PriorityQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class PriorityQueue : public std::priority_queue<T, Sequence, Compare> {
///
void erase_one(const T &t) {
// Linear-search to find the element.
typename Sequence::size_type i =
std::find(this->c.begin(), this->c.end(), t) - this->c.begin();
typename Sequence::size_type i = find(this->c, t) - this->c.begin();

// Logarithmic-time heap bubble-up.
while (i != 0) {
Expand Down
4 changes: 2 additions & 2 deletions include/llvm/ADT/SetVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define LLVM_ADT_SETVECTOR_H

#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallSet.h"
#include <algorithm>
#include <cassert>
Expand Down Expand Up @@ -143,8 +144,7 @@ class SetVector {
/// \brief Remove an item from the set vector.
bool remove(const value_type& X) {
if (set_.erase(X)) {
typename vector_type::iterator I =
std::find(vector_.begin(), vector_.end(), X);
typename vector_type::iterator I = find(vector_, X);
assert(I != vector_.end() && "Corrupted SetVector instances!");
vector_.erase(I);
return true;
Expand Down
4 changes: 2 additions & 2 deletions include/llvm/Analysis/LoopInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class LoopBase {
/// Blocks as appropriate. This does not update the mapping in the LoopInfo
/// class.
void removeBlockFromLoop(BlockT *BB) {
auto I = std::find(Blocks.begin(), Blocks.end(), BB);
auto I = find(Blocks, BB);
assert(I != Blocks.end() && "N is not in this list!");
Blocks.erase(I);

Expand Down Expand Up @@ -594,7 +594,7 @@ class LoopInfoBase {
/// loop.
void changeTopLevelLoop(LoopT *OldLoop,
LoopT *NewLoop) {
auto I = std::find(TopLevelLoops.begin(), TopLevelLoops.end(), OldLoop);
auto I = find(TopLevelLoops, OldLoop);
assert(I != TopLevelLoops.end() && "Old loop not at top level!");
*I = NewLoop;
assert(!NewLoop->ParentLoop && !OldLoop->ParentLoop &&
Expand Down
3 changes: 1 addition & 2 deletions include/llvm/Analysis/LoopInfoImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ void LoopBase<BlockT, LoopT>::
replaceChildLoopWith(LoopT *OldChild, LoopT *NewChild) {
assert(OldChild->ParentLoop == this && "This loop is already broken!");
assert(!NewChild->ParentLoop && "NewChild already has a parent!");
typename std::vector<LoopT *>::iterator I =
std::find(SubLoops.begin(), SubLoops.end(), OldChild);
typename std::vector<LoopT *>::iterator I = find(SubLoops, OldChild);
assert(I != SubLoops.end() && "OldChild not in loop!");
*I = NewChild;
OldChild->ParentLoop = nullptr;
Expand Down
3 changes: 1 addition & 2 deletions include/llvm/CodeGen/LiveVariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ class LiveVariables : public MachineFunctionPass {
/// machine instruction. Returns true if there was a kill
/// corresponding to this instruction, false otherwise.
bool removeKill(MachineInstr &MI) {
std::vector<MachineInstr *>::iterator I =
std::find(Kills.begin(), Kills.end(), &MI);
std::vector<MachineInstr *>::iterator I = find(Kills, &MI);
if (I == Kills.end())
return false;
Kills.erase(I);
Expand Down
4 changes: 1 addition & 3 deletions include/llvm/CodeGen/MachineScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,7 @@ class ReadyQueue {

ArrayRef<SUnit*> elements() { return Queue; }

iterator find(SUnit *SU) {
return std::find(Queue.begin(), Queue.end(), SU);
}
iterator find(SUnit *SU) { return llvm::find(Queue, SU); }

void push(SUnit *SU) {
Queue.push_back(SU);
Expand Down
8 changes: 2 additions & 6 deletions include/llvm/CodeGen/PBQP/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,7 @@ namespace PBQP {

private:
NodeId findNextInUse(NodeId NId) const {
while (NId < EndNId &&
std::find(FreeNodeIds.begin(), FreeNodeIds.end(), NId) !=
FreeNodeIds.end()) {
while (NId < EndNId && is_contained(FreeNodeIds, NId)) {
++NId;
}
return NId;
Expand All @@ -288,9 +286,7 @@ namespace PBQP {

private:
EdgeId findNextInUse(EdgeId EId) const {
while (EId < EndEId &&
std::find(FreeEdgeIds.begin(), FreeEdgeIds.end(), EId) !=
FreeEdgeIds.end()) {
while (EId < EndEId && is_contained(FreeEdgeIds, EId)) {
++EId;
}
return EId;
Expand Down
2 changes: 1 addition & 1 deletion include/llvm/IR/InstrTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ template <typename InstrTy, typename OpIteratorTy> class OperandBundleUser {
bool hasOperandBundlesOtherThan(ArrayRef<uint32_t> IDs) const {
for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) {
uint32_t ID = getOperandBundleAt(i).getTagID();
if (std::find(IDs.begin(), IDs.end(), ID) == IDs.end())
if (!is_contained(IDs, ID))
return true;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions include/llvm/MC/MCAssembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#ifndef LLVM_MC_MCASSEMBLER_H
#define LLVM_MC_MCASSEMBLER_H

#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/ilist.h"
#include "llvm/ADT/ilist_node.h"
Expand Down Expand Up @@ -402,8 +403,7 @@ class MCAssembler {
ArrayRef<std::string> getFileNames() { return FileNames; }

void addFileName(StringRef FileName) {
if (std::find(FileNames.begin(), FileNames.end(), FileName) ==
FileNames.end())
if (!is_contained(FileNames, FileName))
FileNames.push_back(FileName);
}

Expand Down
4 changes: 2 additions & 2 deletions include/llvm/Support/GenericDomTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ template <class NodeT> class DomTreeNodeBase {
assert(IDom && "No immediate dominator?");
if (IDom != NewIDom) {
typename std::vector<DomTreeNodeBase<NodeT> *>::iterator I =
std::find(IDom->Children.begin(), IDom->Children.end(), this);
find(IDom->Children, this);
assert(I != IDom->Children.end() &&
"Not in immediate dominator children set!");
// I am no longer your child...
Expand Down Expand Up @@ -588,7 +588,7 @@ template <class NodeT> class DominatorTreeBase : public DominatorBase<NodeT> {
DomTreeNodeBase<NodeT> *IDom = Node->getIDom();
if (IDom) {
typename std::vector<DomTreeNodeBase<NodeT> *>::iterator I =
std::find(IDom->Children.begin(), IDom->Children.end(), Node);
find(IDom->Children, Node);
assert(I != IDom->Children.end() &&
"Not in immediate dominator children set!");
// I am no longer your child...
Expand Down
2 changes: 1 addition & 1 deletion lib/Analysis/EHPersonalities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ DenseMap<BasicBlock *, ColorVector> llvm::colorEHFunclets(Function &F) {
}
// Note that this is a member of the given color.
ColorVector &Colors = BlockColors[Visiting];
if (std::find(Colors.begin(), Colors.end(), Color) == Colors.end())
if (!is_contained(Colors, Color))
Colors.push_back(Color);
else
continue;
Expand Down
2 changes: 1 addition & 1 deletion lib/Analysis/GlobalsModRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ void GlobalsAAResult::AnalyzeCallGraph(CallGraph &CG, Module &M) {
// Can't say anything about it. However, if it is inside our SCC,
// then nothing needs to be done.
CallGraphNode *CalleeNode = CG[Callee];
if (std::find(SCC.begin(), SCC.end(), CalleeNode) == SCC.end())
if (!is_contained(SCC, CalleeNode))
KnowNothing = true;
}
} else {
Expand Down
3 changes: 1 addition & 2 deletions lib/Analysis/LazyCallGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,7 @@ void LazyCallGraph::RefSCC::removeOutgoingEdge(Node &SourceN, Node &TargetN) {
RefSCC &TargetRC = *G->lookupRefSCC(TargetN);
assert(&TargetRC != this && "The target must not be a member of this RefSCC");

assert(std::find(G->LeafRefSCCs.begin(), G->LeafRefSCCs.end(), this) ==
G->LeafRefSCCs.end() &&
assert(!is_contained(G->LeafRefSCCs, this) &&
"Cannot have a leaf RefSCC source.");

// First remove it from the node.
Expand Down
14 changes: 5 additions & 9 deletions lib/Analysis/PHITransAddr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ static bool VerifySubExpr(Value *Expr,

// If it's an instruction, it is either in Tmp or its operands recursively
// are.
SmallVectorImpl<Instruction*>::iterator Entry =
std::find(InstInputs.begin(), InstInputs.end(), I);
SmallVectorImpl<Instruction *>::iterator Entry = find(InstInputs, I);
if (Entry != InstInputs.end()) {
InstInputs.erase(Entry);
return true;
Expand Down Expand Up @@ -126,8 +125,7 @@ static void RemoveInstInputs(Value *V,
if (!I) return;

// If the instruction is in the InstInputs list, remove it.
SmallVectorImpl<Instruction*>::iterator Entry =
std::find(InstInputs.begin(), InstInputs.end(), I);
SmallVectorImpl<Instruction *>::iterator Entry = find(InstInputs, I);
if (Entry != InstInputs.end()) {
InstInputs.erase(Entry);
return;
Expand All @@ -150,8 +148,7 @@ Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB,
if (!Inst) return V;

// Determine whether 'Inst' is an input to our PHI translatable expression.
bool isInput =
std::find(InstInputs.begin(), InstInputs.end(), Inst) != InstInputs.end();
bool isInput = is_contained(InstInputs, Inst);

// Handle inputs instructions if needed.
if (isInput) {
Expand All @@ -165,7 +162,7 @@ Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB,
// translated, we need to incorporate the value into the expression or fail.

// In either case, the instruction itself isn't an input any longer.
InstInputs.erase(std::find(InstInputs.begin(), InstInputs.end(), Inst));
InstInputs.erase(find(InstInputs, Inst));

// If this is a PHI, go ahead and translate it.
if (PHINode *PN = dyn_cast<PHINode>(Inst))
Expand Down Expand Up @@ -272,8 +269,7 @@ Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB,
isNSW = isNUW = false;

// If the old 'LHS' was an input, add the new 'LHS' as an input.
if (std::find(InstInputs.begin(), InstInputs.end(), BOp) !=
InstInputs.end()) {
if (is_contained(InstInputs, BOp)) {
RemoveInstInputs(BOp, InstInputs);
AddAsInput(LHS);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/CodeGen/AllocationOrder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ AllocationOrder::AllocationOrder(unsigned VirtReg,
});
#ifndef NDEBUG
for (unsigned I = 0, E = Hints.size(); I != E; ++I)
assert(std::find(Order.begin(), Order.end(), Hints[I]) != Order.end() &&
assert(is_contained(Order, Hints[I]) &&
"Target hint is outside allocation order.");
#endif
}
5 changes: 2 additions & 3 deletions lib/CodeGen/AllocationOrder.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define LLVM_LIB_CODEGEN_ALLOCATIONORDER_H

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/MC/MCRegisterInfo.h"

namespace llvm {
Expand Down Expand Up @@ -79,9 +80,7 @@ class LLVM_LIBRARY_VISIBILITY AllocationOrder {
bool isHint() const { return Pos <= 0; }

/// Return true if PhysReg is a preferred register.
bool isHint(unsigned PhysReg) const {
return std::find(Hints.begin(), Hints.end(), PhysReg) != Hints.end();
}
bool isHint(unsigned PhysReg) const { return is_contained(Hints, PhysReg); }
};

} // end namespace llvm
Expand Down
4 changes: 2 additions & 2 deletions lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static void dropRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,
const auto &I = RegVars.find(RegNo);
assert(RegNo != 0U && I != RegVars.end());
auto &VarSet = I->second;
const auto &VarPos = std::find(VarSet.begin(), VarSet.end(), Var);
const auto &VarPos = find(VarSet, Var);
assert(VarPos != VarSet.end());
VarSet.erase(VarPos);
// Don't keep empty sets in a map to keep it as small as possible.
Expand All @@ -96,7 +96,7 @@ static void addRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,
InlinedVariable Var) {
assert(RegNo != 0U);
auto &VarSet = RegVars[RegNo];
assert(std::find(VarSet.begin(), VarSet.end(), Var) == VarSet.end());
assert(!is_contained(VarSet, Var));
VarSet.push_back(Var);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static void EmitCamlGlobal(const Module &M, AsmPrinter &AP, const char *Id) {
std::string SymName;
SymName += "caml";
size_t Letter = SymName.size();
SymName.append(MId.begin(), std::find(MId.begin(), MId.end(), '.'));
SymName.append(MId.begin(), find(MId, '.'));
SymName += "__";
SymName += Id;

Expand Down
3 changes: 1 addition & 2 deletions lib/CodeGen/CodeGenPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3665,8 +3665,7 @@ isProfitableToFoldIntoAddressingMode(Instruction *I, ExtAddrMode &AMBefore,
TPT.rollback(LastKnownGood);

// If the match didn't cover I, then it won't be shared by it.
if (std::find(MatchedAddrModeInsts.begin(), MatchedAddrModeInsts.end(),
I) == MatchedAddrModeInsts.end())
if (!is_contained(MatchedAddrModeInsts, I))
return false;

MatchedAddrModeInsts.clear();
Expand Down
2 changes: 1 addition & 1 deletion lib/CodeGen/LatencyPriorityQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ SUnit *LatencyPriorityQueue::pop() {

void LatencyPriorityQueue::remove(SUnit *SU) {
assert(!Queue.empty() && "Queue is empty!");
std::vector<SUnit *>::iterator I = std::find(Queue.begin(), Queue.end(), SU);
std::vector<SUnit *>::iterator I = find(Queue, SU);
if (I != std::prev(Queue.end()))
std::swap(*I, Queue.back());
Queue.pop_back();
Expand Down
5 changes: 2 additions & 3 deletions lib/CodeGen/LiveIntervalUnion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//===----------------------------------------------------------------------===//

#include "llvm/CodeGen/LiveIntervalUnion.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SparseBitVector.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -102,9 +103,7 @@ void LiveIntervalUnion::verify(LiveVirtRegBitSet& VisitedVRegs) {
// Scan the vector of interfering virtual registers in this union. Assume it's
// quite small.
bool LiveIntervalUnion::Query::isSeenInterference(LiveInterval *VirtReg) const {
SmallVectorImpl<LiveInterval*>::const_iterator I =
std::find(InterferingVRegs.begin(), InterferingVRegs.end(), VirtReg);
return I != InterferingVRegs.end();
return is_contained(InterferingVRegs, VirtReg);
}

// Collect virtual registers in this union that interfere with this
Expand Down
11 changes: 5 additions & 6 deletions lib/CodeGen/MachineBasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ void MachineBasicBlock::addSuccessorWithoutProb(MachineBasicBlock *Succ) {

void MachineBasicBlock::removeSuccessor(MachineBasicBlock *Succ,
bool NormalizeSuccProbs) {
succ_iterator I = std::find(Successors.begin(), Successors.end(), Succ);
succ_iterator I = find(Successors, Succ);
removeSuccessor(I, NormalizeSuccProbs);
}

Expand Down Expand Up @@ -611,7 +611,7 @@ void MachineBasicBlock::addPredecessor(MachineBasicBlock *Pred) {
}

void MachineBasicBlock::removePredecessor(MachineBasicBlock *Pred) {
pred_iterator I = std::find(Predecessors.begin(), Predecessors.end(), Pred);
pred_iterator I = find(Predecessors, Pred);
assert(I != Predecessors.end() && "Pred is not a predecessor of this block!");
Predecessors.erase(I);
}
Expand Down Expand Up @@ -775,7 +775,7 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ,
continue;

unsigned Reg = OI->getReg();
if (std::find(UsedRegs.begin(), UsedRegs.end(), Reg) == UsedRegs.end())
if (!is_contained(UsedRegs, Reg))
UsedRegs.push_back(Reg);
}
}
Expand All @@ -802,9 +802,8 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ,

for (SmallVectorImpl<MachineInstr*>::iterator I = Terminators.begin(),
E = Terminators.end(); I != E; ++I) {
if (std::find(NewTerminators.begin(), NewTerminators.end(), *I) ==
NewTerminators.end())
Indexes->removeMachineInstrFromMaps(**I);
if (!is_contained(NewTerminators, *I))
Indexes->removeMachineInstrFromMaps(**I);
}
}

Expand Down
5 changes: 2 additions & 3 deletions lib/CodeGen/MachineBlockPlacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1166,8 +1166,7 @@ void MachineBlockPlacement::rotateLoop(BlockChain &LoopChain,
}
}

BlockChain::iterator ExitIt =
std::find(LoopChain.begin(), LoopChain.end(), ExitingBB);
BlockChain::iterator ExitIt = find(LoopChain, ExitingBB);
if (ExitIt == LoopChain.end())
return;

Expand All @@ -1190,7 +1189,7 @@ void MachineBlockPlacement::rotateLoop(BlockChain &LoopChain,
void MachineBlockPlacement::rotateLoopWithProfile(
BlockChain &LoopChain, MachineLoop &L, const BlockFilterSet &LoopBlockSet) {
auto HeaderBB = L.getHeader();
auto HeaderIter = std::find(LoopChain.begin(), LoopChain.end(), HeaderBB);
auto HeaderIter = find(LoopChain, HeaderBB);
auto RotationPos = LoopChain.end();

BlockFrequency SmallestRotationCost = BlockFrequency::getMaxFrequency();
Expand Down
2 changes: 1 addition & 1 deletion lib/CodeGen/MachineCopyPropagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) {
// Remember source that's copied to Def. Once it's clobbered, then
// it's no longer available for copy propagation.
RegList &DestList = SrcMap[Src];
if (std::find(DestList.begin(), DestList.end(), Def) == DestList.end())
if (!is_contained(DestList, Def))
DestList.push_back(Def);

continue;
Expand Down
Loading

0 comments on commit 975248e

Please sign in to comment.