1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

[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
This commit is contained in:
Krzysztof Parzyszek 2016-07-22 16:09:47 +00:00
parent 8c90dac8a6
commit c5dafe9b5a
2 changed files with 23 additions and 7 deletions

View File

@ -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<InstrNode*> IA,
// Clear all information in the graph.
void DataFlowGraph::reset() {
Memory.clear();
BlockNodes.clear();
Func = NodeAddr<FuncNode*>();
}
@ -1277,7 +1279,7 @@ void DataFlowGraph::buildBlockRefs(NodeAddr<BlockNode*> 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<NodeId> 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<BlockNode*> 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<BlockNode*> BA) {
};
MachineBasicBlock *MBB = BA.Addr->getCode();
for (auto SB : MBB->successors()) {
auto SBA = Func.Addr->findBlock(SB, *this);
auto SBA = findBlock(SB);
for (NodeAddr<InstrNode*> 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)) {

View File

@ -210,6 +210,7 @@
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <vector>
namespace llvm {
@ -679,7 +680,14 @@ namespace rdf {
StorageType Stack;
};
typedef std::map<RegisterRef,DefStack> 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<RegisterRef,DefStack,RegisterRefHasher>
DefStackMap;
void build(unsigned Options = BuildOptions::None);
void pushDefs(NodeAddr<InstrNode*> IA, DefStackMap &DM);
@ -783,9 +791,15 @@ namespace rdf {
IA.Addr->removeMember(RA, *this);
}
NodeAddr<BlockNode*> findBlock(MachineBasicBlock *BB) {
return BlockNodes[BB];
}
TimerGroup TimeG;
NodeAddr<FuncNode*> Func;
NodeAllocator Memory;
// Local map: MachineBasicBlock -> NodeAddr<BlockNode*>
std::map<MachineBasicBlock*,NodeAddr<BlockNode*>> BlockNodes;
MachineFunction &MF;
const TargetInstrInfo &TII;