aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/IPO/ConstantMerge.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Transforms/IPO/ConstantMerge.cpp')
-rw-r--r--lib/Transforms/IPO/ConstantMerge.cpp29
1 files changed, 15 insertions, 14 deletions
diff --git a/lib/Transforms/IPO/ConstantMerge.cpp b/lib/Transforms/IPO/ConstantMerge.cpp
index 81f3634eaf28..ad877ae1786c 100644
--- a/lib/Transforms/IPO/ConstantMerge.cpp
+++ b/lib/Transforms/IPO/ConstantMerge.cpp
@@ -1,9 +1,8 @@
//===- ConstantMerge.cpp - Merge duplicate global constants ---------------===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
@@ -91,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())
@@ -155,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
@@ -197,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.