From 237c3a6defd13a6af8ffcb786fc1f02fcc3483ea Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 13 Jul 2015 14:18:22 +0000 Subject: [PATCH] Don't change the visibility when converting a definition to a declaration. llvm-svn: 242030 --- llvm/include/llvm/LinkAllPasses.h | 1 + llvm/lib/Transforms/IPO/ElimAvailExtern.cpp | 3 --- llvm/lib/Transforms/IPO/IPO.cpp | 1 + .../EliminateAvailableExternally/visibility.ll | 11 +++++++++++ 4 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 llvm/test/Transforms/EliminateAvailableExternally/visibility.ll diff --git a/llvm/include/llvm/LinkAllPasses.h b/llvm/include/llvm/LinkAllPasses.h index 8ac1b212ae5f..cea5530db3b8 100644 --- a/llvm/include/llvm/LinkAllPasses.h +++ b/llvm/include/llvm/LinkAllPasses.h @@ -176,6 +176,7 @@ namespace { (void) llvm::createStraightLineStrengthReducePass(); (void) llvm::createMemDerefPrinter(); (void) llvm::createFloat2IntPass(); + (void) llvm::createEliminateAvailableExternallyPass(); (void)new llvm::IntervalPartition(); (void)new llvm::ScalarEvolution(); diff --git a/llvm/lib/Transforms/IPO/ElimAvailExtern.cpp b/llvm/lib/Transforms/IPO/ElimAvailExtern.cpp index 1566e85e99bc..e70ab871b88d 100644 --- a/llvm/lib/Transforms/IPO/ElimAvailExtern.cpp +++ b/llvm/lib/Transforms/IPO/ElimAvailExtern.cpp @@ -67,7 +67,6 @@ bool EliminateAvailableExternally::runOnModule(Module &M) { } I->removeDeadConstantUsers(); I->setLinkage(GlobalValue::ExternalLinkage); - I->setVisibility(GlobalValue::DefaultVisibility); NumVariables++; } @@ -78,7 +77,6 @@ bool EliminateAvailableExternally::runOnModule(Module &M) { if (!I->isDeclaration()) // This will set the linkage to external I->deleteBody(); - I->setVisibility(GlobalValue::DefaultVisibility); I->removeDeadConstantUsers(); NumFunctions++; } @@ -91,7 +89,6 @@ bool EliminateAvailableExternally::runOnModule(Module &M) { I->setAliasee(nullptr); I->removeDeadConstantUsers(); I->setLinkage(GlobalValue::ExternalLinkage); - I->setVisibility(GlobalValue::DefaultVisibility); NumAliases++; } diff --git a/llvm/lib/Transforms/IPO/IPO.cpp b/llvm/lib/Transforms/IPO/IPO.cpp index fcacec3286fa..50f56b0f2afe 100644 --- a/llvm/lib/Transforms/IPO/IPO.cpp +++ b/llvm/lib/Transforms/IPO/IPO.cpp @@ -46,6 +46,7 @@ void llvm::initializeIPO(PassRegistry &Registry) { initializeStripDeadDebugInfoPass(Registry); initializeStripNonDebugSymbolsPass(Registry); initializeBarrierNoopPass(Registry); + initializeEliminateAvailableExternallyPass(Registry); } void LLVMInitializeIPO(LLVMPassRegistryRef R) { diff --git a/llvm/test/Transforms/EliminateAvailableExternally/visibility.ll b/llvm/test/Transforms/EliminateAvailableExternally/visibility.ll new file mode 100644 index 000000000000..9966fcf30e85 --- /dev/null +++ b/llvm/test/Transforms/EliminateAvailableExternally/visibility.ll @@ -0,0 +1,11 @@ +; RUN: opt -elim-avail-extern -S < %s | FileCheck %s + +; CHECK: declare hidden void @f() +define available_externally hidden void @f() { + ret void +} + +define void @g() { + call void @f() + ret void +}