From c9f8f416800784ca6453222b307bc44ad24739b0 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 11 Aug 2006 21:55:30 +0000 Subject: [PATCH] Remove 8 more std::map's. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29631 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/SelectionDAG.h | 32 ++--- lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 132 ++++++------------ .../SelectionDAG/SelectionDAGCSEMap.cpp | 18 +++ 3 files changed, 74 insertions(+), 108 deletions(-) diff --git a/include/llvm/CodeGen/SelectionDAG.h b/include/llvm/CodeGen/SelectionDAG.h index d84924e276e..2cc6ba71011 100644 --- a/include/llvm/CodeGen/SelectionDAG.h +++ b/include/llvm/CodeGen/SelectionDAG.h @@ -111,22 +111,30 @@ public: SDOperand getTargetConstant(uint64_t Val, MVT::ValueType VT) { return getConstant(Val, VT, true); } - SDOperand getConstantFP(double Val, MVT::ValueType VT); - SDOperand getTargetConstantFP(double Val, MVT::ValueType VT); + SDOperand getConstantFP(double Val, MVT::ValueType VT, bool isTarget = false); + SDOperand getTargetConstantFP(double Val, MVT::ValueType VT) { + return getConstantFP(Val, VT, true); + } SDOperand getGlobalAddress(const GlobalValue *GV, MVT::ValueType VT, int offset = 0, bool isTargetGA = false); SDOperand getTargetGlobalAddress(const GlobalValue *GV, MVT::ValueType VT, int offset = 0) { return getGlobalAddress(GV, VT, offset, true); } - SDOperand getFrameIndex(int FI, MVT::ValueType VT); - SDOperand getTargetFrameIndex(int FI, MVT::ValueType VT); - SDOperand getJumpTable(int JTI, MVT::ValueType VT); - SDOperand getTargetJumpTable(int JTI, MVT::ValueType VT); + SDOperand getFrameIndex(int FI, MVT::ValueType VT, bool isTarget = false); + SDOperand getTargetFrameIndex(int FI, MVT::ValueType VT) { + return getFrameIndex(FI, VT, true); + } + SDOperand getJumpTable(int JTI, MVT::ValueType VT, bool isTarget = false); + SDOperand getTargetJumpTable(int JTI, MVT::ValueType VT) { + return getJumpTable(JTI, VT, true); + } SDOperand getConstantPool(Constant *C, MVT::ValueType VT, - unsigned Alignment=0, int offset = 0); + unsigned Align = 0, int Offs = 0, bool isT=false); SDOperand getTargetConstantPool(Constant *C, MVT::ValueType VT, - unsigned Alignment=0, int offset = 0); + unsigned Align = 0, int Offset = 0) { + return getConstantPool(C, VT, Align, Offset, true); + } SDOperand getBasicBlock(MachineBasicBlock *MBB); SDOperand getExternalSymbol(const char *Sym, MVT::ValueType VT); SDOperand getTargetExternalSymbol(const char *Sym, MVT::ValueType VT); @@ -452,14 +460,6 @@ private: // Maps to auto-CSE operations. std::vector CondCodeNodes; - std::map, SDNode*> ConstantFPs; - std::map, SDNode*> TargetConstantFPs; - std::map FrameIndices, TargetFrameIndices, JumpTableIndices, - TargetJumpTableIndices; - std::map >, SDNode*> ConstantPoolIndices; - std::map >, SDNode*> TargetConstantPoolIndices; std::vector ValueTypeNodes; std::map ExternalSymbols; std::map TargetExternalSymbols; diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index ab38d94ca6d..72a7d330016 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -341,16 +341,6 @@ void SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) { bool Erased = false; switch (N->getOpcode()) { case ISD::HANDLENODE: return; // noop. - case ISD::ConstantFP: { - uint64_t V = DoubleToBits(cast(N)->getValue()); - Erased = ConstantFPs.erase(std::make_pair(V, N->getValueType(0))); - break; - } - case ISD::TargetConstantFP: { - uint64_t V = DoubleToBits(cast(N)->getValue()); - Erased = TargetConstantFPs.erase(std::make_pair(V, N->getValueType(0))); - break; - } case ISD::STRING: Erased = StringNodes.erase(cast(N)->getValue()); break; @@ -360,31 +350,6 @@ void SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) { Erased = CondCodeNodes[cast(N)->get()] != 0; CondCodeNodes[cast(N)->get()] = 0; break; - case ISD::FrameIndex: - Erased = FrameIndices.erase(cast(N)->getIndex()); - break; - case ISD::TargetFrameIndex: - Erased = TargetFrameIndices.erase(cast(N)->getIndex()); - break; - case ISD::JumpTable: - Erased = JumpTableIndices.erase(cast(N)->getIndex()); - break; - case ISD::TargetJumpTable: - Erased = - TargetJumpTableIndices.erase(cast(N)->getIndex()); - break; - case ISD::ConstantPool: - Erased = ConstantPoolIndices. - erase(std::make_pair(cast(N)->get(), - std::make_pair(cast(N)->getOffset(), - cast(N)->getAlignment()))); - break; - case ISD::TargetConstantPool: - Erased = TargetConstantPoolIndices. - erase(std::make_pair(cast(N)->get(), - std::make_pair(cast(N)->getOffset(), - cast(N)->getAlignment()))); - break; case ISD::ExternalSymbol: Erased = ExternalSymbols.erase(cast(N)->getSymbol()); break; @@ -547,7 +512,8 @@ SDOperand SelectionDAG::getConstant(uint64_t Val, MVT::ValueType VT, bool isT) { } -SDOperand SelectionDAG::getConstantFP(double Val, MVT::ValueType VT) { +SDOperand SelectionDAG::getConstantFP(double Val, MVT::ValueType VT, + bool isTarget) { assert(MVT::isFloatingPoint(VT) && "Cannot create integer FP constant!"); if (VT == MVT::f32) Val = (float)Val; // Mask out extra precision. @@ -555,24 +521,14 @@ SDOperand SelectionDAG::getConstantFP(double Val, MVT::ValueType VT) { // Do the map lookup using the actual bit pattern for the floating point // value, so that we don't have problems with 0.0 comparing equal to -0.0, and // we don't have issues with SNANs. - SDNode *&N = ConstantFPs[std::make_pair(DoubleToBits(Val), VT)]; - if (N) return SDOperand(N, 0); - N = new ConstantFPSDNode(false, Val, VT); - AllNodes.push_back(N); - return SDOperand(N, 0); -} - -SDOperand SelectionDAG::getTargetConstantFP(double Val, MVT::ValueType VT) { - assert(MVT::isFloatingPoint(VT) && "Cannot create integer FP constant!"); - if (VT == MVT::f32) - Val = (float)Val; // Mask out extra precision. - - // Do the map lookup using the actual bit pattern for the floating point - // value, so that we don't have problems with 0.0 comparing equal to -0.0, and - // we don't have issues with SNANs. - SDNode *&N = TargetConstantFPs[std::make_pair(DoubleToBits(Val), VT)]; - if (N) return SDOperand(N, 0); - N = new ConstantFPSDNode(true, Val, VT); + unsigned Opc = isTarget ? ISD::TargetConstantFP : ISD::ConstantFP; + SelectionDAGCSEMap::NodeID ID(Opc, getNodeValueTypes(VT)); + ID.AddInteger(DoubleToBits(Val)); + void *IP = 0; + if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) + return SDOperand(E, 0); + SDNode *N = new ConstantFPSDNode(isTarget, Val, VT); + CSEMap.InsertNode(N, IP); AllNodes.push_back(N); return SDOperand(N, 0); } @@ -593,57 +549,49 @@ SDOperand SelectionDAG::getGlobalAddress(const GlobalValue *GV, return SDOperand(N, 0); } -SDOperand SelectionDAG::getFrameIndex(int FI, MVT::ValueType VT) { - SDNode *&N = FrameIndices[FI]; - if (N) return SDOperand(N, 0); - N = new FrameIndexSDNode(FI, VT, false); +SDOperand SelectionDAG::getFrameIndex(int FI, MVT::ValueType VT, + bool isTarget) { + unsigned Opc = isTarget ? ISD::TargetFrameIndex : ISD::FrameIndex; + SelectionDAGCSEMap::NodeID ID(Opc, getNodeValueTypes(VT)); + ID.AddInteger(FI); + void *IP = 0; + if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) + return SDOperand(E, 0); + SDNode *N = new FrameIndexSDNode(FI, VT, isTarget); + CSEMap.InsertNode(N, IP); AllNodes.push_back(N); return SDOperand(N, 0); } -SDOperand SelectionDAG::getTargetFrameIndex(int FI, MVT::ValueType VT) { - SDNode *&N = TargetFrameIndices[FI]; - if (N) return SDOperand(N, 0); - N = new FrameIndexSDNode(FI, VT, true); - AllNodes.push_back(N); - return SDOperand(N, 0); -} - -SDOperand SelectionDAG::getJumpTable(int JTI, MVT::ValueType VT) { - SDNode *&N = JumpTableIndices[JTI]; - if (N) return SDOperand(N, 0); - N = new JumpTableSDNode(JTI, VT, false); - AllNodes.push_back(N); - return SDOperand(N, 0); -} - -SDOperand SelectionDAG::getTargetJumpTable(int JTI, MVT::ValueType VT) { - SDNode *&N = TargetJumpTableIndices[JTI]; - if (N) return SDOperand(N, 0); - N = new JumpTableSDNode(JTI, VT, true); +SDOperand SelectionDAG::getJumpTable(int JTI, MVT::ValueType VT, bool isTarget){ + unsigned Opc = isTarget ? ISD::TargetJumpTable : ISD::JumpTable; + SelectionDAGCSEMap::NodeID ID(Opc, getNodeValueTypes(VT)); + ID.AddInteger(JTI); + void *IP = 0; + if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) + return SDOperand(E, 0); + SDNode *N = new JumpTableSDNode(JTI, VT, isTarget); + CSEMap.InsertNode(N, IP); AllNodes.push_back(N); return SDOperand(N, 0); } SDOperand SelectionDAG::getConstantPool(Constant *C, MVT::ValueType VT, - unsigned Alignment, int Offset) { - SDNode *&N = ConstantPoolIndices[std::make_pair(C, - std::make_pair(Offset, Alignment))]; - if (N) return SDOperand(N, 0); - N = new ConstantPoolSDNode(false, C, VT, Offset, Alignment); + unsigned Alignment, int Offset, + bool isTarget) { + unsigned Opc = isTarget ? ISD::TargetConstantPool : ISD::ConstantPool; + SelectionDAGCSEMap::NodeID ID(Opc, getNodeValueTypes(VT)); + ID.AddInteger(Alignment); + ID.AddInteger(Offset); + void *IP = 0; + if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) + return SDOperand(E, 0); + SDNode *N = new ConstantPoolSDNode(isTarget, C, VT, Offset, Alignment); + CSEMap.InsertNode(N, IP); AllNodes.push_back(N); return SDOperand(N, 0); } -SDOperand SelectionDAG::getTargetConstantPool(Constant *C, MVT::ValueType VT, - unsigned Alignment, int Offset) { - SDNode *&N = TargetConstantPoolIndices[std::make_pair(C, - std::make_pair(Offset, Alignment))]; - if (N) return SDOperand(N, 0); - N = new ConstantPoolSDNode(true, C, VT, Offset, Alignment); - AllNodes.push_back(N); - return SDOperand(N, 0); -} SDOperand SelectionDAG::getBasicBlock(MachineBasicBlock *MBB) { SelectionDAGCSEMap::NodeID ID(ISD::BasicBlock, getNodeValueTypes(MVT::Other)); diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGCSEMap.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGCSEMap.cpp index bfd2f9eb29a..6fc6a48b1e4 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGCSEMap.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGCSEMap.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "llvm/CodeGen/SelectionDAG.h" +#include "llvm/Support/MathExtras.h" using namespace llvm; //===----------------------------------------------------------------------===// @@ -32,6 +33,10 @@ SelectionDAGCSEMap::NodeID::NodeID(SDNode *N) { case ISD::Constant: AddInteger(cast(N)->getValue()); break; + case ISD::TargetConstantFP: + case ISD::ConstantFP: + AddInteger(DoubleToBits(cast(N)->getValue())); + break; case ISD::TargetGlobalAddress: case ISD::GlobalAddress: AddPointer(cast(N)->getGlobal()); @@ -47,6 +52,19 @@ SelectionDAGCSEMap::NodeID::NodeID(SDNode *N) { AddPointer(cast(N)->getValue()); AddInteger(cast(N)->getOffset()); break; + case ISD::FrameIndex: + case ISD::TargetFrameIndex: + AddInteger(cast(N)->getIndex()); + break; + case ISD::JumpTable: + case ISD::TargetJumpTable: + AddInteger(cast(N)->getIndex()); + break; + case ISD::ConstantPool: + case ISD::TargetConstantPool: + AddInteger(cast(N)->getAlignment()); + AddInteger(cast(N)->getOffset()); + break; } } }