diff options
-rw-r--r-- | llvm/include/llvm/ADT/StringMap.h | 15 | ||||
-rw-r--r-- | llvm/include/llvm/LTO/LTOModule.h | 7 | ||||
-rw-r--r-- | llvm/include/llvm/MC/StringTableBuilder.h | 2 | ||||
-rw-r--r-- | llvm/include/llvm/TableGen/StringToOffsetTable.h | 8 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/CodeGen/GCMetadata.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/IR/LLVMContext.cpp | 7 | ||||
-rw-r--r-- | llvm/lib/IR/Module.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/IR/Type.cpp | 20 | ||||
-rw-r--r-- | llvm/lib/IR/ValueSymbolTable.cpp | 25 | ||||
-rw-r--r-- | llvm/lib/LTO/LTOModule.cpp | 88 | ||||
-rw-r--r-- | llvm/lib/Linker/LinkModules.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/MC/MCContext.cpp | 35 | ||||
-rw-r--r-- | llvm/lib/MC/MCDwarf.cpp | 8 | ||||
-rw-r--r-- | llvm/lib/Support/CommandLine.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Support/Host.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp | 2 | ||||
-rw-r--r-- | llvm/tools/yaml2obj/yaml2elf.cpp | 6 | ||||
-rw-r--r-- | llvm/unittests/ADT/StringMapTest.cpp | 10 | ||||
-rw-r--r-- | llvm/utils/TableGen/CodeGenRegisters.cpp | 9 |
22 files changed, 116 insertions, 157 deletions
diff --git a/llvm/include/llvm/ADT/StringMap.h b/llvm/include/llvm/ADT/StringMap.h index e1a08d9d7f9..2feb2ab0074 100644 --- a/llvm/include/llvm/ADT/StringMap.h +++ b/llvm/include/llvm/ADT/StringMap.h @@ -296,7 +296,7 @@ public: } ValueTy &operator[](StringRef Key) { - return GetOrCreateValue(Key).getValue(); + return insert(std::make_pair(Key, ValueTy())).first->second; } /// count - Return 1 if the element is in the map, 0 otherwise. @@ -363,19 +363,6 @@ public: NumTombstones = 0; } - /// GetOrCreateValue - Look up the specified key in the table. If a value - /// exists, return it. Otherwise, default construct a value, insert it, and - /// return. - template <typename InitTy> - MapEntryTy &GetOrCreateValue(StringRef Key, InitTy &&Val) { - return *insert(std::pair<StringRef, ValueTy>( - Key, std::forward<InitTy>(Val))).first; - } - - MapEntryTy &GetOrCreateValue(StringRef Key) { - return GetOrCreateValue(Key, ValueTy()); - } - /// remove - Remove the specified key/value pair from the map, but do not /// erase it. This aborts if the key is not in the map. void remove(MapEntryTy *KeyValue) { diff --git a/llvm/include/llvm/LTO/LTOModule.h b/llvm/include/llvm/LTO/LTOModule.h index 23b1fce435b..53c2b8e521b 100644 --- a/llvm/include/llvm/LTO/LTOModule.h +++ b/llvm/include/llvm/LTO/LTOModule.h @@ -16,6 +16,7 @@ #include "llvm-c/lto.h" #include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringSet.h" #include "llvm/IR/Module.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCObjectFileInfo.h" @@ -37,8 +38,6 @@ namespace llvm { /// struct LTOModule { private: - typedef StringMap<uint8_t> StringSet; - struct NameAndAttributes { const char *name; uint32_t attributes; @@ -50,13 +49,13 @@ private: std::unique_ptr<object::IRObjectFile> IRFile; std::unique_ptr<TargetMachine> _target; - StringSet _linkeropt_strings; + StringSet<> _linkeropt_strings; std::vector<const char *> _deplibs; std::vector<const char *> _linkeropts; std::vector<NameAndAttributes> _symbols; // _defines and _undefines only needed to disambiguate tentative definitions - StringSet _defines; + StringSet<> _defines; StringMap<NameAndAttributes> _undefines; std::vector<const char*> _asm_undefines; diff --git a/llvm/include/llvm/MC/StringTableBuilder.h b/llvm/include/llvm/MC/StringTableBuilder.h index 04f127a58cf..897d449254e 100644 --- a/llvm/include/llvm/MC/StringTableBuilder.h +++ b/llvm/include/llvm/MC/StringTableBuilder.h @@ -26,7 +26,7 @@ public: /// copy of s. Can only be used before the table is finalized. StringRef add(StringRef s) { assert(!isFinalized()); - return StringIndexMap.GetOrCreateValue(s, 0).getKey(); + return StringIndexMap.insert(std::make_pair(s, 0)).first->first(); } enum Kind { diff --git a/llvm/include/llvm/TableGen/StringToOffsetTable.h b/llvm/include/llvm/TableGen/StringToOffsetTable.h index a044a3c53f0..e3277036dc7 100644 --- a/llvm/include/llvm/TableGen/StringToOffsetTable.h +++ b/llvm/include/llvm/TableGen/StringToOffsetTable.h @@ -28,16 +28,16 @@ class StringToOffsetTable { public: unsigned GetOrAddStringOffset(StringRef Str, bool appendZero = true) { - StringMapEntry<unsigned> &Entry = StringOffset.GetOrCreateValue(Str, -1U); - if (Entry.getValue() == -1U) { + auto IterBool = + StringOffset.insert(std::make_pair(Str, AggregateString.size())); + if (IterBool.second) { // Add the string to the aggregate if this is the first time found. - Entry.setValue(AggregateString.size()); AggregateString.append(Str.begin(), Str.end()); if (appendZero) AggregateString += '\0'; } - return Entry.getValue(); + return IterBool.first->second; } void EmitString(raw_ostream &O) { diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp index 830b04acb3e..d76b66cac69 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp @@ -16,8 +16,7 @@ static std::pair<MCSymbol *, unsigned> & getEntry(AsmPrinter &Asm, StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &> &Pool, StringRef Prefix, StringRef Str) { - std::pair<MCSymbol *, unsigned> &Entry = - Pool.GetOrCreateValue(Str).getValue(); + std::pair<MCSymbol *, unsigned> &Entry = Pool[Str]; if (!Entry.first) { Entry.second = Pool.size() - 1; Entry.first = Asm.GetTempSymbol(Prefix, Entry.second); diff --git a/llvm/lib/CodeGen/GCMetadata.cpp b/llvm/lib/CodeGen/GCMetadata.cpp index c3e4f3ee2fb..ed40982d451 100644 --- a/llvm/lib/CodeGen/GCMetadata.cpp +++ b/llvm/lib/CodeGen/GCMetadata.cpp @@ -73,7 +73,7 @@ GCStrategy *GCModuleInfo::getOrCreateStrategy(const Module *M, std::unique_ptr<GCStrategy> S = I->instantiate(); S->M = M; S->Name = Name; - StrategyMap.GetOrCreateValue(Name).setValue(S.get()); + StrategyMap[Name] = S.get(); StrategyList.push_back(std::move(S)); return StrategyList.back().get(); } diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index c0012458168..ee86b16bfd2 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -2436,14 +2436,16 @@ Constant *ConstantDataSequential::getImpl(StringRef Elements, Type *Ty) { return ConstantAggregateZero::get(Ty); // Do a lookup to see if we have already formed one of these. - StringMap<ConstantDataSequential*>::MapEntryTy &Slot = - Ty->getContext().pImpl->CDSConstants.GetOrCreateValue(Elements); + auto &Slot = + *Ty->getContext() + .pImpl->CDSConstants.insert(std::make_pair(Elements, nullptr)) + .first; // The bucket can point to a linked list of different CDS's that have the same // body but different types. For example, 0,0,0,1 could be a 4 element array // of i8, or a 1-element array of i32. They'll both end up in the same /// StringMap bucket, linked up by their Next pointers. Walk the list. - ConstantDataSequential **Entry = &Slot.getValue(); + ConstantDataSequential **Entry = &Slot.second; for (ConstantDataSequential *Node = *Entry; Node; Entry = &Node->Next, Node = *Entry) if (Node->getType() == Ty) @@ -2452,10 +2454,10 @@ Constant *ConstantDataSequential::getImpl(StringRef Elements, Type *Ty) { // Okay, we didn't get a hit. Create a node of the right class, link it in, // and return it. if (isa<ArrayType>(Ty)) - return *Entry = new ConstantDataArray(Ty, Slot.getKeyData()); + return *Entry = new ConstantDataArray(Ty, Slot.first().data()); assert(isa<VectorType>(Ty)); - return *Entry = new ConstantDataVector(Ty, Slot.getKeyData()); + return *Entry = new ConstantDataVector(Ty, Slot.first().data()); } void ConstantDataSequential::destroyConstant() { diff --git a/llvm/lib/IR/LLVMContext.cpp b/llvm/lib/IR/LLVMContext.cpp index a1a4f63da32..c62bc0936c4 100644 --- a/llvm/lib/IR/LLVMContext.cpp +++ b/llvm/lib/IR/LLVMContext.cpp @@ -253,9 +253,10 @@ unsigned LLVMContext::getMDKindID(StringRef Name) const { assert(isValidName(Name) && "Invalid MDNode name"); // If this is new, assign it its ID. - return - pImpl->CustomMDKindNames.GetOrCreateValue( - Name, pImpl->CustomMDKindNames.size()).second; + return pImpl->CustomMDKindNames.insert(std::make_pair( + Name, + pImpl->CustomMDKindNames.size())) + .first->second; } /// getHandlerNames - Populate client supplied smallvector using custome diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index 28743fae6cd..14e534b8b1b 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -452,9 +452,7 @@ unsigned Module::getDwarfVersion() const { } Comdat *Module::getOrInsertComdat(StringRef Name) { - Comdat C; - StringMapEntry<Comdat> &Entry = - ComdatSymTab.GetOrCreateValue(Name, std::move(C)); + auto &Entry = *ComdatSymTab.insert(std::make_pair(Name, Comdat())).first; Entry.second.Name = &Entry; return &Entry.second; } diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp index 90fde4db192..ad1d928ef14 100644 --- a/llvm/lib/IR/Type.cpp +++ b/llvm/lib/IR/Type.cpp @@ -458,10 +458,11 @@ void StructType::setName(StringRef Name) { } // Look up the entry for the name. - EntryTy *Entry = &getContext().pImpl->NamedStructTypes.GetOrCreateValue(Name); - + auto IterBool = + getContext().pImpl->NamedStructTypes.insert(std::make_pair(Name, this)); + // While we have a name collision, try a random rename. - if (Entry->getValue()) { + if (!IterBool.second) { SmallString<64> TempStr(Name); TempStr.push_back('.'); raw_svector_ostream TmpStream(TempStr); @@ -471,19 +472,16 @@ void StructType::setName(StringRef Name) { TempStr.resize(NameSize + 1); TmpStream.resync(); TmpStream << getContext().pImpl->NamedStructTypesUniqueID++; - - Entry = &getContext().pImpl-> - NamedStructTypes.GetOrCreateValue(TmpStream.str()); - } while (Entry->getValue()); - } - // Okay, we found an entry that isn't used. It's us! - Entry->setValue(this); + IterBool = getContext().pImpl->NamedStructTypes.insert( + std::make_pair(TmpStream.str(), this)); + } while (!IterBool.second); + } // Delete the old string data. if (SymbolTableEntry) ((EntryTy *)SymbolTableEntry)->Destroy(SymbolTable.getAllocator()); - SymbolTableEntry = Entry; + SymbolTableEntry = &*IterBool.first; } //===----------------------------------------------------------------------===// diff --git a/llvm/lib/IR/ValueSymbolTable.cpp b/llvm/lib/IR/ValueSymbolTable.cpp index e9e979a9a72..2b23f6dd15b 100644 --- a/llvm/lib/IR/ValueSymbolTable.cpp +++ b/llvm/lib/IR/ValueSymbolTable.cpp @@ -56,11 +56,10 @@ void ValueSymbolTable::reinsertValue(Value* V) { raw_svector_ostream(UniqueName) << ++LastUnique; // Try insert the vmap entry with this suffix. - ValueName &NewName = vmap.GetOrCreateValue(UniqueName); - if (!NewName.getValue()) { + auto IterBool = vmap.insert(std::make_pair(UniqueName, V)); + if (IterBool.second) { // Newly inserted name. Success! - NewName.setValue(V); - V->Name = &NewName; + V->Name = &*IterBool.first; //DEBUG(dbgs() << " Inserted value: " << UniqueName << ": " << *V << "\n"); return; } @@ -78,12 +77,11 @@ void ValueSymbolTable::removeValueName(ValueName *V) { /// auto-renames the name and returns that instead. ValueName *ValueSymbolTable::createValueName(StringRef Name, Value *V) { // In the common case, the name is not already in the symbol table. - ValueName &Entry = vmap.GetOrCreateValue(Name); - if (!Entry.getValue()) { - Entry.setValue(V); + auto IterBool = vmap.insert(std::make_pair(Name, V)); + if (IterBool.second) { //DEBUG(dbgs() << " Inserted value: " << Entry.getKeyData() << ": " // << *V << "\n"); - return &Entry; + return &*IterBool.first; } // Otherwise, there is a naming conflict. Rename this value. @@ -95,12 +93,11 @@ ValueName *ValueSymbolTable::createValueName(StringRef Name, Value *V) { raw_svector_ostream(UniqueName) << ++LastUnique; // Try insert the vmap entry with this suffix. - ValueName &NewName = vmap.GetOrCreateValue(UniqueName); - if (!NewName.getValue()) { - // Newly inserted name. Success! - NewName.setValue(V); - //DEBUG(dbgs() << " Inserted value: " << UniqueName << ": " << *V << "\n"); - return &NewName; + auto IterBool = vmap.insert(std::make_pair(UniqueName, V)); + if (IterBool.second) { + // DEBUG(dbgs() << " Inserted value: " << UniqueName << ": " << *V << + // "\n"); + return &*IterBool.first; } } } diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp index 34e7f51c7bf..4108ef25be0 100644 --- a/llvm/lib/LTO/LTOModule.cpp +++ b/llvm/lib/LTO/LTOModule.cpp @@ -249,27 +249,24 @@ void LTOModule::addObjCClass(const GlobalVariable *clgv) { // second slot in __OBJC,__class is pointer to superclass name std::string superclassName; if (objcClassNameFromExpression(c->getOperand(1), superclassName)) { - NameAndAttributes info; - StringMap<NameAndAttributes>::value_type &entry = - _undefines.GetOrCreateValue(superclassName); - if (!entry.getValue().name) { - const char *symbolName = entry.getKey().data(); - info.name = symbolName; + auto IterBool = + _undefines.insert(std::make_pair(superclassName, NameAndAttributes())); + if (IterBool.second) { + NameAndAttributes &info = IterBool.first->second; + info.name = IterBool.first->first().data(); info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; info.isFunction = false; info.symbol = clgv; - entry.setValue(info); } } // third slot in __OBJC,__class is pointer to class name std::string className; if (objcClassNameFromExpression(c->getOperand(2), className)) { - StringSet::value_type &entry = _defines.GetOrCreateValue(className); - entry.setValue(1); + auto Iter = _defines.insert(className).first; NameAndAttributes info; - info.name = entry.getKey().data(); + info.name = Iter->first().data(); info.attributes = LTO_SYMBOL_PERMISSIONS_DATA | LTO_SYMBOL_DEFINITION_REGULAR | LTO_SYMBOL_SCOPE_DEFAULT; info.isFunction = false; @@ -288,19 +285,17 @@ void LTOModule::addObjCCategory(const GlobalVariable *clgv) { if (!objcClassNameFromExpression(c->getOperand(1), targetclassName)) return; - NameAndAttributes info; - StringMap<NameAndAttributes>::value_type &entry = - _undefines.GetOrCreateValue(targetclassName); + auto IterBool = + _undefines.insert(std::make_pair(targetclassName, NameAndAttributes())); - if (entry.getValue().name) + if (!IterBool.second) return; - const char *symbolName = entry.getKey().data(); - info.name = symbolName; + NameAndAttributes &info = IterBool.first->second; + info.name = IterBool.first->first().data(); info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; info.isFunction = false; info.symbol = clgv; - entry.setValue(info); } /// addObjCClassRef - Parse i386/ppc ObjC class list data structure. @@ -309,18 +304,17 @@ void LTOModule::addObjCClassRef(const GlobalVariable *clgv) { if (!objcClassNameFromExpression(clgv->getInitializer(), targetclassName)) return; - NameAndAttributes info; - StringMap<NameAndAttributes>::value_type &entry = - _undefines.GetOrCreateValue(targetclassName); - if (entry.getValue().name) + auto IterBool = + _undefines.insert(std::make_pair(targetclassName, NameAndAttributes())); + + if (!IterBool.second) return; - const char *symbolName = entry.getKey().data(); - info.name = symbolName; + NameAndAttributes &info = IterBool.first->second; + info.name = IterBool.first->first().data(); info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; info.isFunction = false; info.symbol = clgv; - entry.setValue(info); } void LTOModule::addDefinedDataSymbol(const object::BasicSymbolRef &Sym) { @@ -439,12 +433,11 @@ void LTOModule::addDefinedSymbol(const char *Name, const GlobalValue *def, else attr |= LTO_SYMBOL_SCOPE_DEFAULT; - StringSet::value_type &entry = _defines.GetOrCreateValue(Name); - entry.setValue(1); + auto Iter = _defines.insert(Name).first; // fill information structure NameAndAttributes info; - StringRef NameRef = entry.getKey(); + StringRef NameRef = Iter->first(); info.name = NameRef.data(); assert(info.name[NameRef.size()] == '\0'); info.attributes = attr; @@ -459,15 +452,13 @@ void LTOModule::addDefinedSymbol(const char *Name, const GlobalValue *def, /// defined list. void LTOModule::addAsmGlobalSymbol(const char *name, lto_symbol_attributes scope) { - StringSet::value_type &entry = _defines.GetOrCreateValue(name); + auto IterBool = _defines.insert(name); // only add new define if not already defined - if (entry.getValue()) + if (!IterBool.second) return; - entry.setValue(1); - - NameAndAttributes &info = _undefines[entry.getKey().data()]; + NameAndAttributes &info = _undefines[IterBool.first->first().data()]; if (info.symbol == nullptr) { // FIXME: This is trying to take care of module ASM like this: @@ -479,7 +470,7 @@ void LTOModule::addAsmGlobalSymbol(const char *name, // much. // fill information structure - info.name = entry.getKey().data(); + info.name = IterBool.first->first().data(); info.attributes = LTO_SYMBOL_PERMISSIONS_DATA | LTO_SYMBOL_DEFINITION_REGULAR | scope; info.isFunction = false; @@ -502,24 +493,21 @@ void LTOModule::addAsmGlobalSymbol(const char *name, /// addAsmGlobalSymbolUndef - Add a global symbol from module-level ASM to the /// undefined list. void LTOModule::addAsmGlobalSymbolUndef(const char *name) { - StringMap<NameAndAttributes>::value_type &entry = - _undefines.GetOrCreateValue(name); + auto IterBool = _undefines.insert(std::make_pair(name, NameAndAttributes())); - _asm_undefines.push_back(entry.getKey().data()); + _asm_undefines.push_back(IterBool.first->first().data()); // we already have the symbol - if (entry.getValue().name) + if (!IterBool.second) return; uint32_t attr = LTO_SYMBOL_DEFINITION_UNDEFINED; attr |= LTO_SYMBOL_SCOPE_DEFAULT; - NameAndAttributes info; - info.name = entry.getKey().data(); + NameAndAttributes &info = IterBool.first->second; + info.name = IterBool.first->first().data(); info.attributes = attr; info.isFunction = false; info.symbol = nullptr; - - entry.setValue(info); } /// Add a symbol which isn't defined just yet to a list to be resolved later. @@ -531,16 +519,15 @@ void LTOModule::addPotentialUndefinedSymbol(const object::BasicSymbolRef &Sym, Sym.printName(OS); } - StringMap<NameAndAttributes>::value_type &entry = - _undefines.GetOrCreateValue(name); + auto IterBool = _undefines.insert(std::make_pair(name, NameAndAttributes())); // we already have the symbol - if (entry.getValue().name) + if (!IterBool.second) return; - NameAndAttributes info; + NameAndAttributes &info = IterBool.first->second; - info.name = entry.getKey().data(); + info.name = IterBool.first->first().data(); const GlobalValue *decl = IRFile->getSymbolGV(Sym.getRawDataRefImpl()); @@ -551,8 +538,6 @@ void LTOModule::addPotentialUndefinedSymbol(const object::BasicSymbolRef &Sym, info.isFunction = isFunc; info.symbol = decl; - - entry.setValue(info); } /// parseSymbols - Parse the symbols from the module and model-level ASM and add @@ -625,8 +610,11 @@ void LTOModule::parseMetadata() { MDNode *MDOptions = cast<MDNode>(LinkerOptions->getOperand(i)); for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) { MDString *MDOption = cast<MDString>(MDOptions->getOperand(ii)); - StringRef Op = _linkeropt_strings. - GetOrCreateValue(MDOption->getString()).getKey(); + // FIXME: Make StringSet::insert match Self-Associative Container + // requirements, returning <iter,bool> rather than bool, and use that + // here. + StringRef Op = + _linkeropt_strings.insert(MDOption->getString()).first->first(); StringRef DepLibName = _target->getSubtargetImpl() ->getTargetLowering() ->getObjFileLowering() diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp index 0a9bbf2a7fc..d3da35f917b 100644 --- a/llvm/lib/Linker/LinkModules.cpp +++ b/llvm/lib/Linker/LinkModules.cpp @@ -1463,7 +1463,7 @@ bool ModuleLinker::run() { computeTypeMapping(); ComdatsChosen.clear(); - for (const StringMapEntry<llvm::Comdat> &SMEC : SrcM->getComdatSymbolTable()) { + for (const auto &SMEC : SrcM->getComdatSymbolTable()) { const Comdat &C = SMEC.getValue(); if (ComdatsChosen.count(&C)) continue; diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index ea6db142fd7..8630b25a84e 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -100,16 +100,11 @@ void MCContext::reset() { MCSymbol *MCContext::GetOrCreateSymbol(StringRef Name) { assert(!Name.empty() && "Normal symbols cannot be unnamed!"); - // Do the lookup and get the entire StringMapEntry. We want access to the - // key if we are creating the entry. - StringMapEntry<MCSymbol*> &Entry = Symbols.GetOrCreateValue(Name); - MCSymbol *Sym = Entry.getValue(); + MCSymbol *&Sym = Symbols[Name]; - if (Sym) - return Sym; + if (!Sym) + Sym = CreateSymbol(Name); - Sym = CreateSymbol(Name); - Entry.setValue(Sym); return Sym; } @@ -120,19 +115,17 @@ MCSymbol *MCContext::getOrCreateSectionSymbol(const MCSectionELF &Section) { StringRef Name = Section.getSectionName(); - StringMapEntry<MCSymbol*> &Entry = Symbols.GetOrCreateValue(Name); - MCSymbol *OldSym = Entry.getValue(); + MCSymbol *&OldSym = Symbols[Name]; if (OldSym && OldSym->isUndefined()) { Sym = OldSym; return OldSym; } - StringMapEntry<bool> *NameEntry = &UsedNames.GetOrCreateValue(Name); - NameEntry->setValue(true); - Sym = new (*this) MCSymbol(NameEntry->getKey(), /*isTemporary*/ false); + auto NameIter = UsedNames.insert(std::make_pair(Name, true)).first; + Sym = new (*this) MCSymbol(NameIter->getKey(), /*isTemporary*/ false); - if (!Entry.getValue()) - Entry.setValue(Sym); + if (!OldSym) + OldSym = Sym; return Sym; } @@ -143,21 +136,21 @@ MCSymbol *MCContext::CreateSymbol(StringRef Name) { if (AllowTemporaryLabels) isTemporary = Name.startswith(MAI->getPrivateGlobalPrefix()); - StringMapEntry<bool> *NameEntry = &UsedNames.GetOrCreateValue(Name); - if (NameEntry->getValue()) { + auto NameEntry = UsedNames.insert(std::make_pair(Name, true)); + if (!NameEntry.second) { assert(isTemporary && "Cannot rename non-temporary symbols"); SmallString<128> NewName = Name; do { NewName.resize(Name.size()); raw_svector_ostream(NewName) << NextUniqueID++; - NameEntry = &UsedNames.GetOrCreateValue(NewName); - } while (NameEntry->getValue()); + NameEntry = UsedNames.insert(std::make_pair(NewName, true)); + } while (!NameEntry.second); } - NameEntry->setValue(true); // Ok, the entry doesn't already exist. Have the MCSymbol object itself refer // to the copy of the string that is embedded in the UsedNames entry. - MCSymbol *Result = new (*this) MCSymbol(NameEntry->getKey(), isTemporary); + MCSymbol *Result = + new (*this) MCSymbol(NameEntry.first->getKey(), isTemporary); return Result; } diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp index 220747d88df..5effb011826 100644 --- a/llvm/lib/MC/MCDwarf.cpp +++ b/llvm/lib/MC/MCDwarf.cpp @@ -368,10 +368,10 @@ unsigned MCDwarfLineTableHeader::getFile(StringRef &Directory, FileNumber = SourceIdMap.size() + 1; assert((MCDwarfFiles.empty() || FileNumber == MCDwarfFiles.size()) && "Don't mix autonumbered and explicit numbered line table usage"); - StringMapEntry<unsigned> &Ent = SourceIdMap.GetOrCreateValue( - (Directory + Twine('\0') + FileName).str(), FileNumber); - if (Ent.getValue() != FileNumber) - return Ent.getValue(); + auto IterBool = SourceIdMap.insert( + std::make_pair((Directory + Twine('\0') + FileName).str(), FileNumber)); + if (!IterBool.second) + return IterBool.first->second; } // Make space for this FileNumber in the MCDwarfFiles vector if needed. MCDwarfFiles.resize(FileNumber + 1); diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index 172381b3d34..984d425fbbb 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -165,7 +165,7 @@ static void GetOptionInfo(SmallVectorImpl<Option*> &PositionalOpts, // Handle named options. for (size_t i = 0, e = OptionNames.size(); i != e; ++i) { // Add argument to the argument map! - if (OptionsMap.GetOrCreateValue(OptionNames[i], O).second != O) { + if (!OptionsMap.insert(std::make_pair(OptionNames[i], O)).second) { errs() << ProgramName << ": CommandLine Error: Option '" << OptionNames[i] << "' registered more than once!\n"; HadErrors = true; diff --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp index e2dd6d522bb..8782e2e9d26 100644 --- a/llvm/lib/Support/Host.cpp +++ b/llvm/lib/Support/Host.cpp @@ -759,13 +759,13 @@ bool sys::getHostCPUFeatures(StringMap<bool> &Features) { #endif if (LLVMFeatureStr != "") - Features.GetOrCreateValue(LLVMFeatureStr).setValue(true); + Features[LLVMFeatureStr] = true; } #if defined(__aarch64__) // If we have all crypto bits we can add the feature if (crypto == (CAP_AES | CAP_PMULL | CAP_SHA1 | CAP_SHA2)) - Features.GetOrCreateValue("crypto").setValue(true); + Features["crypto"] = true; #endif return true; diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp index 20288395fea..98e0ea8b5db 100644 --- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -4140,7 +4140,7 @@ bool AArch64AsmParser::parseDirectiveReq(StringRef Name, SMLoc L) { Parser.Lex(); // Consume the EndOfStatement auto pair = std::make_pair(IsVector, RegNum); - if (RegisterReqs.GetOrCreateValue(Name, pair).getValue() != pair) + if (!RegisterReqs.insert(std::make_pair(Name, pair)).second) Warning(L, "ignoring redefinition of register alias '" + Name + "'"); return true; diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp index adfcd8f44ca..9cc89bd6142 100644 --- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp +++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp @@ -8732,7 +8732,7 @@ bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) { Parser.Lex(); // Consume the EndOfStatement - if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg) { + if (!RegisterReqs.insert(std::make_pair(Name, Reg)).second) { Error(SRegLoc, "redefinition of '" + Name + "' does not match original."); return false; } diff --git a/llvm/tools/yaml2obj/yaml2elf.cpp b/llvm/tools/yaml2obj/yaml2elf.cpp index 0b446c77c2f..44c8c12da89 100644 --- a/llvm/tools/yaml2obj/yaml2elf.cpp +++ b/llvm/tools/yaml2obj/yaml2elf.cpp @@ -62,11 +62,7 @@ class NameToIdxMap { public: /// \returns true if name is already present in the map. bool addName(StringRef Name, unsigned i) { - StringMapEntry<int> &Entry = Map.GetOrCreateValue(Name, -1); - if (Entry.getValue() != -1) - return true; - Entry.setValue((int)i); - return false; + return !Map.insert(std::make_pair(Name, (int)i)).second; } /// \returns true if name is not present in the map bool lookup(StringRef Name, unsigned &Idx) const { diff --git a/llvm/unittests/ADT/StringMapTest.cpp b/llvm/unittests/ADT/StringMapTest.cpp index af9b6115f85..33d668fe2dd 100644 --- a/llvm/unittests/ADT/StringMapTest.cpp +++ b/llvm/unittests/ADT/StringMapTest.cpp @@ -250,7 +250,7 @@ struct StringMapTestStruct { TEST_F(StringMapTest, NonDefaultConstructable) { StringMap<StringMapTestStruct> t; - t.GetOrCreateValue("Test", StringMapTestStruct(123)); + t.insert(std::make_pair("Test", StringMapTestStruct(123))); StringMap<StringMapTestStruct>::iterator iter = t.find("Test"); ASSERT_NE(iter, t.end()); ASSERT_EQ(iter->second.i, 123); @@ -278,15 +278,13 @@ private: TEST_F(StringMapTest, MoveOnly) { StringMap<MoveOnly> t; - t.GetOrCreateValue("Test", MoveOnly(42)); + t.insert(std::make_pair("Test", MoveOnly(42))); StringRef Key = "Test"; StringMapEntry<MoveOnly>::Create(Key, MoveOnly(42)) ->Destroy(); } TEST_F(StringMapTest, CtorArg) { - StringMap<MoveOnly> t; - t.GetOrCreateValue("Test", Immovable()); StringRef Key = "Test"; StringMapEntry<MoveOnly>::Create(Key, Immovable()) ->Destroy(); @@ -294,7 +292,7 @@ TEST_F(StringMapTest, CtorArg) { TEST_F(StringMapTest, MoveConstruct) { StringMap<int> A; - A.GetOrCreateValue("x", 42); + A["x"] = 42; StringMap<int> B = std::move(A); ASSERT_EQ(A.size(), 0u); ASSERT_EQ(B.size(), 1u); @@ -339,7 +337,7 @@ struct Countable { TEST_F(StringMapTest, MoveDtor) { int InstanceCount = 0; StringMap<Countable> A; - A.GetOrCreateValue("x", Countable(42, InstanceCount)); + A.insert(std::make_pair("x", Countable(42, InstanceCount))); ASSERT_EQ(InstanceCount, 1); auto I = A.find("x"); ASSERT_NE(I, A.end()); diff --git a/llvm/utils/TableGen/CodeGenRegisters.cpp b/llvm/utils/TableGen/CodeGenRegisters.cpp index dd3442bcc4b..678222f315e 100644 --- a/llvm/utils/TableGen/CodeGenRegisters.cpp +++ b/llvm/utils/TableGen/CodeGenRegisters.cpp @@ -966,9 +966,12 @@ CodeGenRegBank::CodeGenRegBank(RecordKeeper &Records) { // Compute register name map. for (unsigned i = 0, e = Registers.size(); i != e; ++i) - RegistersByName.GetOrCreateValue( - Registers[i]->TheDef->getValueAsString("AsmName"), - Registers[i]); + // FIXME: This could just be RegistersByName[name] = register, except that + // causes some failures in MIPS - perhaps they have duplicate register name + // entries? (or maybe there's a reason for it - I don't know much about this + // code, just drive-by refactoring) + RegistersByName.insert(std::make_pair( + Registers[i]->TheDef->getValueAsString("AsmName"), Registers[i])); // Precompute all sub-register maps. // This will create Composite entries for all inferred sub-register indices. |