git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256281
91177308-0d34-0410-b5e6-
96231b3b80d8
bool OptimizeGlobalVars(Module &M);
bool OptimizeGlobalAliases(Module &M);
bool deleteIfDead(GlobalValue &GV);
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);
bool processInternalGlobal(GlobalVariable *GV, const GlobalStatus &GS);
bool OptimizeEmptyGlobalCXXDtors(Function *CXAAtExitFn);
/// Analyze the specified global variable and optimize it if possible. If we
/// make a change, return true.
/// 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.
// Do more involved optimizations if the global is internal.
- if (!GV->hasLocalLinkage())
+ if (!GV.hasLocalLinkage())
return false;
GlobalStatus GS;
return false;
GlobalStatus GS;
- if (GlobalStatus::analyzeGlobal(GV, GS))
+ if (GlobalStatus::analyzeGlobal(&GV, GS))
- if (!GS.IsCompared && !GV->hasUnnamedAddr()) {
- GV->setUnnamedAddr(true);
+ bool Changed = false;
+ if (!GS.IsCompared && !GV.hasUnnamedAddr()) {
+ GV.setUnnamedAddr(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) {
}
bool GlobalOpt::isPointerValueDeadOnEntryToFunction(const Function *F, GlobalValue *GV) {
Changed = true;
continue;
}
Changed = true;
continue;
}
+
+ Changed |= processGlobal(*F);
+
if (!F->hasLocalLinkage())
continue;
if (isProfitableToMakeFastCC(F) && !F->isVarArg() &&
if (!F->hasLocalLinkage())
continue;
if (isProfitableToMakeFastCC(F) && !F->isVarArg() &&
GV->setInitializer(New);
}
GV->setInitializer(New);
}
- Changed |= processGlobal(GV);
+ if (deleteIfDead(*GV)) {
+ Changed = true;
+ continue;
+ }
+
+ Changed |= processGlobal(*GV);
; CHECK: @d = internal unnamed_addr constant [4 x i8] c"foo\00", align 1
; CHECK: @e = linkonce_odr global i32 0
; 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
+}
+
+ call void @used_internal()
%t = load i32, i32* @e
ret i32 %t
}
%t = load i32, i32* @e
ret i32 %t
}