From 70814bc38435d61a8c7cc32f2375c09e21f12a8a Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 29 Jan 2006 07:58:15 +0000 Subject: [PATCH] Remove some special case hacks for CALLSEQ_*, using UpdateNodeOperands instead. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25780 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 37 +++++++++-------- lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 50 +++-------------------- 2 files changed, 27 insertions(+), 60 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index fb5329a5c0c..57e0077d919 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -589,22 +589,24 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) { case ISD::CALLSEQ_START: case ISD::CALLSEQ_END: Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. - // Do not try to legalize the target-specific arguments (#1+) - Tmp2 = Node->getOperand(0); - if (Tmp1 != Tmp2) - Node->setAdjCallChain(Tmp1); - - // If this has a flag input, do legalize it. - if (Node->getOperand(Node->getNumOperands()-1).getValueType() == MVT::Flag){ - Tmp1 = LegalizeOp(Node->getOperand(Node->getNumOperands()-1)); - if (Tmp1 != Node->getOperand(Node->getNumOperands()-1)) - Node->setAdjCallFlag(Tmp1); + // Do not try to legalize the target-specific arguments (#1+), except for + // an optional flag input. + if (Node->getOperand(Node->getNumOperands()-1).getValueType() != MVT::Flag){ + if (Tmp1 != Node->getOperand(0)) { + std::vector Ops(Node->op_begin(), Node->op_end()); + Ops[0] = Tmp1; + Result = DAG.UpdateNodeOperands(Result, Ops); + } + } else { + Tmp2 = LegalizeOp(Node->getOperand(Node->getNumOperands()-1)); + if (Tmp1 != Node->getOperand(0) || + Tmp2 != Node->getOperand(Node->getNumOperands()-1)) { + std::vector Ops(Node->op_begin(), Node->op_end()); + Ops[0] = Tmp1; + Ops.back() = Tmp2; + Result = DAG.UpdateNodeOperands(Result, Ops); + } } - - // Note that we do not create new CALLSEQ_DOWN/UP nodes here. These - // nodes are treated specially and are mutated in place. This makes the dag - // legalization process more efficient and also makes libcall insertion - // easier. break; case ISD::DYNAMIC_STACKALLOC: { Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. @@ -2964,7 +2966,10 @@ void SelectionDAGLegalize::SpliceCallInto(const SDOperand &CallResult, SDOperand InToken = DAG.getNode(ISD::TokenFactor, MVT::Other, CallResult, OutChain->getOperand(0)); // Change the node to refer to the new token. - OutChain->setAdjCallChain(InToken); + std::vector Ops(OutChain->op_begin(), OutChain->op_end()); + Ops[0] = InToken; + SDOperand Res = DAG.UpdateNodeOperands(SDOperand(OutChain, 0), Ops); + assert(Res.Val == OutChain && "Didn't update in place!"); } diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index b9a6ec0d452..aa9ea638f8e 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -380,9 +380,7 @@ void SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) { // flag result (which cannot be CSE'd) or is one of the special cases that are // not subject to CSE. if (!Erased && N->getValueType(N->getNumValues()-1) != MVT::Flag && - N->getOpcode() != ISD::CALLSEQ_START && - N->getOpcode() != ISD::CALLSEQ_END && !N->isTargetOpcode()) { - + !N->isTargetOpcode()) { N->dump(); assert(0 && "Node is not in map!"); } @@ -396,9 +394,7 @@ void SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) { /// SDNode *SelectionDAG::AddNonLeafNodeToCSEMaps(SDNode *N) { assert(N->getNumOperands() && "This is a leaf node!"); - if (N->getOpcode() == ISD::CALLSEQ_START || - N->getOpcode() == ISD::CALLSEQ_END || - N->getOpcode() == ISD::HANDLENODE || N->getValueType(0) == MVT::Flag) + if (N->getOpcode() == ISD::HANDLENODE || N->getValueType(0) == MVT::Flag) return 0; // Never add these nodes. // Check that remaining values produced are not flags. @@ -451,9 +447,7 @@ SDNode *SelectionDAG::AddNonLeafNodeToCSEMaps(SDNode *N) { /// return null, otherwise return a pointer to the slot it would take. If a /// node already exists with these operands, the slot will be non-null. SDNode **SelectionDAG::FindModifiedNodeSlot(SDNode *N, SDOperand Op) { - if (N->getOpcode() == ISD::CALLSEQ_START || - N->getOpcode() == ISD::CALLSEQ_END || - N->getOpcode() == ISD::HANDLENODE || N->getValueType(0) == MVT::Flag) + if (N->getOpcode() == ISD::HANDLENODE || N->getValueType(0) == MVT::Flag) return 0; // Never add these nodes. // Check that remaining values produced are not flags. @@ -481,9 +475,7 @@ SDNode **SelectionDAG::FindModifiedNodeSlot(SDNode *N, SDOperand Op) { /// node already exists with these operands, the slot will be non-null. SDNode **SelectionDAG::FindModifiedNodeSlot(SDNode *N, SDOperand Op1, SDOperand Op2) { - if (N->getOpcode() == ISD::CALLSEQ_START || - N->getOpcode() == ISD::CALLSEQ_END || - N->getOpcode() == ISD::HANDLENODE || N->getValueType(0) == MVT::Flag) + if (N->getOpcode() == ISD::HANDLENODE || N->getValueType(0) == MVT::Flag) return 0; // Never add these nodes. // Check that remaining values produced are not flags. @@ -512,9 +504,7 @@ SDNode **SelectionDAG::FindModifiedNodeSlot(SDNode *N, /// node already exists with these operands, the slot will be non-null. SDNode **SelectionDAG::FindModifiedNodeSlot(SDNode *N, const std::vector &Ops) { - if (N->getOpcode() == ISD::CALLSEQ_START || - N->getOpcode() == ISD::CALLSEQ_END || - N->getOpcode() == ISD::HANDLENODE || N->getValueType(0) == MVT::Flag) + if (N->getOpcode() == ISD::HANDLENODE || N->getValueType(0) == MVT::Flag) return 0; // Never add these nodes. // Check that remaining values produced are not flags. @@ -1296,8 +1286,7 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT, // Memoize this node if possible. SDNode *N; - if (Opcode != ISD::CALLSEQ_START && Opcode != ISD::CALLSEQ_END && - VT != MVT::Flag) { + if (VT != MVT::Flag) { SDNode *&BON = BinaryOps[std::make_pair(Opcode, std::make_pair(N1, N2))]; if (BON) return SDOperand(BON, 0); @@ -1387,33 +1376,6 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT, return getNode(Opcode, VT, Ops); } -// setAdjCallChain - This method changes the token chain of an -// CALLSEQ_START/END node to be the specified operand. -void SDNode::setAdjCallChain(SDOperand N) { - assert(N.getValueType() == MVT::Other); - assert((getOpcode() == ISD::CALLSEQ_START || - getOpcode() == ISD::CALLSEQ_END) && "Cannot adjust this node!"); - - OperandList[0].Val->removeUser(this); - OperandList[0] = N; - OperandList[0].Val->Uses.push_back(this); -} - -// setAdjCallFlag - This method changes the flag input of an -// CALLSEQ_START/END node to be the specified operand. -void SDNode::setAdjCallFlag(SDOperand N) { - assert(N.getValueType() == MVT::Flag); - assert((getOpcode() == ISD::CALLSEQ_START || - getOpcode() == ISD::CALLSEQ_END) && "Cannot adjust this node!"); - - SDOperand &FlagOp = OperandList[getNumOperands()-1]; - assert(FlagOp.getValueType() == MVT::Flag); - FlagOp.Val->removeUser(this); - FlagOp = N; - FlagOp.Val->Uses.push_back(this); -} - - SDOperand SelectionDAG::getLoad(MVT::ValueType VT, SDOperand Chain, SDOperand Ptr, SDOperand SV) { -- 2.34.1