OpenASIP  2.0
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 }

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 }

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 }

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) {
162  MachineInstrDDG::Register virtReg = vregMap_[*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 }

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:
VirtRegIndependenceGraph::vrm_
llvm::VirtRegMap & vrm_
Definition: VirtRegIndependenceGraph.hh:102
Application::logStream
static std::ostream & logStream()
Definition: Application.cc:155
MachineInstrDDG::RegisterSet
std::set< Register > RegisterSet
Definition: MachineInstrDDG.hh:144
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
MachineInstrDDG
Definition: MachineInstrDDG.hh:140
MIDDGNode
Definition: MachineInstrDDG.hh:58
VirtRegIndependenceGraph::adjacentNodes
std::set< MachineInstrDDG::Register > adjacentNodes(MachineInstrDDG::Register node)
Definition: VirtRegIndependenceGraph.cc:155
VirtRegIndependenceGraph::addNode
void addNode(MachineInstrDDG::Register virtReg)
Definition: VirtRegIndependenceGraph.cc:142
VirtRegIndependenceGraph::vregMap_
std::map< FDPG::vertex_descriptor, MachineInstrDDG::Register > vregMap_
Definition: VirtRegIndependenceGraph.hh:107
VirtRegIndependenceGraph::addEdge
void addEdge(MachineInstrDDG::Register nodeA, MachineInstrDDG::Register nodeB)
Definition: VirtRegIndependenceGraph.cc:149
MachineInstrDDG::Register
unsigned Register
Definition: MachineInstrDDG.hh:143
VirtRegIndependenceGraph::vertexMap_
std::map< MachineInstrDDG::Register, FDPG::vertex_descriptor > vertexMap_
Definition: VirtRegIndependenceGraph.hh:106
VirtRegIndependenceGraph::fdpg_
FDPG fdpg_
Definition: VirtRegIndependenceGraph.hh:104