[llvm] r256281 - Also add unnamed_addr to functions.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 22 12:43:31 PST 2015
Author: rafael
Date: Tue Dec 22 14:43:30 2015
New Revision: 256281
URL: http://llvm.org/viewvc/llvm-project?rev=256281&view=rev
Log:
Also add unnamed_addr to functions.
Modified:
llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
llvm/trunk/test/Transforms/GlobalOpt/unnamed-addr.ll
Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=256281&r1=256280&r2=256281&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Tue Dec 22 14:43:30 2015
@@ -83,7 +83,7 @@ namespace {
bool OptimizeGlobalVars(Module &M);
bool OptimizeGlobalAliases(Module &M);
bool deleteIfDead(GlobalValue &GV);
- bool processGlobal(GlobalVariable *GV);
+ bool processGlobal(GlobalValue &GV);
bool processInternalGlobal(GlobalVariable *GV, const GlobalStatus &GS);
bool OptimizeEmptyGlobalCXXDtors(Function *CXAAtExitFn);
@@ -1705,28 +1705,31 @@ bool GlobalOpt::deleteIfDead(GlobalValue
/// Analyze the specified global variable and optimize it if possible. If we
/// make a change, return true.
-bool GlobalOpt::processGlobal(GlobalVariable *GV) {
- if (deleteIfDead(*GV))
- return true;
-
+bool GlobalOpt::processGlobal(GlobalValue &GV) {
// Do more involved optimizations if the global is internal.
- if (!GV->hasLocalLinkage())
+ if (!GV.hasLocalLinkage())
return false;
GlobalStatus GS;
- if (GlobalStatus::analyzeGlobal(GV, GS))
+ if (GlobalStatus::analyzeGlobal(&GV, GS))
return false;
- if (!GS.IsCompared && !GV->hasUnnamedAddr()) {
- GV->setUnnamedAddr(true);
+ bool Changed = false;
+ if (!GS.IsCompared && !GV.hasUnnamedAddr()) {
+ GV.setUnnamedAddr(true);
NumUnnamed++;
+ Changed = true;
}
- if (GV->isConstant() || !GV->hasInitializer())
- return false;
+ auto *GVar = dyn_cast<GlobalVariable>(&GV);
+ if (!GVar)
+ return Changed;
+
+ if (GVar->isConstant() || !GVar->hasInitializer())
+ return Changed;
- return processInternalGlobal(GV, GS);
+ return processInternalGlobal(GVar, GS) || Changed;
}
bool GlobalOpt::isPointerValueDeadOnEntryToFunction(const Function *F, GlobalValue *GV) {
@@ -2044,6 +2047,9 @@ bool GlobalOpt::OptimizeFunctions(Module
Changed = true;
continue;
}
+
+ Changed |= processGlobal(*F);
+
if (!F->hasLocalLinkage())
continue;
if (isProfitableToMakeFastCC(F) && !F->isVarArg() &&
@@ -2087,7 +2093,12 @@ bool GlobalOpt::OptimizeGlobalVars(Modul
GV->setInitializer(New);
}
- Changed |= processGlobal(GV);
+ if (deleteIfDead(*GV)) {
+ Changed = true;
+ continue;
+ }
+
+ Changed |= processGlobal(*GV);
}
return Changed;
}
Modified: llvm/trunk/test/Transforms/GlobalOpt/unnamed-addr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/unnamed-addr.ll?rev=256281&r1=256280&r2=256281&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GlobalOpt/unnamed-addr.ll (original)
+++ llvm/trunk/test/Transforms/GlobalOpt/unnamed-addr.ll Tue Dec 22 14:43:30 2015
@@ -12,7 +12,13 @@
; CHECK: @d = internal unnamed_addr constant [4 x i8] c"foo\00", align 1
; CHECK: @e = linkonce_odr global i32 0
+; CHECK: define internal fastcc void @used_internal() unnamed_addr {
+define internal void @used_internal() {
+ ret void
+}
+
define i32 @get_e() {
+ call void @used_internal()
%t = load i32, i32* @e
ret i32 %t
}
More information about the llvm-commits
mailing list