[llvm-commits] [llvm] r53057 - in /llvm/trunk: include/llvm/CodeGen/SelectionDAG.h lib/CodeGen/SelectionDAG/ScheduleDAG.cpp lib/CodeGen/SelectionDAG/SelectionDAG.cpp utils/TableGen/DAGISelEmitter.cpp

Dan Gohman gohman at apple.com
Wed Jul 2 16:23:19 PDT 2008


Author: djg
Date: Wed Jul  2 18:23:19 2008
New Revision: 53057

URL: http://llvm.org/viewvc/llvm-project?rev=53057&view=rev
Log:
Replace a few uses of SelectionDAG::getTargetNode with
SelectionDAG::SelectNodeTo in the instruction selector. This
updates existing nodes in place instead of creating new ones.

Go back to selecting ISD::DBG_LABEL nodes into
TargetInstrInfo::DBG_LABEL nodes instead of leaving them
unselected, now that SelectNodeTo allows us to update them
in place.

Modified:
    llvm/trunk/include/llvm/CodeGen/SelectionDAG.h
    llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
    llvm/trunk/utils/TableGen/DAGISelEmitter.cpp

Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAG.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SelectionDAG.h?rev=53057&r1=53056&r2=53057&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/SelectionDAG.h (original)
+++ llvm/trunk/include/llvm/CodeGen/SelectionDAG.h Wed Jul  2 18:23:19 2008
@@ -461,10 +461,19 @@
                        SDOperand Op1, SDOperand Op2, SDOperand Op3);
   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT,
                        SDOperandPtr Ops, unsigned NumOps);
+  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, MVT VT2);
+  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
+                       MVT VT2, SDOperandPtr Ops, unsigned NumOps);
+  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
+                       MVT VT2, MVT VT3, SDOperandPtr Ops, unsigned NumOps);
+  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
+                       MVT VT2, SDOperand Op1);
   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
                        MVT VT2, SDOperand Op1, SDOperand Op2);
   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
                        MVT VT2, SDOperand Op1, SDOperand Op2, SDOperand Op3);
+  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, SDVTList VTs,
+                       SDOperandPtr Ops, unsigned NumOps);
 
 
   /// getTargetNode - These are used for target selectors to create a new node

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp?rev=53057&r1=53056&r2=53057&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp Wed Jul  2 18:23:19 2008
@@ -885,16 +885,6 @@
     assert(0 && "EntryToken should have been excluded from the schedule!");
     break;
   case ISD::TokenFactor: // fall thru
