diff options
| author | Vedant Kumar <vsk@apple.com> | 2019-01-20 02:44:43 +0000 |
|---|---|---|
| committer | Vedant Kumar <vsk@apple.com> | 2019-01-20 02:44:43 +0000 |
| commit | 857cacd9de0a35e04fd248ed208bd3910d85530a (patch) | |
| tree | d108beeb8c17f89368a9f3088d49d0dfa1ac3bcb | |
| parent | 85bdbbf9a12a17a128eadb90644389a276e4e433 (diff) | |
| download | llvm-857cacd9de0a35e04fd248ed208bd3910d85530a.zip llvm-857cacd9de0a35e04fd248ed208bd3910d85530a.tar.gz llvm-857cacd9de0a35e04fd248ed208bd3910d85530a.tar.bz2 | |
[ConstantMerge] Factor out check for un-mergeable globals, NFC
llvm-svn: 351671
| -rw-r--r-- | llvm/lib/Transforms/IPO/ConstantMerge.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/IPO/ConstantMerge.cpp b/llvm/lib/Transforms/IPO/ConstantMerge.cpp index 0933bc5..ad877ae 100644 --- a/llvm/lib/Transforms/IPO/ConstantMerge.cpp +++ b/llvm/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<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. |
