diff options
Diffstat (limited to 'llvm/lib/MC/MCContext.cpp')
| -rw-r--r-- | llvm/lib/MC/MCContext.cpp | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index b0e7cf50d69..3cb3ea12afd 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -34,7 +34,7 @@ MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri, const MCObjectFileInfo *mofi, const SourceMgr *mgr, bool DoAutoReset) : SrcMgr(mgr), MAI(mai), MRI(mri), MOFI(mofi), Allocator(), - Symbols(Allocator), UsedNames(Allocator), NextUniqueID(0), + Symbols(Allocator), UsedNames(Allocator), CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0), DwarfLocSeen(false), GenDwarfForAssembly(false), GenDwarfFileNumber(0), DwarfVersion(4), AllowTemporaryLabels(true), DwarfCompileUnitID(0), @@ -87,7 +87,7 @@ void MCContext::reset() { ELFUniquingMap.clear(); COFFUniquingMap.clear(); - NextUniqueID = 0; + NextID.clear(); AllowTemporaryLabels = true; DwarfLocSeen = false; GenDwarfForAssembly = false; @@ -106,7 +106,7 @@ MCSymbol *MCContext::GetOrCreateSymbol(const Twine &Name) { MCSymbol *&Sym = Symbols[NameRef]; if (!Sym) - Sym = CreateSymbol(NameRef); + Sym = CreateSymbol(NameRef, false); return Sym; } @@ -139,49 +139,48 @@ MCSymbol *MCContext::getOrCreateFrameAllocSymbol(StringRef FuncName, "$frame_escape_" + Twine(Idx)); } -MCSymbol *MCContext::CreateSymbol(StringRef Name) { +MCSymbol *MCContext::CreateSymbol(StringRef Name, bool AlwaysAddSuffix) { // Determine whether this is an assembler temporary or normal label, if used. - bool isTemporary = false; + bool IsTemporary = false; if (AllowTemporaryLabels) - isTemporary = Name.startswith(MAI->getPrivateGlobalPrefix()); + IsTemporary = Name.startswith(MAI->getPrivateGlobalPrefix()); - auto NameEntry = UsedNames.insert(std::make_pair(Name, true)); - if (!NameEntry.second) { - assert(isTemporary && "Cannot rename non-temporary symbols"); - SmallString<128> NewName = Name; - do { + SmallString<128> NewName = Name; + bool AddSuffix = AlwaysAddSuffix; + unsigned &NextUniqueID = NextID[Name]; + for (;;) { + if (AddSuffix) { NewName.resize(Name.size()); raw_svector_ostream(NewName) << NextUniqueID++; - NameEntry = UsedNames.insert(std::make_pair(NewName, true)); - } while (!NameEntry.second); + } + auto NameEntry = UsedNames.insert(std::make_pair(NewName, true)); + if (NameEntry.second) { + // Ok, we found a name. 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.first->getKey(), IsTemporary); + return Result; + } + assert(IsTemporary && "Cannot rename non-temporary symbols"); + AddSuffix = 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.first->getKey(), isTemporary); - - return Result; + llvm_unreachable("Infinite loop"); } -MCSymbol *MCContext::createTempSymbol(const Twine &Name) { +MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix) { SmallString<128> NameSV; raw_svector_ostream(NameSV) << MAI->getPrivateGlobalPrefix() << Name; - return CreateSymbol(NameSV); + return CreateSymbol(NameSV, AlwaysAddSuffix); } MCSymbol *MCContext::CreateLinkerPrivateTempSymbol() { SmallString<128> NameSV; - raw_svector_ostream(NameSV) - << MAI->getLinkerPrivateGlobalPrefix() << "tmp" << NextUniqueID++; - return CreateSymbol(NameSV); + raw_svector_ostream(NameSV) << MAI->getLinkerPrivateGlobalPrefix() << "tmp"; + return CreateSymbol(NameSV, true); } MCSymbol *MCContext::CreateTempSymbol() { - SmallString<128> NameSV; - raw_svector_ostream(NameSV) - << MAI->getPrivateGlobalPrefix() << "tmp" << NextUniqueID++; - return CreateSymbol(NameSV); + return createTempSymbol("tmp", true); } unsigned MCContext::NextInstance(unsigned LocalLabelVal) { @@ -251,7 +250,7 @@ MCContext::getMachOSection(StringRef Segment, StringRef Section, MCSymbol *Begin = nullptr; if (BeginSymName) - Begin = createTempSymbol(BeginSymName); + Begin = createTempSymbol(BeginSymName, false); // Otherwise, return a new section. return Entry = new (*this) MCSectionMachO(Segment, Section, TypeAndAttributes, @@ -302,7 +301,7 @@ const MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type, MCSymbol *Begin = nullptr; if (BeginSymName) - Begin = createTempSymbol(BeginSymName); + Begin = createTempSymbol(BeginSymName, false); MCSectionELF *Result = new (*this) MCSectionELF( CachedName, Type, Flags, Kind, EntrySize, GroupSym, Unique, Begin); @@ -344,7 +343,7 @@ MCContext::getCOFFSection(StringRef Section, unsigned Characteristics, MCSymbol *Begin = nullptr; if (BeginSymName) - Begin = createTempSymbol(BeginSymName); + Begin = createTempSymbol(BeginSymName, false); StringRef CachedName = std::get<0>(Iter->first); MCSectionCOFF *Result = new (*this) MCSectionCOFF( |