-  case ISD::DECLARE:
-  case ISD::SRCVALUE:
-    break;
-  case ISD::DBG_LABEL:
-    BB->push_back(BuildMI(TII->get(TargetInstrInfo::DBG_LABEL))
-                  .addImm(cast<LabelSDNode>(Node)->getLabelID()));
-    break;
-  case ISD::EH_LABEL:
-    BB->push_back(BuildMI(TII->get(TargetInstrInfo::EH_LABEL))
-                  .addImm(cast<LabelSDNode>(Node)->getLabelID()));
     break;
   case ISD::CopyToReg: {
     unsigned SrcReg;
@@ -951,34 +941,14 @@
         
       switch (Flags & 7) {
       default: assert(0 && "Bad flags!");
-      case 1:  // Use of register.
-        for (; NumVals; --NumVals, ++i) {
-          unsigned Reg = cast<RegisterSDNode>(Node->getOperand(i))->getReg();
-          MI->addOperand(MachineOperand::CreateReg(Reg, false));
-        }
-        break;
       case 2:   // Def of register.
         for (; NumVals; --NumVals, ++i) {
           unsigned Reg = cast<RegisterSDNode>(Node->getOperand(i))->getReg();
           MI->addOperand(MachineOperand::CreateReg(Reg, true));
         }
         break;
-      case 3: { // Immediate.
-        for (; NumVals; --NumVals, ++i) {
-          if (ConstantSDNode *CS =
-              dyn_cast<ConstantSDNode>(Node->getOperand(i))) {
-            MI->addOperand(MachineOperand::CreateImm(CS->getValue()));
-          } else if (GlobalAddressSDNode *GA = 
-                     dyn_cast<GlobalAddressSDNode>(Node->getOperand(i))) {
-            MI->addOperand(MachineOperand::CreateGA(GA->getGlobal(),
-                                                    GA->getOffset()));
-          } else {
-            BasicBlockSDNode *BB =cast<BasicBlockSDNode>(Node->getOperand(i));
-            MI->addOperand(MachineOperand::CreateMBB(BB->getBasicBlock()));
-          }
-        }
-        break;
-      }
+      case 1:  // Use of register.
+      case 3:  // Immediate.
       case 4:  // Addressing mode.
         // The addressing mode has been selected, just add all of the
         // operands to the machine instruction.

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=53057&r1=53056&r2=53057&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Wed Jul  2 18:23:19 2008
@@ -3693,130 +3693,97 @@
 SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc,
                                    MVT VT) {
   SDVTList VTs = getVTList(VT);
-  FoldingSetNodeID ID;
-  AddNodeIDNode(ID, ISD::BUILTIN_OP_END+TargetOpc, VTs, (SDOperand*)0, 0);
-  void *IP = 0;
-  if (SDNode *ON = CSEMap.FindNodeOrInsertPos(ID, IP))
-    return ON;
-   
-  RemoveNodeFromCSEMaps(N);
-  
-  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs, SDOperandPtr(), 0);
-
-  CSEMap.InsertNode(N, IP);
-  return N;
+  return SelectNodeTo(N, TargetOpc, VTs, (SDOperand*)0, 0);
 }
 
 SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc,
                                    MVT VT, SDOperand Op1) {
-  // If an identical node already exists, use it.
   SDVTList VTs = getVTList(VT);
   SDOperand Ops[] = { Op1 };
-  
-  FoldingSetNodeID ID;
-  AddNodeIDNode(ID, ISD::BUILTIN_OP_END+TargetOpc, VTs, Ops, 1);
-  void *IP = 0;
-  if (SDNode *ON = CSEMap.FindNodeOrInsertPos(ID, IP))
-    return ON;
-                                       
-  RemoveNodeFromCSEMaps(N);
-  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs, Ops, 1);
-  CSEMap.InsertNode(N, IP);
-  return N;
+  return SelectNodeTo(N, TargetOpc, VTs, Ops, 1);
 }
 
 SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc,
                                    MVT VT, SDOperand Op1,
                                    SDOperand Op2) {
-  // If an identical node already exists, use it.
   SDVTList VTs = getVTList(VT);
   SDOperand Ops[] = { Op1, Op2 };
-  
-  FoldingSetNodeID ID;
-  AddNodeIDNode(ID, ISD::BUILTIN_OP_END+TargetOpc, VTs, Ops, 2);
-  void *IP = 0;
-  if (SDNode *ON = CSEMap.FindNodeOrInsertPos(ID, IP))
-    return ON;
-                                       
-  RemoveNodeFromCSEMaps(N);
-  
-  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs, Ops, 2);
-  
-  CSEMap.InsertNode(N, IP);   // Memoize the new node.
-  return N;
+  return SelectNodeTo(N, TargetOpc, VTs, Ops, 2);
 }
 
 SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc,
                                    MVT VT, SDOperand Op1,
                                    SDOperand Op2, SDOperand Op3) {
-  // If an identical node already exists, use it.
   SDVTList VTs = getVTList(VT);
   SDOperand Ops[] = { Op1, Op2, Op3 };
-  FoldingSetNodeID ID;
-  AddNodeIDNode(ID, ISD::BUILTIN_OP_END+TargetOpc, VTs, Ops, 3);
-  void *IP = 0;
-  if (SDNode *ON = CSEMap.FindNodeOrInsertPos(ID, IP))
-    return ON;
-                                       
-  RemoveNodeFromCSEMaps(N);
-  
-  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs, Ops, 3);
-
-  CSEMap.InsertNode(N, IP);   // Memoize the new node.
-  return N;
+  return SelectNodeTo(N, TargetOpc, VTs, Ops, 3);
 }
 
 SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc,
                                    MVT VT, SDOperandPtr Ops,
                                    unsigned NumOps) {
-  // If an identical node already exists, use it.
   SDVTList VTs = getVTList(VT);
-  FoldingSetNodeID ID;
-  AddNodeIDNode(ID, ISD::BUILTIN_OP_END+TargetOpc, VTs, Ops, NumOps);
-  void *IP = 0;
-  if (SDNode *ON = CSEMap.FindNodeOrInsertPos(ID, IP))
-    return ON;
-                                       
-  RemoveNodeFromCSEMaps(N);
-  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs, Ops, NumOps);
-  
-  CSEMap.InsertNode(N, IP);   // Memoize the new node.
-  return N;
+  return SelectNodeTo(N, TargetOpc, VTs, Ops, NumOps);
+}
+
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc,
+                                   MVT VT1, MVT VT2, SDOperandPtr Ops,
+                                   unsigned NumOps) {
+  SDVTList VTs = getVTList(VT1, VT2);
+  return SelectNodeTo(N, TargetOpc, VTs, Ops, NumOps);
+}
+
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc,
+                                   MVT VT1, MVT VT2) {
+  SDVTList VTs = getVTList(VT1, VT2);
+  return SelectNodeTo(N, TargetOpc, VTs, (SDOperand *)0, 0);
+}
+
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc,
+                                   MVT VT1, MVT VT2, MVT VT3, SDOperandPtr Ops,
+                                   unsigned NumOps) {
+  SDVTList VTs = getVTList(VT1, VT2, VT3);
+  return SelectNodeTo(N, TargetOpc, VTs, Ops, NumOps);
+}
+
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc, 
+                                   MVT VT1, MVT VT2,
+                                   SDOperand Op1) {
+  SDVTList VTs = getVTList(VT1, VT2);
+  SDOperand Ops[] = { Op1 };
+  return SelectNodeTo(N, TargetOpc, VTs, Ops, 1);
 }
 
 SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc, 
                                    MVT VT1, MVT VT2,
                                    SDOperand Op1, SDOperand Op2) {
   SDVTList VTs = getVTList(VT1, VT2);
-  FoldingSetNodeID ID;
   SDOperand Ops[] = { Op1, Op2 };
-  AddNodeIDNode(ID, ISD::BUILTIN_OP_END+TargetOpc, VTs, Ops, 2);
-  void *IP = 0;
-  if (SDNode *ON = CSEMap.FindNodeOrInsertPos(ID, IP))
-    return ON;
-
-  RemoveNodeFromCSEMaps(N);
-  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs, Ops, 2);
-  CSEMap.InsertNode(N, IP);   // Memoize the new node.
-  return N;
+  return SelectNodeTo(N, TargetOpc, VTs, Ops, 2);
 }
 
 SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc,
                                    MVT VT1, MVT VT2,
                                    SDOperand Op1, SDOperand Op2, 
                                    SDOperand Op3) {
-  // If an identical node already exists, use it.
   SDVTList VTs = getVTList(VT1, VT2);
   SDOperand Ops[] = { Op1, Op2, Op3 };
+  return SelectNodeTo(N, TargetOpc, VTs, Ops, 3);
+}
+
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc,
+                                   SDVTList VTs, SDOperandPtr Ops,
+                                   unsigned NumOps) {
+  // If an identical node already exists, use it.
   FoldingSetNodeID ID;
-  AddNodeIDNode(ID, ISD::BUILTIN_OP_END+TargetOpc, VTs, Ops, 3);
+  AddNodeIDNode(ID, ISD::BUILTIN_OP_END+TargetOpc, VTs, Ops, NumOps);
   void *IP = 0;
   if (SDNode *ON = CSEMap.FindNodeOrInsertPos(ID, IP))
     return ON;
 
   RemoveNodeFromCSEMaps(N);
 
-  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs, Ops, 3);
+  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs, Ops, NumOps);
   CSEMap.InsertNode(N, IP);   // Memoize the new node.
   return N;
 }
