diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-03-13 18:09:26 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-03-13 18:09:26 +0000 |
| commit | 4269b9eed5f68832ecbf1b59e9ab07ce8ac38517 (patch) | |
| tree | 49afa296c1b54d3de3a72ff9e9f8af66e6ada316 /llvm/lib/MC | |
| parent | 91cdc28d9300eb5dc8ced47cb31db26d8f5ca7d4 (diff) | |
| download | bcm5719-llvm-4269b9eed5f68832ecbf1b59e9ab07ce8ac38517.tar.gz bcm5719-llvm-4269b9eed5f68832ecbf1b59e9ab07ce8ac38517.zip | |
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.
llvm-svn: 203826
Diffstat (limited to 'llvm/lib/MC')
| -rw-r--r-- | llvm/lib/MC/MCContext.cpp | 33 | ||||
| -rw-r--r-- | llvm/lib/MC/MCParser/AsmParser.cpp | 2 |
2 files changed, 21 insertions, 14 deletions
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index 7f211255c6f..27f66d8393f 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/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 { diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index 3d2131f10be..db448ae8be2 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -884,7 +884,7 @@ bool AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) { } if (IDVal == "f" || IDVal == "b") { MCSymbol *Sym = - Ctx.GetDirectionalLocalSymbol(IntVal, IDVal == "f" ? 1 : 0); + Ctx.GetDirectionalLocalSymbol(IntVal, IDVal == "b"); Res = MCSymbolRefExpr::Create(Sym, Variant, getContext()); if (IDVal == "b" && Sym->isUndefined()) return Error(Loc, "invalid reference to undefined symbol"); |

