diff options
author | Stephen Hines <srhines@google.com> | 2014-12-01 14:51:49 -0800 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2014-12-02 16:08:10 -0800 |
commit | 37ed9c199ca639565f6ce88105f9e39e898d82d0 (patch) | |
tree | 8fb36d3910e3ee4c4e1b7422f4f017108efc52f5 /lib/MC/MCContext.cpp | |
parent | d2327b22152ced7bc46dc629fc908959e8a52d03 (diff) | |
download | external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.zip external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.tar.gz external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.tar.bz2 |
Update aosp/master LLVM for rebase to r222494.
Change-Id: Ic787f5e0124df789bd26f3f24680f45e678eef2d
Diffstat (limited to 'lib/MC/MCContext.cpp')
-rw-r--r-- | lib/MC/MCContext.cpp | 62 |
1 files changed, 49 insertions, 13 deletions
diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index 960a071..8630b25 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -73,7 +73,10 @@ void MCContext::reset() { Symbols.clear(); Allocator.Reset(); Instances.clear(); + CompilationDir.clear(); + MainFileName.clear(); MCDwarfLineTablesCUMap.clear(); + SectionStartEndSyms.clear(); MCGenDwarfLabelEntries.clear(); DwarfDebugFlags = StringRef(); DwarfCompileUnitID = 0; @@ -97,16 +100,33 @@ 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) + Sym = CreateSymbol(Name); + + return Sym; +} + +MCSymbol *MCContext::getOrCreateSectionSymbol(const MCSectionELF &Section) { + MCSymbol *&Sym = SectionSymbols[&Section]; if (Sym) return Sym; - Sym = CreateSymbol(Name); - Entry.setValue(Sym); + StringRef Name = Section.getSectionName(); + + MCSymbol *&OldSym = Symbols[Name]; + if (OldSym && OldSym->isUndefined()) { + Sym = OldSym; + return OldSym; + } + + auto NameIter = UsedNames.insert(std::make_pair(Name, true)).first; + Sym = new (*this) MCSymbol(NameIter->getKey(), /*isTemporary*/ false); + + if (!OldSym) + OldSym = Sym; + return Sym; } @@ -116,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; } @@ -291,7 +311,7 @@ const MCSectionCOFF *MCContext::getCOFFSection(StringRef Section, if (!IterBool.second) return Iter->second; - const MCSymbol *COMDATSymbol = nullptr; + MCSymbol *COMDATSymbol = nullptr; if (!COMDATSymName.empty()) COMDATSymbol = GetOrCreateSymbol(COMDATSymName); @@ -317,6 +337,22 @@ const MCSectionCOFF *MCContext::getCOFFSection(StringRef Section) { return Iter->second; } +const MCSectionCOFF * +MCContext::getAssociativeCOFFSection(const MCSectionCOFF *Sec, + const MCSymbol *KeySym) { + // Return the normal section if we don't have to be associative. + if (!KeySym) + return Sec; + + // Make an associative section with the same name and kind as the normal + // section. + unsigned Characteristics = + Sec->getCharacteristics() | COFF::IMAGE_SCN_LNK_COMDAT; + return getCOFFSection(Sec->getSectionName(), Characteristics, Sec->getKind(), + KeySym->getName(), + COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE); +} + //===----------------------------------------------------------------------===// // Dwarf Management //===----------------------------------------------------------------------===// |