From 61b09412fe2c98367730c7064d56eff537b03434 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 11 Aug 2006 21:01:22 +0000 Subject: [PATCH] Move the BBNodes, GlobalValues, TargetGlobalValues, Constants, TargetConstants, RegNodes, and ValueNodes maps into the CSEMap. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29626 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 145 +++++++----------- .../SelectionDAG/SelectionDAGCSEMap.cpp | 26 ++++ 2 files changed, 83 insertions(+), 88 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 4175c38214d..ab38d94ca6d 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -341,15 +341,6 @@ void SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) { bool Erased = false; switch (N->getOpcode()) { case ISD::HANDLENODE: return; // noop. - case ISD::Constant: - Erased = Constants.erase(std::make_pair(cast(N)->getValue(), - N->getValueType(0))); - break; - case ISD::TargetConstant: - Erased = TargetConstants.erase(std::make_pair( - cast(N)->getValue(), - N->getValueType(0))); - break; case ISD::ConstantFP: { uint64_t V = DoubleToBits(cast(N)->getValue()); Erased = ConstantFPs.erase(std::make_pair(V, N->getValueType(0))); @@ -369,18 +360,6 @@ void SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) { Erased = CondCodeNodes[cast(N)->get()] != 0; CondCodeNodes[cast(N)->get()] = 0; break; - case ISD::GlobalAddress: { - GlobalAddressSDNode *GN = cast(N); - Erased = GlobalValues.erase(std::make_pair(GN->getGlobal(), - GN->getOffset())); - break; - } - case ISD::TargetGlobalAddress: { - GlobalAddressSDNode *GN = cast(N); - Erased =TargetGlobalValues.erase(std::make_pair(GN->getGlobal(), - GN->getOffset())); - break; - } case ISD::FrameIndex: Erased = FrameIndices.erase(cast(N)->getIndex()); break; @@ -406,9 +385,6 @@ void SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) { std::make_pair(cast(N)->getOffset(), cast(N)->getAlignment()))); break; - case ISD::BasicBlock: - Erased = BBNodes.erase(cast(N)->getBasicBlock()); - break; case ISD::ExternalSymbol: Erased = ExternalSymbols.erase(cast(N)->getSymbol()); break; @@ -420,15 +396,6 @@ void SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) { Erased = ValueTypeNodes[cast(N)->getVT()] != 0; ValueTypeNodes[cast(N)->getVT()] = 0; break; - case ISD::Register: - Erased = RegNodes.erase(std::make_pair(cast(N)->getReg(), - N->getValueType(0))); - break; - case ISD::SRCVALUE: { - SrcValueSDNode *SVN = cast(N); - Erased =ValueNodes.erase(std::make_pair(SVN->getValue(), SVN->getOffset())); - break; - } default: // Remove it from the CSE Map. Erased = CSEMap.RemoveNode(N); @@ -551,21 +518,6 @@ SDOperand SelectionDAG::getZeroExtendInReg(SDOperand Op, MVT::ValueType VT) { getConstant(Imm, Op.getValueType())); } -SDOperand SelectionDAG::getConstant(uint64_t Val, MVT::ValueType VT) { - assert(MVT::isInteger(VT) && "Cannot create FP integer constant!"); - assert(!MVT::isVector(VT) && "Cannot create Vector ConstantSDNodes!"); - - // Mask out any bits that are not valid for this constant. - if (VT != MVT::i64) - Val &= ((uint64_t)1 << MVT::getSizeInBits(VT)) - 1; - - SDNode *&N = Constants[std::make_pair(Val, VT)]; - if (N) return SDOperand(N, 0); - N = new ConstantSDNode(false, Val, VT); - AllNodes.push_back(N); - return SDOperand(N, 0); -} - SDOperand SelectionDAG::getString(const std::string &Val) { StringSDNode *&N = StringNodes[Val]; if (!N) { @@ -575,19 +527,26 @@ SDOperand SelectionDAG::getString(const std::string &Val) { return SDOperand(N, 0); } -SDOperand SelectionDAG::getTargetConstant(uint64_t Val, MVT::ValueType VT) { +SDOperand SelectionDAG::getConstant(uint64_t Val, MVT::ValueType VT, bool isT) { assert(MVT::isInteger(VT) && "Cannot create FP integer constant!"); - // Mask out any bits that are not valid for this constant. - if (VT != MVT::i64) - Val &= ((uint64_t)1 << MVT::getSizeInBits(VT)) - 1; + assert(!MVT::isVector(VT) && "Cannot create Vector ConstantSDNodes!"); - SDNode *&N = TargetConstants[std::make_pair(Val, VT)]; - if (N) return SDOperand(N, 0); - N = new ConstantSDNode(true, Val, VT); + // Mask out any bits that are not valid for this constant. + Val &= MVT::getIntVTBitMask(VT); + + unsigned Opc = isT ? ISD::TargetConstant : ISD::Constant; + SelectionDAGCSEMap::NodeID ID(Opc, getNodeValueTypes(VT)); + ID.AddInteger(Val); + void *IP = 0; + if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) + return SDOperand(E, 0); + SDNode *N = new ConstantSDNode(isT, Val, VT); + CSEMap.InsertNode(N, IP); AllNodes.push_back(N); return SDOperand(N, 0); } + SDOperand SelectionDAG::getConstantFP(double Val, MVT::ValueType VT) { assert(MVT::isFloatingPoint(VT) && "Cannot create integer FP constant!"); if (VT == MVT::f32) @@ -619,19 +578,17 @@ SDOperand SelectionDAG::getTargetConstantFP(double Val, MVT::ValueType VT) { } SDOperand SelectionDAG::getGlobalAddress(const GlobalValue *GV, - MVT::ValueType VT, int offset) { - SDNode *&N = GlobalValues[std::make_pair(GV, offset)]; - if (N) return SDOperand(N, 0); - N = new GlobalAddressSDNode(false, GV, VT, offset); - AllNodes.push_back(N); - return SDOperand(N, 0); -} - -SDOperand SelectionDAG::getTargetGlobalAddress(const GlobalValue *GV, - MVT::ValueType VT, int offset) { - SDNode *&N = TargetGlobalValues[std::make_pair(GV, offset)]; - if (N) return SDOperand(N, 0); - N = new GlobalAddressSDNode(true, GV, VT, offset); + MVT::ValueType VT, int Offset, + bool isTargetGA) { + unsigned Opc = isTargetGA ? ISD::TargetGlobalAddress : ISD::GlobalAddress; + SelectionDAGCSEMap::NodeID ID(Opc, getNodeValueTypes(VT)); + ID.AddPointer(GV); + ID.AddInteger(Offset); + void *IP = 0; + if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) + return SDOperand(E, 0); + SDNode *N = new GlobalAddressSDNode(isTargetGA, GV, VT, Offset); + CSEMap.InsertNode(N, IP); AllNodes.push_back(N); return SDOperand(N, 0); } @@ -689,9 +646,13 @@ SDOperand SelectionDAG::getTargetConstantPool(Constant *C, MVT::ValueType VT, } SDOperand SelectionDAG::getBasicBlock(MachineBasicBlock *MBB) { - SDNode *&N = BBNodes[MBB]; - if (N) return SDOperand(N, 0); - N = new BasicBlockSDNode(MBB); + SelectionDAGCSEMap::NodeID ID(ISD::BasicBlock, getNodeValueTypes(MVT::Other)); + ID.AddPointer(MBB); + void *IP = 0; + if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) + return SDOperand(E, 0); + SDNode *N = new BasicBlockSDNode(MBB); + CSEMap.InsertNode(N, IP); AllNodes.push_back(N); return SDOperand(N, 0); } @@ -736,12 +697,31 @@ SDOperand SelectionDAG::getCondCode(ISD::CondCode Cond) { } SDOperand SelectionDAG::getRegister(unsigned RegNo, MVT::ValueType VT) { - RegisterSDNode *&Reg = RegNodes[std::make_pair(RegNo, VT)]; - if (!Reg) { - Reg = new RegisterSDNode(RegNo, VT); - AllNodes.push_back(Reg); - } - return SDOperand(Reg, 0); + SelectionDAGCSEMap::NodeID ID(ISD::Register, getNodeValueTypes(VT)); + ID.AddInteger(RegNo); + void *IP = 0; + if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) + return SDOperand(E, 0); + SDNode *N = new RegisterSDNode(RegNo, VT); + CSEMap.InsertNode(N, IP); + AllNodes.push_back(N); + return SDOperand(N, 0); +} + +SDOperand SelectionDAG::getSrcValue(const Value *V, int Offset) { + assert((!V || isa(V->getType())) && + "SrcValue is not a pointer?"); + + SelectionDAGCSEMap::NodeID ID(ISD::SRCVALUE, getNodeValueTypes(MVT::Other)); + ID.AddPointer(V); + ID.AddInteger(Offset); + void *IP = 0; + if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) + return SDOperand(E, 0); + SDNode *N = new SrcValueSDNode(V, Offset); + CSEMap.InsertNode(N, IP); + AllNodes.push_back(N); + return SDOperand(N, 0); } SDOperand SelectionDAG::SimplifySetCC(MVT::ValueType VT, SDOperand N1, @@ -1540,17 +1520,6 @@ SDOperand SelectionDAG::getExtLoad(unsigned Opcode, MVT::ValueType VT, return getNode(Opcode, VTs, Ops, 4); } -SDOperand SelectionDAG::getSrcValue(const Value *V, int Offset) { - assert((!V || isa(V->getType())) && - "SrcValue is not a pointer?"); - SDNode *&N = ValueNodes[std::make_pair(V, Offset)]; - if (N) return SDOperand(N, 0); - - N = new SrcValueSDNode(V, Offset); - AllNodes.push_back(N); - return SDOperand(N, 0); -} - SDOperand SelectionDAG::getVAArg(MVT::ValueType VT, SDOperand Chain, SDOperand Ptr, SDOperand SV) { diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGCSEMap.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGCSEMap.cpp index 63599927bf8..bfd2f9eb29a 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGCSEMap.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGCSEMap.cpp @@ -23,6 +23,32 @@ SelectionDAGCSEMap::NodeID::NodeID(SDNode *N) { SetValueTypes(N->value_begin()); // Add the operand info. SetOperands(N->op_begin(), N->getNumOperands()); + + // Handle SDNode leafs with special info. + if (N->getNumOperands() == 0) { + switch (N->getOpcode()) { + default: break; // Normal nodes don't need extra info. + case ISD::TargetConstant: + case ISD::Constant: + AddInteger(cast(N)->getValue()); + break; + case ISD::TargetGlobalAddress: + case ISD::GlobalAddress: + AddPointer(cast(N)->getGlobal()); + AddInteger(cast(N)->getOffset()); + break; + case ISD::BasicBlock: + AddPointer(cast(N)->getBasicBlock()); + break; + case ISD::Register: + AddInteger(cast(N)->getReg()); + break; + case ISD::SRCVALUE: + AddPointer(cast(N)->getValue()); + AddInteger(cast(N)->getOffset()); + break; + } + } } SelectionDAGCSEMap::NodeID::NodeID(unsigned short ID, const void *VTList) { -- 2.34.1