[PATCH] D10965: [GlobalMerge] Allow targets to enable merging of extern variables, NFC.

John Brawn john.brawn at arm.com
Mon Jul 6 09:38:14 PDT 2015


john.brawn added reviewers: ab, echristo.
john.brawn added a subscriber: llvm-commits.

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.

Repository:
  rL LLVM

http://reviews.llvm.org/D10965

Files:
  include/llvm/Transforms/Scalar.h
  lib/CodeGen/GlobalMerge.cpp

Index: lib/CodeGen/GlobalMerge.cpp
===================================================================
--- lib/CodeGen/GlobalMerge.cpp
+++ lib/CodeGen/GlobalMerge.cpp
@@ -108,10 +108,9 @@
 
 // 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 {
@@ -130,6 +129,9 @@
     /// 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 GlobalMergeOnExternal;
+
     bool doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
                  Module &M, bool isConst, unsigned AddrSpace) const;
     /// \brief Merge everything in \p Globals for which the corresponding bit
@@ -159,9 +161,11 @@
     static char ID;             // Pass identification, replacement for typeid.
     explicit GlobalMerge(const TargetMachine *TM = nullptr,
                          unsigned MaximalOffset = 0,
-                         bool OnlyOptimizeForSize = false)
+                         bool OnlyOptimizeForSize = false,
+                         bool GlobalMergeOnExternal = false)
         : FunctionPass(ID), TM(TM), DL(TM->getDataLayout()),
-          MaxOffset(MaximalOffset), OnlyOptimizeForSize(OnlyOptimizeForSize) {
+          MaxOffset(MaximalOffset), OnlyOptimizeForSize(OnlyOptimizeForSize),
+          GlobalMergeOnExternal(GlobalMergeOnExternal) {
       initializeGlobalMergePass(*PassRegistry::getPassRegistry());
     }
 
@@ -538,7 +542,7 @@
     if (I->isDeclaration() || I->isThreadLocal() || I->hasSection())
       continue;
 
-    if (!(EnableGlobalMergeOnExternal && I->hasExternalLinkage()) &&
+    if (!(GlobalMergeOnExternal && I->hasExternalLinkage()) &&
         !I->hasInternalLinkage())
       continue;
 
@@ -601,6 +605,12 @@
 }
 
 Pass *llvm::createGlobalMergePass(const TargetMachine *TM, unsigned Offset,
-                                  bool OnlyOptimizeForSize) {
-  return new GlobalMerge(TM, Offset, OnlyOptimizeForSize);
+                                  bool OnlyOptimizeForSize,
+                                  bool MergeExternalByDefault) {
+  bool MergeExternal;
+  if (EnableGlobalMergeOnExternal == cl::BOU_UNSET)
+    MergeExternal = MergeExternalByDefault;
+  else
+    MergeExternal = (EnableGlobalMergeOnExternal == cl::BOU_TRUE);
+  return new GlobalMerge(TM, Offset, OnlyOptimizeForSize, MergeExternal);
 }
Index: include/llvm/Transforms/Scalar.h
===================================================================
--- include/llvm/Transforms/Scalar.h
+++ include/llvm/Transforms/Scalar.h
@@ -161,7 +161,8 @@
 // It can also be configured to focus on size optimizations only.
 //
 Pass *createGlobalMergePass(const TargetMachine *TM, unsigned MaximalOffset,
-                            bool OnlyOptimizeForSize = false);
+                            bool OnlyOptimizeForSize = false,
+                            bool MergeExternalByDefault = false);
 
 //===----------------------------------------------------------------------===//
 //


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10965.29099.patch
Type: text/x-patch
Size: 3461 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150706/dec681f7/attachment.bin>


More information about the llvm-commits mailing list