[llvm] r351671 - [ConstantMerge] Factor out check for un-mergeable globals, NFC
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 19 18:44:43 PST 2019
Author: vedantk
Date: Sat Jan 19 18:44:43 2019
New Revision: 351671
URL: http://llvm.org/viewvc/llvm-project?rev=351671&view=rev
Log:
[ConstantMerge] Factor out check for un-mergeable globals, NFC
Modified:
llvm/trunk/lib/Transforms/IPO/ConstantMerge.cpp
Modified: llvm/trunk/lib/Transforms/IPO/ConstantMerge.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/ConstantMerge.cpp?rev=351671&r1=351670&r2=351671&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/ConstantMerge.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/ConstantMerge.cpp Sat Jan 19 18:44:43 2019
@@ -90,6 +90,16 @@ static unsigned getAlignment(GlobalVaria
return GV->getParent()->getDataLayout().getPreferredAlignment(GV);
}
+static bool
+isUnmergeableGlobal(GlobalVariable *GV,
+ const SmallPtrSetImpl<const GlobalValue *> &UsedGlobals) {
+ // Only process constants with initializers in the default address space.
+ return !GV->isConstant() || !GV->hasDefinitiveInitializer() ||
+ GV->getType()->getAddressSpace() != 0 || GV->hasSection() ||
+ // Don't touch values marked with attribute(used).
+ UsedGlobals.count(GV);
+}
+
enum class CanMerge { No, Yes };
static CanMerge makeMergeable(GlobalVariable *Old, GlobalVariable *New) {
if (!Old->hasGlobalUnnamedAddr() && !New->hasGlobalUnnamedAddr())
@@ -154,11 +164,7 @@ static bool mergeConstants(Module &M) {
continue;
}
- // Only process constants with initializers in the default address space.
- if (!GV->isConstant() || !GV->hasDefinitiveInitializer() ||
- GV->getType()->getAddressSpace() != 0 || GV->hasSection() ||
- // Don't touch values marked with attribute(used).
- UsedGlobals.count(GV))
+ if (isUnmergeableGlobal(GV, UsedGlobals))
continue;
// This transformation is legal for weak ODR globals in the sense it
@@ -196,11 +202,7 @@ static bool mergeConstants(Module &M) {
GVI != E; ) {
GlobalVariable *GV = &*GVI++;
- // Only process constants with initializers in the default address space.
- if (!GV->isConstant() || !GV->hasDefinitiveInitializer() ||
- GV->getType()->getAddressSpace() != 0 || GV->hasSection() ||
- // Don't touch values marked with attribute(used).
- UsedGlobals.count(GV))
+ if (isUnmergeableGlobal(GV, UsedGlobals))
continue;
// We can only replace constant with local linkage.
More information about the llvm-commits
mailing list