summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/GlobalMerge.cpp
diff options
context:
space:
mode:
authorJohn Brawn <john.brawn@arm.com>2015-08-03 12:08:41 +0000
committerJohn Brawn <john.brawn@arm.com>2015-08-03 12:08:41 +0000
commit8b954241f85b8383fb8725b0a1108c55f31f14e9 (patch)
treea27e54ea62c24559bf9f60fd841ecab82aa4f926 /llvm/lib/CodeGen/GlobalMerge.cpp
parentcd86c9791c73e663993a965b628c92a11b43460e (diff)
downloadbcm5719-llvm-8b954241f85b8383fb8725b0a1108c55f31f14e9.tar.gz
bcm5719-llvm-8b954241f85b8383fb8725b0a1108c55f31f14e9.zip
[GlobalMerge] Allow targets to enable merging of extern variables, NFC.
Adjust the GlobalMergeOnExternal option so that the default behaviour is to do whatever the Target thinks is best. Explicitly enabled or disabling the option will override this default. Differential Revision: http://reviews.llvm.org/D10965 llvm-svn: 243873
Diffstat (limited to 'llvm/lib/CodeGen/GlobalMerge.cpp')
-rw-r--r--llvm/lib/CodeGen/GlobalMerge.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp
index 6f9e8394081..04c97f6796c 100644
--- a/llvm/lib/CodeGen/GlobalMerge.cpp
+++ b/llvm/lib/CodeGen/GlobalMerge.cpp
@@ -108,10 +108,9 @@ EnableGlobalMergeOnConst("global-merge-on-const", cl::Hidden,
// FIXME: this could be a transitional option, and we probably need to remove
// it if only we are sure this optimization could always benefit all targets.
-static cl::opt<bool>
+static cl::opt<cl::boolOrDefault>
EnableGlobalMergeOnExternal("global-merge-on-external", cl::Hidden,
- cl::desc("Enable global merge pass on external linkage"),
- cl::init(false));
+ cl::desc("Enable global merge pass on external linkage"));
STATISTIC(NumMerged, "Number of globals merged");
namespace {
@@ -129,6 +128,9 @@ namespace {
/// FIXME: This could learn about optsize, and be used in the cost model.
bool OnlyOptimizeForSize;
+ /// Whether we should merge global variables that have external linkage.
+ bool MergeExternalGlobals;
+
bool doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
Module &M, bool isConst, unsigned AddrSpace) const;
/// \brief Merge everything in \p Globals for which the corresponding bit
@@ -158,9 +160,11 @@ namespace {
static char ID; // Pass identification, replacement for typeid.
explicit GlobalMerge(const TargetMachine *TM = nullptr,
unsigned MaximalOffset = 0,
- bool OnlyOptimizeForSize = false)
+ bool OnlyOptimizeForSize = false,
+ bool MergeExternalGlobals = false)
: FunctionPass(ID), TM(TM), MaxOffset(MaximalOffset),
- OnlyOptimizeForSize(OnlyOptimizeForSize) {
+ OnlyOptimizeForSize(OnlyOptimizeForSize),
+ MergeExternalGlobals(MergeExternalGlobals) {
initializeGlobalMergePass(*PassRegistry::getPassRegistry());
}
@@ -541,7 +545,7 @@ bool GlobalMerge::doInitialization(Module &M) {
if (I->isDeclaration() || I->isThreadLocal() || I->hasSection())
continue;
- if (!(EnableGlobalMergeOnExternal && I->hasExternalLinkage()) &&
+ if (!(MergeExternalGlobals && I->hasExternalLinkage()) &&
!I->hasInternalLinkage())
continue;
@@ -604,6 +608,9 @@ bool GlobalMerge::doFinalization(Module &M) {
}
Pass *llvm::createGlobalMergePass(const TargetMachine *TM, unsigned Offset,
- bool OnlyOptimizeForSize) {
- return new GlobalMerge(TM, Offset, OnlyOptimizeForSize);
+ bool OnlyOptimizeForSize,
+ bool MergeExternalByDefault) {
+ bool MergeExternal = (EnableGlobalMergeOnExternal == cl::BOU_UNSET) ?
+ MergeExternalByDefault : (EnableGlobalMergeOnExternal == cl::BOU_TRUE);
+ return new GlobalMerge(TM, Offset, OnlyOptimizeForSize, MergeExternal);
}
OpenPOWER on IntegriCloud