From 7e9df19d5f935c52ed4f550997f944930874146d Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 13 Mar 2014 18:09:26 +0000 Subject: Use printable names to implement directional labels. This changes the implementation of local directional labels to use a dedicated map. With that it can then just use CreateTempSymbol, which is what the rest of MC uses. CreateTempSymbol doesn't do a great job at making sure the names are unique (or being efficient when the names are not needed), but that should probably be fixed in a followup patch. This fixes pr18928. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203826 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCContext.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'lib/MC/MCContext.cpp') diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index 7f211255c6..27f66d8393 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -162,32 +162,39 @@ MCSymbol *MCContext::CreateTempSymbol() { return CreateSymbol(NameSV); } -unsigned MCContext::NextInstance(int64_t LocalLabelVal) { +unsigned MCContext::NextInstance(unsigned LocalLabelVal) { MCLabel *&Label = Instances[LocalLabelVal]; if (!Label) Label = new (*this) MCLabel(0); return Label->incInstance(); } -unsigned MCContext::GetInstance(int64_t LocalLabelVal) { +unsigned MCContext::GetInstance(unsigned LocalLabelVal) { MCLabel *&Label = Instances[LocalLabelVal]; if (!Label) Label = new (*this) MCLabel(0); return Label->getInstance(); } -MCSymbol *MCContext::CreateDirectionalLocalSymbol(int64_t LocalLabelVal) { - return GetOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + - Twine(LocalLabelVal) + - "\2" + - Twine(NextInstance(LocalLabelVal))); +MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal, + unsigned Instance) { + MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)]; + if (!Sym) + Sym = CreateTempSymbol(); + return Sym; +} + +MCSymbol *MCContext::CreateDirectionalLocalSymbol(unsigned LocalLabelVal) { + unsigned Instance = NextInstance(LocalLabelVal); + return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance); } -MCSymbol *MCContext::GetDirectionalLocalSymbol(int64_t LocalLabelVal, - int bORf) { - return GetOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + - Twine(LocalLabelVal) + - "\2" + - Twine(GetInstance(LocalLabelVal) + bORf)); + +MCSymbol *MCContext::GetDirectionalLocalSymbol(unsigned LocalLabelVal, + bool Before) { + unsigned Instance = GetInstance(LocalLabelVal); + if (!Before) + ++Instance; + return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance); } MCSymbol *MCContext::LookupSymbol(StringRef Name) const { -- cgit v1.2.3