[llvm] r279326 - [GraphTraits] Make nodes_iterator dereference to NodeType*/NodeRef
Tim Shen via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 19 14:20:13 PDT 2016
Author: timshen
Date: Fri Aug 19 16:20:13 2016
New Revision: 279326
URL: http://llvm.org/viewvc/llvm-project?rev=279326&view=rev
Log:
[GraphTraits] Make nodes_iterator dereference to NodeType*/NodeRef
Currently nodes_iterator may dereference to a NodeType* or a NodeType&. Make them all dereference to NodeType*, which is NodeRef later.
Differential Revision: https://reviews.llvm.org/D23704
Differential Revision: https://reviews.llvm.org/D23705
Modified:
llvm/trunk/include/llvm/ADT/GraphTraits.h
llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h
llvm/trunk/include/llvm/Analysis/CallGraph.h
llvm/trunk/include/llvm/CodeGen/MachineFunction.h
llvm/trunk/include/llvm/CodeGen/ScheduleDAG.h
llvm/trunk/include/llvm/CodeGen/SelectionDAG.h
llvm/trunk/include/llvm/IR/CFG.h
llvm/trunk/include/llvm/Support/GenericDomTree.h
llvm/trunk/include/llvm/Support/GraphWriter.h
llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp
llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp
llvm/trunk/lib/Target/AMDGPU/AMDILCFGStructurizer.cpp
llvm/trunk/lib/Transforms/Scalar/NaryReassociate.cpp
llvm/trunk/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
llvm/trunk/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
llvm/trunk/unittests/Analysis/CallGraphTest.cpp
Modified: llvm/trunk/include/llvm/ADT/GraphTraits.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/GraphTraits.h?rev=279326&r1=279325&r2=279326&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/GraphTraits.h (original)
+++ llvm/trunk/include/llvm/ADT/GraphTraits.h Fri Aug 19 16:20:13 2016
@@ -34,7 +34,8 @@ struct GraphTraits {
//
// typedef NodeType - Type of Node in the graph
// typedef NodeRef - NodeType *
- // typedef ChildIteratorType - Type used to iterate over children in graph
+ // typedef ChildIteratorType - Type used to iterate over children in graph,
+ // dereference to a NodeRef
// static NodeRef getEntryNode(const GraphType &)
// Return the entry node of the graph
@@ -45,7 +46,7 @@ struct GraphTraits {
// node list for the specified node.
//
- // typedef ...iterator nodes_iterator;
+ // typedef ...iterator nodes_iterator; - dereference to a NodeRef
// static nodes_iterator nodes_begin(GraphType *G)
// static nodes_iterator nodes_end (GraphType *G)
// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
Modified: llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h?rev=279326&r1=279325&r2=279326&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h (original)
+++ llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h Fri Aug 19 16:20:13 2016
@@ -1271,7 +1271,7 @@ struct BFIDOTGraphTraitsBase : public De
for (NodeIter I = GTraits::nodes_begin(Graph),
E = GTraits::nodes_end(Graph);
I != E; ++I) {
- NodeRef N = &*I;
+ NodeRef N = *I;
MaxFrequency =
std::max(MaxFrequency, Graph->getBlockFreq(N).getFrequency());
}
Modified: llvm/trunk/include/llvm/Analysis/CallGraph.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/CallGraph.h?rev=279326&r1=279325&r2=279326&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/CallGraph.h (original)
+++ llvm/trunk/include/llvm/Analysis/CallGraph.h Fri Aug 19 16:20:13 2016
@@ -460,7 +460,7 @@ struct GraphTraits<CallGraph *> : public
}
typedef std::pair<const Function *const, std::unique_ptr<CallGraphNode>>
PairTy;
- typedef std::pointer_to_unary_function<const PairTy &, CallGraphNode &>
+ typedef std::pointer_to_unary_function<const PairTy &, CallGraphNode *>
DerefFun;
// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
@@ -472,7 +472,7 @@ struct GraphTraits<CallGraph *> : public
return map_iterator(CG->end(), DerefFun(CGdereference));
}
- static CallGraphNode &CGdereference(const PairTy &P) { return *P.second; }
+ static CallGraphNode *CGdereference(const PairTy &P) { return P.second.get(); }
};
template <>
@@ -483,7 +483,7 @@ struct GraphTraits<const CallGraph *> :
}
typedef std::pair<const Function *const, std::unique_ptr<CallGraphNode>>
PairTy;
- typedef std::pointer_to_unary_function<const PairTy &, const CallGraphNode &>
+ typedef std::pointer_to_unary_function<const PairTy &, const CallGraphNode *>
DerefFun;
// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
@@ -495,8 +495,8 @@ struct GraphTraits<const CallGraph *> :
return map_iterator(CG->end(), DerefFun(CGdereference));
}
- static const CallGraphNode &CGdereference(const PairTy &P) {
- return *P.second;
+ static const CallGraphNode *CGdereference(const PairTy &P) {
+ return P.second.get();
}
};
Modified: llvm/trunk/include/llvm/CodeGen/MachineFunction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineFunction.h?rev=279326&r1=279325&r2=279326&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineFunction.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineFunction.h Fri Aug 19 16:20:13 2016
@@ -625,9 +625,13 @@ template <> struct GraphTraits<MachineFu
}
// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
- typedef MachineFunction::iterator nodes_iterator;
- static nodes_iterator nodes_begin(MachineFunction *F) { return F->begin(); }
- static nodes_iterator nodes_end (MachineFunction *F) { return F->end(); }
+ typedef pointer_iterator<MachineFunction::iterator> nodes_iterator;
+ static nodes_iterator nodes_begin(MachineFunction *F) {
+ return nodes_iterator(F->begin());
+ }
+ static nodes_iterator nodes_end(MachineFunction *F) {
+ return nodes_iterator(F->end());
+ }
static unsigned size (MachineFunction *F) { return F->size(); }
};
template <> struct GraphTraits<const MachineFunction*> :
@@ -637,12 +641,12 @@ template <> struct GraphTraits<const Mac
}
// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
- typedef MachineFunction::const_iterator nodes_iterator;
+ typedef pointer_iterator<MachineFunction::const_iterator> nodes_iterator;
static nodes_iterator nodes_begin(const MachineFunction *F) {
- return F->begin();
+ return nodes_iterator(F->begin());
}
static nodes_iterator nodes_end (const MachineFunction *F) {
- return F->end();
+ return nodes_iterator(F->end());
}
static unsigned size (const MachineFunction *F) {
return F->size();
Modified: llvm/trunk/include/llvm/CodeGen/ScheduleDAG.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/ScheduleDAG.h?rev=279326&r1=279325&r2=279326&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/ScheduleDAG.h (original)
+++ llvm/trunk/include/llvm/CodeGen/ScheduleDAG.h Fri Aug 19 16:20:13 2016
@@ -692,12 +692,12 @@ namespace llvm {
};
template <> struct GraphTraits<ScheduleDAG*> : public GraphTraits<SUnit*> {
- typedef std::vector<SUnit>::iterator nodes_iterator;
+ typedef pointer_iterator<std::vector<SUnit>::iterator> nodes_iterator;
static nodes_iterator nodes_begin(ScheduleDAG *G) {
- return G->SUnits.begin();
+ return nodes_iterator(G->SUnits.begin());
}
static nodes_iterator nodes_end(ScheduleDAG *G) {
- return G->SUnits.end();
+ return nodes_iterator(G->SUnits.end());
}
};
Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAG.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SelectionDAG.h?rev=279326&r1=279325&r2=279326&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/SelectionDAG.h (original)
+++ llvm/trunk/include/llvm/CodeGen/SelectionDAG.h Fri Aug 19 16:20:13 2016
@@ -1416,12 +1416,12 @@ private:
};
template <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> {
- typedef SelectionDAG::allnodes_iterator nodes_iterator;
+ typedef pointer_iterator<SelectionDAG::allnodes_iterator> nodes_iterator;
static nodes_iterator nodes_begin(SelectionDAG *G) {
- return G->allnodes_begin();
+ return nodes_iterator(G->allnodes_begin());
}
static nodes_iterator nodes_end(SelectionDAG *G) {
- return G->allnodes_end();
+ return nodes_iterator(G->allnodes_end());
}
};
Modified: llvm/trunk/include/llvm/IR/CFG.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/CFG.h?rev=279326&r1=279325&r2=279326&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/CFG.h (original)
+++ llvm/trunk/include/llvm/IR/CFG.h Fri Aug 19 16:20:13 2016
@@ -229,9 +229,13 @@ template <> struct GraphTraits<Function*
static NodeType *getEntryNode(Function *F) { return &F->getEntryBlock(); }
// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
- typedef Function::iterator nodes_iterator;
- static nodes_iterator nodes_begin(Function *F) { return F->begin(); }
- static nodes_iterator nodes_end (Function *F) { return F->end(); }
+ typedef pointer_iterator<Function::iterator> nodes_iterator;
+ static nodes_iterator nodes_begin(Function *F) {
+ return nodes_iterator(F->begin());
+ }
+ static nodes_iterator nodes_end(Function *F) {
+ return nodes_iterator(F->end());
+ }
static size_t size (Function *F) { return F->size(); }
};
template <> struct GraphTraits<const Function*> :
@@ -239,9 +243,13 @@ template <> struct GraphTraits<const Fun
static NodeType *getEntryNode(const Function *F) {return &F->getEntryBlock();}
// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
- typedef Function::const_iterator nodes_iterator;
- static nodes_iterator nodes_begin(const Function *F) { return F->begin(); }
- static nodes_iterator nodes_end (const Function *F) { return F->end(); }
+ typedef pointer_iterator<Function::const_iterator> nodes_iterator;
+ static nodes_iterator nodes_begin(const Function *F) {
+ return nodes_iterator(F->begin());
+ }
+ static nodes_iterator nodes_end(const Function *F) {
+ return nodes_iterator(F->end());
+ }
static size_t size (const Function *F) { return F->size(); }
};
Modified: llvm/trunk/include/llvm/Support/GenericDomTree.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/GenericDomTree.h?rev=279326&r1=279325&r2=279326&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/GenericDomTree.h (original)
+++ llvm/trunk/include/llvm/Support/GenericDomTree.h Fri Aug 19 16:20:13 2016
@@ -750,8 +750,8 @@ public:
for (typename TraitsTy::nodes_iterator I = TraitsTy::nodes_begin(&F),
E = TraitsTy::nodes_end(&F);
I != E; ++I)
- if (TraitsTy::child_begin(&*I) == TraitsTy::child_end(&*I))
- addRoot(&*I);
+ if (TraitsTy::child_begin(*I) == TraitsTy::child_end(*I))
+ addRoot(*I);
Calculate<FT, Inverse<NodeT *>>(*this, F);
}
Modified: llvm/trunk/include/llvm/Support/GraphWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/GraphWriter.h?rev=279326&r1=279325&r2=279326&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/GraphWriter.h (original)
+++ llvm/trunk/include/llvm/Support/GraphWriter.h Fri Aug 19 16:20:13 2016
@@ -145,22 +145,14 @@ public:
// Loop over the graph, printing it out...
for (node_iterator I = GTraits::nodes_begin(G), E = GTraits::nodes_end(G);
I != E; ++I)
- if (!isNodeHidden(&*I))
- writeNode(&*I);
- }
-
- bool isNodeHidden(NodeRef const *Node) {
- return isNodeHidden(*Node);
+ if (!isNodeHidden(*I))
+ writeNode(*I);
}
bool isNodeHidden(NodeRef Node) {
return DTraits.isNodeHidden(Node);
}
- void writeNode(NodeRef const *Node) {
- writeNode(*Node);
- }
-
void writeNode(NodeRef Node) {
std::string NodeAttributes = DTraits.getNodeAttributes(Node, G);
Modified: llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp?rev=279326&r1=279325&r2=279326&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp Fri Aug 19 16:20:13 2016
@@ -63,7 +63,7 @@ struct GraphTraits<BlockFrequencyInfo *>
typedef const BasicBlock NodeType;
typedef const BasicBlock *NodeRef;
typedef succ_const_iterator ChildIteratorType;
- typedef Function::const_iterator nodes_iterator;
+ typedef pointer_iterator<Function::const_iterator> nodes_iterator;
static inline const NodeType *getEntryNode(const BlockFrequencyInfo *G) {
return &G->getFunction()->front();
@@ -75,10 +75,10 @@ struct GraphTraits<BlockFrequencyInfo *>
return succ_end(N);
}
static nodes_iterator nodes_begin(const BlockFrequencyInfo *G) {
- return G->getFunction()->begin();
+ return nodes_iterator(G->getFunction()->begin());
}
static nodes_iterator nodes_end(const BlockFrequencyInfo *G) {
- return G->getFunction()->end();
+ return nodes_iterator(G->getFunction()->end());
}
};
Modified: llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp?rev=279326&r1=279325&r2=279326&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp Fri Aug 19 16:20:13 2016
@@ -55,7 +55,7 @@ template <> struct GraphTraits<MachineBl
typedef const MachineBasicBlock NodeType;
typedef const MachineBasicBlock *NodeRef;
typedef MachineBasicBlock::const_succ_iterator ChildIteratorType;
- typedef MachineFunction::const_iterator nodes_iterator;
+ typedef pointer_iterator<MachineFunction::const_iterator> nodes_iterator;
static inline const NodeType *
getEntryNode(const MachineBlockFrequencyInfo *G) {
@@ -71,11 +71,11 @@ template <> struct GraphTraits<MachineBl
}
static nodes_iterator nodes_begin(const MachineBlockFrequencyInfo *G) {
- return G->getFunction()->begin();
+ return nodes_iterator(G->getFunction()->begin());
}
static nodes_iterator nodes_end(const MachineBlockFrequencyInfo *G) {
- return G->getFunction()->end();
+ return nodes_iterator(G->getFunction()->end());
}
};
Modified: llvm/trunk/lib/Target/AMDGPU/AMDILCFGStructurizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/AMDILCFGStructurizer.cpp?rev=279326&r1=279325&r2=279326&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/AMDILCFGStructurizer.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/AMDILCFGStructurizer.cpp Fri Aug 19 16:20:13 2016
@@ -840,7 +840,7 @@ bool AMDGPUCFGStructurizer::run() {
} //while, "one iteration" over the function.
MachineBasicBlock *EntryMBB =
- &*GraphTraits<MachineFunction *>::nodes_begin(FuncRep);
+ *GraphTraits<MachineFunction *>::nodes_begin(FuncRep);
if (EntryMBB->succ_size() == 0) {
Finish = true;
DEBUG(
@@ -863,7 +863,7 @@ bool AMDGPUCFGStructurizer::run() {
} while (!Finish && MakeProgress);
// Misc wrap up to maintain the consistency of the Function representation.
- wrapup(&*GraphTraits<MachineFunction *>::nodes_begin(FuncRep));
+ wrapup(*GraphTraits<MachineFunction *>::nodes_begin(FuncRep));
// Detach retired Block, release memory.
for (MBBInfoMap::iterator It = BlockInfoMap.begin(), E = BlockInfoMap.end();
@@ -907,9 +907,9 @@ void AMDGPUCFGStructurizer::orderBlocks(
//walk through all the block in func to check for unreachable
typedef GraphTraits<MachineFunction *> GTM;
- MachineFunction::iterator It = GTM::nodes_begin(MF), E = GTM::nodes_end(MF);
+ auto It = GTM::nodes_begin(MF), E = GTM::nodes_end(MF);
for (; It != E; ++It) {
- MachineBasicBlock *MBB = &(*It);
+ MachineBasicBlock *MBB = *It;
SccNum = getSCCNum(MBB);
if (SccNum == INVALIDSCCNUM)
dbgs() << "unreachable block BB" << MBB->getNumber() << "\n";
Modified: llvm/trunk/lib/Transforms/Scalar/NaryReassociate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/NaryReassociate.cpp?rev=279326&r1=279325&r2=279326&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/NaryReassociate.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/NaryReassociate.cpp Fri Aug 19 16:20:13 2016
@@ -211,7 +211,7 @@ bool NaryReassociatePass::doOneIteration
// ensures that all bases of a candidate are in Candidates when we process it.
for (auto Node = GraphTraits<DominatorTree *>::nodes_begin(DT);
Node != GraphTraits<DominatorTree *>::nodes_end(DT); ++Node) {
- BasicBlock *BB = Node->getBlock();
+ BasicBlock *BB = (*Node)->getBlock();
for (auto I = BB->begin(); I != BB->end(); ++I) {
if (SE->isSCEVable(I->getType()) && isPotentiallyNaryReassociable(&*I)) {
const SCEV *OldSCEV = SE->getSCEV(&*I);
Modified: llvm/trunk/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp?rev=279326&r1=279325&r2=279326&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp Fri Aug 19 16:20:13 2016
@@ -1152,7 +1152,7 @@ bool SeparateConstOffsetFromGEP::reunite
DominatingExprs.clear();
for (auto Node = GraphTraits<DominatorTree *>::nodes_begin(DT);
Node != GraphTraits<DominatorTree *>::nodes_end(DT); ++Node) {
- BasicBlock *BB = Node->getBlock();
+ BasicBlock *BB = (*Node)->getBlock();
for (auto I = BB->begin(); I != BB->end(); ) {
Instruction *Cur = &*I++;
Changed |= reuniteExts(Cur);
Modified: llvm/trunk/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp?rev=279326&r1=279325&r2=279326&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp Fri Aug 19 16:20:13 2016
@@ -676,7 +676,7 @@ bool StraightLineStrengthReduce::runOnFu
// all bases of a candidate are in Candidates when we process it.
for (auto node = GraphTraits<DominatorTree *>::nodes_begin(DT);
node != GraphTraits<DominatorTree *>::nodes_end(DT); ++node) {
- for (auto &I : *node->getBlock())
+ for (auto &I : *(*node)->getBlock())
allocateCandidatesAndFindBasis(&I);
}
Modified: llvm/trunk/unittests/Analysis/CallGraphTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Analysis/CallGraphTest.cpp?rev=279326&r1=279325&r2=279326&view=diff
==============================================================================
--- llvm/trunk/unittests/Analysis/CallGraphTest.cpp (original)
+++ llvm/trunk/unittests/Analysis/CallGraphTest.cpp Fri Aug 19 16:20:13 2016
@@ -24,11 +24,11 @@ template <typename Ty> void canSpecializ
auto X = ++I;
// Should be able to iterate over all nodes of the graph.
- static_assert(std::is_same<decltype(*I), NodeTy &>::value,
+ static_assert(std::is_same<decltype(*I), NodeTy *>::value,
"Node type does not match");
- static_assert(std::is_same<decltype(*X), NodeTy &>::value,
+ static_assert(std::is_same<decltype(*X), NodeTy *>::value,
"Node type does not match");
- static_assert(std::is_same<decltype(*E), NodeTy &>::value,
+ static_assert(std::is_same<decltype(*E), NodeTy *>::value,
"Node type does not match");
NodeTy *N = GraphTraits<Ty *>::getEntryNode(G);
More information about the llvm-commits
mailing list