llvm.org GIT mirror llvm / 1d4f28c
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 David Blaikie 4 years ago
22 changed file(s) with 131 addition(s) and 172 deletion(s). Raw diff Collapse all Expand all
295295 }
296296
297297 ValueTy &operator[](StringRef Key) {
298 return GetOrCreateValue(Key).getValue();
298 return insert(std::make_pair(Key, ValueTy())).first->second;
299299 }
300300
301301 /// count - Return 1 if the element is in the map, 0 otherwise.
360360
361361 NumItems = 0;
362362 NumTombstones = 0;
363 }
364
365 /// GetOrCreateValue - Look up the specified key in the table. If a value
366 /// exists, return it. Otherwise, default construct a value, insert it, and
367 /// return.
368 template
369 MapEntryTy &GetOrCreateValue(StringRef Key, InitTy &&Val) {
370 return *insert(std::pair(
371 Key, std::forward(Val))).first;
372 }
373
374 MapEntryTy &GetOrCreateValue(StringRef Key) {
375 return GetOrCreateValue(Key, ValueTy());
376363 }
377364
378365 /// remove - Remove the specified key/value pair from the map, but do not
1515
1616 #include "llvm-c/lto.h"
1717 #include "llvm/ADT/StringMap.h"
18 #include "llvm/ADT/StringSet.h"
1819 #include "llvm/IR/Module.h"
1920 #include "llvm/MC/MCContext.h"
2021 #include "llvm/MC/MCObjectFileInfo.h"
3637 ///
3738 struct LTOModule {
3839 private:
39 typedef StringMap StringSet;
40
4140 struct NameAndAttributes {
4241 const char *name;
4342 uint32_t attributes;
4948
5049 std::unique_ptr IRFile;
5150 std::unique_ptr _target;
52 StringSet _linkeropt_strings;
51 StringSet<> _linkeropt_strings;
5352 std::vector _deplibs;
5453 std::vector _linkeropts;
5554 std::vector _symbols;
5655
5756 // _defines and _undefines only needed to disambiguate tentative definitions
58 StringSet _defines;
57 StringSet<> _defines;
5958 StringMap _undefines;
6059 std::vector _asm_undefines;
6160
2525 /// copy of s. Can only be used before the table is finalized.
2626 StringRef add(StringRef s) {
2727 assert(!isFinalized());
28 return StringIndexMap.GetOrCreateValue(s, 0).getKey();
28 return StringIndexMap.insert(std::make_pair(s, 0)).first->first();
2929 }
3030
3131 enum Kind {
2727
2828 public:
2929 unsigned GetOrAddStringOffset(StringRef Str, bool appendZero = true) {
30 StringMapEntry &Entry = StringOffset.GetOrCreateValue(Str, -1U);
31 if (Entry.getValue() == -1U) {
30 auto IterBool =
31 StringOffset.insert(std::make_pair(Str, AggregateString.size()));
32 if (IterBool.second) {
3233 // Add the string to the aggregate if this is the first time found.
33 Entry.setValue(AggregateString.size());
3434 AggregateString.append(Str.begin(), Str.end());
3535 if (appendZero)
3636 AggregateString += '\0';
3737 }
3838
39 return Entry.getValue();
39 return IterBool.first->second;
4040 }
4141
4242 void EmitString(raw_ostream &O) {
1515 getEntry(AsmPrinter &Asm,
1616 StringMap, BumpPtrAllocator &> &Pool,
1717 StringRef Prefix, StringRef Str) {
18 std::pair &Entry =
19 Pool.GetOrCreateValue(Str).getValue();
18 std::pair &Entry = Pool[Str];
2019 if (!Entry.first) {
2120 Entry.second = Pool.size() - 1;
2221 Entry.first = Asm.GetTempSymbol(Prefix, Entry.second);
7272 std::unique_ptr S = I->instantiate();
7373 S->M = M;
7474 S->Name = Name;
75 StrategyMap.GetOrCreateValue(Name).setValue(S.get());
75 StrategyMap[Name] = S.get();
7676 StrategyList.push_back(std::move(S));
7777 return StrategyList.back().get();
7878 }
24352435 return ConstantAggregateZero::get(Ty);
24362436
24372437 // Do a lookup to see if we have already formed one of these.
2438 StringMap::MapEntryTy &Slot =
2439 Ty->getContext().pImpl->CDSConstants.GetOrCreateValue(Elements);
2438 auto &Slot =
2439 *Ty->getContext()
2440 .pImpl->CDSConstants.insert(std::make_pair(Elements, nullptr))
2441 .first;
24402442
24412443 // The bucket can point to a linked list of different CDS's that have the same
24422444 // body but different types. For example, 0,0,0,1 could be a 4 element array
24432445 // of i8, or a 1-element array of i32. They'll both end up in the same
24442446 /// StringMap bucket, linked up by their Next pointers. Walk the list.
2445 ConstantDataSequential **Entry = &Slot.getValue();
2447 ConstantDataSequential **Entry = &Slot.second;
24462448 for (ConstantDataSequential *Node = *Entry; Node;
24472449 Entry = &Node->Next, Node = *Entry)
24482450 if (Node->getType() == Ty)
24512453 // Okay, we didn't get a hit. Create a node of the right class, link it in,
24522454 // and return it.
24532455 if (isa(Ty))
2454 return *Entry = new ConstantDataArray(Ty, Slot.getKeyData());
2456 return *Entry = new ConstantDataArray(Ty, Slot.first().data());
24552457
24562458 assert(isa(Ty));
2457 return *Entry = new ConstantDataVector(Ty, Slot.getKeyData());
2459 return *Entry = new ConstantDataVector(Ty, Slot.first().data());
24582460 }
24592461
24602462 void ConstantDataSequential::destroyConstant() {
252252 assert(isValidName(Name) && "Invalid MDNode name");
253253
254254 // If this is new, assign it its ID.
255 return
256 pImpl->CustomMDKindNames.GetOrCreateValue(
257 Name, pImpl->CustomMDKindNames.size()).second;
255 return pImpl->CustomMDKindNames.insert(std::make_pair(
256 Name,
257 pImpl->CustomMDKindNames.size()))
258 .first->second;
258259 }
259260
260261 /// getHandlerNames - Populate client supplied smallvector using custome
451451 }
452452
453453 Comdat *Module::getOrInsertComdat(StringRef Name) {
454 Comdat C;
455 StringMapEntry &Entry =
456 ComdatSymTab.GetOrCreateValue(Name, std::move(C));
454 auto &Entry = *ComdatSymTab.insert(std::make_pair(Name, Comdat())).first;
457455 Entry.second.Name = &Entry;
458456 return &Entry.second;
459457 }
457457 }
458458
459459 // Look up the entry for the name.
460 EntryTy *Entry = &getContext().pImpl->NamedStructTypes.GetOrCreateValue(Name);
461
460 auto IterBool =
461 getContext().pImpl->NamedStructTypes.insert(std::make_pair(Name, this));
462
462463 // While we have a name collision, try a random rename.
463 if (Entry->getValue()) {
464 if (!IterBool.second) {
464465 SmallString<64> TempStr(Name);
465466 TempStr.push_back('.');
466467 raw_svector_ostream TmpStream(TempStr);
470471 TempStr.resize(NameSize + 1);
471472 TmpStream.resync();
472473 TmpStream << getContext().pImpl->NamedStructTypesUniqueID++;
473
474 Entry = &getContext().pImpl->
475 NamedStructTypes.GetOrCreateValue(TmpStream.str());
476 } while (Entry->getValue());
477 }
478
479 // Okay, we found an entry that isn't used. It's us!
480 Entry->setValue(this);
474
475 IterBool = getContext().pImpl->NamedStructTypes.insert(
476 std::make_pair(TmpStream.str(), this));
477 } while (!IterBool.second);
478 }
481479
482480 // Delete the old string data.
483481 if (SymbolTableEntry)
484482 ((EntryTy *)SymbolTableEntry)->Destroy(SymbolTable.getAllocator());
485 SymbolTableEntry = Entry;
483 SymbolTableEntry = &*IterBool.first;
486484 }
487485
488486 //===----------------------------------------------------------------------===//
5555 raw_svector_ostream(UniqueName) << ++LastUnique;
5656
5757 // Try insert the vmap entry with this suffix.
58 ValueName &NewName = vmap.GetOrCreateValue(UniqueName);
59 if (!NewName.getValue()) {
58 auto IterBool = vmap.insert(std::make_pair(UniqueName, V));
59 if (IterBool.second) {
6060 // Newly inserted name. Success!
61 NewName.setValue(V);
62 V->Name = &NewName;
61 V->Name = &*IterBool.first;
6362 //DEBUG(dbgs() << " Inserted value: " << UniqueName << ": " << *V << "\n");
6463 return;
6564 }
7776 /// auto-renames the name and returns that instead.
7877 ValueName *ValueSymbolTable::createValueName(StringRef Name, Value *V) {
7978 // In the common case, the name is not already in the symbol table.
80 ValueName &Entry = vmap.GetOrCreateValue(Name);
81 if (!Entry.getValue()) {
82 Entry.setValue(V);
79 auto IterBool = vmap.insert(std::make_pair(Name, V));
80 if (IterBool.second) {
8381 //DEBUG(dbgs() << " Inserted value: " << Entry.getKeyData() << ": "
8482 // << *V << "\n");
85 return &Entry;
83 return &*IterBool.first;
8684 }
8785
8886 // Otherwise, there is a naming conflict. Rename this value.
9492 raw_svector_ostream(UniqueName) << ++LastUnique;
9593
9694 // Try insert the vmap entry with this suffix.
97 ValueName &NewName = vmap.GetOrCreateValue(UniqueName);
98 if (!NewName.getValue()) {
99 // Newly inserted name. Success!
100 NewName.setValue(V);
101 //DEBUG(dbgs() << " Inserted value: " << UniqueName << ": " << *V << "\n");
102 return &NewName;
95 auto IterBool = vmap.insert(std::make_pair(UniqueName, V));
96 if (IterBool.second) {
97 // DEBUG(dbgs() << " Inserted value: " << UniqueName << ": " << *V <<
98 // "\n");
99 return &*IterBool.first;
103100 }
104101 }
105102 }
248248 // second slot in __OBJC,__class is pointer to superclass name
249249 std::string superclassName;
250250 if (objcClassNameFromExpression(c->getOperand(1), superclassName)) {
251 NameAndAttributes info;
252 StringMap::value_type &entry =
253 _undefines.GetOrCreateValue(superclassName);
254 if (!entry.getValue().name) {
255 const char *symbolName = entry.getKey().data();
256 info.name = symbolName;
251 auto IterBool =
252 _undefines.insert(std::make_pair(superclassName, NameAndAttributes()));
253 if (IterBool.second) {
254 NameAndAttributes &info = IterBool.first->second;
255 info.name = IterBool.first->first().data();
257256 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
258257 info.isFunction = false;
259258 info.symbol = clgv;
260 entry.setValue(info);
261259 }
262260 }
263261
264262 // third slot in __OBJC,__class is pointer to class name
265263 std::string className;
266264 if (objcClassNameFromExpression(c->getOperand(2), className)) {
267 StringSet::value_type &entry = _defines.GetOrCreateValue(className);
268 entry.setValue(1);
265 auto Iter = _defines.insert(className).first;
269266
270267 NameAndAttributes info;
271 info.name = entry.getKey().data();
268 info.name = Iter->first().data();
272269 info.attributes = LTO_SYMBOL_PERMISSIONS_DATA |
273270 LTO_SYMBOL_DEFINITION_REGULAR | LTO_SYMBOL_SCOPE_DEFAULT;
274271 info.isFunction = false;
287284 if (!objcClassNameFromExpression(c->getOperand(1), targetclassName))
288285 return;
289286
290 NameAndAttributes info;
291 StringMap::value_type &entry =
292 _undefines.GetOrCreateValue(targetclassName);
293
294 if (entry.getValue().name)
295 return;
296
297 const char *symbolName = entry.getKey().data();
298 info.name = symbolName;
287 auto IterBool =
288 _undefines.insert(std::make_pair(targetclassName, NameAndAttributes()));
289
290 if (!IterBool.second)
291 return;
292
293 NameAndAttributes &info = IterBool.first->second;
294 info.name = IterBool.first->first().data();
299295 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
300296 info.isFunction = false;
301297 info.symbol = clgv;
302 entry.setValue(info);
303298 }
304299
305300 /// addObjCClassRef - Parse i386/ppc ObjC class list data structure.
308303 if (!objcClassNameFromExpression(clgv->getInitializer(), targetclassName))
309304 return;
310305
311 NameAndAttributes info;
312 StringMap::value_type &entry =
313 _undefines.GetOrCreateValue(targetclassName);
314 if (entry.getValue().name)
315 return;
316
317 const char *symbolName = entry.getKey().data();
318 info.name = symbolName;
306 auto IterBool =
307 _undefines.insert(std::make_pair(targetclassName, NameAndAttributes()));
308
309 if (!IterBool.second)
310 return;
311
312 NameAndAttributes &info = IterBool.first->second;
313 info.name = IterBool.first->first().data();
319314 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
320315 info.isFunction = false;
321316 info.symbol = clgv;
322 entry.setValue(info);
323317 }
324318
325319 void LTOModule::addDefinedDataSymbol(const object::BasicSymbolRef &Sym) {
438432 else
439433 attr |= LTO_SYMBOL_SCOPE_DEFAULT;
440434
441 StringSet::value_type &entry = _defines.GetOrCreateValue(Name);
442 entry.setValue(1);
435 auto Iter = _defines.insert(Name).first;
443436
444437 // fill information structure
445438 NameAndAttributes info;
446 StringRef NameRef = entry.getKey();
439 StringRef NameRef = Iter->first();
447440 info.name = NameRef.data();
448441 assert(info.name[NameRef.size()] == '\0');
449442 info.attributes = attr;
458451 /// defined list.
459452 void LTOModule::addAsmGlobalSymbol(const char *name,
460453 lto_symbol_attributes scope) {
461 StringSet::value_type &entry = _defines.GetOrCreateValue(name);
454 auto IterBool = _defines.insert(name);
462455
463456 // only add new define if not already defined
464 if (entry.getValue())
465 return;
466
467 entry.setValue(1);
468
469 NameAndAttributes &info = _undefines[entry.getKey().data()];
457 if (!IterBool.second)
458 return;
459
460 NameAndAttributes &info = _undefines[IterBool.first->first().data()];
470461
471462 if (info.symbol == nullptr) {
472463 // FIXME: This is trying to take care of module ASM like this:
478469 // much.
479470
480471 // fill information structure
481 info.name = entry.getKey().data();
472 info.name = IterBool.first->first().data();
482473 info.attributes =
483474 LTO_SYMBOL_PERMISSIONS_DATA | LTO_SYMBOL_DEFINITION_REGULAR | scope;
484475 info.isFunction = false;
501492 /// addAsmGlobalSymbolUndef - Add a global symbol from module-level ASM to the
502493 /// undefined list.
503494 void LTOModule::addAsmGlobalSymbolUndef(const char *name) {
504 StringMap::value_type &entry =
505 _undefines.GetOrCreateValue(name);
506
507 _asm_undefines.push_back(entry.getKey().data());
495 auto IterBool = _undefines.insert(std::make_pair(name, NameAndAttributes()));
496
497 _asm_undefines.push_back(IterBool.first->first().data());
508498
509499 // we already have the symbol
510 if (entry.getValue().name)
500 if (!IterBool.second)
511501 return;
512502
513503 uint32_t attr = LTO_SYMBOL_DEFINITION_UNDEFINED;
514504 attr |= LTO_SYMBOL_SCOPE_DEFAULT;
515 NameAndAttributes info;
516 info.name = entry.getKey().data();
505 NameAndAttributes &info = IterBool.first->second;
506 info.name = IterBool.first->first().data();
517507 info.attributes = attr;
518508 info.isFunction = false;
519509 info.symbol = nullptr;
520
521 entry.setValue(info);
522510 }
523511
524512 /// Add a symbol which isn't defined just yet to a list to be resolved later.
530518 Sym.printName(OS);
531519 }
532520
533 StringMap::value_type &entry =
534 _undefines.GetOrCreateValue(name);
521 auto IterBool = _undefines.insert(std::make_pair(name, NameAndAttributes()));
535522
536523 // we already have the symbol
537 if (entry.getValue().name)
538 return;
539
540 NameAndAttributes info;
541
542 info.name = entry.getKey().data();
524 if (!IterBool.second)
525 return;
526
527 NameAndAttributes &info = IterBool.first->second;
528
529 info.name = IterBool.first->first().data();
543530
544531 const GlobalValue *decl = IRFile->getSymbolGV(Sym.getRawDataRefImpl());
545532
550537
551538 info.isFunction = isFunc;
552539 info.symbol = decl;
553
554 entry.setValue(info);
555540 }
556541
557542 /// parseSymbols - Parse the symbols from the module and model-level ASM and add
624609 MDNode *MDOptions = cast(LinkerOptions->getOperand(i));
625610 for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) {
626611 MDString *MDOption = cast(MDOptions->getOperand(ii));
627 StringRef Op = _linkeropt_strings.
628 GetOrCreateValue(MDOption->getString()).getKey();
612 // FIXME: Make StringSet::insert match Self-Associative Container
613 // requirements, returning rather than bool, and use that
614 // here.
615 StringRef Op =
616 _linkeropt_strings.insert(MDOption->getString()).first->first();
629617 StringRef DepLibName = _target->getSubtargetImpl()
630618 ->getTargetLowering()
631619 ->getObjFileLowering()
14621462 computeTypeMapping();
14631463
14641464 ComdatsChosen.clear();
1465 for (const StringMapEntry &SMEC : SrcM->getComdatSymbolTable()) {
1465 for (const auto &SMEC : SrcM->getComdatSymbolTable()) {
14661466 const Comdat &C = SMEC.getValue();
14671467 if (ComdatsChosen.count(&C))
14681468 continue;
9999 MCSymbol *MCContext::GetOrCreateSymbol(StringRef Name) {
100100 assert(!Name.empty() && "Normal symbols cannot be unnamed!");
101101
102 // Do the lookup and get the entire StringMapEntry. We want access to the
103 // key if we are creating the entry.
104 StringMapEntry &Entry = Symbols.GetOrCreateValue(Name);
105 MCSymbol *Sym = Entry.getValue();
106
107 if (Sym)
108 return Sym;
109
110 Sym = CreateSymbol(Name);
111 Entry.setValue(Sym);
102 MCSymbol *&Sym = Symbols[Name];
103
104 if (!Sym)
105 Sym = CreateSymbol(Name);
106
112107 return Sym;
113108 }
114109
119114
120115 StringRef Name = Section.getSectionName();
121116
122 StringMapEntry &Entry = Symbols.GetOrCreateValue(Name);
123 MCSymbol *OldSym = Entry.getValue();
117 MCSymbol *&OldSym = Symbols[Name];
124118 if (OldSym && OldSym->isUndefined()) {
125119 Sym = OldSym;
126120 return OldSym;
127121 }
128122
129 StringMapEntry *NameEntry = &UsedNames.GetOrCreateValue(Name);
130 NameEntry->setValue(true);
131 Sym = new (*this) MCSymbol(NameEntry->getKey(), /*isTemporary*/ false);
132
133 if (!Entry.getValue())
134 Entry.setValue(Sym);
123 auto NameIter = UsedNames.insert(std::make_pair(Name, true)).first;
124 Sym = new (*this) MCSymbol(NameIter->getKey(), /*isTemporary*/ false);
125
126 if (!OldSym)
127 OldSym = Sym;
135128
136129 return Sym;
137130 }
142135 if (AllowTemporaryLabels)
143136 isTemporary = Name.startswith(MAI->getPrivateGlobalPrefix());
144137
145 StringMapEntry *NameEntry = &UsedNames.GetOrCreateValue(Name);
146 if (NameEntry->getValue()) {
138 auto NameEntry = UsedNames.insert(std::make_pair(Name, true));
139 if (!NameEntry.second) {
147140 assert(isTemporary && "Cannot rename non-temporary symbols");
148141 SmallString<128> NewName = Name;
149142 do {
150143 NewName.resize(Name.size());
151144 raw_svector_ostream(NewName) << NextUniqueID++;
152 NameEntry = &UsedNames.GetOrCreateValue(NewName);
153 } while (NameEntry->getValue());
145 NameEntry = UsedNames.insert(std::make_pair(NewName, true));
146 } while (!NameEntry.second);
154147 }
155 NameEntry->setValue(true);
156148
157149 // Ok, the entry doesn't already exist. Have the MCSymbol object itself refer
158150 // to the copy of the string that is embedded in the UsedNames entry.
159 MCSymbol *Result = new (*this) MCSymbol(NameEntry->getKey(), isTemporary);
151 MCSymbol *Result =
152 new (*this) MCSymbol(NameEntry.first->getKey(), isTemporary);
160153
161154 return Result;
162155 }
367367 FileNumber = SourceIdMap.size() + 1;
368368 assert((MCDwarfFiles.empty() || FileNumber == MCDwarfFiles.size()) &&
369369 "Don't mix autonumbered and explicit numbered line table usage");
370 StringMapEntry &Ent = SourceIdMap.GetOrCreateValue(
371 (Directory + Twine('\0') + FileName).str(), FileNumber);
372 if (Ent.getValue() != FileNumber)
373 return Ent.getValue();
370 auto IterBool = SourceIdMap.insert(
371 std::make_pair((Directory + Twine('\0') + FileName).str(), FileNumber));
372 if (!IterBool.second)
373 return IterBool.first->second;
374374 }
375375 // Make space for this FileNumber in the MCDwarfFiles vector if needed.
376376 MCDwarfFiles.resize(FileNumber + 1);
164164 // Handle named options.
165165 for (size_t i = 0, e = OptionNames.size(); i != e; ++i) {
166166 // Add argument to the argument map!
167 if (OptionsMap.GetOrCreateValue(OptionNames[i], O).second != O) {
167 if (!OptionsMap.insert(std::make_pair(OptionNames[i], O)).second) {
168168 errs() << ProgramName << ": CommandLine Error: Option '"
169169 << OptionNames[i] << "' registered more than once!\n";
170170 HadErrors = true;
758758 #endif
759759
760760 if (LLVMFeatureStr != "")
761 Features.GetOrCreateValue(LLVMFeatureStr).setValue(true);
761 Features[LLVMFeatureStr] = true;
762762 }
763763
764764 #if defined(__aarch64__)
765765 // If we have all crypto bits we can add the feature
766766 if (crypto == (CAP_AES | CAP_PMULL | CAP_SHA1 | CAP_SHA2))
767 Features.GetOrCreateValue("crypto").setValue(true);
767 Features["crypto"] = true;
768768 #endif
769769
770770 return true;
41394139 Parser.Lex(); // Consume the EndOfStatement
41404140
41414141 auto pair = std::make_pair(IsVector, RegNum);
4142 if (RegisterReqs.GetOrCreateValue(Name, pair).getValue() != pair)
4142 if (!RegisterReqs.insert(std::make_pair(Name, pair)).second)
41434143 Warning(L, "ignoring redefinition of register alias '" + Name + "'");
41444144
41454145 return true;
87318731
87328732 Parser.Lex(); // Consume the EndOfStatement
87338733
8734 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg) {
8734 if (!RegisterReqs.insert(std::make_pair(Name, Reg)).second) {
87358735 Error(SRegLoc, "redefinition of '" + Name + "' does not match original.");
87368736 return false;
87378737 }
6161 public:
6262 /// \returns true if name is already present in the map.
6363 bool addName(StringRef Name, unsigned i) {
64 StringMapEntry &Entry = Map.GetOrCreateValue(Name, -1);
65 if (Entry.getValue() != -1)
66 return true;
67 Entry.setValue((int)i);
68 return false;
64 return !Map.insert(std::make_pair(Name, (int)i)).second;
6965 }
7066 /// \returns true if name is not present in the map
7167 bool lookup(StringRef Name, unsigned &Idx) const {
249249
250250 TEST_F(StringMapTest, NonDefaultConstructable) {
251251 StringMap t;
252 t.GetOrCreateValue("Test", StringMapTestStruct(123));
252 t.insert(std::make_pair("Test", StringMapTestStruct(123)));
253253 StringMap::iterator iter = t.find("Test");
254254 ASSERT_NE(iter, t.end());
255255 ASSERT_EQ(iter->second.i, 123);
277277
278278 TEST_F(StringMapTest, MoveOnly) {
279279 StringMap t;
280 t.GetOrCreateValue("Test", MoveOnly(42));
280 t.insert(std::make_pair("Test", MoveOnly(42)));
281281 StringRef Key = "Test";
282282 StringMapEntry::Create(Key, MoveOnly(42))
283283 ->Destroy();
284284 }
285285
286286 TEST_F(StringMapTest, CtorArg) {
287 StringMap t;
288 t.GetOrCreateValue("Test", Immovable());
289287 StringRef Key = "Test";
290288 StringMapEntry::Create(Key, Immovable())
291289 ->Destroy();
293291
294292 TEST_F(StringMapTest, MoveConstruct) {
295293 StringMap A;
296 A.GetOrCreateValue("x", 42);
294 A["x"] = 42;
297295 StringMap B = std::move(A);
298296 ASSERT_EQ(A.size(), 0u);
299297 ASSERT_EQ(B.size(), 1u);
338336 TEST_F(StringMapTest, MoveDtor) {
339337 int InstanceCount = 0;
340338 StringMap A;
341 A.GetOrCreateValue("x", Countable(42, InstanceCount));
339 A.insert(std::make_pair("x", Countable(42, InstanceCount)));
342340 ASSERT_EQ(InstanceCount, 1);
343341 auto I = A.find("x");
344342 ASSERT_NE(I, A.end());
965965
966966 // Compute register name map.
967967 for (unsigned i = 0, e = Registers.size(); i != e; ++i)
968 RegistersByName.GetOrCreateValue(
969 Registers[i]->TheDef->getValueAsString("AsmName"),
970 Registers[i]);
968 // FIXME: This could just be RegistersByName[name] = register, except that
969 // causes some failures in MIPS - perhaps they have duplicate register name
970 // entries? (or maybe there's a reason for it - I don't know much about this
971 // code, just drive-by refactoring)
972 RegistersByName.insert(std::make_pair(
973 Registers[i]->TheDef->getValueAsString("AsmName"), Registers[i]));
971974
972975 // Precompute all sub-register maps.
973976 // This will create Composite entries for all inferred sub-register indices.