}
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.
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) {
#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"
///
struct LTOModule {
private:
- typedef StringMap<uint8_t> StringSet;
-
struct NameAndAttributes {
const char *name;
uint32_t attributes;
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;
/// 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 {
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) {
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);
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();
}
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)
// 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() {
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
}
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;
}
}
// 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);
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;
}
//===----------------------------------------------------------------------===//
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;
}
/// 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.
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;
}
}
}
// 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;
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.
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) {
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;
/// 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:
// 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;
/// 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.
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());
info.isFunction = isFunc;
info.symbol = decl;
-
- entry.setValue(info);
}
/// parseSymbols - Parse the symbols from the module and model-level ASM and add
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()
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;
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;
}
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;
}
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;
}
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);
// 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;
#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;
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;
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;
}
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 {
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);
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();
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);
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());
// 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.