From 047149f7452ac3eeeff226683d7fb1d354fc36cf Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Fri, 22 Jul 2016 16:09:47 +0000 Subject: [PATCH] [RDF] Make the graph construction/use less expensive - FuncNode::findBlock traverses the function every time. Avoid using it, and keep a cache of block addresses in DataFlowGraph instead. - The operator[] in the map of definition stacks was very slow. Replace the map with unordered_map. llvm-svn: 276429 --- llvm/lib/Target/Hexagon/RDFGraph.cpp | 14 ++++++++------ llvm/lib/Target/Hexagon/RDFGraph.h | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Target/Hexagon/RDFGraph.cpp b/llvm/lib/Target/Hexagon/RDFGraph.cpp index 273d6b7cb0c8..5070d9c6f415 100644 --- a/llvm/lib/Target/Hexagon/RDFGraph.cpp +++ b/llvm/lib/Target/Hexagon/RDFGraph.cpp @@ -936,6 +936,7 @@ void DataFlowGraph::build(unsigned Options) { for (auto &B : MF) { auto BA = newBlock(Func, &B); + BlockNodes.insert(std::make_pair(&B, BA)); for (auto &I : B) { if (I.isDebugValue()) continue; @@ -1069,6 +1070,7 @@ NodeList DataFlowGraph::getRelatedRefs(NodeAddr IA, // Clear all information in the graph. void DataFlowGraph::reset() { Memory.clear(); + BlockNodes.clear(); Func = NodeAddr(); } @@ -1277,7 +1279,7 @@ void DataFlowGraph::buildBlockRefs(NodeAddr BA, assert(N); for (auto I : *N) { MachineBasicBlock *SB = I->getBlock(); - auto SBA = Func.Addr->findBlock(SB, *this); + auto SBA = findBlock(SB); buildBlockRefs(SBA, RefM); const auto &SRs = RefM[SBA.Id]; Refs.insert(SRs.begin(), SRs.end()); @@ -1329,13 +1331,13 @@ void DataFlowGraph::recordDefsForDF(BlockRefsMap &PhiM, BlockRefsMap &RefM, // Get the register references that are reachable from this block. RegisterSet &Refs = RefM[BA.Id]; for (auto DB : IDF) { - auto DBA = Func.Addr->findBlock(DB, *this); + auto DBA = findBlock(DB); const auto &Rs = RefM[DBA.Id]; Refs.insert(Rs.begin(), Rs.end()); } for (auto DB : IDF) { - auto DBA = Func.Addr->findBlock(DB, *this); + auto DBA = findBlock(DB); PhiM[DBA.Id].insert(Defs.begin(), Defs.end()); } } @@ -1392,7 +1394,7 @@ void DataFlowGraph::buildPhis(BlockRefsMap &PhiM, BlockRefsMap &RefM, std::vector PredList; const MachineBasicBlock *MBB = BA.Addr->getCode(); for (auto PB : MBB->predecessors()) { - auto B = Func.Addr->findBlock(PB, *this); + auto B = findBlock(PB); PredList.push_back(B.Id); } @@ -1584,7 +1586,7 @@ void DataFlowGraph::linkBlockRefs(DefStackMap &DefM, NodeAddr BA) { MachineDomTreeNode *N = MDT.getNode(BA.Addr->getCode()); for (auto I : *N) { MachineBasicBlock *SB = I->getBlock(); - auto SBA = Func.Addr->findBlock(SB, *this); + auto SBA = findBlock(SB); linkBlockRefs(DefM, SBA); } @@ -1598,7 +1600,7 @@ void DataFlowGraph::linkBlockRefs(DefStackMap &DefM, NodeAddr BA) { }; MachineBasicBlock *MBB = BA.Addr->getCode(); for (auto SB : MBB->successors()) { - auto SBA = Func.Addr->findBlock(SB, *this); + auto SBA = findBlock(SB); for (NodeAddr IA : SBA.Addr->members_if(IsPhi, *this)) { // Go over each phi use associated with MBB, and link it. for (auto U : IA.Addr->members_if(IsUseForBA, *this)) { diff --git a/llvm/lib/Target/Hexagon/RDFGraph.h b/llvm/lib/Target/Hexagon/RDFGraph.h index 49b053741263..56ae6a7c507c 100644 --- a/llvm/lib/Target/Hexagon/RDFGraph.h +++ b/llvm/lib/Target/Hexagon/RDFGraph.h @@ -210,6 +210,7 @@ #include #include #include +#include #include namespace llvm { @@ -679,7 +680,14 @@ namespace rdf { StorageType Stack; }; - typedef std::map DefStackMap; + struct RegisterRefHasher { + unsigned operator() (RegisterRef RR) const { + return RR.Reg | (RR.Sub << 24); + } + }; + // Make this std::unordered_map for speed of accessing elements. + typedef std::unordered_map + DefStackMap; void build(unsigned Options = BuildOptions::None); void pushDefs(NodeAddr IA, DefStackMap &DM); @@ -783,9 +791,15 @@ namespace rdf { IA.Addr->removeMember(RA, *this); } + NodeAddr findBlock(MachineBasicBlock *BB) { + return BlockNodes[BB]; + } + TimerGroup TimeG; NodeAddr Func; NodeAllocator Memory; + // Local map: MachineBasicBlock -> NodeAddr + std::map> BlockNodes; MachineFunction &MF; const TargetInstrInfo &TII; -- GitLab