mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-27 21:50:40 +00:00
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265064 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e6ec1e3b8f
commit
47094ef9e3
@ -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>();
|
||||
|
15
test/CodeGen/Generic/asm-printer-topological-order.ll
Normal file
15
test/CodeGen/Generic/asm-printer-topological-order.ll
Normal file
@ -0,0 +1,15 @@
|
||||
; RUN: llc < %s | FileCheck %s
|
||||
|
||||
@TestA = alias void (), void ()* @TestC
|
||||
@TestB = alias void (), void ()* @TestC
|
||||
@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
|
Loading…
Reference in New Issue
Block a user