switch the SUnit pred/succ sets from being std::sets to being smallvectors.
[oota-llvm.git] / lib / CodeGen / SelectionDAG / ScheduleDAG.cpp
index 528225223decbf8f56de94a62013fba319b99d0f..d33e1ecef7ea8a33ac4abb7d06e8c3827d43773f 100644 (file)
@@ -55,11 +55,16 @@ void ScheduleDAG::BuildSchedUnits() {
     
     // Scan up, adding flagged preds to FlaggedNodes.
     SDNode *N = NI;
-    while (N->getNumOperands() &&
-           N->getOperand(N->getNumOperands()-1).getValueType() == MVT::Flag) {
-      N = N->getOperand(N->getNumOperands()-1).Val;
-      NodeSUnit->FlaggedNodes.push_back(N);
-      SUnitMap[N] = NodeSUnit;
+    if (N->getNumOperands() &&
+        N->getOperand(N->getNumOperands()-1).getValueType() == MVT::Flag) {
+      do {
+        N = N->getOperand(N->getNumOperands()-1).Val;
+        NodeSUnit->FlaggedNodes.push_back(N);
+        SUnitMap[N] = NodeSUnit;
+      } while (N->getNumOperands() &&
+               N->getOperand(N->getNumOperands()-1).getValueType()== MVT::Flag);
+      std::reverse(NodeSUnit->FlaggedNodes.begin(),
+                   NodeSUnit->FlaggedNodes.end());
     }
     
     // Scan down, adding this node and any flagged succs to FlaggedNodes if they
@@ -79,7 +84,7 @@ void ScheduleDAG::BuildSchedUnits() {
           N = *UI;
           break;
         }
-          if (!HasFlagUse) break;
+      if (!HasFlagUse) break;
     }
     
     // Now all flagged nodes are in FlaggedNodes and N is the bottom-most node.
@@ -145,7 +150,7 @@ void ScheduleDAG::BuildSchedUnits() {
         assert(OpVT != MVT::Flag && "Flagged nodes should be in same sunit!");
         bool isChain = OpVT == MVT::Other;
         
-        if (SU->Preds.insert(std::make_pair(OpSU, isChain)).second) {
+        if (SU->addPred(OpSU, isChain)) {
           if (!isChain) {
             SU->NumPreds++;
             SU->NumPredsLeft++;
@@ -153,7 +158,7 @@ void ScheduleDAG::BuildSchedUnits() {
             SU->NumChainPredsLeft++;
           }
         }
-        if (OpSU->Succs.insert(std::make_pair(SU, isChain)).second) {
+        if (OpSU->addSucc(SU, isChain)) {
           if (!isChain) {
             OpSU->NumSuccs++;
             OpSU->NumSuccsLeft++;
@@ -171,35 +176,35 @@ void ScheduleDAG::BuildSchedUnits() {
   return;
 }
 
-static void CalculateDepths(SUnit *SU, unsigned Depth) {
-  if (SU->Depth == 0 || Depth > SU->Depth) {
-    SU->Depth = Depth;
-    for (std::set<std::pair<SUnit*, bool> >::iterator I = SU->Succs.begin(),
-           E = SU->Succs.end(); I != E; ++I)
-      CalculateDepths(I->first, Depth+1);
+static void CalculateDepths(SUnit &SU, unsigned Depth) {
+  if (SU.Depth == 0 || Depth > SU.Depth) {
+    SU.Depth = Depth;
+    for (SUnit::succ_iterator I = SU.Succs.begin(), E = SU.Succs.end();
+         I != E; ++I)
+      CalculateDepths(*I->first, Depth+1);
   }
 }
 
 void ScheduleDAG::CalculateDepths() {
   SUnit *Entry = SUnitMap[DAG.getEntryNode().Val];
-  ::CalculateDepths(Entry, 0U);
+  ::CalculateDepths(*Entry, 0U);
   for (unsigned i = 0, e = SUnits.size(); i != e; ++i)
     if (SUnits[i].Preds.size() == 0 && &SUnits[i] != Entry) {
-      ::CalculateDepths(&SUnits[i], 0U);
+      ::CalculateDepths(SUnits[i], 0U);
     }
 }
 
-static void CalculateHeights(SUnit *SU, unsigned Height) {
-  if (SU->Height == 0 || Height > SU->Height) {
-    SU->Height = Height;
-    for (std::set<std::pair<SUnit*, bool> >::iterator I = SU->Preds.begin(),
-           E = SU->Preds.end(); I != E; ++I)
-      CalculateHeights(I->first, Height+1);
+static void CalculateHeights(SUnit &SU, unsigned Height) {
+  if (SU.Height == 0 || Height > SU.Height) {
+    SU.Height = Height;
+    for (SUnit::pred_iterator I = SU.Preds.begin(), E = SU.Preds.end();
+         I != E; ++I)
+      CalculateHeights(*I->first, Height+1);
   }
 }
 void ScheduleDAG::CalculateHeights() {
   SUnit *Root = SUnitMap[DAG.getRoot().Val];
-  ::CalculateHeights(Root, 0U);
+  ::CalculateHeights(*Root, 0U);
 }
 
 /// CountResults - The results of target nodes have register or immediate
@@ -226,7 +231,22 @@ static unsigned CountOperands(SDNode *Node) {
   return N;
 }
 
-static unsigned CreateVirtualRegisters(MachineInstr *MI,
+static const TargetRegisterClass *getInstrOperandRegClass(
+        const MRegisterInfo *MRI, 
+        const TargetInstrInfo *TII,
+        const TargetInstrDescriptor *II,
+        unsigned Op) {
+  if (Op >= II->numOperands) {
+    assert((II->Flags & M_VARIABLE_OPS)&& "Invalid operand # of instruction");
+    return NULL;
+  }
+  const TargetOperandInfo &toi = II->OpInfo[Op];
+  return (toi.Flags & M_LOOK_UP_PTR_REG_CLASS)
+         ? TII->getPointerRegClass() : MRI->getRegClass(toi.RegClass);
+}
+
+static unsigned CreateVirtualRegisters(const MRegisterInfo *MRI,
+                                       MachineInstr *MI,
                                        unsigned NumResults,
                                        SSARegMap *RegMap,
                                        const TargetInstrInfo *TII,
@@ -234,10 +254,10 @@ static unsigned CreateVirtualRegisters(MachineInstr *MI,
   // Create the result registers for this node and add the result regs to
   // the machine instruction.
   unsigned ResultReg =
-    RegMap->createVirtualRegister(TII->getInstrOperandRegClass(&II, 0));
+    RegMap->createVirtualRegister(getInstrOperandRegClass(MRI, TII, &II, 0));
   MI->addRegOperand(ResultReg, MachineOperand::Def);
   for (unsigned i = 1; i != NumResults; ++i) {
-    const TargetRegisterClass *RC = TII->getInstrOperandRegClass(&II, i);
+    const TargetRegisterClass *RC = getInstrOperandRegClass(MRI, TII, &II, i);
     assert(RC && "Isn't a register operand!");
     MI->addRegOperand(RegMap->createVirtualRegister(RC), MachineOperand::Def);
   }
@@ -276,7 +296,8 @@ void ScheduleDAG::AddOperand(MachineInstr *MI, SDOperand Op,
     // Verify that it is right.
     assert(MRegisterInfo::isVirtualRegister(VReg) && "Not a vreg?");
     if (II) {
-      const TargetRegisterClass *RC = TII->getInstrOperandRegClass(II, IIOpNum);
+      const TargetRegisterClass *RC =
+                          getInstrOperandRegClass(MRI, TII, II, IIOpNum);
       assert(RC && "Don't have operand info for this instruction!");
       assert(RegMap->getRegClass(VReg) == RC &&
              "Register class of operand and regclass of use don't agree!");
@@ -333,7 +354,8 @@ void ScheduleDAG::AddOperand(MachineInstr *MI, SDOperand Op,
     // Verify that it is right.
     assert(MRegisterInfo::isVirtualRegister(VReg) && "Not a vreg?");
     if (II) {
-      const TargetRegisterClass *RC = TII->getInstrOperandRegClass(II, IIOpNum);
+      const TargetRegisterClass *RC =
+                            getInstrOperandRegClass(MRI, TII, II, IIOpNum);
       assert(RC && "Don't have operand info for this instruction!");
       assert(RegMap->getRegClass(VReg) == RC &&
              "Register class of operand and regclass of use don't agree!");
@@ -389,7 +411,7 @@ void ScheduleDAG::EmitNode(SDNode *Node,
     
     // Otherwise, create new virtual registers.
     if (NumResults && VRBase == 0)
-      VRBase = CreateVirtualRegisters(MI, NumResults, RegMap, TII, II);
+      VRBase = CreateVirtualRegisters(MRI, MI, NumResults, RegMap, TII, II);
     
     // Emit all of the actual operands of this instruction, adding them to the
     // instruction as appropriate.
@@ -421,7 +443,9 @@ void ScheduleDAG::EmitNode(SDNode *Node,
   } else {
     switch (Node->getOpcode()) {
     default:
-      DEBUG(Node->dump()); 
+#ifndef NDEBUG
+      Node->dump();
+#endif
       assert(0 && "This target-independent node should have been selected!");
     case ISD::EntryToken: // fall thru
     case ISD::TokenFactor:
@@ -622,24 +646,24 @@ void SUnit::dumpAll(const SelectionDAG *G) const {
 
   if (Preds.size() != 0) {
     std::cerr << "  Predecessors:\n";
-    for (std::set<std::pair<SUnit*,bool> >::const_iterator I = Preds.begin(),
-           E = Preds.end(); I != E; ++I) {
+    for (SUnit::const_succ_iterator I = Preds.begin(), E = Preds.end();
+         I != E; ++I) {
       if (I->second)
-        std::cerr << "   ch  ";
+        std::cerr << "   ch  #";
       else
-        std::cerr << "   val ";
-      I->first->dump(G);
+        std::cerr << "   val #";
+      std::cerr << I->first << "\n";
     }
   }
   if (Succs.size() != 0) {
     std::cerr << "  Successors:\n";
-    for (std::set<std::pair<SUnit*, bool> >::const_iterator I = Succs.begin(),
-           E = Succs.end(); I != E; ++I) {
+    for (SUnit::const_succ_iterator I = Succs.begin(), E = Succs.end();
+         I != E; ++I) {
       if (I->second)
-        std::cerr << "   ch  ";
+        std::cerr << "   ch  #";
       else
-        std::cerr << "   val ";
-      I->first->dump(G);
+        std::cerr << "   val #";
+      std::cerr << I->first << "\n";
     }
   }
   std::cerr << "\n";