From: Chris Lattner Date: Tue, 8 Nov 2005 23:30:28 +0000 (+0000) Subject: Change the ValueList array for each node to be shared instead of individuallyallocate... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=a32551197ab7f39bb2bff8cee24ecf70c2a40f6f;p=oota-llvm.git Change the ValueList array for each node to be shared instead of individuallyallocated. Further, in the common case where a node has a single value, justreference an element from a small array. This is a small compile-time win. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24251 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 753364ecb3c..0c7473d0a43 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -426,7 +426,6 @@ SDNode *SelectionDAG::AddNonLeafNodeToCSEMaps(SDNode *N) { AN = N; } return 0; - } @@ -1100,7 +1099,7 @@ SDOperand SelectionDAG::getLoad(MVT::ValueType VT, N = new SDNode(ISD::LOAD, Chain, Ptr, SV); // Loads have a token chain. - N->setValueTypes(VT, MVT::Other); + setNodeValueTypes(N, VT, MVT::Other); AllNodes.push_back(N); return SDOperand(N, 0); } @@ -1344,11 +1343,46 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, } else { N = new SDNode(Opcode, Ops); } - N->setValueTypes(ResultTys); + setNodeValueTypes(N, ResultTys); AllNodes.push_back(N); return SDOperand(N, 0); } +void SelectionDAG::setNodeValueTypes(SDNode *N, + std::vector &RetVals) { + switch (RetVals.size()) { + case 0: return; + case 1: N->setValueTypes(RetVals[0]); return; + case 2: setNodeValueTypes(N, RetVals[0], RetVals[1]); return; + default: break; + } + + std::list >::iterator I = + std::find(VTList.begin(), VTList.end(), RetVals); + if (I == VTList.end()) { + VTList.push_front(RetVals); + I = VTList.begin(); + } + + N->setValueTypes(&(*I)[0], I->size()); +} + +void SelectionDAG::setNodeValueTypes(SDNode *N, MVT::ValueType VT1, + MVT::ValueType VT2) { + for (std::list >::iterator I = VTList.begin(), + E = VTList.end(); I != E; ++I) { + if (I->size() == 2 && (*I)[0] == VT1 && (*I)[1] == VT2) { + N->setValueTypes(&(*I)[0], 2); + return; + } + } + std::vector V; + V.push_back(VT1); + V.push_back(VT2); + VTList.push_front(V); + N->setValueTypes(&(*VTList.begin())[0], 2); +} + /// SelectNodeTo - These are used for target selectors to *mutate* the /// specified node to have the specified return type, Target opcode, and @@ -1380,7 +1414,7 @@ void SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc, SDOperand Op1, SDOperand Op2) { RemoveNodeFromCSEMaps(N); N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc); - N->setValueTypes(VT1, VT2); + setNodeValueTypes(N, VT1, VT2); N->setOperands(Op1, Op2); } void SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc, @@ -1396,7 +1430,7 @@ void SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc, SDOperand Op1, SDOperand Op2, SDOperand Op3) { RemoveNodeFromCSEMaps(N); N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc); - N->setValueTypes(VT1, VT2); + setNodeValueTypes(N, VT1, VT2); N->setOperands(Op1, Op2, Op3); } @@ -1546,6 +1580,15 @@ void SelectionDAG::ReplaceAllUsesWith(SDNode *From, // SDNode Class //===----------------------------------------------------------------------===// + +/// getValueTypeList - Return a pointer to the specified value type. +/// +MVT::ValueType *SDNode::getValueTypeList(MVT::ValueType VT) { + static MVT::ValueType VTs[MVT::LAST_VALUETYPE]; + VTs[VT] = VT; + return &VTs[VT]; +} + /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the /// indicated value. This method ignores uses of other values defined by this /// operation.