@@ -4109,8 +4076,7 @@
   for (SDNode::use_iterator UI = From.Val->use_begin(), 
       E = From.Val->use_end(); UI != E; ++UI) {
     SDNode *User = UI->getUser();
-    if (!Users.count(User))
-      Users.insert(User);
+    Users.insert(User);
   }
 
   // When one of the recursive merges deletes nodes from the graph, we need to

Modified: llvm/trunk/utils/TableGen/DAGISelEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelEmitter.cpp?rev=53057&r1=53056&r2=53057&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/DAGISelEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/DAGISelEmitter.cpp Wed Jul  2 18:23:19 2008
@@ -1860,8 +1860,26 @@
      << "}\n\n";
 
   OS << "SDNode *Select_UNDEF(const SDOperand &N) {\n"
-     << "  return CurDAG->getTargetNode(TargetInstrInfo::IMPLICIT_DEF,\n"
-     << "                               N.getValueType());\n"
+     << "  return CurDAG->SelectNodeTo(N.Val, TargetInstrInfo::IMPLICIT_DEF,\n"
+     << "                              N.getValueType());\n"
+     << "}\n\n";
+
+  OS << "SDNode *Select_DBG_LABEL(const SDOperand &N) {\n"
+     << "  SDOperand Chain = N.getOperand(0);\n"
+     << "  unsigned C = cast<LabelSDNode>(N)->getLabelID();\n"
+     << "  SDOperand Tmp = CurDAG->getTargetConstant(C, MVT::i32);\n"
+     << "  AddToISelQueue(Chain);\n"
+     << "  return CurDAG->SelectNodeTo(N.Val, TargetInstrInfo::DBG_LABEL,\n"
+     << "                              MVT::Other, Tmp, Chain);\n"
+     << "}\n\n";
+
+  OS << "SDNode *Select_EH_LABEL(const SDOperand &N) {\n"
+     << "  SDOperand Chain = N.getOperand(0);\n"
+     << "  unsigned C = cast<LabelSDNode>(N)->getLabelID();\n"
+     << "  SDOperand Tmp = CurDAG->getTargetConstant(C, MVT::i32);\n"
+     << "  AddToISelQueue(Chain);\n"
+     << "  return CurDAG->SelectNodeTo(N.Val, TargetInstrInfo::EH_LABEL,\n"
+     << "                              MVT::Other, Tmp, Chain);\n"
      << "}\n\n";
 
   OS << "SDNode *Select_DECLARE(const SDOperand &N) {\n"
