2002-08-09 18:55:18 +00:00
|
|
|
//===- SchedGraph.cpp - Scheduling Graph Implementation -------------------===//
|
2003-10-20 19:43:21 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2002-08-09 18:55:18 +00:00
|
|
|
//
|
|
|
|
// Scheduling graph based on SSA graph plus extra dependence edges capturing
|
|
|
|
// dependences due to machine resources (machine registers, CC registers, and
|
|
|
|
// any others).
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2001-09-14 16:56:32 +00:00
|
|
|
#include "SchedGraph.h"
|
2002-04-07 20:49:59 +00:00
|
|
|
#include "llvm/Function.h"
|
2001-10-02 03:41:24 +00:00
|
|
|
#include "llvm/iOther.h"
|
2003-08-27 02:42:58 +00:00
|
|
|
#include "llvm/CodeGen/MachineCodeForInstruction.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetRegInfo.h"
|
|
|
|
#include "Support/STLExtras.h"
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2001-09-30 23:36:58 +00:00
|
|
|
//*********************** Internal Data Structures *************************/
|
|
|
|
|
2001-11-05 04:04:23 +00:00
|
|
|
// The following two types need to be classes, not typedefs, so we can use
|
|
|
|
// opaque declarations in SchedGraph.h
|
|
|
|
//
|
2003-05-22 21:24:35 +00:00
|
|
|
struct RefVec: public std::vector<std::pair<SchedGraphNode*, int> > {
|
|
|
|
typedef std::vector<std::pair<SchedGraphNode*,int> >::iterator iterator;
|
|
|
|
typedef
|
|
|
|
std::vector<std::pair<SchedGraphNode*,int> >::const_iterator const_iterator;
|
2001-11-05 04:04:23 +00:00
|
|
|
};
|
2001-09-30 23:36:58 +00:00
|
|
|
|
2001-10-13 06:51:01 +00:00
|
|
|
struct RegToRefVecMap: public hash_map<int, RefVec> {
|
2001-11-05 04:04:23 +00:00
|
|
|
typedef hash_map<int, RefVec>:: iterator iterator;
|
2001-09-30 23:36:58 +00:00
|
|
|
typedef hash_map<int, RefVec>::const_iterator const_iterator;
|
|
|
|
};
|
|
|
|
|
2003-07-02 01:16:01 +00:00
|
|
|
struct ValueToDefVecMap: public hash_map<const Value*, RefVec> {
|
|
|
|
typedef hash_map<const Value*, RefVec>:: iterator iterator;
|
|
|
|
typedef hash_map<const Value*, RefVec>::const_iterator const_iterator;
|
2001-11-05 04:04:23 +00:00
|
|
|
};
|
|
|
|
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// class SchedGraphNode
|
|
|
|
//
|
|
|
|
|
2003-08-27 02:42:58 +00:00
|
|
|
SchedGraphNode::SchedGraphNode(unsigned NID, MachineBasicBlock *mbb,
|
|
|
|
int indexInBB, const TargetMachine& Target)
|
2003-08-28 15:30:40 +00:00
|
|
|
: SchedGraphNodeCommon(NID,indexInBB), MBB(mbb), MI(mbb ? (*mbb)[indexInBB] : 0) {
|
2003-08-27 02:42:58 +00:00
|
|
|
if (MI) {
|
|
|
|
MachineOpCode mopCode = MI->getOpCode();
|
|
|
|
latency = Target.getInstrInfo().hasResultInterlock(mopCode)
|
|
|
|
? Target.getInstrInfo().minLatency(mopCode)
|
|
|
|
: Target.getInstrInfo().maxLatency(mopCode);
|
|
|
|
}
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
|
|
|
|
2003-08-28 21:43:17 +00:00
|
|
|
//
|
|
|
|
// Method: SchedGraphNode Destructor
|
|
|
|
//
|
|
|
|
// Description:
|
|
|
|
// Free memory allocated by the SchedGraphNode object.
|
|
|
|
//
|
|
|
|
// Notes:
|
|
|
|
// Do not delete the edges here. The base class will take care of that.
|
|
|
|
// Only handle subclass specific stuff here (where currently there is
|
|
|
|
// none).
|
|
|
|
//
|
2003-08-27 02:42:58 +00:00
|
|
|
SchedGraphNode::~SchedGraphNode() {
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// class SchedGraph
|
|
|
|
//
|
2002-10-28 18:50:08 +00:00
|
|
|
SchedGraph::SchedGraph(MachineBasicBlock &mbb, const TargetMachine& target)
|
|
|
|
: MBB(mbb) {
|
2002-01-20 22:54:45 +00:00
|
|
|
buildGraph(target);
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
|
|
|
|
2003-08-28 21:43:17 +00:00
|
|
|
//
|
|
|
|
// Method: SchedGraph Destructor
|
|
|
|
//
|
|
|
|
// Description:
|
|
|
|
// This method deletes memory allocated by the SchedGraph object.
|
|
|
|
//
|
|
|
|
// Notes:
|
|
|
|
// Do not delete the graphRoot or graphLeaf here. The base class handles
|
|
|
|
// that bit of work.
|
|
|
|
//
|
2003-08-27 02:42:58 +00:00
|
|
|
SchedGraph::~SchedGraph() {
|
2002-01-20 22:54:45 +00:00
|
|
|
for (const_iterator I = begin(); I != end(); ++I)
|
2002-04-09 05:15:33 +00:00
|
|
|
delete I->second;
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
|
|
|
|
2003-08-27 02:42:58 +00:00
|
|
|
void SchedGraph::dump() const {
|
2003-05-22 21:24:35 +00:00
|
|
|
std::cerr << " Sched Graph for Basic Block: ";
|
|
|
|
std::cerr << MBB.getBasicBlock()->getName()
|
|
|
|
<< " (" << MBB.getBasicBlock() << ")";
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2003-05-22 21:24:35 +00:00
|
|
|
std::cerr << "\n\n Actual Root nodes : ";
|
2001-08-28 23:06:02 +00:00
|
|
|
for (unsigned i=0, N=graphRoot->outEdges.size(); i < N; i++)
|
2003-05-22 21:24:35 +00:00
|
|
|
std::cerr << graphRoot->outEdges[i]->getSink()->getNodeId()
|
|
|
|
<< ((i == N-1)? "" : ", ");
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2003-05-22 21:24:35 +00:00
|
|
|
std::cerr << "\n Graph Nodes:\n";
|
2001-08-28 23:06:02 +00:00
|
|
|
for (const_iterator I=begin(); I != end(); ++I)
|
2003-05-22 21:24:35 +00:00
|
|
|
std::cerr << "\n" << *I->second;
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2003-05-22 21:24:35 +00:00
|
|
|
std::cerr << "\n";
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-18 12:50:40 +00:00
|
|
|
|
2003-08-27 02:42:58 +00:00
|
|
|
void SchedGraph::addDummyEdges() {
|
2001-08-28 23:06:02 +00:00
|
|
|
assert(graphRoot->outEdges.size() == 0);
|
|
|
|
|
2003-08-27 02:42:58 +00:00
|
|
|
for (const_iterator I=begin(); I != end(); ++I) {
|
2003-05-22 21:49:18 +00:00
|
|
|
SchedGraphNode* node = (*I).second;
|
|
|
|
assert(node != graphRoot && node != graphLeaf);
|
|
|
|
if (node->beginInEdges() == node->endInEdges())
|
|
|
|
(void) new SchedGraphEdge(graphRoot, node, SchedGraphEdge::CtrlDep,
|
|
|
|
SchedGraphEdge::NonDataDep, 0);
|
|
|
|
if (node->beginOutEdges() == node->endOutEdges())
|
|
|
|
(void) new SchedGraphEdge(node, graphLeaf, SchedGraphEdge::CtrlDep,
|
|
|
|
SchedGraphEdge::NonDataDep, 0);
|
|
|
|
}
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-27 02:42:58 +00:00
|
|
|
void SchedGraph::addCDEdges(const TerminatorInst* term,
|
|
|
|
const TargetMachine& target) {
|
2003-01-14 22:00:31 +00:00
|
|
|
const TargetInstrInfo& mii = target.getInstrInfo();
|
2002-02-03 07:29:45 +00:00
|
|
|
MachineCodeForInstruction &termMvec = MachineCodeForInstruction::get(term);
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
// Find the first branch instr in the sequence of machine instrs for term
|
|
|
|
//
|
|
|
|
unsigned first = 0;
|
2002-10-13 00:39:22 +00:00
|
|
|
while (! mii.isBranch(termMvec[first]->getOpCode()) &&
|
|
|
|
! mii.isReturn(termMvec[first]->getOpCode()))
|
2001-08-28 23:06:02 +00:00
|
|
|
++first;
|
|
|
|
assert(first < termMvec.size() &&
|
2002-10-13 00:39:22 +00:00
|
|
|
"No branch instructions for terminator? Ok, but weird!");
|
2001-08-28 23:06:02 +00:00
|
|
|
if (first == termMvec.size())
|
|
|
|
return;
|
2003-08-27 02:42:58 +00:00
|
|
|
|
2002-08-09 18:55:18 +00:00
|
|
|
SchedGraphNode* firstBrNode = getGraphNodeForInstr(termMvec[first]);
|
2003-08-27 02:42:58 +00:00
|
|
|
|
2001-08-28 23:06:02 +00:00
|
|
|
// Add CD edges from each instruction in the sequence to the
|
|
|
|
// *last preceding* branch instr. in the sequence
|
2001-10-28 21:43:33 +00:00
|
|
|
// Use a latency of 0 because we only need to prevent out-of-order issue.
|
2001-08-28 23:06:02 +00:00
|
|
|
//
|
2003-08-27 02:42:58 +00:00
|
|
|
for (unsigned i = termMvec.size(); i > first+1; --i) {
|
2003-05-22 21:49:18 +00:00
|
|
|
SchedGraphNode* toNode = getGraphNodeForInstr(termMvec[i-1]);
|
|
|
|
assert(toNode && "No node for instr generated for branch/ret?");
|
2003-08-27 02:42:58 +00:00
|
|
|
|
2003-05-22 21:49:18 +00:00
|
|
|
for (unsigned j = i-1; j != 0; --j)
|
|
|
|
if (mii.isBranch(termMvec[j-1]->getOpCode()) ||
|
2003-08-27 02:42:58 +00:00
|
|
|
mii.isReturn(termMvec[j-1]->getOpCode())) {
|
2003-05-22 21:49:18 +00:00
|
|
|
SchedGraphNode* brNode = getGraphNodeForInstr(termMvec[j-1]);
|
|
|
|
assert(brNode && "No node for instr generated for branch/ret?");
|
|
|
|
(void) new SchedGraphEdge(brNode, toNode, SchedGraphEdge::CtrlDep,
|
|
|
|
SchedGraphEdge::NonDataDep, 0);
|
|
|
|
break; // only one incoming edge is enough
|
|
|
|
}
|
|
|
|
}
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
// Add CD edges from each instruction preceding the first branch
|
2001-10-28 21:43:33 +00:00
|
|
|
// to the first branch. Use a latency of 0 as above.
|
2001-08-28 23:06:02 +00:00
|
|
|
//
|
2003-08-27 02:42:58 +00:00
|
|
|
for (unsigned i = first; i != 0; --i) {
|
2003-05-22 21:49:18 +00:00
|
|
|
SchedGraphNode* fromNode = getGraphNodeForInstr(termMvec[i-1]);
|
|
|
|
assert(fromNode && "No node for instr generated for branch?");
|
|
|
|
(void) new SchedGraphEdge(fromNode, firstBrNode, SchedGraphEdge::CtrlDep,
|
|
|
|
SchedGraphEdge::NonDataDep, 0);
|
|
|
|
}
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2001-10-28 21:43:33 +00:00
|
|
|
// Now add CD edges to the first branch instruction in the sequence from
|
|
|
|
// all preceding instructions in the basic block. Use 0 latency again.
|
2001-08-28 23:06:02 +00:00
|
|
|
//
|
2003-08-27 02:42:58 +00:00
|
|
|
for (unsigned i=0, N=MBB.size(); i < N; i++) {
|
2003-05-22 21:49:18 +00:00
|
|
|
if (MBB[i] == termMvec[first]) // reached the first branch
|
|
|
|
break;
|
2003-08-27 02:42:58 +00:00
|
|
|
|
2003-05-22 21:49:18 +00:00
|
|
|
SchedGraphNode* fromNode = this->getGraphNodeForInstr(MBB[i]);
|
|
|
|
if (fromNode == NULL)
|
|
|
|
continue; // dummy instruction, e.g., PHI
|
2003-08-27 02:42:58 +00:00
|
|
|
|
2003-05-22 21:49:18 +00:00
|
|
|
(void) new SchedGraphEdge(fromNode, firstBrNode,
|
|
|
|
SchedGraphEdge::CtrlDep,
|
|
|
|
SchedGraphEdge::NonDataDep, 0);
|
2001-11-12 18:53:43 +00:00
|
|
|
|
2003-05-22 21:49:18 +00:00
|
|
|
// If we find any other machine instructions (other than due to
|
|
|
|
// the terminator) that also have delay slots, add an outgoing edge
|
|
|
|
// from the instruction to the instructions in the delay slots.
|
|
|
|
//
|
|
|
|
unsigned d = mii.getNumDelaySlots(MBB[i]->getOpCode());
|
|
|
|
assert(i+d < N && "Insufficient delay slots for instruction?");
|
2001-11-12 18:53:43 +00:00
|
|
|
|
2003-08-27 02:42:58 +00:00
|
|
|
for (unsigned j=1; j <= d; j++) {
|
2003-05-22 21:49:18 +00:00
|
|
|
SchedGraphNode* toNode = this->getGraphNodeForInstr(MBB[i+j]);
|
|
|
|
assert(toNode && "No node for machine instr in delay slot?");
|
|
|
|
(void) new SchedGraphEdge(fromNode, toNode,
|
|
|
|
SchedGraphEdge::CtrlDep,
|
|
|
|
SchedGraphEdge::NonDataDep, 0);
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
2003-05-22 21:49:18 +00:00
|
|
|
}
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
|
|
|
|
2001-10-28 21:43:33 +00:00
|
|
|
static const int SG_LOAD_REF = 0;
|
|
|
|
static const int SG_STORE_REF = 1;
|
|
|
|
static const int SG_CALL_REF = 2;
|
|
|
|
|
|
|
|
static const unsigned int SG_DepOrderArray[][3] = {
|
|
|
|
{ SchedGraphEdge::NonDataDep,
|
2003-08-27 02:42:58 +00:00
|
|
|
SchedGraphEdge::AntiDep,
|
|
|
|
SchedGraphEdge::AntiDep },
|
2001-10-28 21:43:33 +00:00
|
|
|
{ SchedGraphEdge::TrueDep,
|
2003-08-27 02:42:58 +00:00
|
|
|
SchedGraphEdge::OutputDep,
|
|
|
|
SchedGraphEdge::TrueDep | SchedGraphEdge::OutputDep },
|
2001-10-28 21:43:33 +00:00
|
|
|
{ SchedGraphEdge::TrueDep,
|
2003-08-27 02:42:58 +00:00
|
|
|
SchedGraphEdge::AntiDep | SchedGraphEdge::OutputDep,
|
|
|
|
SchedGraphEdge::TrueDep | SchedGraphEdge::AntiDep
|
|
|
|
| SchedGraphEdge::OutputDep }
|
2001-10-28 21:43:33 +00:00
|
|
|
};
|
|
|
|
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2001-11-08 05:20:23 +00:00
|
|
|
// Add a dependence edge between every pair of machine load/store/call
|
|
|
|
// instructions, where at least one is a store or a call.
|
|
|
|
// Use latency 1 just to ensure that memory operations are ordered;
|
|
|
|
// latency does not otherwise matter (true dependences enforce that).
|
|
|
|
//
|
2003-08-27 02:42:58 +00:00
|
|
|
void SchedGraph::addMemEdges(const std::vector<SchedGraphNode*>& memNodeVec,
|
|
|
|
const TargetMachine& target) {
|
2003-01-14 22:00:31 +00:00
|
|
|
const TargetInstrInfo& mii = target.getInstrInfo();
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2001-11-08 05:20:23 +00:00
|
|
|
// Instructions in memNodeVec are in execution order within the basic block,
|
|
|
|
// so simply look at all pairs <memNodeVec[i], memNodeVec[j: j > i]>.
|
|
|
|
//
|
2003-08-27 02:42:58 +00:00
|
|
|
for (unsigned im=0, NM=memNodeVec.size(); im < NM; im++) {
|
2003-05-22 21:49:18 +00:00
|
|
|
MachineOpCode fromOpCode = memNodeVec[im]->getOpCode();
|
2003-05-31 07:37:05 +00:00
|
|
|
int fromType = (mii.isCall(fromOpCode)? SG_CALL_REF
|
|
|
|
: (mii.isLoad(fromOpCode)? SG_LOAD_REF
|
|
|
|
: SG_STORE_REF));
|
2003-08-27 02:42:58 +00:00
|
|
|
for (unsigned jm=im+1; jm < NM; jm++) {
|
2003-05-22 21:49:18 +00:00
|
|
|
MachineOpCode toOpCode = memNodeVec[jm]->getOpCode();
|
2003-05-31 07:37:05 +00:00
|
|
|
int toType = (mii.isCall(toOpCode)? SG_CALL_REF
|
|
|
|
: (mii.isLoad(toOpCode)? SG_LOAD_REF
|
|
|
|
: SG_STORE_REF));
|
2003-08-27 02:42:58 +00:00
|
|
|
|
2003-05-22 21:49:18 +00:00
|
|
|
if (fromType != SG_LOAD_REF || toType != SG_LOAD_REF)
|
|
|
|
(void) new SchedGraphEdge(memNodeVec[im], memNodeVec[jm],
|
|
|
|
SchedGraphEdge::MemoryDep,
|
|
|
|
SG_DepOrderArray[fromType][toType], 1);
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
2003-05-22 21:49:18 +00:00
|
|
|
}
|
2001-11-08 05:20:23 +00:00
|
|
|
}
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2001-11-08 05:20:23 +00:00
|
|
|
// Add edges from/to CC reg instrs to/from call instrs.
|
|
|
|
// Essentially this prevents anything that sets or uses a CC reg from being
|
|
|
|
// reordered w.r.t. a call.
|
|
|
|
// Use a latency of 0 because we only need to prevent out-of-order issue,
|
|
|
|
// like with control dependences.
|
|
|
|
//
|
2003-08-27 02:42:58 +00:00
|
|
|
void SchedGraph::addCallDepEdges(const std::vector<SchedGraphNode*>& callDepNodeVec,
|
|
|
|
const TargetMachine& target) {
|
2003-01-14 22:00:31 +00:00
|
|
|
const TargetInstrInfo& mii = target.getInstrInfo();
|
2001-10-28 21:43:33 +00:00
|
|
|
|
2003-05-31 07:37:05 +00:00
|
|
|
// Instructions in memNodeVec are in execution order within the basic block,
|
|
|
|
// so simply look at all pairs <memNodeVec[i], memNodeVec[j: j > i]>.
|
|
|
|
//
|
|
|
|
for (unsigned ic=0, NC=callDepNodeVec.size(); ic < NC; ic++)
|
2003-08-27 02:42:58 +00:00
|
|
|
if (mii.isCall(callDepNodeVec[ic]->getOpCode())) {
|
|
|
|
// Add SG_CALL_REF edges from all preds to this instruction.
|
|
|
|
for (unsigned jc=0; jc < ic; jc++)
|
|
|
|
(void) new SchedGraphEdge(callDepNodeVec[jc], callDepNodeVec[ic],
|
|
|
|
SchedGraphEdge::MachineRegister,
|
|
|
|
MachineIntRegsRID, 0);
|
|
|
|
|
|
|
|
// And do the same from this instruction to all successors.
|
|
|
|
for (unsigned jc=ic+1; jc < NC; jc++)
|
|
|
|
(void) new SchedGraphEdge(callDepNodeVec[ic], callDepNodeVec[jc],
|
|
|
|
SchedGraphEdge::MachineRegister,
|
|
|
|
MachineIntRegsRID, 0);
|
|
|
|
}
|
2003-05-31 07:37:05 +00:00
|
|
|
|
|
|
|
#ifdef CALL_DEP_NODE_VEC_CANNOT_WORK
|
2001-11-08 05:20:23 +00:00
|
|
|
// Find the call instruction nodes and put them in a vector.
|
2003-05-31 07:37:05 +00:00
|
|
|
std::vector<SchedGraphNode*> callNodeVec;
|
2001-11-08 05:20:23 +00:00
|
|
|
for (unsigned im=0, NM=memNodeVec.size(); im < NM; im++)
|
|
|
|
if (mii.isCall(memNodeVec[im]->getOpCode()))
|
|
|
|
callNodeVec.push_back(memNodeVec[im]);
|
2001-10-28 21:43:33 +00:00
|
|
|
|
2001-11-08 05:20:23 +00:00
|
|
|
// Now walk the entire basic block, looking for CC instructions *and*
|
|
|
|
// call instructions, and keep track of the order of the instructions.
|
|
|
|
// Use the call node vec to quickly find earlier and later call nodes
|
|
|
|
// relative to the current CC instruction.
|
2001-10-28 21:43:33 +00:00
|
|
|
//
|
|
|
|
int lastCallNodeIdx = -1;
|
|
|
|
for (unsigned i=0, N=bbMvec.size(); i < N; i++)
|
2003-08-27 02:42:58 +00:00
|
|
|
if (mii.isCall(bbMvec[i]->getOpCode())) {
|
2003-05-22 21:49:18 +00:00
|
|
|
++lastCallNodeIdx;
|
|
|
|
for ( ; lastCallNodeIdx < (int)callNodeVec.size(); ++lastCallNodeIdx)
|
|
|
|
if (callNodeVec[lastCallNodeIdx]->getMachineInstr() == bbMvec[i])
|
|
|
|
break;
|
|
|
|
assert(lastCallNodeIdx < (int)callNodeVec.size() && "Missed Call?");
|
2003-05-31 07:37:05 +00:00
|
|
|
}
|
2003-08-27 02:42:58 +00:00
|
|
|
else if (mii.isCCInstr(bbMvec[i]->getOpCode())) {
|
2003-05-22 21:49:18 +00:00
|
|
|
// Add incoming/outgoing edges from/to preceding/later calls
|
|
|
|
SchedGraphNode* ccNode = this->getGraphNodeForInstr(bbMvec[i]);
|
|
|
|
int j=0;
|
|
|
|
for ( ; j <= lastCallNodeIdx; j++)
|
|
|
|
(void) new SchedGraphEdge(callNodeVec[j], ccNode,
|
|
|
|
MachineCCRegsRID, 0);
|
|
|
|
for ( ; j < (int) callNodeVec.size(); j++)
|
|
|
|
(void) new SchedGraphEdge(ccNode, callNodeVec[j],
|
|
|
|
MachineCCRegsRID, 0);
|
|
|
|
}
|
2003-05-31 07:37:05 +00:00
|
|
|
#endif
|
2001-10-28 21:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-27 02:42:58 +00:00
|
|
|
void SchedGraph::addMachineRegEdges(RegToRefVecMap& regToRefVecMap,
|
|
|
|
const TargetMachine& target) {
|
2003-05-31 07:37:05 +00:00
|
|
|
// This code assumes that two registers with different numbers are
|
2001-08-28 23:06:02 +00:00
|
|
|
// not aliased!
|
|
|
|
//
|
2001-09-30 23:36:58 +00:00
|
|
|
for (RegToRefVecMap::iterator I = regToRefVecMap.begin();
|
2003-08-27 02:42:58 +00:00
|
|
|
I != regToRefVecMap.end(); ++I) {
|
2003-05-22 21:49:18 +00:00
|
|
|
int regNum = (*I).first;
|
|
|
|
RefVec& regRefVec = (*I).second;
|
2003-08-27 02:42:58 +00:00
|
|
|
|
2003-05-22 21:49:18 +00:00
|
|
|
// regRefVec is ordered by control flow order in the basic block
|
|
|
|
for (unsigned i=0; i < regRefVec.size(); ++i) {
|
|
|
|
SchedGraphNode* node = regRefVec[i].first;
|
|
|
|
unsigned int opNum = regRefVec[i].second;
|
2003-05-31 07:37:05 +00:00
|
|
|
const MachineOperand& mop =
|
|
|
|
node->getMachineInstr()->getExplOrImplOperand(opNum);
|
2003-12-14 13:24:17 +00:00
|
|
|
bool isDef = mop.isDef() && !mop.isUse();
|
|
|
|
bool isDefAndUse = mop.isDef() && mop.isUse();
|
2002-07-08 22:59:23 +00:00
|
|
|
|
2003-05-22 21:49:18 +00:00
|
|
|
for (unsigned p=0; p < i; ++p) {
|
|
|
|
SchedGraphNode* prevNode = regRefVec[p].first;
|
|
|
|
if (prevNode != node) {
|
|
|
|
unsigned int prevOpNum = regRefVec[p].second;
|
2003-05-31 07:37:05 +00:00
|
|
|
const MachineOperand& prevMop =
|
|
|
|
prevNode->getMachineInstr()->getExplOrImplOperand(prevOpNum);
|
2003-12-14 13:24:17 +00:00
|
|
|
bool prevIsDef = prevMop.isDef() && !prevMop.isUse();
|
|
|
|
bool prevIsDefAndUse = prevMop.isDef() && prevMop.isUse();
|
2003-05-22 21:49:18 +00:00
|
|
|
if (isDef) {
|
|
|
|
if (prevIsDef)
|
|
|
|
new SchedGraphEdge(prevNode, node, regNum,
|
|
|
|
SchedGraphEdge::OutputDep);
|
|
|
|
if (!prevIsDef || prevIsDefAndUse)
|
|
|
|
new SchedGraphEdge(prevNode, node, regNum,
|
|
|
|
SchedGraphEdge::AntiDep);
|
|
|
|
}
|
2003-08-27 02:42:58 +00:00
|
|
|
|
2003-05-22 21:49:18 +00:00
|
|
|
if (prevIsDef)
|
|
|
|
if (!isDef || isDefAndUse)
|
|
|
|
new SchedGraphEdge(prevNode, node, regNum,
|
|
|
|
SchedGraphEdge::TrueDep);
|
2001-09-30 23:36:58 +00:00
|
|
|
}
|
2003-05-22 21:49:18 +00:00
|
|
|
}
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
2003-05-22 21:49:18 +00:00
|
|
|
}
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
|
|
|
|
2001-11-05 04:04:23 +00:00
|
|
|
|
2002-07-08 22:59:23 +00:00
|
|
|
// Adds dependences to/from refNode from/to all other defs
|
|
|
|
// in the basic block. refNode may be a use, a def, or both.
|
|
|
|
// We do not consider other uses because we are not building use-use deps.
|
|
|
|
//
|
2003-08-27 02:42:58 +00:00
|
|
|
void SchedGraph::addEdgesForValue(SchedGraphNode* refNode,
|
|
|
|
const RefVec& defVec,
|
|
|
|
const Value* defValue,
|
|
|
|
bool refNodeIsDef,
|
2003-12-14 13:24:17 +00:00
|
|
|
bool refNodeIsUse,
|
2003-08-27 02:42:58 +00:00
|
|
|
const TargetMachine& target) {
|
2001-11-12 18:53:43 +00:00
|
|
|
// Add true or output dep edges from all def nodes before refNode in BB.
|
|
|
|
// Add anti or output dep edges to all def nodes after refNode.
|
2003-08-27 02:42:58 +00:00
|
|
|
for (RefVec::const_iterator I=defVec.begin(), E=defVec.end(); I != E; ++I) {
|
2003-05-22 21:49:18 +00:00
|
|
|
if ((*I).first == refNode)
|
|
|
|
continue; // Dont add any self-loops
|
2003-08-27 02:42:58 +00:00
|
|
|
|
2003-05-22 21:49:18 +00:00
|
|
|
if ((*I).first->getOrigIndexInBB() < refNode->getOrigIndexInBB()) {
|
|
|
|
// (*).first is before refNode
|
2003-12-14 13:24:17 +00:00
|
|
|
if (refNodeIsDef && !refNodeIsUse)
|
2003-05-22 21:49:18 +00:00
|
|
|
(void) new SchedGraphEdge((*I).first, refNode, defValue,
|
|
|
|
SchedGraphEdge::OutputDep);
|
|
|
|
if (refNodeIsUse)
|
|
|
|
(void) new SchedGraphEdge((*I).first, refNode, defValue,
|
|
|
|
SchedGraphEdge::TrueDep);
|
|
|
|
} else {
|
|
|
|
// (*).first is after refNode
|
2003-12-14 13:24:17 +00:00
|
|
|
if (refNodeIsDef && !refNodeIsUse)
|
2003-05-22 21:49:18 +00:00
|
|
|
(void) new SchedGraphEdge(refNode, (*I).first, defValue,
|
|
|
|
SchedGraphEdge::OutputDep);
|
|
|
|
if (refNodeIsUse)
|
|
|
|
(void) new SchedGraphEdge(refNode, (*I).first, defValue,
|
|
|
|
SchedGraphEdge::AntiDep);
|
2001-11-12 18:53:43 +00:00
|
|
|
}
|
2003-05-22 21:49:18 +00:00
|
|
|
}
|
2001-11-05 04:04:23 +00:00
|
|
|
}
|
|
|
|
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2003-08-27 02:42:58 +00:00
|
|
|
void SchedGraph::addEdgesForInstruction(const MachineInstr& MI,
|
|
|
|
const ValueToDefVecMap& valueToDefVecMap,
|
|
|
|
const TargetMachine& target) {
|
2002-10-28 04:45:29 +00:00
|
|
|
SchedGraphNode* node = getGraphNodeForInstr(&MI);
|
2001-09-30 23:36:58 +00:00
|
|
|
if (node == NULL)
|
|
|
|
return;
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2001-09-30 23:36:58 +00:00
|
|
|
// Add edges for all operands of the machine instruction.
|
2001-08-28 23:06:02 +00:00
|
|
|
//
|
2003-08-27 02:42:58 +00:00
|
|
|
for (unsigned i = 0, numOps = MI.getNumOperands(); i != numOps; ++i) {
|
|
|
|
switch (MI.getOperand(i).getType()) {
|
2003-05-22 21:49:18 +00:00
|
|
|
case MachineOperand::MO_VirtualRegister:
|
|
|
|
case MachineOperand::MO_CCRegister:
|
2003-08-27 02:42:58 +00:00
|
|
|
if (const Value* srcI = MI.getOperand(i).getVRegValue()) {
|
2003-05-22 21:49:18 +00:00
|
|
|
ValueToDefVecMap::const_iterator I = valueToDefVecMap.find(srcI);
|
|
|
|
if (I != valueToDefVecMap.end())
|
|
|
|
addEdgesForValue(node, I->second, srcI,
|
2003-12-14 13:24:17 +00:00
|
|
|
MI.getOperand(i).isDef(), MI.getOperand(i).isUse(),
|
|
|
|
target);
|
2003-05-22 21:49:18 +00:00
|
|
|
}
|
|
|
|
break;
|
2003-08-27 02:42:58 +00:00
|
|
|
|
2003-05-22 21:49:18 +00:00
|
|
|
case MachineOperand::MO_MachineRegister:
|
|
|
|
break;
|
2003-08-27 02:42:58 +00:00
|
|
|
|
2003-05-22 21:49:18 +00:00
|
|
|
case MachineOperand::MO_SignExtendedImmed:
|
|
|
|
case MachineOperand::MO_UnextendedImmed:
|
|
|
|
case MachineOperand::MO_PCRelativeDisp:
|
2003-11-06 00:04:11 +00:00
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
2003-05-22 21:49:18 +00:00
|
|
|
break; // nothing to do for immediate fields
|
2003-08-27 02:42:58 +00:00
|
|
|
|
2003-05-22 21:49:18 +00:00
|
|
|
default:
|
|
|
|
assert(0 && "Unknown machine operand type in SchedGraph builder");
|
|
|
|
break;
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
2003-05-22 21:49:18 +00:00
|
|
|
}
|
2001-10-11 04:22:45 +00:00
|
|
|
|
|
|
|
// Add edges for values implicitly used by the machine instruction.
|
|
|
|
// Examples include function arguments to a Call instructions or the return
|
|
|
|
// value of a Ret instruction.
|
2001-09-30 23:36:58 +00:00
|
|
|
//
|
2002-10-28 04:45:29 +00:00
|
|
|
for (unsigned i=0, N=MI.getNumImplicitRefs(); i < N; ++i)
|
2003-12-14 13:24:17 +00:00
|
|
|
if (MI.getImplicitOp(i).isUse())
|
2003-08-27 02:42:58 +00:00
|
|
|
if (const Value* srcI = MI.getImplicitRef(i)) {
|
2003-05-22 21:49:18 +00:00
|
|
|
ValueToDefVecMap::const_iterator I = valueToDefVecMap.find(srcI);
|
|
|
|
if (I != valueToDefVecMap.end())
|
|
|
|
addEdgesForValue(node, I->second, srcI,
|
2003-12-14 13:24:17 +00:00
|
|
|
MI.getImplicitOp(i).isDef(),
|
|
|
|
MI.getImplicitOp(i).isUse(), target);
|
2003-05-22 21:49:18 +00:00
|
|
|
}
|
2001-09-30 23:36:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-27 02:42:58 +00:00
|
|
|
void SchedGraph::findDefUseInfoAtInstr(const TargetMachine& target,
|
|
|
|
SchedGraphNode* node,
|
|
|
|
std::vector<SchedGraphNode*>& memNodeVec,
|
|
|
|
std::vector<SchedGraphNode*>& callDepNodeVec,
|
|
|
|
RegToRefVecMap& regToRefVecMap,
|
|
|
|
ValueToDefVecMap& valueToDefVecMap) {
|
2003-01-14 22:00:31 +00:00
|
|
|
const TargetInstrInfo& mii = target.getInstrInfo();
|
2001-11-05 04:04:23 +00:00
|
|
|
|
2001-11-08 05:20:23 +00:00
|
|
|
MachineOpCode opCode = node->getOpCode();
|
2003-08-27 02:42:58 +00:00
|
|
|
|
2003-05-31 07:37:05 +00:00
|
|
|
if (mii.isCall(opCode) || mii.isCCInstr(opCode))
|
|
|
|
callDepNodeVec.push_back(node);
|
2003-08-27 02:42:58 +00:00
|
|
|
|
2001-11-08 05:20:23 +00:00
|
|
|
if (mii.isLoad(opCode) || mii.isStore(opCode) || mii.isCall(opCode))
|
|
|
|
memNodeVec.push_back(node);
|
|
|
|
|
2001-11-05 04:04:23 +00:00
|
|
|
// Collect the register references and value defs. for explicit operands
|
|
|
|
//
|
2003-08-25 22:42:20 +00:00
|
|
|
const MachineInstr& MI = *node->getMachineInstr();
|
2003-08-27 02:42:58 +00:00
|
|
|
for (int i=0, numOps = (int) MI.getNumOperands(); i < numOps; i++) {
|
2003-08-25 22:42:20 +00:00
|
|
|
const MachineOperand& mop = MI.getOperand(i);
|
2003-08-27 02:42:58 +00:00
|
|
|
|
2003-05-22 21:49:18 +00:00
|
|
|
// if this references a register other than the hardwired
|
|
|
|
// "zero" register, record the reference.
|
2003-08-27 02:42:58 +00:00
|
|
|
if (mop.hasAllocatedReg()) {
|
2003-05-31 07:37:05 +00:00
|
|
|
int regNum = mop.getAllocatedRegNum();
|
2003-08-27 02:42:58 +00:00
|
|
|
|
2003-05-31 07:37:05 +00:00
|
|
|
// If this is not a dummy zero register, record the reference in order
|
2003-05-22 21:49:18 +00:00
|
|
|
if (regNum != target.getRegInfo().getZeroRegNum())
|
2003-05-31 07:37:05 +00:00
|
|
|
regToRefVecMap[mop.getAllocatedRegNum()]
|
2003-05-22 21:49:18 +00:00
|
|
|
.push_back(std::make_pair(node, i));
|
2003-05-31 07:37:05 +00:00
|
|
|
|
|
|
|
// If this is a volatile register, add the instruction to callDepVec
|
|
|
|
// (only if the node is not already on the callDepVec!)
|
|
|
|
if (callDepNodeVec.size() == 0 || callDepNodeVec.back() != node)
|
|
|
|
{
|
|
|
|
unsigned rcid;
|
|
|
|
int regInClass = target.getRegInfo().getClassRegNum(regNum, rcid);
|
|
|
|
if (target.getRegInfo().getMachineRegClass(rcid)
|
|
|
|
->isRegVolatile(regInClass))
|
|
|
|
callDepNodeVec.push_back(node);
|
|
|
|
}
|
|
|
|
|
2003-05-22 21:49:18 +00:00
|
|
|
continue; // nothing more to do
|
|
|
|
}
|
2003-05-31 07:37:05 +00:00
|
|
|
|
2003-05-22 21:49:18 +00:00
|
|
|
// ignore all other non-def operands
|
2003-12-14 13:24:17 +00:00
|
|
|
if (!MI.getOperand(i).isDef())
|
2003-05-22 21:49:18 +00:00
|
|
|
continue;
|
2001-11-05 04:04:23 +00:00
|
|
|
|
2003-05-22 21:49:18 +00:00
|
|
|
// We must be defining a value.
|
|
|
|
assert((mop.getType() == MachineOperand::MO_VirtualRegister ||
|
|
|
|
mop.getType() == MachineOperand::MO_CCRegister)
|
|
|
|
&& "Do not expect any other kind of operand to be defined!");
|
2003-07-02 01:16:01 +00:00
|
|
|
assert(mop.getVRegValue() != NULL && "Null value being defined?");
|
2003-08-27 02:42:58 +00:00
|
|
|
|
2003-07-02 01:16:01 +00:00
|
|
|
valueToDefVecMap[mop.getVRegValue()].push_back(std::make_pair(node, i));
|
2003-05-22 21:49:18 +00:00
|
|
|
}
|
2001-11-08 05:20:23 +00:00
|
|
|
|
2001-11-05 04:04:23 +00:00
|
|
|
//
|
2003-05-31 07:37:05 +00:00
|
|
|
// Collect value defs. for implicit operands. They may have allocated
|
|
|
|
// physical registers also.
|
2001-11-05 04:04:23 +00:00
|
|
|
//
|
2003-08-27 02:42:58 +00:00
|
|
|
for (unsigned i=0, N = MI.getNumImplicitRefs(); i != N; ++i) {
|
2003-08-25 22:42:20 +00:00
|
|
|
const MachineOperand& mop = MI.getImplicitOp(i);
|
2003-08-27 02:42:58 +00:00
|
|
|
if (mop.hasAllocatedReg()) {
|
2003-05-31 07:37:05 +00:00
|
|
|
int regNum = mop.getAllocatedRegNum();
|
|
|
|
if (regNum != target.getRegInfo().getZeroRegNum())
|
|
|
|
regToRefVecMap[mop.getAllocatedRegNum()]
|
2003-08-25 22:42:20 +00:00
|
|
|
.push_back(std::make_pair(node, i + MI.getNumOperands()));
|
2003-05-31 07:37:05 +00:00
|
|
|
continue; // nothing more to do
|
|
|
|
}
|
|
|
|
|
2003-12-14 13:24:17 +00:00
|
|
|
if (mop.isDef()) {
|
2003-08-25 22:42:20 +00:00
|
|
|
assert(MI.getImplicitRef(i) != NULL && "Null value being defined?");
|
2003-12-14 13:24:17 +00:00
|
|
|
valueToDefVecMap[MI.getImplicitRef(i)].push_back(
|
|
|
|
std::make_pair(node, -i));
|
2003-07-02 01:16:01 +00:00
|
|
|
}
|
2003-05-31 07:37:05 +00:00
|
|
|
}
|
2001-11-05 04:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-27 02:42:58 +00:00
|
|
|
void SchedGraph::buildNodesForBB(const TargetMachine& target,
|
|
|
|
MachineBasicBlock& MBB,
|
|
|
|
std::vector<SchedGraphNode*>& memNodeVec,
|
|
|
|
std::vector<SchedGraphNode*>& callDepNodeVec,
|
|
|
|
RegToRefVecMap& regToRefVecMap,
|
|
|
|
ValueToDefVecMap& valueToDefVecMap) {
|
2003-01-14 22:00:31 +00:00
|
|
|
const TargetInstrInfo& mii = target.getInstrInfo();
|
2001-11-11 01:23:27 +00:00
|
|
|
|
|
|
|
// Build graph nodes for each VM instruction and gather def/use info.
|
|
|
|
// Do both those together in a single pass over all machine instructions.
|
2002-10-28 18:50:08 +00:00
|
|
|
for (unsigned i=0; i < MBB.size(); i++)
|
|
|
|
if (!mii.isDummyPhiInstr(MBB[i]->getOpCode())) {
|
|
|
|
SchedGraphNode* node = new SchedGraphNode(getNumNodes(), &MBB, i, target);
|
|
|
|
noteGraphNodeForInstr(MBB[i], node);
|
|
|
|
|
|
|
|
// Remember all register references and value defs
|
2003-05-31 07:37:05 +00:00
|
|
|
findDefUseInfoAtInstr(target, node, memNodeVec, callDepNodeVec,
|
|
|
|
regToRefVecMap, valueToDefVecMap);
|
2002-10-28 18:50:08 +00:00
|
|
|
}
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-27 02:42:58 +00:00
|
|
|
void SchedGraph::buildGraph(const TargetMachine& target) {
|
2001-11-05 04:04:23 +00:00
|
|
|
// Use this data structure to note all machine operands that compute
|
|
|
|
// ordinary LLVM values. These must be computed defs (i.e., instructions).
|
|
|
|
// Note that there may be multiple machine instructions that define
|
|
|
|
// each Value.
|
|
|
|
ValueToDefVecMap valueToDefVecMap;
|
|
|
|
|
2001-11-08 05:20:23 +00:00
|
|
|
// Use this data structure to note all memory instructions.
|
2001-08-28 23:06:02 +00:00
|
|
|
// We use this to add memory dependence edges without a second full walk.
|
2003-05-22 21:24:35 +00:00
|
|
|
std::vector<SchedGraphNode*> memNodeVec;
|
2003-05-31 07:37:05 +00:00
|
|
|
|
|
|
|
// Use this data structure to note all instructions that access physical
|
|
|
|
// registers that can be modified by a call (including call instructions)
|
|
|
|
std::vector<SchedGraphNode*> callDepNodeVec;
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2001-11-05 04:04:23 +00:00
|
|
|
// Use this data structure to note any uses or definitions of
|
2001-08-28 23:06:02 +00:00
|
|
|
// machine registers so we can add edges for those later without
|
|
|
|
// extra passes over the nodes.
|
|
|
|
// The vector holds an ordered list of references to the machine reg,
|
|
|
|
// ordered according to control-flow order. This only works for a
|
|
|
|
// single basic block, hence the assertion. Each reference is identified
|
|
|
|
// by the pair: <node, operand-number>.
|
|
|
|
//
|
2001-09-30 23:36:58 +00:00
|
|
|
RegToRefVecMap regToRefVecMap;
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
// Make a dummy root node. We'll add edges to the real roots later.
|
2002-10-28 18:50:08 +00:00
|
|
|
graphRoot = new SchedGraphNode(0, NULL, -1, target);
|
|
|
|
graphLeaf = new SchedGraphNode(1, NULL, -1, target);
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
2001-09-30 23:36:58 +00:00
|
|
|
// First add nodes for all the machine instructions in the basic block
|
|
|
|
// because this greatly simplifies identifying which edges to add.
|
|
|
|
// Do this one VM instruction at a time since the SchedGraphNode needs that.
|
2001-08-28 23:06:02 +00:00
|
|
|
// Also, remember the load/store instructions to add memory deps later.
|
|
|
|
//----------------------------------------------------------------
|
2002-10-28 18:50:08 +00:00
|
|
|
|
2003-05-31 07:37:05 +00:00
|
|
|
buildNodesForBB(target, MBB, memNodeVec, callDepNodeVec,
|
|
|
|
regToRefVecMap, valueToDefVecMap);
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
2001-09-30 23:36:58 +00:00
|
|
|
// Now add edges for the following (all are incoming edges except (4)):
|
|
|
|
// (1) operands of the machine instruction, including hidden operands
|
|
|
|
// (2) machine register dependences
|
|
|
|
// (3) memory load/store dependences
|
|
|
|
// (3) other resource dependences for the machine instruction, if any
|
|
|
|
// (4) output dependences when multiple machine instructions define the
|
|
|
|
// same value; all must have been generated from a single VM instrn
|
|
|
|
// (5) control dependences to branch instructions generated for the
|
|
|
|
// terminator instruction of the BB. Because of delay slots and
|
|
|
|
// 2-way conditional branches, multiple CD edges are needed
|
|
|
|
// (see addCDEdges for details).
|
|
|
|
// Also, note any uses or defs of machine registers.
|
|
|
|
//
|
2001-08-28 23:06:02 +00:00
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
// First, add edges to the terminator instruction of the basic block.
|
2002-10-28 18:50:08 +00:00
|
|
|
this->addCDEdges(MBB.getBasicBlock()->getTerminator(), target);
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2001-10-28 21:43:33 +00:00
|
|
|
// Then add memory dep edges: store->load, load->store, and store->store.
|
|
|
|
// Call instructions are treated as both load and store.
|
2001-11-08 05:20:23 +00:00
|
|
|
this->addMemEdges(memNodeVec, target);
|
2001-10-28 21:43:33 +00:00
|
|
|
|
|
|
|
// Then add edges between call instructions and CC set/use instructions
|
2003-05-31 07:37:05 +00:00
|
|
|
this->addCallDepEdges(callDepNodeVec, target);
|
2001-10-28 21:43:33 +00:00
|
|
|
|
2001-11-05 04:04:23 +00:00
|
|
|
// Then add incoming def-use (SSA) edges for each machine instruction.
|
2002-10-28 18:50:08 +00:00
|
|
|
for (unsigned i=0, N=MBB.size(); i < N; i++)
|
|
|
|
addEdgesForInstruction(*MBB[i], valueToDefVecMap, target);
|
2001-09-30 23:36:58 +00:00
|
|
|
|
2001-11-12 18:53:43 +00:00
|
|
|
#ifdef NEED_SEPARATE_NONSSA_EDGES_CODE
|
2001-11-05 04:04:23 +00:00
|
|
|
// Then add non-SSA edges for all VM instructions in the block.
|
2001-09-30 23:36:58 +00:00
|
|
|
// We assume that all machine instructions that define a value are
|
|
|
|
// generated from the VM instruction corresponding to that value.
|
2001-11-05 04:04:23 +00:00
|
|
|
// TODO: This could probably be done much more efficiently.
|
2001-09-30 23:36:58 +00:00
|
|
|
for (BasicBlock::const_iterator II = bb->begin(); II != bb->end(); ++II)
|
2001-11-05 04:04:23 +00:00
|
|
|
this->addNonSSAEdgesForValue(*II, target);
|
2001-11-26 18:56:52 +00:00
|
|
|
#endif //NEED_SEPARATE_NONSSA_EDGES_CODE
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
// Then add edges for dependences on machine registers
|
|
|
|
this->addMachineRegEdges(regToRefVecMap, target);
|
|
|
|
|
|
|
|
// Finally, add edges from the dummy root and to dummy leaf
|
|
|
|
this->addDummyEdges();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// class SchedGraphSet
|
|
|
|
//
|
2002-04-07 20:49:59 +00:00
|
|
|
SchedGraphSet::SchedGraphSet(const Function* _function,
|
2001-08-28 23:06:02 +00:00
|
|
|
const TargetMachine& target) :
|
2003-08-27 02:42:58 +00:00
|
|
|
function(_function) {
|
2003-08-25 22:42:20 +00:00
|
|
|
buildGraphsForMethod(function, target);
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
|
|
|
|
2003-08-27 02:42:58 +00:00
|
|
|
SchedGraphSet::~SchedGraphSet() {
|
2001-08-28 23:06:02 +00:00
|
|
|
// delete all the graphs
|
2002-04-09 05:15:33 +00:00
|
|
|
for(iterator I = begin(), E = end(); I != E; ++I)
|
|
|
|
delete *I; // destructor is a friend
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-27 02:42:58 +00:00
|
|
|
void SchedGraphSet::dump() const {
|
2003-08-25 22:42:20 +00:00
|
|
|
std::cerr << "======== Sched graphs for function `" << function->getName()
|
2003-05-22 21:24:35 +00:00
|
|
|
<< "' ========\n\n";
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
for (const_iterator I=begin(); I != end(); ++I)
|
2002-03-24 03:40:59 +00:00
|
|
|
(*I)->dump();
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2003-08-25 22:42:20 +00:00
|
|
|
std::cerr << "\n====== End graphs for function `" << function->getName()
|
2003-05-22 21:24:35 +00:00
|
|
|
<< "' ========\n\n";
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-27 02:42:58 +00:00
|
|
|
void SchedGraphSet::buildGraphsForMethod(const Function *F,
|
|
|
|
const TargetMachine& target) {
|
2002-10-28 18:50:08 +00:00
|
|
|
MachineFunction &MF = MachineFunction::get(F);
|
|
|
|
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
|
|
|
|
addGraph(new SchedGraph(*I, target));
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-27 02:42:58 +00:00
|
|
|
void SchedGraphEdge::print(std::ostream &os) const {
|
|
|
|
os << "edge [" << src->getNodeId() << "] -> ["
|
|
|
|
<< sink->getNodeId() << "] : ";
|
|
|
|
|
|
|
|
switch(depType) {
|
|
|
|
case SchedGraphEdge::CtrlDep:
|
|
|
|
os<< "Control Dep";
|
|
|
|
break;
|
|
|
|
case SchedGraphEdge::ValueDep:
|
|
|
|
os<< "Reg Value " << val;
|
|
|
|
break;
|
|
|
|
case SchedGraphEdge::MemoryDep:
|
|
|
|
os<< "Memory Dep";
|
|
|
|
break;
|
|
|
|
case SchedGraphEdge::MachineRegister:
|
|
|
|
os<< "Reg " << machineRegNum;
|
|
|
|
break;
|
|
|
|
case SchedGraphEdge::MachineResource:
|
|
|
|
os<<"Resource "<< resourceId;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
break;
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
|
|
|
|
2003-08-27 02:42:58 +00:00
|
|
|
os << " : delay = " << minDelay << "\n";
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
|
|
|
|
2003-08-27 02:42:58 +00:00
|
|
|
void SchedGraphNode::print(std::ostream &os) const {
|
2002-01-20 22:54:45 +00:00
|
|
|
os << std::string(8, ' ')
|
2003-08-27 02:42:58 +00:00
|
|
|
<< "Node " << ID << " : "
|
|
|
|
<< "latency = " << latency << "\n" << std::string(12, ' ');
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2003-08-27 02:42:58 +00:00
|
|
|
if (getMachineInstr() == NULL)
|
2002-01-20 22:54:45 +00:00
|
|
|
os << "(Dummy node)\n";
|
2003-05-22 21:49:18 +00:00
|
|
|
else {
|
2003-08-27 02:42:58 +00:00
|
|
|
os << *getMachineInstr() << "\n" << std::string(12, ' ');
|
|
|
|
os << inEdges.size() << " Incoming Edges:\n";
|
|
|
|
for (unsigned i=0, N = inEdges.size(); i < N; i++)
|
|
|
|
os << std::string(16, ' ') << *inEdges[i];
|
2003-05-22 21:49:18 +00:00
|
|
|
|
2003-08-27 02:42:58 +00:00
|
|
|
os << std::string(12, ' ') << outEdges.size()
|
2003-05-22 21:49:18 +00:00
|
|
|
<< " Outgoing Edges:\n";
|
2003-08-27 02:42:58 +00:00
|
|
|
for (unsigned i=0, N= outEdges.size(); i < N; i++)
|
|
|
|
os << std::string(16, ' ') << *outEdges[i];
|
2003-05-22 21:49:18 +00:00
|
|
|
}
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
} // End llvm namespace
|