From 94d7a5f8156e62532870fbaf197377b34e52ff2a Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Sat, 21 Jun 2008 19:18:17 +0000 Subject: [PATCH] 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 --- include/llvm/CodeGen/ScheduleDAG.h | 4 +- lib/CodeGen/SelectionDAG/ScheduleDAG.cpp | 26 ++++++---- lib/CodeGen/SelectionDAG/ScheduleDAGList.cpp | 5 +- .../SelectionDAG/ScheduleDAGRRList.cpp | 51 +++++++------------ .../SelectionDAG/SelectionDAGPrinter.cpp | 6 +-- 5 files changed, 39 insertions(+), 53 deletions(-) diff --git a/include/llvm/CodeGen/ScheduleDAG.h b/include/llvm/CodeGen/ScheduleDAG.h index e032df89018..0c393a0628a 100644 --- a/include/llvm/CodeGen/ScheduleDAG.h +++ b/include/llvm/CodeGen/ScheduleDAG.h @@ -214,8 +214,7 @@ namespace llvm { public: virtual ~SchedulingPriorityQueue() {} - virtual void initNodes(DenseMap &SUMap, - std::vector &SUnits) = 0; + virtual void initNodes(std::vector &SUnits) = 0; virtual void addNode(const SUnit *SU) = 0; virtual void updateNode(const SUnit *SU) = 0; virtual void releaseState() = 0; @@ -250,7 +249,6 @@ namespace llvm { MachineConstantPool *ConstPool; // Target constant pool std::vector Sequence; // The schedule. Null SUnit*'s // represent noop instructions. - DenseMap SUnitMap; // SDNode to SUnit mapping (n -> n). std::vector SUnits; // The scheduling units. SmallSet CommuteSet; // Nodes that should be commuted. diff --git a/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp b/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp index f144b986604..745367bd007 100644 --- a/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp +++ b/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp @@ -97,13 +97,20 @@ void ScheduleDAG::BuildSchedUnits() { // invalidated. 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(), E = DAG.allnodes_end(); NI != E; ++NI) { if (isPassiveNode(NI)) // Leaf node, e.g. a TargetImmediate. continue; // If this node has already been processed, stop now. - if (SUnitMap.count(NI)) continue; + if (NI->getNodeId() != -1) continue; SUnit *NodeSUnit = NewSUnit(NI); @@ -118,9 +125,8 @@ void ScheduleDAG::BuildSchedUnits() { do { N = N->getOperand(N->getNumOperands()-1).Val; NodeSUnit->FlaggedNodes.push_back(N); - bool isNew = SUnitMap.insert(std::make_pair(N, NodeSUnit)); - isNew = isNew; - assert(isNew && "Node already inserted!"); + assert(N->getNodeId() == -1 && "Node already inserted!"); + N->setNodeId(NodeSUnit->NodeNum); } while (N->getNumOperands() && N->getOperand(N->getNumOperands()-1).getValueType()== MVT::Flag); std::reverse(NodeSUnit->FlaggedNodes.begin(), @@ -140,9 +146,8 @@ void ScheduleDAG::BuildSchedUnits() { if (FlagVal.isOperandOf(UI->getUser())) { HasFlagUse = true; NodeSUnit->FlaggedNodes.push_back(N); - bool isNew = SUnitMap.insert(std::make_pair(N, NodeSUnit)); - isNew = isNew; - assert(isNew && "Node already inserted!"); + assert(N->getNodeId() == -1 && "Node already inserted!"); + N->setNodeId(NodeSUnit->NodeNum); N = UI->getUser(); break; } @@ -152,9 +157,8 @@ void ScheduleDAG::BuildSchedUnits() { // Now all flagged nodes are in FlaggedNodes and N is the bottom-most node. // Update the SUnit NodeSUnit->Node = N; - bool isNew = SUnitMap.insert(std::make_pair(N, NodeSUnit)); - isNew = isNew; - assert(isNew && "Node already inserted!"); + assert(N->getNodeId() == -1 && "Node already inserted!"); + N->setNodeId(NodeSUnit->NodeNum); ComputeLatency(NodeSUnit); } @@ -191,7 +195,7 @@ void ScheduleDAG::BuildSchedUnits() { for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { SDNode *OpN = N->getOperand(i).Val; if (isPassiveNode(OpN)) continue; // Not scheduled. - SUnit *OpSU = SUnitMap[OpN]; + SUnit *OpSU = &SUnits[OpN->getNodeId()]; assert(OpSU && "Node has no SUnit!"); if (OpSU == SU) continue; // In the same group. diff --git a/lib/CodeGen/SelectionDAG/ScheduleDAGList.cpp b/lib/CodeGen/SelectionDAG/ScheduleDAGList.cpp index 909588cad54..ab6e92db46e 100644 --- a/lib/CodeGen/SelectionDAG/ScheduleDAGList.cpp +++ b/lib/CodeGen/SelectionDAG/ScheduleDAGList.cpp @@ -94,7 +94,7 @@ void ScheduleDAGList::Schedule() { // Build scheduling units. BuildSchedUnits(); - AvailableQueue->initNodes(SUnitMap, SUnits); + AvailableQueue->initNodes(SUnits); ListScheduleTopDown(); @@ -320,8 +320,7 @@ public: LatencyPriorityQueue() : Queue(latency_sort(this)) { } - void initNodes(DenseMap &sumap, - std::vector &sunits) { + void initNodes(std::vector &sunits) { SUnits = &sunits; // Calculate node priorities. CalculatePriorities(); diff --git a/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp b/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp index 99a5537f13a..6175bc275ea 100644 --- a/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp +++ b/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp @@ -216,7 +216,7 @@ void ScheduleDAGRRList::Schedule() { CalculateHeights(); InitDAGTopologicalSorting(); - AvailableQueue->initNodes(SUnitMap, SUnits); + AvailableQueue->initNodes(SUnits); // Execute the actual scheduling loop Top-Down or Bottom-Up as appropriate. if (isBottomUp) @@ -255,7 +255,7 @@ void ScheduleDAGRRList::CommuteNodesToReducePressure() { continue; 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) { // 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 @@ -264,7 +264,7 @@ void ScheduleDAGRRList::CommuteNodesToReducePressure() { for (unsigned k = 0; k < NumOps; ++k) { if (k != j) { 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) { DoCommute = false; break; @@ -678,9 +678,8 @@ SUnit *ScheduleDAGRRList::CopyAndMoveSuccessors(SUnit *SU) { SDOperand(LoadNode, 1)); SUnit *NewSU = CreateNewSUnit(N); - bool isNew = SUnitMap.insert(std::make_pair(N, NewSU)); - isNew = isNew; - assert(isNew && "Node already inserted!"); + assert(N->getNodeId() == -1 && "Node already inserted!"); + N->setNodeId(NewSU->NodeNum); const TargetInstrDesc &TID = TII->get(N->getTargetOpcode()); for (unsigned i = 0; i != TID.getNumOperands(); ++i) { @@ -701,15 +700,12 @@ SUnit *ScheduleDAGRRList::CopyAndMoveSuccessors(SUnit *SU) { // but it has different alignment or volatileness. bool isNewLoad = true; SUnit *LoadSU; - DenseMap::iterator SMI = SUnitMap.find(LoadNode); - if (SMI != SUnitMap.end()) { - LoadSU = SMI->second; + if (LoadNode->getNodeId() != -1) { + LoadSU = &SUnits[LoadNode->getNodeId()]; isNewLoad = false; } else { LoadSU = CreateNewSUnit(LoadNode); - bool isNew = SUnitMap.insert(std::make_pair(LoadNode, LoadSU)); - isNew = isNew; - assert(isNew && "Node already inserted!"); + LoadNode->setNodeId(LoadSU->NodeNum); LoadSU->Depth = SU->Depth; LoadSU->Height = SU->Height; @@ -948,7 +944,7 @@ void ScheduleDAGRRList::ListScheduleBottomUp() { unsigned CurCycle = 0; // Add root to Available queue. 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!"); RootSU->isAvailable = true; AvailableQueue->push(RootSU); @@ -1284,8 +1280,7 @@ namespace { RegReductionPriorityQueue() : Queue(SF(this)), currentQueueId(0) {} - virtual void initNodes(DenseMap &sumap, - std::vector &sunits) {} + virtual void initNodes(std::vector &sunits) {} virtual void addNode(const SUnit *SU) {} @@ -1330,9 +1325,6 @@ namespace { class VISIBILITY_HIDDEN BURegReductionPriorityQueue : public RegReductionPriorityQueue { - // SUnitMap SDNode to SUnit mapping (n -> n). - DenseMap *SUnitMap; - // SUnits - The SUnits for the current graph. const std::vector *SUnits; @@ -1347,9 +1339,7 @@ namespace { const TargetRegisterInfo *tri) : TII(tii), TRI(tri), scheduleDAG(NULL) {} - void initNodes(DenseMap &sumap, - std::vector &sunits) { - SUnitMap = &sumap; + void initNodes(std::vector &sunits) { SUnits = &sunits; // Add pseudo dependency edges for two-address nodes. AddPseudoTwoAddrDeps(); @@ -1417,9 +1407,6 @@ namespace { class VISIBILITY_HIDDEN TDRegReductionPriorityQueue : public RegReductionPriorityQueue { - // SUnitMap SDNode to SUnit mapping (n -> n). - DenseMap *SUnitMap; - // SUnits - The SUnits for the current graph. const std::vector *SUnits; @@ -1429,9 +1416,7 @@ namespace { public: TDRegReductionPriorityQueue() {} - void initNodes(DenseMap &sumap, - std::vector &sunits) { - SUnitMap = &sumap; + void initNodes(std::vector &sunits) { SUnits = &sunits; // Calculate node priorities. CalculateSethiUllmanNumbers(); @@ -1563,8 +1548,8 @@ BURegReductionPriorityQueue::canClobber(const SUnit *SU, const SUnit *Op) { for (unsigned i = 0; i != NumOps; ++i) { if (TID.getOperandConstraint(i+NumRes, TOI::TIED_TO) != -1) { SDNode *DU = SU->Node->getOperand(i).Val; - if ((*SUnitMap).find(DU) != (*SUnitMap).end() && - Op->OrigNode == (*SUnitMap)[DU]) + if (DU->getNodeId() != -1 && + Op->OrigNode == &(*SUnits)[DU->getNodeId()]) return true; } } @@ -1638,12 +1623,12 @@ void BURegReductionPriorityQueue::AddPseudoTwoAddrDeps() { for (unsigned j = 0; j != NumOps; ++j) { if (TID.getOperandConstraint(j+NumRes, TOI::TIED_TO) != -1) { SDNode *DU = SU->Node->getOperand(j).Val; - if ((*SUnitMap).find(DU) == (*SUnitMap).end()) + if (DU->getNodeId() == -1) continue; - SUnit *DUSU = (*SUnitMap)[DU]; + const SUnit *DUSU = &(*SUnits)[DU->getNodeId()]; if (!DUSU) continue; - for (SUnit::succ_iterator I = DUSU->Succs.begin(),E = DUSU->Succs.end(); - I != E; ++I) { + for (SUnit::const_succ_iterator I = DUSU->Succs.begin(), + E = DUSU->Succs.end(); I != E; ++I) { if (I->isCtrl) continue; SUnit *SuccSU = I->Dep; if (SuccSU == SU) diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp index 995d877d9da..07f3221777d 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp @@ -301,9 +301,9 @@ namespace llvm { static void addCustomGraphFeatures(ScheduleDAG *G, GraphWriter &GW) { GW.emitSimpleNode(0, "plaintext=circle", "GraphRoot"); - if (G->DAG.getRoot().Val && - G->SUnitMap.find(G->DAG.getRoot().Val) != G->SUnitMap.end()) - GW.emitEdge(0, -1, G->SUnitMap[G->DAG.getRoot().Val], -1, ""); + const SDNode *N = G->DAG.getRoot().Val; + if (N && N->getNodeId() != -1) + GW.emitEdge(0, -1, &G->SUnits[N->getNodeId()], -1, ""); } }; }