@@ -1880,9 +1898,8 @@
      << "  SDOperand Tmp2 = "
      << "CurDAG->getTargetGlobalAddress(GV, TLI.getPointerTy());\n"
      << "  AddToISelQueue(Chain);\n"
-     << "  SDOperand Ops[] = { Tmp1, Tmp2, Chain };\n"
-     << "  return CurDAG->getTargetNode(TargetInstrInfo::DECLARE,\n"
-     << "                               MVT::Other, Ops, 3);\n"
+     << "  return CurDAG->SelectNodeTo(N.Val, TargetInstrInfo::DECLARE,\n"
+     << "                              MVT::Other, Tmp1, Tmp2, Chain);\n"
      << "}\n\n";
 
   OS << "SDNode *Select_EXTRACT_SUBREG(const SDOperand &N) {\n"
@@ -1891,9 +1908,8 @@
      << "  unsigned C = cast<ConstantSDNode>(N1)->getValue();\n"
      << "  SDOperand Tmp = CurDAG->getTargetConstant(C, MVT::i32);\n"
      << "  AddToISelQueue(N0);\n"
-     << "  SDOperand Ops[] = { N0, Tmp };\n"
-     << "  return CurDAG->getTargetNode(TargetInstrInfo::EXTRACT_SUBREG,\n"
-     << "                               N.getValueType(), Ops, 2);\n"
+     << "  return CurDAG->SelectNodeTo(N.Val, TargetInstrInfo::EXTRACT_SUBREG,\n"
+     << "                              N.getValueType(), N0, Tmp);\n"
      << "}\n\n";
 
   OS << "SDNode *Select_INSERT_SUBREG(const SDOperand &N) {\n"
@@ -1903,10 +1919,9 @@
      << "  unsigned C = cast<ConstantSDNode>(N2)->getValue();\n"
      << "  SDOperand Tmp = CurDAG->getTargetConstant(C, MVT::i32);\n"
      << "  AddToISelQueue(N1);\n"
-     << "  SDOperand Ops[] = { N0, N1, Tmp };\n"
      << "  AddToISelQueue(N0);\n"
-     << "  return CurDAG->getTargetNode(TargetInstrInfo::INSERT_SUBREG,\n"
-     << "                               N.getValueType(), Ops, 3);\n"
+     << "  return CurDAG->SelectNodeTo(N.Val, TargetInstrInfo::INSERT_SUBREG,\n"
+     << "                              N.getValueType(), N0, N1, Tmp);\n"
      << "}\n\n";
 
   OS << "// The main instruction selector code.\n"
@@ -1942,13 +1957,13 @@
      << "  case ISD::TokenFactor:\n"
      << "  case ISD::CopyFromReg:\n"
      << "  case ISD::CopyToReg: {\n"
-     << "  case ISD::DBG_LABEL:\n"
-     << "  case ISD::EH_LABEL:\n"
      << "    for (unsigned i = 0, e = N.getNumOperands(); i != e; ++i)\n"
      << "      AddToISelQueue(N.getOperand(i));\n"
      << "    return NULL;\n"
      << "  }\n"
      << "  case ISD::INLINEASM: return Select_INLINEASM(N);\n"
+     << "  case ISD::DBG_LABEL: return Select_DBG_LABEL(N);\n"
+     << "  case ISD::EH_LABEL: return Select_EH_LABEL(N);\n"
      << "  case ISD::DECLARE: return Select_DECLARE(N);\n"
      << "  case ISD::EXTRACT_SUBREG: return Select_EXTRACT_SUBREG(N);\n"
      << "  case ISD::INSERT_SUBREG: return Select_INSERT_SUBREG(N);\n"





More information about the llvm-commits mailing list