diff options
| author | Tim Shen <timshen91@gmail.com> | 2016-03-31 22:08:19 +0000 |
|---|---|---|
| committer | Tim Shen <timshen91@gmail.com> | 2016-03-31 22:08:19 +0000 |
| commit | 800ed436e543997e061348ec5b700a45b3b3d675 (patch) | |
| tree | d959b2cbd3d1409cd99f5e30fb7e0d4efd184902 /llvm/lib/CodeGen | |
| parent | b472856a73118fe8cebc2b53f5cd963e2125d518 (diff) | |
| download | bcm5719-llvm-800ed436e543997e061348ec5b700a45b3b3d675.tar.gz bcm5719-llvm-800ed436e543997e061348ec5b700a45b3b3d675.zip | |
[AsmPrinter] Print aliases in topological order
Print aliases in topological order, that is, for any alias a = b,
b must be printed before a. This is because on some targets (e.g. PowerPC)
linker expects aliases in such an order to generate correct TOC information.
GCC also prints aliases in topological order.
llvm-svn: 265064
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 67153d1d20f..0559a3c6acc 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1148,7 +1148,7 @@ bool AsmPrinter::doFinalization(Module &M) { } OutStreamer->AddBlankLine(); - for (const auto &Alias : M.aliases()) { + const auto printAlias = [this, &M](const GlobalAlias &Alias) { MCSymbol *Name = getSymbol(&Alias); if (Alias.hasExternalLinkage() || !MAI->getWeakRefDirective()) @@ -1186,6 +1186,23 @@ bool AsmPrinter::doFinalization(Module &M) { OutStreamer->emitELFSize(cast<MCSymbolELF>(Name), MCConstantExpr::create(Size, OutContext)); } + }; + // Print aliases in topological order, that is, for each alias a = b, + // b must be printed before a. + // This is because on some targets (e.g. PowerPC) linker expects aliases in + // such an order to generate correct TOC information. + SmallVector<const GlobalAlias *, 16> AliasStack; + SmallPtrSet<const GlobalAlias *, 16> AliasVisited; + for (const auto &Alias : M.aliases()) { + for (const GlobalAlias *Cur = &Alias; Cur; + Cur = dyn_cast<GlobalAlias>(Cur->getAliasee())) { + if (!AliasVisited.insert(Cur).second) + break; + AliasStack.push_back(Cur); + } + for (const GlobalAlias *AncestorAlias : reverse(AliasStack)) + printAlias(*AncestorAlias); + AliasStack.clear(); } GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>(); |

