mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 19:12:56 +02:00
Eliminate most uses of the machine instruction vector for each LLVM instr,
since some m. instr. may be generated by LLVM instrs. in other blocks. Handle non-SSA (anti and output) edges and true edges uniformly by working with machine instructions alone. llvm-svn: 1269
This commit is contained in:
parent
29ad087a83
commit
624846d3fd
@ -65,6 +65,7 @@ SchedGraphEdge::SchedGraphEdge(SchedGraphNode* _src,
|
|||||||
minDelay((_minDelay >= 0)? _minDelay : _src->getLatency()),
|
minDelay((_minDelay >= 0)? _minDelay : _src->getLatency()),
|
||||||
val(NULL)
|
val(NULL)
|
||||||
{
|
{
|
||||||
|
assert(src != sink && "Self-loop in scheduling graph!");
|
||||||
src->addOutEdge(this);
|
src->addOutEdge(this);
|
||||||
sink->addInEdge(this);
|
sink->addInEdge(this);
|
||||||
}
|
}
|
||||||
@ -78,11 +79,12 @@ SchedGraphEdge::SchedGraphEdge(SchedGraphNode* _src,
|
|||||||
int _minDelay)
|
int _minDelay)
|
||||||
: src(_src),
|
: src(_src),
|
||||||
sink(_sink),
|
sink(_sink),
|
||||||
depType(DefUseDep),
|
depType(ValueDep),
|
||||||
depOrderType(_depOrderType),
|
depOrderType(_depOrderType),
|
||||||
minDelay((_minDelay >= 0)? _minDelay : _src->getLatency()),
|
minDelay((_minDelay >= 0)? _minDelay : _src->getLatency()),
|
||||||
val(_val)
|
val(_val)
|
||||||
{
|
{
|
||||||
|
assert(src != sink && "Self-loop in scheduling graph!");
|
||||||
src->addOutEdge(this);
|
src->addOutEdge(this);
|
||||||
sink->addInEdge(this);
|
sink->addInEdge(this);
|
||||||
}
|
}
|
||||||
@ -101,6 +103,7 @@ SchedGraphEdge::SchedGraphEdge(SchedGraphNode* _src,
|
|||||||
minDelay((_minDelay >= 0)? _minDelay : _src->getLatency()),
|
minDelay((_minDelay >= 0)? _minDelay : _src->getLatency()),
|
||||||
machineRegNum(_regNum)
|
machineRegNum(_regNum)
|
||||||
{
|
{
|
||||||
|
assert(src != sink && "Self-loop in scheduling graph!");
|
||||||
src->addOutEdge(this);
|
src->addOutEdge(this);
|
||||||
sink->addInEdge(this);
|
sink->addInEdge(this);
|
||||||
}
|
}
|
||||||
@ -118,6 +121,7 @@ SchedGraphEdge::SchedGraphEdge(SchedGraphNode* _src,
|
|||||||
minDelay((_minDelay >= 0)? _minDelay : _src->getLatency()),
|
minDelay((_minDelay >= 0)? _minDelay : _src->getLatency()),
|
||||||
resourceId(_resourceId)
|
resourceId(_resourceId)
|
||||||
{
|
{
|
||||||
|
assert(src != sink && "Self-loop in scheduling graph!");
|
||||||
src->addOutEdge(this);
|
src->addOutEdge(this);
|
||||||
sink->addInEdge(this);
|
sink->addInEdge(this);
|
||||||
}
|
}
|
||||||
@ -392,41 +396,36 @@ SchedGraph::addCDEdges(const TerminatorInst* term,
|
|||||||
// Now add CD edges to the first branch instruction in the sequence from
|
// Now add CD edges to the first branch instruction in the sequence from
|
||||||
// all preceding instructions in the basic block. Use 0 latency again.
|
// all preceding instructions in the basic block. Use 0 latency again.
|
||||||
//
|
//
|
||||||
const BasicBlock* bb = term->getParent();
|
const BasicBlock* bb = firstBrNode->getBB();
|
||||||
for (BasicBlock::const_iterator II = bb->begin(); II != bb->end(); ++II)
|
const MachineCodeForBasicBlock& mvec = bb->getMachineInstrVec();
|
||||||
|
for (unsigned i=0, N=mvec.size(); i < N; i++)
|
||||||
{
|
{
|
||||||
if ((*II) == (const Instruction*) term) // special case, handled above
|
if (mvec[i] == termMvec[first]) // reached the first branch
|
||||||
continue;
|
break;
|
||||||
|
|
||||||
assert(! (*II)->isTerminator() && "Two terminators in basic block?");
|
SchedGraphNode* fromNode = this->getGraphNodeForInstr(mvec[i]);
|
||||||
|
if (fromNode == NULL)
|
||||||
|
continue; // dummy instruction, e.g., PHI
|
||||||
|
|
||||||
const MachineCodeForVMInstr& mvec = (*II)->getMachineInstrVec();
|
(void) new SchedGraphEdge(fromNode, firstBrNode,
|
||||||
for (unsigned i=0, N=mvec.size(); i < N; i++)
|
SchedGraphEdge::CtrlDep,
|
||||||
{
|
SchedGraphEdge::NonDataDep, 0);
|
||||||
SchedGraphNode* fromNode = this->getGraphNodeForInstr(mvec[i]);
|
|
||||||
if (fromNode == NULL)
|
|
||||||
continue; // dummy instruction, e.g., PHI
|
|
||||||
|
|
||||||
(void) new SchedGraphEdge(fromNode, firstBrNode,
|
// If we find any other machine instructions (other than due to
|
||||||
SchedGraphEdge::CtrlDep,
|
// the terminator) that also have delay slots, add an outgoing edge
|
||||||
SchedGraphEdge::NonDataDep, 0);
|
// from the instruction to the instructions in the delay slots.
|
||||||
|
//
|
||||||
|
unsigned d = mii.getNumDelaySlots(mvec[i]->getOpCode());
|
||||||
|
assert(i+d < N && "Insufficient delay slots for instruction?");
|
||||||
|
|
||||||
// If we find any other machine instructions (other than due to
|
for (unsigned j=1; j <= d; j++)
|
||||||
// the terminator) that also have delay slots, add an outgoing edge
|
{
|
||||||
// from the instruction to the instructions in the delay slots.
|
SchedGraphNode* toNode = this->getGraphNodeForInstr(mvec[i+j]);
|
||||||
//
|
assert(toNode && "No node for machine instr in delay slot?");
|
||||||
unsigned d = mii.getNumDelaySlots(mvec[i]->getOpCode());
|
(void) new SchedGraphEdge(fromNode, toNode,
|
||||||
assert(i+d < N && "Insufficient delay slots for instruction?");
|
SchedGraphEdge::CtrlDep,
|
||||||
|
SchedGraphEdge::NonDataDep, 0);
|
||||||
for (unsigned j=1; j <= d; j++)
|
}
|
||||||
{
|
|
||||||
SchedGraphNode* toNode = this->getGraphNodeForInstr(mvec[i+j]);
|
|
||||||
assert(toNode && "No node for machine instr in delay slot?");
|
|
||||||
(void) new SchedGraphEdge(fromNode, toNode,
|
|
||||||
SchedGraphEdge::CtrlDep,
|
|
||||||
SchedGraphEdge::NonDataDep, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -580,17 +579,30 @@ SchedGraph::addMachineRegEdges(RegToRefVecMap& regToRefVecMap,
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SchedGraph::addSSAEdge(SchedGraphNode* destNode,
|
SchedGraph::addEdgesForValue(SchedGraphNode* refNode,
|
||||||
const RefVec& defVec,
|
const RefVec& defVec,
|
||||||
const Value* defValue,
|
const Value* defValue,
|
||||||
const TargetMachine& target)
|
bool refNodeIsDef,
|
||||||
|
const TargetMachine& target)
|
||||||
{
|
{
|
||||||
// Add edges from all def nodes that are before destNode in the BB.
|
// Add true or output dep edges from all def nodes before refNode in BB.
|
||||||
// BIGTIME FIXME:
|
// Add anti or output dep edges to all def nodes after refNode.
|
||||||
// We could probably add non-SSA edges here too! But I'll do that later.
|
|
||||||
for (RefVec::const_iterator I=defVec.begin(), E=defVec.end(); I != E; ++I)
|
for (RefVec::const_iterator I=defVec.begin(), E=defVec.end(); I != E; ++I)
|
||||||
if ((*I).first->getOrigIndexInBB() < destNode->getOrigIndexInBB())
|
{
|
||||||
(void) new SchedGraphEdge((*I).first, destNode, defValue);
|
if ((*I).first == refNode)
|
||||||
|
continue; // Dont add any self-loops
|
||||||
|
|
||||||
|
if ((*I).first->getOrigIndexInBB() < refNode->getOrigIndexInBB())
|
||||||
|
// (*).first is before refNode
|
||||||
|
(void) new SchedGraphEdge((*I).first, refNode, defValue,
|
||||||
|
(refNodeIsDef)? SchedGraphEdge::OutputDep
|
||||||
|
: SchedGraphEdge::TrueDep);
|
||||||
|
else
|
||||||
|
// (*).first is after refNode
|
||||||
|
(void) new SchedGraphEdge(refNode, (*I).first, defValue,
|
||||||
|
(refNodeIsDef)? SchedGraphEdge::OutputDep
|
||||||
|
: SchedGraphEdge::AntiDep);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -607,12 +619,7 @@ SchedGraph::addEdgesForInstruction(const MachineInstr& minstr,
|
|||||||
//
|
//
|
||||||
for (unsigned i=0, numOps=minstr.getNumOperands(); i < numOps; i++)
|
for (unsigned i=0, numOps=minstr.getNumOperands(); i < numOps; i++)
|
||||||
{
|
{
|
||||||
// ignore def operands here
|
|
||||||
if (minstr.operandIsDefined(i))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
const MachineOperand& mop = minstr.getOperand(i);
|
const MachineOperand& mop = minstr.getOperand(i);
|
||||||
|
|
||||||
switch(mop.getOperandType())
|
switch(mop.getOperandType())
|
||||||
{
|
{
|
||||||
case MachineOperand::MO_VirtualRegister:
|
case MachineOperand::MO_VirtualRegister:
|
||||||
@ -622,7 +629,8 @@ SchedGraph::addEdgesForInstruction(const MachineInstr& minstr,
|
|||||||
{
|
{
|
||||||
ValueToDefVecMap::const_iterator I = valueToDefVecMap.find(srcI);
|
ValueToDefVecMap::const_iterator I = valueToDefVecMap.find(srcI);
|
||||||
if (I != valueToDefVecMap.end())
|
if (I != valueToDefVecMap.end())
|
||||||
addSSAEdge(node, (*I).second, mop.getVRegValue(), target);
|
addEdgesForValue(node, (*I).second, mop.getVRegValue(),
|
||||||
|
minstr.operandIsDefined(i), target);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -651,11 +659,14 @@ SchedGraph::addEdgesForInstruction(const MachineInstr& minstr,
|
|||||||
{
|
{
|
||||||
ValueToDefVecMap::const_iterator I = valueToDefVecMap.find(srcI);
|
ValueToDefVecMap::const_iterator I = valueToDefVecMap.find(srcI);
|
||||||
if (I != valueToDefVecMap.end())
|
if (I != valueToDefVecMap.end())
|
||||||
addSSAEdge(node, (*I).second, minstr.getImplicitRef(i), target);
|
addEdgesForValue(node, (*I).second, minstr.getImplicitRef(i),
|
||||||
|
minstr.implicitRefIsDefined(i), target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#undef NEED_SEPARATE_NONSSA_EDGES_CODE
|
||||||
|
#ifdef NEED_SEPARATE_NONSSA_EDGES_CODE
|
||||||
void
|
void
|
||||||
SchedGraph::addNonSSAEdgesForValue(const Instruction* instr,
|
SchedGraph::addNonSSAEdgesForValue(const Instruction* instr,
|
||||||
const TargetMachine& target)
|
const TargetMachine& target)
|
||||||
@ -699,13 +710,14 @@ SchedGraph::addNonSSAEdgesForValue(const Instruction* instr,
|
|||||||
{
|
{
|
||||||
bool prevIsDef = prevNode->getMachineInstr()->
|
bool prevIsDef = prevNode->getMachineInstr()->
|
||||||
operandIsDefined(refVec[p].second);
|
operandIsDefined(refVec[p].second);
|
||||||
new SchedGraphEdge(prevNode, node, SchedGraphEdge::DefUseDep,
|
new SchedGraphEdge(prevNode, node, SchedGraphEdge::ValueDep,
|
||||||
(prevIsDef)? SchedGraphEdge::OutputDep
|
(prevIsDef)? SchedGraphEdge::OutputDep
|
||||||
: SchedGraphEdge::AntiDep);
|
: SchedGraphEdge::AntiDep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif NEED_SEPARATE_NONSSA_EDGES_CODE
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -920,12 +932,14 @@ SchedGraph::buildGraph(const TargetMachine& target)
|
|||||||
for (unsigned i=0, N=bbMvec.size(); i < N; i++)
|
for (unsigned i=0, N=bbMvec.size(); i < N; i++)
|
||||||
addEdgesForInstruction(*bbMvec[i], valueToDefVecMap, target);
|
addEdgesForInstruction(*bbMvec[i], valueToDefVecMap, target);
|
||||||
|
|
||||||
|
#ifdef NEED_SEPARATE_NONSSA_EDGES_CODE
|
||||||
// Then add non-SSA edges for all VM instructions in the block.
|
// Then add non-SSA edges for all VM instructions in the block.
|
||||||
// We assume that all machine instructions that define a value are
|
// We assume that all machine instructions that define a value are
|
||||||
// generated from the VM instruction corresponding to that value.
|
// generated from the VM instruction corresponding to that value.
|
||||||
// TODO: This could probably be done much more efficiently.
|
// TODO: This could probably be done much more efficiently.
|
||||||
for (BasicBlock::const_iterator II = bb->begin(); II != bb->end(); ++II)
|
for (BasicBlock::const_iterator II = bb->begin(); II != bb->end(); ++II)
|
||||||
this->addNonSSAEdgesForValue(*II, target);
|
this->addNonSSAEdgesForValue(*II, target);
|
||||||
|
#endif NEED_SEPARATE_NONSSA_EDGES_CODE
|
||||||
|
|
||||||
// Then add edges for dependences on machine registers
|
// Then add edges for dependences on machine registers
|
||||||
this->addMachineRegEdges(regToRefVecMap, target);
|
this->addMachineRegEdges(regToRefVecMap, target);
|
||||||
@ -994,8 +1008,8 @@ operator<<(ostream& os, const SchedGraphEdge& edge)
|
|||||||
|
|
||||||
switch(edge.depType) {
|
switch(edge.depType) {
|
||||||
case SchedGraphEdge::CtrlDep: os<< "Control Dep"; break;
|
case SchedGraphEdge::CtrlDep: os<< "Control Dep"; break;
|
||||||
case SchedGraphEdge::DefUseDep: os<< "Reg Value " << edge.val; break;
|
case SchedGraphEdge::ValueDep: os<< "Reg Value " << edge.val; break;
|
||||||
case SchedGraphEdge::MemoryDep: os<< "Mem Value " << edge.val; break;
|
case SchedGraphEdge::MemoryDep: os<< "Memory Dep"; break;
|
||||||
case SchedGraphEdge::MachineRegister: os<< "Reg " <<edge.machineRegNum;break;
|
case SchedGraphEdge::MachineRegister: os<< "Reg " <<edge.machineRegNum;break;
|
||||||
case SchedGraphEdge::MachineResource: os<<"Resource "<<edge.resourceId;break;
|
case SchedGraphEdge::MachineResource: os<<"Resource "<<edge.resourceId;break;
|
||||||
default: assert(0); break;
|
default: assert(0); break;
|
||||||
|
@ -56,7 +56,7 @@ const ResourceId MachineFPRegsRID = -4; // use +ve numbers for actual regs
|
|||||||
class SchedGraphEdge: public NonCopyable {
|
class SchedGraphEdge: public NonCopyable {
|
||||||
public:
|
public:
|
||||||
enum SchedGraphEdgeDepType {
|
enum SchedGraphEdgeDepType {
|
||||||
CtrlDep, MemoryDep, DefUseDep, MachineRegister, MachineResource
|
CtrlDep, MemoryDep, ValueDep, MachineRegister, MachineResource
|
||||||
};
|
};
|
||||||
enum DataDepOrderType {
|
enum DataDepOrderType {
|
||||||
TrueDep = 0x1, AntiDep=0x2, OutputDep=0x4, NonDataDep=0x8
|
TrueDep = 0x1, AntiDep=0x2, OutputDep=0x4, NonDataDep=0x8
|
||||||
@ -82,21 +82,21 @@ public:
|
|||||||
/*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
|
/*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
|
||||||
SchedGraphNode* _sink,
|
SchedGraphNode* _sink,
|
||||||
SchedGraphEdgeDepType _depType,
|
SchedGraphEdgeDepType _depType,
|
||||||
unsigned int _depOrderType =TrueDep,
|
unsigned int _depOrderType,
|
||||||
int _minDelay = -1);
|
int _minDelay = -1);
|
||||||
|
|
||||||
// constructor for explicit def-use or memory def-use edge
|
// constructor for explicit value dependence (may be true/anti/output)
|
||||||
/*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
|
/*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
|
||||||
SchedGraphNode* _sink,
|
SchedGraphNode* _sink,
|
||||||
const Value* _val,
|
const Value* _val,
|
||||||
unsigned int _depOrderType =TrueDep,
|
unsigned int _depOrderType,
|
||||||
int _minDelay = -1);
|
int _minDelay = -1);
|
||||||
|
|
||||||
// constructor for machine register dependence
|
// constructor for machine register dependence
|
||||||
/*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
|
/*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
|
||||||
SchedGraphNode* _sink,
|
SchedGraphNode* _sink,
|
||||||
unsigned int _regNum,
|
unsigned int _regNum,
|
||||||
unsigned int _depOrderType =TrueDep,
|
unsigned int _depOrderType,
|
||||||
int _minDelay = -1);
|
int _minDelay = -1);
|
||||||
|
|
||||||
// constructor for any other machine resource dependences.
|
// constructor for any other machine resource dependences.
|
||||||
@ -115,7 +115,7 @@ public:
|
|||||||
SchedGraphEdgeDepType getDepType () const { return depType; }
|
SchedGraphEdgeDepType getDepType () const { return depType; }
|
||||||
|
|
||||||
const Value* getValue () const {
|
const Value* getValue () const {
|
||||||
assert(depType == DefUseDep || depType == MemoryDep); return val;
|
assert(depType == ValueDep); return val;
|
||||||
}
|
}
|
||||||
int getMachineReg () const {
|
int getMachineReg () const {
|
||||||
assert(depType == MachineRegister); return machineRegNum;
|
assert(depType == MachineRegister); return machineRegNum;
|
||||||
@ -335,12 +335,10 @@ private:
|
|||||||
void addMachineRegEdges (RegToRefVecMap& regToRefVecMap,
|
void addMachineRegEdges (RegToRefVecMap& regToRefVecMap,
|
||||||
const TargetMachine& target);
|
const TargetMachine& target);
|
||||||
|
|
||||||
void addSSAEdge (SchedGraphNode* node,
|
void addEdgesForValue (SchedGraphNode* refNode,
|
||||||
const RefVec& defVec,
|
const RefVec& defVec,
|
||||||
const Value* defValue,
|
const Value* defValue,
|
||||||
const TargetMachine& target);
|
bool refNodeIsDef,
|
||||||
|
|
||||||
void addNonSSAEdgesForValue (const Instruction* instr,
|
|
||||||
const TargetMachine& target);
|
const TargetMachine& target);
|
||||||
|
|
||||||
void addDummyEdges ();
|
void addDummyEdges ();
|
||||||
|
Loading…
Reference in New Issue
Block a user