[llvm] r265064 - [AsmPrinter] Print aliases in topological order
Tim Shen via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 31 15:08:19 PDT 2016
Author: timshen
Date: Thu Mar 31 17:08:19 2016
New Revision: 265064
URL: http://llvm.org/viewvc/llvm-project?rev=265064&view=rev
Log:
[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.
Added:
llvm/trunk/test/CodeGen/Generic/asm-printer-topological-order.ll
Modified:
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=265064&r1=265063&r2=265064&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Thu Mar 31 17:08:19 2016
@@ -1148,7 +1148,7 @@ bool AsmPrinter::doFinalization(Module &
}
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 &
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>();
Added: llvm/trunk/test/CodeGen/Generic/asm-printer-topological-order.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/asm-printer-topological-order.ll?rev=265064&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Generic/asm-printer-topological-order.ll (added)
+++ llvm/trunk/test/CodeGen/Generic/asm-printer-topological-order.ll Thu Mar 31 17:08:19 2016
@@ -0,0 +1,15 @@
+; RUN: llc < %s | FileCheck %s
+
+ at TestA = alias void (), void ()* @TestC
+ at TestB = alias void (), void ()* @TestC
+ at TestC = alias void (), void ()* @TestD
+
+define void @TestD() {
+entry:
+ ret void
+}
+
+; CHECK-LABEL: TestD:
+; CHECK: TestC = TestD
+; CHECK-DAG: TestB = TestC
+; CHECK-DAG: TestA = TestC
More information about the llvm-commits
mailing list