OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Attributes | List of all members
VirtRegIndependenceGraph Class Reference

#include <VirtRegIndependenceGraph.hh>

Collaboration diagram for VirtRegIndependenceGraph:
Collaboration graph

Public Member Functions

 VirtRegIndependenceGraph (llvm::MachineFunction &mf, llvm::VirtRegMap &vrm)
 
int newFalseDepsFromAssign (llvm::LiveInterval *interval, MachineInstrDDG::Register physReg)
 
void addNode (MachineInstrDDG::Register virtReg)
 
void addEdge (MachineInstrDDG::Register nodeA, MachineInstrDDG::Register nodeB)
 
std::set< MachineInstrDDG::RegisteradjacentNodes (MachineInstrDDG::Register node)
 

Private Types

typedef boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, boost::property< boost::vertex_name_t, MachineInstrDDG::Register > > FDPG
 

Private Attributes

llvm::VirtRegMap & vrm_
 
FDPG fdpg_
 
std::map< MachineInstrDDG::Register, FDPG::vertex_descriptor > vertexMap_
 
std::map< FDPG::vertex_descriptor, MachineInstrDDG::RegistervregMap_
 

Detailed Description

Virtual register independence graph AKA False Dependence Prevention Graph (FDPG).

Nodes in the graph are virtual registers. They have edges between if the live ranges could be scheduled in parallel or reordered if there were no false dependencies. In other words, two virtual registers / live ranges / variables are considered independent in case they do not have real data dependencies between them.

Todo:
This approach has at least the following unsolved problems:

Definition at line 80 of file VirtRegIndependenceGraph.hh.

Member Typedef Documentation

◆ FDPG

typedef boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, boost::property<boost::vertex_name_t, MachineInstrDDG::Register> > VirtRegIndependenceGraph::FDPG
private

Definition at line 99 of file VirtRegIndependenceGraph.hh.

Constructor & Destructor Documentation

◆ VirtRegIndependenceGraph()

VirtRegIndependenceGraph::VirtRegIndependenceGraph ( llvm::MachineFunction &  mf,
llvm::VirtRegMap &  vrm 
)

Constructs the graph from an LLVM MachineFunction.

Definition at line 46 of file VirtRegIndependenceGraph.cc.

47 :
48 vrm_(vrm) {
49
50 MachineInstrDDG tddg(*vrm.TII, *vrm.TRI, mf, true);
51 MachineInstrDDG::RegisterSet regs = tddg.allRegisters();
52#ifdef DEBUG_FDPG
53 Application::logStream() << "building FDPG" << std::endl;
54#endif
55 // add the virtual regs as nodes
56 for (MachineInstrDDG::RegisterSet::const_iterator i = regs.begin();
57 i != regs.end(); ++i) {
59
60 if (llvm::TargetRegisterInfo::isPhysicalRegister(reg))
61 continue;
62
63 addNode(reg);
64 }
65
66#ifdef DEBUG_FDPG
67 Application::logStream() << "finding TDDG paths" << std::endl;
68#endif
69 // this should speed up hasPath() as all known paths are
70 // computed only once
71 tddg.findAllPaths();
72#ifdef DEBUG_FDPG
73 Application::logStream() << "finding TDDG paths done" << std::endl;
74#endif
75 MachineInstrDDG::RegisterSet unhandledRegs = regs;
76 for (MachineInstrDDG::RegisterSet::const_iterator i = regs.begin();
77 i != regs.end(); ++i) {
79 MIDDGNode* instrA = tddg.vregDefiner(reg);
80 for (MachineInstrDDG::RegisterSet::const_iterator u =
81 unhandledRegs.begin();
82 u != unhandledRegs.end(); ++u) {
83 MachineInstrDDG::Register otherReg = *u;
84 MIDDGNode* instrB = tddg.vregDefiner(otherReg);
85 if (instrB == NULL) {
87 << "could not find definer for " << otherReg << std::endl;
88 abortWithError("Cannot proceed.");
89 }
90 if (!tddg.hasPath(*instrA, *instrB) &&
91 !tddg.hasPath(*instrB, *instrA)) {
92 addEdge(reg, otherReg);
93 }
94 }
95 unhandledRegs.erase(reg);
96 }
97#ifdef DEBUG_FDPG
98 Application::logStream() << "building FDPG done" << std::endl;
99#endif
100#if 0
101 // this is exremely slow as there are often huge number of edges in FDPG
102 std::string s(mf.getFunction()->getNameStr() + "_fdpg.dot");
103 std::ofstream o(s.c_str());
104 boost::write_graphviz(
105 o, fdpg_, make_label_writer(get(boost::vertex_name, fdpg_)));
106#endif
107}
#define abortWithError(message)
static std::ostream & logStream()
std::set< Register > RegisterSet
void addEdge(MachineInstrDDG::Register nodeA, MachineInstrDDG::Register nodeB)
void addNode(MachineInstrDDG::Register virtReg)

