1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

llvm-extract changes linkages so that functions on both sides of the

split module can see each other. If it is keeping a symbol that already has
a non local linkage, it doesn't need to change it.

llvm-svn: 166908
This commit is contained in:
Rafael Espindola 2012-10-29 01:59:03 +00:00
parent 218ef13219
commit c460831626
3 changed files with 53 additions and 16 deletions

View File

@ -51,32 +51,44 @@ namespace {
// Visit the GlobalVariables.
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I) {
if (deleteStuff == (bool)Named.count(I) && !I->isDeclaration()) {
I->setInitializer(0);
} else {
bool Delete =
deleteStuff == (bool)Named.count(I) && !I->isDeclaration();
if (!Delete) {
if (I->hasAvailableExternallyLinkage())
continue;
if (I->getName() == "llvm.global_ctors")
continue;
}
if (I->hasLocalLinkage())
bool Local = I->hasLocalLinkage();
if (Local)
I->setVisibility(GlobalValue::HiddenVisibility);
I->setLinkage(GlobalValue::ExternalLinkage);
if (Local || Delete)
I->setLinkage(GlobalValue::ExternalLinkage);
if (Delete)
I->setInitializer(0);
}
// Visit the Functions.
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
if (deleteStuff == (bool)Named.count(I) && !I->isDeclaration()) {
I->deleteBody();
} else {
bool Delete =
deleteStuff == (bool)Named.count(I) && !I->isDeclaration();
if (!Delete) {
if (I->hasAvailableExternallyLinkage())
continue;
}
if (I->hasLocalLinkage())
bool Local = I->hasLocalLinkage();
if (Local)
I->setVisibility(GlobalValue::HiddenVisibility);
I->setLinkage(GlobalValue::ExternalLinkage);
if (Local || Delete)
I->setLinkage(GlobalValue::ExternalLinkage);
if (Delete)
I->deleteBody();
}
// Visit the Aliases.
@ -85,9 +97,10 @@ namespace {
Module::alias_iterator CurI = I;
++I;
if (CurI->hasLocalLinkage())
if (CurI->hasLocalLinkage()) {
CurI->setVisibility(GlobalValue::HiddenVisibility);
CurI->setLinkage(GlobalValue::ExternalLinkage);
CurI->setLinkage(GlobalValue::ExternalLinkage);
}
if (deleteStuff == (bool)Named.count(CurI)) {
Type *Ty = CurI->getType()->getElementType();

View File

@ -0,0 +1,23 @@
; RUN: llvm-extract -func foo -S < %s | FileCheck %s
; RUN: llvm-extract -delete -func foo -S < %s | FileCheck --check-prefix=DELETE %s
; Test that we don't convert weak_odr to external definitions.
; CHECK: @bar = external global i32
; CHECK: define weak_odr i32* @foo() {
; CHECK-NEXT: ret i32* @bar
; CHECK-NEXT: }
; DELETE: @bar = weak_odr global i32 42
; DELETE: declare i32* @foo()
@bar = weak_odr global i32 42
define weak_odr i32* @foo() {
ret i32* @bar
}
define void @g() {
%c = call i32* @foo()
ret void
}

View File

@ -7,18 +7,19 @@
; llvm-extract uses lazy bitcode loading, so make sure it correctly reads
; from bitcode files in addition to assembly files.
; CHECK: define void @foo() {
; CHECK: define hidden void @foo() {
; CHECK: ret void
; CHECK: }
; The linkonce_odr linkage for foo() should be changed to external linkage.
; DELETE: declare void @foo()
; The private linkage for foo() should be changed to external linkage and
; hidden visibility added.
; DELETE: declare hidden void @foo()
; DELETE: define void @bar() {
; DELETE: call void @foo()
; DELETE: ret void
; DELETE: }
define linkonce_odr void @foo() {
define private void @foo() {
ret void
}
define void @bar() {