[llvm-commits] [llvm] r166908 - in /llvm/trunk: lib/Transforms/IPO/ExtractGV.cpp test/Other/extract-weak-odr.ll test/Other/extract.ll
Rafael Espindola
rafael.espindola at gmail.com
Sun Oct 28 18:59:04 PDT 2012
Author: rafael
Date: Sun Oct 28 20:59:03 2012
New Revision: 166908
URL: http://llvm.org/viewvc/llvm-project?rev=166908&view=rev
Log:
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.
Added:
llvm/trunk/test/Other/extract-weak-odr.ll
Modified:
llvm/trunk/lib/Transforms/IPO/ExtractGV.cpp
llvm/trunk/test/Other/extract.ll
Modified: llvm/trunk/lib/Transforms/IPO/ExtractGV.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/ExtractGV.cpp?rev=166908&r1=166907&r2=166908&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/ExtractGV.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/ExtractGV.cpp Sun Oct 28 20:59:03 2012
@@ -51,32 +51,44 @@
// 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 @@
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();
Added: llvm/trunk/test/Other/extract-weak-odr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/extract-weak-odr.ll?rev=166908&view=auto
==============================================================================
--- llvm/trunk/test/Other/extract-weak-odr.ll (added)
+++ llvm/trunk/test/Other/extract-weak-odr.ll Sun Oct 28 20:59:03 2012
@@ -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()
+
+ at bar = weak_odr global i32 42
+
+define weak_odr i32* @foo() {
+ ret i32* @bar
+}
+
+define void @g() {
+ %c = call i32* @foo()
+ ret void
+}
Modified: llvm/trunk/test/Other/extract.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/extract.ll?rev=166908&r1=166907&r2=166908&view=diff
==============================================================================
--- llvm/trunk/test/Other/extract.ll (original)
+++ llvm/trunk/test/Other/extract.ll Sun Oct 28 20:59:03 2012
@@ -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() {
More information about the llvm-commits
mailing list