From: David Majnemer Date: Tue, 1 Jul 2014 15:26:50 +0000 (+0000) Subject: GlobalOpt: Don't swap private for internal linkage X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5c92115972dd7f831f1994bb8e0e347cd80559a1;p=platform%2Fupstream%2Fllvm.git GlobalOpt: Don't swap private for internal linkage There were transforms whose *intent* was to downgrade the linkage of external objects to have internal linkage. However, it fired on things with private linkage as well. llvm-svn: 212104 --- diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index 63a6058..c1d0d3b 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -1908,7 +1908,7 @@ bool GlobalOpt::OptimizeFunctions(Module &M) { for (Module::iterator FI = M.begin(), E = M.end(); FI != E; ) { Function *F = FI++; // Functions without names cannot be referenced outside this module. - if (!F->hasName() && !F->isDeclaration()) + if (!F->hasName() && !F->isDeclaration() && !F->hasLocalLinkage()) F->setLinkage(GlobalValue::InternalLinkage); F->removeDeadConstantUsers(); if (F->isDefTriviallyDead()) { @@ -1953,7 +1953,7 @@ bool GlobalOpt::OptimizeGlobalVars(Module &M) { GVI != E; ) { GlobalVariable *GV = GVI++; // Global variables without names cannot be referenced outside this module. - if (!GV->hasName() && !GV->isDeclaration()) + if (!GV->hasName() && !GV->isDeclaration() && !GV->hasLocalLinkage()) GV->setLinkage(GlobalValue::InternalLinkage); // Simplify the initializer. if (GV->hasInitializer()) @@ -2858,7 +2858,7 @@ bool GlobalOpt::OptimizeGlobalAliases(Module &M) { I != E;) { Module::alias_iterator J = I++; // Aliases without names cannot be referenced outside this module. - if (!J->hasName() && !J->isDeclaration()) + if (!J->hasName() && !J->isDeclaration() && !J->hasLocalLinkage()) J->setLinkage(GlobalValue::InternalLinkage); // If the aliasee may change at link time, nothing can be done - bail out. if (J->mayBeOverridden()) diff --git a/llvm/test/Transforms/GlobalOpt/2009-03-06-Anonymous.ll b/llvm/test/Transforms/GlobalOpt/2009-03-06-Anonymous.ll index db2673a..930a96e 100644 --- a/llvm/test/Transforms/GlobalOpt/2009-03-06-Anonymous.ll +++ b/llvm/test/Transforms/GlobalOpt/2009-03-06-Anonymous.ll @@ -1,13 +1,23 @@ ; RUN: opt < %s -globalopt -S | FileCheck %s global i32 0 -; CHECK: @0 = internal global i32 0 -define i32* @1() { +; CHECK-DAG: @0 = internal global i32 0 + +private global i32 0 +; CHECK-DAG: @1 = private global i32 0 + +define i32* @2() { ret i32* @0 } -; CHECK: define internal fastcc i32* @1() +; CHECK-DAG: define internal fastcc i32* @2() + define i32* @f() { entry: - call i32* @1() + call i32* @2() ret i32* %0 } + +define i32* @g() { +entry: + ret i32* @1 +}