summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2015-06-19 12:16:55 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2015-06-19 12:16:55 +0000
commit284a750c5ff95a29cd8cc9130d3eb7ec6d25e352 (patch)
tree38c934be221f58276592baa899f0514b9ac2d46b /llvm/lib
parent9fb676a2543434ed0df96649195a0529b23a8dea (diff)
downloadbcm5719-llvm-284a750c5ff95a29cd8cc9130d3eb7ec6d25e352.tar.gz
bcm5719-llvm-284a750c5ff95a29cd8cc9130d3eb7ec6d25e352.zip
Make all temporary symbols unnamed.
What this does is make all symbols that would otherwise start with a .L (or L on MachO) unnamed. Some of these symbols still show up in the symbol table, but we can just make them unnamed. In order to make sure we produce identical results when going thought assembly, all .L (not just the compiler produced ones), are now unnamed. Running llc on llvm-as.opt.bc, the peak memory usage goes from 208.24MB to 205.57MB. llvm-svn: 240130
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/MC/ELFObjectWriter.cpp13
-rw-r--r--llvm/lib/MC/MCContext.cpp28
-rw-r--r--llvm/lib/MC/MachObjectWriter.cpp3
3 files changed, 25 insertions, 19 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 0765937d0ea..bbf0b2b69d3 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -786,10 +786,15 @@ void ELFObjectWriter::computeSymbolTable(
Renames.count(&Symbol)))
continue;
+ if (Symbol.isTemporary() && Symbol.isUndefined())
+ Ctx.reportFatalError(SMLoc(), "Undefined temporary");
+
ELFSymbolData MSD;
MSD.Symbol = cast<MCSymbolELF>(&Symbol);
bool Local = Symbol.getBinding() == ELF::STB_LOCAL;
+ assert(Local || !Symbol.isTemporary());
+
if (Symbol.isAbsolute()) {
MSD.SectionIndex = ELF::SHN_ABS;
} else if (Symbol.isCommon()) {
@@ -888,9 +893,11 @@ void ELFObjectWriter::computeSymbolTable(
unsigned Index = FileNames.size() + 1;
for (ELFSymbolData &MSD : LocalSymbolData) {
- unsigned StringIndex = MSD.Symbol->getType() == ELF::STT_SECTION
- ? 0
- : StrTabBuilder.getOffset(MSD.Name);
+ unsigned StringIndex;
+ if (MSD.Symbol->getType() == ELF::STT_SECTION || MSD.Name.empty())
+ StringIndex = 0;
+ else
+ StringIndex = StrTabBuilder.getOffset(MSD.Name);
MSD.Symbol->setIndex(Index++);
writeSymbol(Writer, StringIndex, MSD, Layout);
}
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index c601c56f395..01074eb5e79 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -116,7 +116,7 @@ MCSymbol *MCContext::getOrCreateSymbol(const Twine &Name) {
MCSymbol *&Sym = Symbols[NameRef];
if (!Sym)
- Sym = createSymbol(NameRef, false, false);
+ Sym = createSymbol(NameRef, false);
return Sym;
}
@@ -175,17 +175,16 @@ MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
IsTemporary);
}
-MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix,
- bool CanBeUnnamed) {
- if (CanBeUnnamed && !UseNamesOnTempLabels)
- return createSymbolImpl(nullptr, true);
-
+MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix) {
// Determine whether this is an user writter assembler temporary or normal
// label, if used.
- bool IsTemporary = CanBeUnnamed;
- if (AllowTemporaryLabels && !IsTemporary)
+ bool IsTemporary = false;
+ if (AllowTemporaryLabels)
IsTemporary = Name.startswith(MAI->getPrivateGlobalPrefix());
+ if (IsTemporary && !UseNamesOnTempLabels)
+ return createSymbolImpl(nullptr, true);
+
SmallString<128> NewName = Name;
bool AddSuffix = AlwaysAddSuffix;
unsigned &NextUniqueID = NextID[Name];
@@ -206,21 +205,20 @@ MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix,
llvm_unreachable("Infinite loop");
}
-MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix,
- bool CanBeUnnamed) {
+MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix) {
SmallString<128> NameSV;
raw_svector_ostream(NameSV) << MAI->getPrivateGlobalPrefix() << Name;
- return createSymbol(NameSV, AlwaysAddSuffix, CanBeUnnamed);
+ return createSymbol(NameSV, AlwaysAddSuffix);
}
MCSymbol *MCContext::createLinkerPrivateTempSymbol() {
SmallString<128> NameSV;
raw_svector_ostream(NameSV) << MAI->getLinkerPrivateGlobalPrefix() << "tmp";
- return createSymbol(NameSV, true, false);
+ return createSymbol(NameSV, true);
}
-MCSymbol *MCContext::createTempSymbol(bool CanBeUnnamed) {
- return createTempSymbol("tmp", true, CanBeUnnamed);
+MCSymbol *MCContext::createTempSymbol() {
+ return createTempSymbol("tmp", true);
}
unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
@@ -241,7 +239,7 @@ MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
unsigned Instance) {
MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)];
if (!Sym)
- Sym = createTempSymbol(false);
+ Sym = createTempSymbol();
return Sym;
}
diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp
index 8ce6127e386..d7934ad80c6 100644
--- a/llvm/lib/MC/MachObjectWriter.cpp
+++ b/llvm/lib/MC/MachObjectWriter.cpp
@@ -565,7 +565,8 @@ void MachObjectWriter::computeSymbolTable(
MachSymbolData MSD;
MSD.Symbol = &Symbol;
- MSD.StringIndex = StringTable.getOffset(Symbol.getName());
+ StringRef Name = Symbol.getName();
+ MSD.StringIndex = Name.empty() ? 0 : StringTable.getOffset(Name);
if (Symbol.isAbsolute()) {
MSD.SectionIndex = 0;
OpenPOWER on IntegriCloud