[llvm] r293864 - Linker: Move special casing for available_externally in IRMover to clients. NFCI.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 1 21:12:15 PST 2017
Author: pcc
Date: Wed Feb 1 23:12:15 2017
New Revision: 293864
URL: http://llvm.org/viewvc/llvm-project?rev=293864&view=rev
Log:
Linker: Move special casing for available_externally in IRMover to clients. NFCI.
The goal is to simplify the semantic model for clients of IRMover.
Differential Revision: https://reviews.llvm.org/D29435
Added:
llvm/trunk/test/LTO/Resolution/X86/Inputs/link-odr-availextern-ae.ll
llvm/trunk/test/LTO/Resolution/X86/link-odr-availextern.ll
Modified:
llvm/trunk/lib/LTO/LTO.cpp
llvm/trunk/lib/Linker/IRMover.cpp
llvm/trunk/lib/Linker/LinkModules.cpp
llvm/trunk/test/Linker/available_externally_a.ll
Modified: llvm/trunk/lib/LTO/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTO.cpp?rev=293864&r1=293863&r2=293864&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTO.cpp (original)
+++ llvm/trunk/lib/LTO/LTO.cpp Wed Feb 1 23:12:15 2017
@@ -455,20 +455,29 @@ Error LTO::addRegularLTO(BitcodeModule B
SymbolResolution Res = *ResI++;
addSymbolToGlobalRes(Used, Sym, Res, 0);
- if (Sym.getFlags() & object::BasicSymbolRef::SF_Undefined)
- continue;
- if (Res.Prevailing && Sym.isGV()) {
+ if (Sym.isGV()) {
GlobalValue *GV = Sym.getGV();
- Keep.push_back(GV);
- switch (GV->getLinkage()) {
- default:
- break;
- case GlobalValue::LinkOnceAnyLinkage:
- GV->setLinkage(GlobalValue::WeakAnyLinkage);
- break;
- case GlobalValue::LinkOnceODRLinkage:
- GV->setLinkage(GlobalValue::WeakODRLinkage);
- break;
+ if (Res.Prevailing) {
+ if (Sym.getFlags() & object::BasicSymbolRef::SF_Undefined)
+ continue;
+ Keep.push_back(GV);
+ switch (GV->getLinkage()) {
+ default:
+ break;
+ case GlobalValue::LinkOnceAnyLinkage:
+ GV->setLinkage(GlobalValue::WeakAnyLinkage);
+ break;
+ case GlobalValue::LinkOnceODRLinkage:
+ GV->setLinkage(GlobalValue::WeakODRLinkage);
+ break;
+ }
+ } else if (GV->hasAvailableExternallyLinkage()) {
+ // We can link available_externally symbols even if they are
+ // non-prevailing.
+ GlobalValue *CombinedGV =
+ RegularLTO.CombinedModule->getNamedValue(GV->getName());
+ if (!CombinedGV || CombinedGV->isDeclaration())
+ Keep.push_back(GV);
}
}
// Common resolution: collect the maximum size/alignment over all commons.
Modified: llvm/trunk/lib/Linker/IRMover.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/IRMover.cpp?rev=293864&r1=293863&r2=293864&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/IRMover.cpp (original)
+++ llvm/trunk/lib/Linker/IRMover.cpp Wed Feb 1 23:12:15 2017
@@ -870,9 +870,6 @@ bool IRLinker::shouldLink(GlobalValue *D
if (DGV && !DGV->isDeclarationForLinker())
return false;
- if (SGV.hasAvailableExternallyLinkage())
- return true;
-
if (SGV.isDeclaration() || DoneLinkingBodies)
return false;
Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=293864&r1=293863&r2=293864&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Wed Feb 1 23:12:15 2017
@@ -425,7 +425,8 @@ void ModuleLinker::addLazyFor(GlobalValu
return;
// Add these to the internalize list
- if (!GV.hasLinkOnceLinkage() && !shouldLinkOnlyNeeded())
+ if (!GV.hasLinkOnceLinkage() && !GV.hasAvailableExternallyLinkage() &&
+ !shouldLinkOnlyNeeded())
return;
if (shouldInternalizeLinkedSymbols())
Added: llvm/trunk/test/LTO/Resolution/X86/Inputs/link-odr-availextern-ae.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/Resolution/X86/Inputs/link-odr-availextern-ae.ll?rev=293864&view=auto
==============================================================================
--- llvm/trunk/test/LTO/Resolution/X86/Inputs/link-odr-availextern-ae.ll (added)
+++ llvm/trunk/test/LTO/Resolution/X86/Inputs/link-odr-availextern-ae.ll Wed Feb 1 23:12:15 2017
@@ -0,0 +1,6 @@
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define available_externally i32 @f() {
+ ret i32 2
+}
Added: llvm/trunk/test/LTO/Resolution/X86/link-odr-availextern.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/Resolution/X86/link-odr-availextern.ll?rev=293864&view=auto
==============================================================================
--- llvm/trunk/test/LTO/Resolution/X86/link-odr-availextern.ll (added)
+++ llvm/trunk/test/LTO/Resolution/X86/link-odr-availextern.ll Wed Feb 1 23:12:15 2017
@@ -0,0 +1,25 @@
+; Tests for correct behavior for non-prevailing resolutions in cases involving
+; *_odr and available_externally linkages.
+
+; RUN: llvm-as %s -o %t1
+; RUN: llvm-as %S/Inputs/link-odr-availextern-ae.ll -o %t2ae
+
+; RUN: llvm-lto2 -o %t3 %t1 %t2ae -r %t1,f,p -r %t2ae,f, -save-temps
+; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=PREVAILING %s
+
+; RUN: llvm-lto2 -o %t3 %t2ae %t1 -r %t1,f,p -r %t2ae,f, -save-temps
+; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=PREVAILING %s
+
+; RUN: llvm-lto2 -o %t3 %t2ae -r %t2ae,f, -save-temps
+; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=NONPREVAILING %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; PREVAILING: define weak_odr i32 @f()
+; PREVAILING-NEXT: ret i32 1
+; NONPREVAILING: define available_externally i32 @f()
+; NONPREVAILING-NEXT: ret i32 2
+define linkonce_odr i32 @f() {
+ ret i32 1
+}
Modified: llvm/trunk/test/Linker/available_externally_a.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/available_externally_a.ll?rev=293864&r1=293863&r2=293864&view=diff
==============================================================================
--- llvm/trunk/test/Linker/available_externally_a.ll (original)
+++ llvm/trunk/test/Linker/available_externally_a.ll Wed Feb 1 23:12:15 2017
@@ -1,5 +1,7 @@
; RUN: llvm-link %s %p/available_externally_b.ll -S -o - | FileCheck %s
+; RUN: llvm-link %s -S -o - | FileCheck --check-prefix=AE-ONLY %s
@foo = available_externally unnamed_addr constant i32 0
; CHECK: @foo = hidden unnamed_addr constant i32 0
+; AE-ONLY-NOT: @foo
More information about the llvm-commits
mailing list