From 6b345ee9b2833cf1b2f79dc16d06d4060bec36ef Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 7 Jul 2008 17:46:23 +0000 Subject: [PATCH] Make DenseMap's insert return a pair, to more closely resemble std::map. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53177 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/DenseMap.h | 10 +++++---- include/llvm/ADT/DenseSet.h | 8 +++---- lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 5 +++-- lib/CodeGen/SelectionDAG/ScheduleDAG.cpp | 18 +++++++++------- lib/Linker/LinkModules.cpp | 2 +- lib/Target/X86/X86InstrInfo.cpp | 21 ++++++++++++------- .../Scalar/InstructionCombining.cpp | 2 +- 7 files changed, 39 insertions(+), 27 deletions(-) diff --git a/include/llvm/ADT/DenseMap.h b/include/llvm/ADT/DenseMap.h index fd9edd240fa..e584973e4f1 100644 --- a/include/llvm/ADT/DenseMap.h +++ b/include/llvm/ADT/DenseMap.h @@ -147,14 +147,16 @@ public: return end(); } - bool insert(const std::pair &KV) { + std::pair insert(const std::pair &KV) { BucketT *TheBucket; if (LookupBucketFor(KV.first, TheBucket)) - return false; // Already in map. + return std::make_pair(iterator(TheBucket, Buckets+NumBuckets), + false); // Already in map. // Otherwise, insert the new element. - InsertIntoBucket(KV.first, KV.second, TheBucket); - return true; + TheBucket = InsertIntoBucket(KV.first, KV.second, TheBucket); + return std::make_pair(iterator(TheBucket, Buckets+NumBuckets), + true); } bool erase(const KeyT &Val) { diff --git a/include/llvm/ADT/DenseSet.h b/include/llvm/ADT/DenseSet.h index 06d0fa8e0d6..eb93e6c5fe6 100644 --- a/include/llvm/ADT/DenseSet.h +++ b/include/llvm/ADT/DenseSet.h @@ -41,10 +41,6 @@ public: return TheMap.count(V); } - bool insert(const ValueT &V) { - return TheMap.insert(std::make_pair(V, 0)); - } - void erase(const ValueT &V) { TheMap.erase(V); } @@ -90,6 +86,10 @@ public: const_iterator begin() const { return ConstIterator(TheMap.begin()); } const_iterator end() const { return ConstIterator(TheMap.end()); } + + std::pair insert(const ValueT &V) { + return TheMap.insert(std::make_pair(V, 0)); + } }; } // end namespace llvm diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index 1fa1f3fa2a3..5cf637e0468 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -115,7 +115,7 @@ class VISIBILITY_HIDDEN SelectionDAGLegalize { LegalizedNodes.insert(std::make_pair(To, To)); } void AddPromotedOperand(SDOperand From, SDOperand To) { - bool isNew = PromotedNodes.insert(std::make_pair(From, To)); + bool isNew = PromotedNodes.insert(std::make_pair(From, To)).second; assert(isNew && "Got into the map somehow?"); // If someone requests legalization of the new node, return itself. LegalizedNodes.insert(std::make_pair(To, To)); @@ -6734,7 +6734,8 @@ void SelectionDAGLegalize::ExpandOp(SDOperand Op, SDOperand &Lo, SDOperand &Hi){ } // Remember in a map if the values will be reused later. - bool isNew = ExpandedNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))); + bool isNew = + ExpandedNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second; assert(isNew && "Value already expanded?!?"); } diff --git a/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp b/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp index f41e14aa7e1..10a5e8c9df3 100644 --- a/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp +++ b/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp @@ -413,9 +413,10 @@ void ScheduleDAG::EmitCopyFromReg(SDNode *Node, unsigned ResNo, unsigned VRBase = 0; if (TargetRegisterInfo::isVirtualRegister(SrcReg)) { // Just use the input register directly! + SDOperand Op(Node, ResNo); if (IsClone) - VRBaseMap.erase(SDOperand(Node, ResNo)); - bool isNew = VRBaseMap.insert(std::make_pair(SDOperand(Node,ResNo),SrcReg)); + VRBaseMap.erase(Op); + bool isNew = VRBaseMap.insert(std::make_pair(Op, SrcReg)).second; isNew = isNew; // Silence compiler warning. assert(isNew && "Node emitted out of order - early"); return; @@ -472,9 +473,10 @@ void ScheduleDAG::EmitCopyFromReg(SDNode *Node, unsigned ResNo, TII->copyRegToReg(*BB, BB->end(), VRBase, SrcReg, DstRC, SrcRC); } + SDOperand Op(Node, ResNo); if (IsClone) - VRBaseMap.erase(SDOperand(Node, ResNo)); - bool isNew = VRBaseMap.insert(std::make_pair(SDOperand(Node,ResNo), VRBase)); + VRBaseMap.erase(Op); + bool isNew = VRBaseMap.insert(std::make_pair(Op, VRBase)).second; isNew = isNew; // Silence compiler warning. assert(isNew && "Node emitted out of order - early"); } @@ -532,7 +534,8 @@ void ScheduleDAG::CreateVirtualRegisters(SDNode *Node, MachineInstr *MI, MI->addOperand(MachineOperand::CreateReg(VRBase, true)); } - bool isNew = VRBaseMap.insert(std::make_pair(SDOperand(Node,i), VRBase)); + SDOperand Op(Node, i); + bool isNew = VRBaseMap.insert(std::make_pair(Op, VRBase)).second; isNew = isNew; // Silence compiler warning. assert(isNew && "Node emitted out of order - early"); } @@ -786,7 +789,8 @@ void ScheduleDAG::EmitSubregNode(SDNode *Node, } else assert(0 && "Node is not insert_subreg, extract_subreg, or subreg_to_reg"); - bool isNew = VRBaseMap.insert(std::make_pair(SDOperand(Node,0), VRBase)); + SDOperand Op(Node, 0); + bool isNew = VRBaseMap.insert(std::make_pair(Op, VRBase)).second; isNew = isNew; // Silence compiler warning. assert(isNew && "Node emitted out of order - early"); } @@ -992,7 +996,7 @@ void ScheduleDAG::EmitCrossRCCopy(SUnit *SU, // Copy from physical register. assert(I->Reg && "Unknown physical register!"); unsigned VRBase = MRI.createVirtualRegister(SU->CopyDstRC); - bool isNew = VRBaseMap.insert(std::make_pair(SU, VRBase)); + bool isNew = VRBaseMap.insert(std::make_pair(SU, VRBase)).second; isNew = isNew; // Silence compiler warning. assert(isNew && "Node emitted out of order - early"); TII->copyRegToReg(*BB, BB->end(), VRBase, I->Reg, diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index a2a298fba9d..cd18bf4aa16 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -114,7 +114,7 @@ public: /// insert - This returns true if the pointer was new to the set, false if it /// was already in the set. bool insert(const Type *Src, const Type *Dst) { - if (!TheMap.insert(std::make_pair(Src, PATypeHolder(Dst)))) + if (!TheMap.insert(std::make_pair(Src, PATypeHolder(Dst))).second) return false; // Already in map. if (Src->isAbstract()) Src->addAbstractTypeUser(this); diff --git a/lib/Target/X86/X86InstrInfo.cpp b/lib/Target/X86/X86InstrInfo.cpp index c833de51576..76aa4559b90 100644 --- a/lib/Target/X86/X86InstrInfo.cpp +++ b/lib/Target/X86/X86InstrInfo.cpp @@ -209,11 +209,13 @@ X86InstrInfo::X86InstrInfo(X86TargetMachine &tm) for (unsigned i = 0, e = array_lengthof(OpTbl2Addr); i != e; ++i) { unsigned RegOp = OpTbl2Addr[i][0]; unsigned MemOp = OpTbl2Addr[i][1]; - if (!RegOp2MemOpTable2Addr.insert(std::make_pair((unsigned*)RegOp, MemOp))) + if (!RegOp2MemOpTable2Addr.insert(std::make_pair((unsigned*)RegOp, + MemOp)).second) assert(false && "Duplicated entries?"); unsigned AuxInfo = 0 | (1 << 4) | (1 << 5); // Index 0,folded load and store if (!MemOp2RegOpTable.insert(std::make_pair((unsigned*)MemOp, - std::make_pair(RegOp, AuxInfo)))) + std::make_pair(RegOp, + AuxInfo))).second) AmbEntries.push_back(MemOp); } @@ -297,14 +299,15 @@ X86InstrInfo::X86InstrInfo(X86TargetMachine &tm) for (unsigned i = 0, e = array_lengthof(OpTbl0); i != e; ++i) { unsigned RegOp = OpTbl0[i][0]; unsigned MemOp = OpTbl0[i][1]; - if (!RegOp2MemOpTable0.insert(std::make_pair((unsigned*)RegOp, MemOp))) + if (!RegOp2MemOpTable0.insert(std::make_pair((unsigned*)RegOp, + MemOp)).second) assert(false && "Duplicated entries?"); unsigned FoldedLoad = OpTbl0[i][2]; // Index 0, folded load or store. unsigned AuxInfo = 0 | (FoldedLoad << 4) | ((FoldedLoad^1) << 5); if (RegOp != X86::FsMOVAPDrr && RegOp != X86::FsMOVAPSrr) if (!MemOp2RegOpTable.insert(std::make_pair((unsigned*)MemOp, - std::make_pair(RegOp, AuxInfo)))) + std::make_pair(RegOp, AuxInfo))).second) AmbEntries.push_back(MemOp); } @@ -423,12 +426,13 @@ X86InstrInfo::X86InstrInfo(X86TargetMachine &tm) for (unsigned i = 0, e = array_lengthof(OpTbl1); i != e; ++i) { unsigned RegOp = OpTbl1[i][0]; unsigned MemOp = OpTbl1[i][1]; - if (!RegOp2MemOpTable1.insert(std::make_pair((unsigned*)RegOp, MemOp))) + if (!RegOp2MemOpTable1.insert(std::make_pair((unsigned*)RegOp, + MemOp)).second) assert(false && "Duplicated entries?"); unsigned AuxInfo = 1 | (1 << 4); // Index 1, folded load if (RegOp != X86::FsMOVAPDrr && RegOp != X86::FsMOVAPSrr) if (!MemOp2RegOpTable.insert(std::make_pair((unsigned*)MemOp, - std::make_pair(RegOp, AuxInfo)))) + std::make_pair(RegOp, AuxInfo))).second) AmbEntries.push_back(MemOp); } @@ -629,11 +633,12 @@ X86InstrInfo::X86InstrInfo(X86TargetMachine &tm) for (unsigned i = 0, e = array_lengthof(OpTbl2); i != e; ++i) { unsigned RegOp = OpTbl2[i][0]; unsigned MemOp = OpTbl2[i][1]; - if (!RegOp2MemOpTable2.insert(std::make_pair((unsigned*)RegOp, MemOp))) + if (!RegOp2MemOpTable2.insert(std::make_pair((unsigned*)RegOp, + MemOp)).second) assert(false && "Duplicated entries?"); unsigned AuxInfo = 2 | (1 << 4); // Index 1, folded load if (!MemOp2RegOpTable.insert(std::make_pair((unsigned*)MemOp, - std::make_pair(RegOp, AuxInfo)))) + std::make_pair(RegOp, AuxInfo))).second) AmbEntries.push_back(MemOp); } diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 8c3f2d5a74a..8bc909196af 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -85,7 +85,7 @@ namespace { /// AddToWorkList - Add the specified instruction to the worklist if it /// isn't already in it. void AddToWorkList(Instruction *I) { - if (WorklistMap.insert(std::make_pair(I, Worklist.size()))) + if (WorklistMap.insert(std::make_pair(I, Worklist.size())).second) Worklist.push_back(I); } -- 2.34.1