Remove StringMap::GetOrCreateValue in favor of StringMap::insert

Having two ways to do this doesn't seem terribly helpful and
consistently using the insert version (which we already has) seems like
it'll make the code easier to understand to anyone working with standard
data structures. (I also updated many references to the Entry's
key and value to use first() and second instead of getKey{Data,Length,}
and get/setValue - for similar consistency)

Also removes the GetOrCreateValue functions so there's less surface area
to StringMap to fix/improve/change/accommodate move semantics, etc.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222319 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Blaikie 2014-11-19 05:49:42 +00:00
parent fb44491356
commit 1d4f28c6bc
22 changed files with 116 additions and 157 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -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 {

View File

@ -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) {

View File

@ -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);

View File

@ -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();
}

View File

@ -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() {

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}
//===----------------------------------------------------------------------===//

View File

@ -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;
}
}
}

View File

@ -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()

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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 {

View File

@ -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());

View File

@ -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.