summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC/MCContext.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2015-03-17 20:07:06 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2015-03-17 20:07:06 +0000
commit9ab09237dcfedb123340676d75e59821dac35513 (patch)
tree435f70f63ffcd0c9e9232b6fd186f46aec16461e /llvm/lib/MC/MCContext.cpp
parent0641ca1a2dc2d4923ee702651aab2a9704d563b5 (diff)
downloadbcm5719-llvm-9ab09237dcfedb123340676d75e59821dac35513.tar.gz
bcm5719-llvm-9ab09237dcfedb123340676d75e59821dac35513.zip
Centralize the handling of unique ids for temporary labels.
Before this patch code wanting to create temporary labels for a given entity (function, cu, exception range, etc) had to keep its own counter to have stable symbol names. createTempSymbol would still add a suffix to make sure a new symbol was always returned, but it kept a single counter. Because of that, if we were to use just createTempSymbol("cu_begin"), the label could change from cu_begin42 to cu_begin43 because some other code started using temporary labels. Simplify this by just keeping one counter per prefix and removing the various specialized counters. llvm-svn: 232535
Diffstat (limited to 'llvm/lib/MC/MCContext.cpp')
-rw-r--r--llvm/lib/MC/MCContext.cpp63
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(
OpenPOWER on IntegriCloud