From f27fa2bb9d6078013cc95750748a435611aa511b Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 17 Jun 2015 16:26:47 +0000 Subject: [PATCH] Use named temporaries for directional labels. Directional labels can show up in symbol tables (and we have a llvm-mc test for that). Given that, we need to make sure they are named. With that out of the way, use setUseNamesOnTempLabels in llvm-mc so that it too benefits from the memory saving. llvm-svn: 239914 --- llvm/include/llvm/MC/MCContext.h | 7 ++++--- llvm/lib/MC/MCContext.cpp | 19 ++++++++++--------- llvm/tools/llvm-mc/llvm-mc.cpp | 3 +++ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h index 1790905..52017fd 100644 --- a/llvm/include/llvm/MC/MCContext.h +++ b/llvm/include/llvm/MC/MCContext.h @@ -207,7 +207,7 @@ namespace llvm { bool AutoReset; MCSymbol *createSymbolImpl(const StringMapEntry *Name, - bool IsTemporary); + bool CanBeUnnamed); MCSymbol *createSymbol(StringRef Name, bool AlwaysAddSuffix, bool IsTemporary); @@ -249,9 +249,10 @@ namespace llvm { /// Create and return a new assembler temporary symbol with a unique but /// unspecified name. - MCSymbol *createTempSymbol(); + MCSymbol *createTempSymbol(bool CanBeUnnamed = true); - MCSymbol *createTempSymbol(const Twine &Name, bool AlwaysAddSuffix); + MCSymbol *createTempSymbol(const Twine &Name, bool AlwaysAddSuffix, + bool CanBeUnnamed = true); /// Create the definition of a directional local symbol for numbered label /// (used for "1:" definitions). diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index 785f9ac..c601c56 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -176,14 +176,14 @@ MCSymbol *MCContext::createSymbolImpl(const StringMapEntry *Name, } MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix, - bool IsTemporary) { - if (IsTemporary && !UseNamesOnTempLabels) + bool CanBeUnnamed) { + if (CanBeUnnamed && !UseNamesOnTempLabels) return createSymbolImpl(nullptr, true); // Determine whether this is an user writter assembler temporary or normal // label, if used. - IsTemporary = false; - if (AllowTemporaryLabels) + bool IsTemporary = CanBeUnnamed; + if (AllowTemporaryLabels && !IsTemporary) IsTemporary = Name.startswith(MAI->getPrivateGlobalPrefix()); SmallString<128> NewName = Name; @@ -206,10 +206,11 @@ MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix, llvm_unreachable("Infinite loop"); } -MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix) { +MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix, + bool CanBeUnnamed) { SmallString<128> NameSV; raw_svector_ostream(NameSV) << MAI->getPrivateGlobalPrefix() << Name; - return createSymbol(NameSV, AlwaysAddSuffix, true); + return createSymbol(NameSV, AlwaysAddSuffix, CanBeUnnamed); } MCSymbol *MCContext::createLinkerPrivateTempSymbol() { @@ -218,8 +219,8 @@ MCSymbol *MCContext::createLinkerPrivateTempSymbol() { return createSymbol(NameSV, true, false); } -MCSymbol *MCContext::createTempSymbol() { - return createTempSymbol("tmp", true); +MCSymbol *MCContext::createTempSymbol(bool CanBeUnnamed) { + return createTempSymbol("tmp", true, CanBeUnnamed); } unsigned MCContext::NextInstance(unsigned LocalLabelVal) { @@ -240,7 +241,7 @@ MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal, unsigned Instance) { MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)]; if (!Sym) - Sym = createTempSymbol(); + Sym = createTempSymbol(false); return Sym; } diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp index ef728f3..6ecdb2e 100644 --- a/llvm/tools/llvm-mc/llvm-mc.cpp +++ b/llvm/tools/llvm-mc/llvm-mc.cpp @@ -500,6 +500,9 @@ int main(int argc, char **argv) { } else { assert(FileType == OFT_ObjectFile && "Invalid file type!"); + // Don't waste memory on names of temp labels. + Ctx.setUseNamesOnTempLabels(false); + if (!Out->os().supportsSeeking()) { BOS = make_unique(Out->os()); OS = BOS.get(); -- 2.7.4