References abortWithError, addEdge(), addNode(), MachineInstrDDG::allRegisters(), fdpg_, BoostGraph< GraphNode, GraphEdge >::findAllPaths(), BoostGraph< GraphNode, GraphEdge >::hasPath(), Application::logStream(), and MachineInstrDDG::vregDefiner().

Here is the call graph for this function:

Member Function Documentation

◆ addEdge()

void VirtRegIndependenceGraph::addEdge ( MachineInstrDDG::Register  nodeA,
MachineInstrDDG::Register  nodeB 
)

Definition at line 149 of file VirtRegIndependenceGraph.cc.

150 {
151 boost::add_edge(vertexMap_[nodeA], vertexMap_[nodeB], fdpg_);
152}
std::map< MachineInstrDDG::Register, FDPG::vertex_descriptor > vertexMap_

References fdpg_, and vertexMap_.

Referenced by VirtRegIndependenceGraph().

◆ addNode()

void VirtRegIndependenceGraph::addNode ( MachineInstrDDG::Register  virtReg)

Definition at line 142 of file VirtRegIndependenceGraph.cc.

142 {
143 vertexMap_[virtReg] = boost::add_vertex(fdpg_);
144 vregMap_[vertexMap_[virtReg]] = virtReg;
145 boost::put(boost::vertex_name, fdpg_, vertexMap_[virtReg], virtReg);
146}
std::map< FDPG::vertex_descriptor, MachineInstrDDG::Register > vregMap_

References fdpg_, vertexMap_, and vregMap_.

Referenced by VirtRegIndependenceGraph().

◆ adjacentNodes()

std::set< MachineInstrDDG::Register > VirtRegIndependenceGraph::adjacentNodes ( MachineInstrDDG::Register  node)

Definition at line 155 of file VirtRegIndependenceGraph.cc.

155 {
156 std::set<MachineInstrDDG::Register> nodes;
157
158 boost::graph_traits<FDPG>::adjacency_iterator i, end;
159 i = boost::adjacent_vertices(vertexMap_[node], fdpg_).first;
160 end = boost::adjacent_vertices(vertexMap_[node], fdpg_).second;
161 for (; i != end; ++i) {
163 nodes.insert(virtReg);
164 }
165
166 return nodes;
167}

References fdpg_, vertexMap_, and vregMap_.

Referenced by newFalseDepsFromAssign().

◆ newFalseDepsFromAssign()

int VirtRegIndependenceGraph::newFalseDepsFromAssign ( llvm::LiveInterval *  interval,
MachineInstrDDG::Register  physReg 
)

Returns the number of new false deps introduced by assigning the given physical register to the given live interval.

Definition at line 114 of file VirtRegIndependenceGraph.cc.

115 {
116
117 if (llvm::TargetRegisterInfo::isPhysicalRegister(interval->reg)) {
119 << "Should not see assigned intervals here. Got: "
120 << interval->reg
121 << std::endl;
122 return true;
123 }
124
125 // look at all connected live Intervals in the FDPG and see if they have
126 // been assigned the same PhysReg we are trying to assign this one
127
128 int foundFalseDeps = 0;
129 std::set<MachineInstrDDG::Register> adjacent = adjacentNodes(interval->reg);
130 for (std::set<MachineInstrDDG::Register>::const_iterator i =
131 adjacent.begin(); i != adjacent.end(); ++i) {
132 MachineInstrDDG::Register virtReg = *i;
133 bool isPhysRegAssigned = vrm_.hasPhys(virtReg);
134 if (isPhysRegAssigned && vrm_.getPhys(virtReg) == physReg) {
135 ++foundFalseDeps;
136 }
137 }
138 return foundFalseDeps;
139}
std::set< MachineInstrDDG::Register > adjacentNodes(MachineInstrDDG::Register node)

References adjacentNodes(), Application::logStream(), and vrm_.

Here is the call graph for this function:

Member Data Documentation

◆ fdpg_

FDPG VirtRegIndependenceGraph::fdpg_
private

◆ vertexMap_

std::map<MachineInstrDDG::Register, FDPG::vertex_descriptor> VirtRegIndependenceGraph::vertexMap_
private

Definition at line 106 of file VirtRegIndependenceGraph.hh.

Referenced by addEdge(), addNode(), and adjacentNodes().

◆ vregMap_

std::map<FDPG::vertex_descriptor, MachineInstrDDG::Register> VirtRegIndependenceGraph::vregMap_
private

Definition at line 107 of file VirtRegIndependenceGraph.hh.

Referenced by addNode(), and adjacentNodes().

◆ vrm_

llvm::VirtRegMap& VirtRegIndependenceGraph::vrm_
private

Definition at line 102 of file VirtRegIndependenceGraph.hh.

Referenced by newFalseDepsFromAssign().


The documentation for this class was generated from the following files: