From: Vedant Kumar Date: Sun, 20 Jan 2019 02:44:43 +0000 (+0000) Subject: [ConstantMerge] Factor out check for un-mergeable globals, NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4a94358e030887ca4bde0eec06b127c7cbe6b2b1;p=llvm [ConstantMerge] Factor out check for un-mergeable globals, NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351671 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/IPO/ConstantMerge.cpp b/lib/Transforms/IPO/ConstantMerge.cpp index 0933bc5b765..ad877ae1786 100644 --- a/lib/Transforms/IPO/ConstantMerge.cpp +++ b/lib/Transforms/IPO/ConstantMerge.cpp @@ -90,6 +90,16 @@ static unsigned getAlignment(GlobalVariable *GV) { return GV->getParent()->getDataLayout().getPreferredAlignment(GV); } +static bool +isUnmergeableGlobal(GlobalVariable *GV, + const SmallPtrSetImpl &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.