Remove ScheduleDAG's SUnitMap altogether. Instead, use SDNode's NodeId

field, which is otherwise unused after instruction selection, as an index
into the SUnit array.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52583 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2008-06-21 19:18:17 +00:00
parent 3627e34486
commit 94d7a5f815
5 changed files with 39 additions and 53 deletions

View File

@ -214,8 +214,7 @@ namespace llvm {
public: public:
virtual ~SchedulingPriorityQueue() {} virtual ~SchedulingPriorityQueue() {}
virtual void initNodes(DenseMap<SDNode*, SUnit*> &SUMap, virtual void initNodes(std::vector<SUnit> &SUnits) = 0;
std::vector<SUnit> &SUnits) = 0;
virtual void addNode(const SUnit *SU) = 0; virtual void addNode(const SUnit *SU) = 0;
virtual void updateNode(const SUnit *SU) = 0; virtual void updateNode(const SUnit *SU) = 0;
virtual void releaseState() = 0; virtual void releaseState() = 0;
@ -250,7 +249,6 @@ namespace llvm {
MachineConstantPool *ConstPool; // Target constant pool MachineConstantPool *ConstPool; // Target constant pool
std::vector<SUnit*> Sequence; // The schedule. Null SUnit*'s std::vector<SUnit*> Sequence; // The schedule. Null SUnit*'s
// represent noop instructions. // represent noop instructions.
DenseMap<SDNode*, SUnit*> SUnitMap; // SDNode to SUnit mapping (n -> n).
std::vector<SUnit> SUnits; // The scheduling units. std::vector<SUnit> SUnits; // The scheduling units.
SmallSet<SDNode*, 16> CommuteSet; // Nodes that should be commuted. SmallSet<SDNode*, 16> CommuteSet; // Nodes that should be commuted.

View File

@ -97,13 +97,20 @@ void ScheduleDAG::BuildSchedUnits() {
// invalidated. // invalidated.
SUnits.reserve(DAG.allnodes_size()); SUnits.reserve(DAG.allnodes_size());
// During scheduling, the NodeId field of SDNode is used to map SDNodes
// to their associated SUnits by holding SUnits table indices. A value
// of -1 means the SDNode does not yet have an associated SUnit.
for (SelectionDAG::allnodes_iterator NI = DAG.allnodes_begin(),
E = DAG.allnodes_end(); NI != E; ++NI)
NI->setNodeId(-1);
for (SelectionDAG::allnodes_iterator NI = DAG.allnodes_begin(), for (SelectionDAG::allnodes_iterator NI = DAG.allnodes_begin(),
E = DAG.allnodes_end(); NI != E; ++NI) { E = DAG.allnodes_end(); NI != E; ++NI) {
if (isPassiveNode(NI)) // Leaf node, e.g. a TargetImmediate. if (isPassiveNode(NI)) // Leaf node, e.g. a TargetImmediate.
continue; continue;
// If this node has already been processed, stop now. // If this node has already been processed, stop now.
if (SUnitMap.count(NI)) continue; if (NI->getNodeId() != -1) continue;
SUnit *NodeSUnit = NewSUnit(NI); SUnit *NodeSUnit = NewSUnit(NI);
@ -118,9 +125,8 @@ void ScheduleDAG::BuildSchedUnits() {
do { do {
N = N->getOperand(N->getNumOperands()-1).Val; N = N->getOperand(N->getNumOperands()-1).Val;
NodeSUnit->FlaggedNodes.push_back(N); NodeSUnit->FlaggedNodes.push_back(N);
bool isNew = SUnitMap.insert(std::make_pair(N, NodeSUnit)); assert(N->getNodeId() == -1 && "Node already inserted!");
isNew = isNew; N->setNodeId(NodeSUnit->NodeNum);
assert(isNew && "Node already inserted!");
} while (N->getNumOperands() && } while (N->getNumOperands() &&
N->getOperand(N->getNumOperands()-1).getValueType()== MVT::Flag); N->getOperand(N->getNumOperands()-1).getValueType()== MVT::Flag);
std::reverse(NodeSUnit->FlaggedNodes.begin(), std::reverse(NodeSUnit->FlaggedNodes.begin(),
@ -140,9 +146,8 @@ void ScheduleDAG::BuildSchedUnits() {
if (FlagVal.isOperandOf(UI->getUser())) { if (FlagVal.isOperandOf(UI->getUser())) {
HasFlagUse = true; HasFlagUse = true;
NodeSUnit->FlaggedNodes.push_back(N); NodeSUnit->FlaggedNodes.push_back(N);
bool isNew = SUnitMap.insert(std::make_pair(N, NodeSUnit)); assert(N->getNodeId() == -1 && "Node already inserted!");
isNew = isNew; N->setNodeId(NodeSUnit->NodeNum);
assert(isNew && "Node already inserted!");
N = UI->getUser(); N = UI->getUser();
break; break;
} }
@ -152,9 +157,8 @@ void ScheduleDAG::BuildSchedUnits() {
// Now all flagged nodes are in FlaggedNodes and N is the bottom-most node. // Now all flagged nodes are in FlaggedNodes and N is the bottom-most node.
// Update the SUnit // Update the SUnit
NodeSUnit->Node = N; NodeSUnit->Node = N;
bool isNew = SUnitMap.insert(std::make_pair(N, NodeSUnit)); assert(N->getNodeId() == -1 && "Node already inserted!");
isNew = isNew; N->setNodeId(NodeSUnit->NodeNum);
assert(isNew && "Node already inserted!");
ComputeLatency(NodeSUnit); ComputeLatency(NodeSUnit);
} }
@ -191,7 +195,7 @@ void ScheduleDAG::BuildSchedUnits() {
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
SDNode *OpN = N->getOperand(i).Val; SDNode *OpN = N->getOperand(i).Val;
if (isPassiveNode(OpN)) continue; // Not scheduled. if (isPassiveNode(OpN)) continue; // Not scheduled.
SUnit *OpSU = SUnitMap[OpN]; SUnit *OpSU = &SUnits[OpN->getNodeId()];
assert(OpSU && "Node has no SUnit!"); assert(OpSU && "Node has no SUnit!");
if (OpSU == SU) continue; // In the same group. if (OpSU == SU) continue; // In the same group.

View File

@ -94,7 +94,7 @@ void ScheduleDAGList::Schedule() {
// Build scheduling units. // Build scheduling units.
BuildSchedUnits(); BuildSchedUnits();
AvailableQueue->initNodes(SUnitMap, SUnits); AvailableQueue->initNodes(SUnits);
ListScheduleTopDown(); ListScheduleTopDown();
@ -320,8 +320,7 @@ public:
LatencyPriorityQueue() : Queue(latency_sort(this)) { LatencyPriorityQueue() : Queue(latency_sort(this)) {
} }
void initNodes(DenseMap<SDNode*, SUnit*> &sumap, void initNodes(std::vector<SUnit> &sunits) {
std::vector<SUnit> &sunits) {
SUnits = &sunits; SUnits = &sunits;
// Calculate node priorities. // Calculate node priorities.
CalculatePriorities(); CalculatePriorities();

View File

@ -216,7 +216,7 @@ void ScheduleDAGRRList::Schedule() {
CalculateHeights(); CalculateHeights();
InitDAGTopologicalSorting(); InitDAGTopologicalSorting();
AvailableQueue->initNodes(SUnitMap, SUnits); AvailableQueue->initNodes(SUnits);
// Execute the actual scheduling loop Top-Down or Bottom-Up as appropriate. // Execute the actual scheduling loop Top-Down or Bottom-Up as appropriate.
if (isBottomUp) if (isBottomUp)
@ -255,7 +255,7 @@ void ScheduleDAGRRList::CommuteNodesToReducePressure() {
continue; continue;
SDNode *OpN = SU->Node->getOperand(j).Val; SDNode *OpN = SU->Node->getOperand(j).Val;
SUnit *OpSU = isPassiveNode(OpN) ? NULL : SUnitMap[OpN]; SUnit *OpSU = isPassiveNode(OpN) ? NULL : &SUnits[OpN->getNodeId()];
if (OpSU && OperandSeen.count(OpSU) == 1) { if (OpSU && OperandSeen.count(OpSU) == 1) {
// Ok, so SU is not the last use of OpSU, but SU is two-address so // Ok, so SU is not the last use of OpSU, but SU is two-address so
// it will clobber OpSU. Try to commute SU if no other source operands // it will clobber OpSU. Try to commute SU if no other source operands
@ -264,7 +264,7 @@ void ScheduleDAGRRList::CommuteNodesToReducePressure() {
for (unsigned k = 0; k < NumOps; ++k) { for (unsigned k = 0; k < NumOps; ++k) {
if (k != j) { if (k != j) {
OpN = SU->Node->getOperand(k).Val; OpN = SU->Node->getOperand(k).Val;
OpSU = isPassiveNode(OpN) ? NULL : SUnitMap[OpN]; OpSU = isPassiveNode(OpN) ? NULL : &SUnits[OpN->getNodeId()];
if (OpSU && OperandSeen.count(OpSU) == 1) { if (OpSU && OperandSeen.count(OpSU) == 1) {
DoCommute = false; DoCommute = false;
break; break;
@ -678,9 +678,8 @@ SUnit *ScheduleDAGRRList::CopyAndMoveSuccessors(SUnit *SU) {
SDOperand(LoadNode, 1)); SDOperand(LoadNode, 1));
SUnit *NewSU = CreateNewSUnit(N); SUnit *NewSU = CreateNewSUnit(N);
bool isNew = SUnitMap.insert(std::make_pair(N, NewSU)); assert(N->getNodeId() == -1 && "Node already inserted!");
isNew = isNew; N->setNodeId(NewSU->NodeNum);
assert(isNew && "Node already inserted!");
const TargetInstrDesc &TID = TII->get(N->getTargetOpcode()); const TargetInstrDesc &TID = TII->get(N->getTargetOpcode());
for (unsigned i = 0; i != TID.getNumOperands(); ++i) { for (unsigned i = 0; i != TID.getNumOperands(); ++i) {
@ -701,15 +700,12 @@ SUnit *ScheduleDAGRRList::CopyAndMoveSuccessors(SUnit *SU) {
// but it has different alignment or volatileness. // but it has different alignment or volatileness.
bool isNewLoad = true; bool isNewLoad = true;
SUnit *LoadSU; SUnit *LoadSU;
DenseMap<SDNode*, SUnit*>::iterator SMI = SUnitMap.find(LoadNode); if (LoadNode->getNodeId() != -1) {
if (SMI != SUnitMap.end()) { LoadSU = &SUnits[LoadNode->getNodeId()];
LoadSU = SMI->second;
isNewLoad = false; isNewLoad = false;
} else { } else {
LoadSU = CreateNewSUnit(LoadNode); LoadSU = CreateNewSUnit(LoadNode);
bool isNew = SUnitMap.insert(std::make_pair(LoadNode, LoadSU)); LoadNode->setNodeId(LoadSU->NodeNum);
isNew = isNew;
assert(isNew && "Node already inserted!");
LoadSU->Depth = SU->Depth; LoadSU->Depth = SU->Depth;
LoadSU->Height = SU->Height; LoadSU->Height = SU->Height;
@ -948,7 +944,7 @@ void ScheduleDAGRRList::ListScheduleBottomUp() {
unsigned CurCycle = 0; unsigned CurCycle = 0;
// Add root to Available queue. // Add root to Available queue.
if (!SUnits.empty()) { if (!SUnits.empty()) {
SUnit *RootSU = SUnitMap[DAG.getRoot().Val]; SUnit *RootSU = &SUnits[DAG.getRoot().Val->getNodeId()];
assert(RootSU->Succs.empty() && "Graph root shouldn't have successors!"); assert(RootSU->Succs.empty() && "Graph root shouldn't have successors!");
RootSU->isAvailable = true; RootSU->isAvailable = true;
AvailableQueue->push(RootSU); AvailableQueue->push(RootSU);
@ -1284,8 +1280,7 @@ namespace {
RegReductionPriorityQueue() : RegReductionPriorityQueue() :
Queue(SF(this)), currentQueueId(0) {} Queue(SF(this)), currentQueueId(0) {}
virtual void initNodes(DenseMap<SDNode*, SUnit*> &sumap, virtual void initNodes(std::vector<SUnit> &sunits) {}
std::vector<SUnit> &sunits) {}
virtual void addNode(const SUnit *SU) {} virtual void addNode(const SUnit *SU) {}
@ -1330,9 +1325,6 @@ namespace {
class VISIBILITY_HIDDEN BURegReductionPriorityQueue class VISIBILITY_HIDDEN BURegReductionPriorityQueue
: public RegReductionPriorityQueue<bu_ls_rr_sort> { : public RegReductionPriorityQueue<bu_ls_rr_sort> {
// SUnitMap SDNode to SUnit mapping (n -> n).
DenseMap<SDNode*, SUnit*> *SUnitMap;
// SUnits - The SUnits for the current graph. // SUnits - The SUnits for the current graph.
const std::vector<SUnit> *SUnits; const std::vector<SUnit> *SUnits;
@ -1347,9 +1339,7 @@ namespace {
const TargetRegisterInfo *tri) const TargetRegisterInfo *tri)
: TII(tii), TRI(tri), scheduleDAG(NULL) {} : TII(tii), TRI(tri), scheduleDAG(NULL) {}
void initNodes(DenseMap<SDNode*, SUnit*> &sumap, void initNodes(std::vector<SUnit> &sunits) {
std::vector<SUnit> &sunits) {
SUnitMap = &sumap;
SUnits = &sunits; SUnits = &sunits;
// Add pseudo dependency edges for two-address nodes. // Add pseudo dependency edges for two-address nodes.
AddPseudoTwoAddrDeps(); AddPseudoTwoAddrDeps();
@ -1417,9 +1407,6 @@ namespace {
class VISIBILITY_HIDDEN TDRegReductionPriorityQueue class VISIBILITY_HIDDEN TDRegReductionPriorityQueue
: public RegReductionPriorityQueue<td_ls_rr_sort> { : public RegReductionPriorityQueue<td_ls_rr_sort> {
// SUnitMap SDNode to SUnit mapping (n -> n).
DenseMap<SDNode*, SUnit*> *SUnitMap;
// SUnits - The SUnits for the current graph. // SUnits - The SUnits for the current graph.
const std::vector<SUnit> *SUnits; const std::vector<SUnit> *SUnits;
@ -1429,9 +1416,7 @@ namespace {
public: public:
TDRegReductionPriorityQueue() {} TDRegReductionPriorityQueue() {}
void initNodes(DenseMap<SDNode*, SUnit*> &sumap, void initNodes(std::vector<SUnit> &sunits) {
std::vector<SUnit> &sunits) {
SUnitMap = &sumap;
SUnits = &sunits; SUnits = &sunits;
// Calculate node priorities. // Calculate node priorities.
CalculateSethiUllmanNumbers(); CalculateSethiUllmanNumbers();
@ -1563,8 +1548,8 @@ BURegReductionPriorityQueue::canClobber(const SUnit *SU, const SUnit *Op) {
for (unsigned i = 0; i != NumOps; ++i) { for (unsigned i = 0; i != NumOps; ++i) {
if (TID.getOperandConstraint(i+NumRes, TOI::TIED_TO) != -1) { if (TID.getOperandConstraint(i+NumRes, TOI::TIED_TO) != -1) {
SDNode *DU = SU->Node->getOperand(i).Val; SDNode *DU = SU->Node->getOperand(i).Val;
if ((*SUnitMap).find(DU) != (*SUnitMap).end() && if (DU->getNodeId() != -1 &&
Op->OrigNode == (*SUnitMap)[DU]) Op->OrigNode == &(*SUnits)[DU->getNodeId()])
return true; return true;
} }
} }
@ -1638,12 +1623,12 @@ void BURegReductionPriorityQueue::AddPseudoTwoAddrDeps() {
for (unsigned j = 0; j != NumOps; ++j) { for (unsigned j = 0; j != NumOps; ++j) {
if (TID.getOperandConstraint(j+NumRes, TOI::TIED_TO) != -1) { if (TID.getOperandConstraint(j+NumRes, TOI::TIED_TO) != -1) {
SDNode *DU = SU->Node->getOperand(j).Val; SDNode *DU = SU->Node->getOperand(j).Val;
if ((*SUnitMap).find(DU) == (*SUnitMap).end()) if (DU->getNodeId() == -1)
continue; continue;
SUnit *DUSU = (*SUnitMap)[DU]; const SUnit *DUSU = &(*SUnits)[DU->getNodeId()];
if (!DUSU) continue; if (!DUSU) continue;
for (SUnit::succ_iterator I = DUSU->Succs.begin(),E = DUSU->Succs.end(); for (SUnit::const_succ_iterator I = DUSU->Succs.begin(),
I != E; ++I) { E = DUSU->Succs.end(); I != E; ++I) {
if (I->isCtrl) continue; if (I->isCtrl) continue;
SUnit *SuccSU = I->Dep; SUnit *SuccSU = I->Dep;
if (SuccSU == SU) if (SuccSU == SU)

View File

@ -301,9 +301,9 @@ namespace llvm {
static void addCustomGraphFeatures(ScheduleDAG *G, static void addCustomGraphFeatures(ScheduleDAG *G,
GraphWriter<ScheduleDAG*> &GW) { GraphWriter<ScheduleDAG*> &GW) {
GW.emitSimpleNode(0, "plaintext=circle", "GraphRoot"); GW.emitSimpleNode(0, "plaintext=circle", "GraphRoot");
if (G->DAG.getRoot().Val && const SDNode *N = G->DAG.getRoot().Val;
G->SUnitMap.find(G->DAG.getRoot().Val) != G->SUnitMap.end()) if (N && N->getNodeId() != -1)
GW.emitEdge(0, -1, G->SUnitMap[G->DAG.getRoot().Val], -1, ""); GW.emitEdge(0, -1, &G->SUnits[N->getNodeId()], -1, "");
} }
}; };
} }