[PATCH] [CodeGen] Use module flag metadata to enable global-merge.
Ahmed Bougacha
ahmed.bougacha at gmail.com
Mon Mar 2 16:13:02 PST 2015
- Match http://reviews.llvm.org/D7968 changes (i32, "Global Merge")
http://reviews.llvm.org/D7969
Files:
lib/CodeGen/GlobalMerge.cpp
test/CodeGen/AArch64/global-merge-moduleflag-disabled.ll
test/CodeGen/AArch64/global-merge-moduleflag-enabled.ll
Index: lib/CodeGen/GlobalMerge.cpp
===================================================================
--- lib/CodeGen/GlobalMerge.cpp
+++ lib/CodeGen/GlobalMerge.cpp
@@ -73,10 +73,10 @@
#define DEBUG_TYPE "global-merge"
-static cl::opt<bool>
+static cl::opt<cl::boolOrDefault>
EnableGlobalMerge("enable-global-merge", cl::Hidden,
cl::desc("Enable global merge pass"),
- cl::init(true));
+ cl::init(cl::BOU_UNSET));
static cl::opt<bool>
EnableGlobalMergeOnConst("global-merge-on-const", cl::Hidden,
@@ -278,8 +278,25 @@
}
}
+static bool shouldEnableGlobalMergeForModule(const Module &M) {
+ Metadata *FlagMD = M.getModuleFlag("Global Merge");
+
+ // If not explicitly specified otherwise, enable the pass.
+ if (!FlagMD)
+ return true;
+
+ ConstantAsMetadata *Flag = dyn_cast<ConstantAsMetadata>(FlagMD);
+ if (!Flag || !isa<ConstantInt>(Flag->getValue()))
+ report_fatal_error("Unexpected type for \"Global Merge\" module flag "
+ "value, should be an integer constant!");
+
+ return !cast<ConstantInt>(Flag->getValue())->isZero();
+}
+
bool GlobalMerge::doInitialization(Module &M) {
- if (!EnableGlobalMerge)
+ if (EnableGlobalMerge == cl::BOU_FALSE ||
+ (EnableGlobalMerge == cl::BOU_UNSET &&
+ !shouldEnableGlobalMergeForModule(M)))
return false;
DenseMap<unsigned, SmallVector<GlobalVariable*, 16> > Globals, ConstGlobals,
Index: test/CodeGen/AArch64/global-merge-moduleflag-disabled.ll
===================================================================
--- /dev/null
+++ test/CodeGen/AArch64/global-merge-moduleflag-disabled.ll
@@ -0,0 +1,21 @@
+; RUN: llc %s -mtriple=aarch64-none-linux-gnu -o - | FileCheck %s --check-prefix=CHECK-NGM
+; RUN: llc %s -mtriple=aarch64-none-linux-gnu -enable-global-merge -o - | FileCheck %s --check-prefix=CHECK-GM
+; RUN: llc %s -mtriple=aarch64-none-linux-gnu -enable-global-merge=false -o - | FileCheck %s --check-prefix=CHECK-NGM
+
+ at m = internal global i32 0, align 4
+ at n = internal global i32 0, align 4
+
+define void @f1(i32 %a1, i32 %a2) {
+ store i32 %a1, i32* @m, align 4
+ store i32 %a2, i32* @n, align 4
+ ret void
+}
+
+!0 = !{ i32 4, !"Global Merge", i32 0 }
+!llvm.module.flags = !{ !0 }
+
+;CHECK-GM: .type _MergedGlobals, at object // @_MergedGlobals
+;CHECK-GM: .local _MergedGlobals
+;CHECK-GM: .comm _MergedGlobals,8,8
+
+;CHECK-NGM-NOT: MergedGlobals
Index: test/CodeGen/AArch64/global-merge-moduleflag-enabled.ll
===================================================================
--- /dev/null
+++ test/CodeGen/AArch64/global-merge-moduleflag-enabled.ll
@@ -0,0 +1,21 @@
+; RUN: llc %s -mtriple=aarch64-none-linux-gnu -o - | FileCheck %s --check-prefix=CHECK-GM
+; RUN: llc %s -mtriple=aarch64-none-linux-gnu -enable-global-merge -o - | FileCheck %s --check-prefix=CHECK-GM
+; RUN: llc %s -mtriple=aarch64-none-linux-gnu -enable-global-merge=false -o - | FileCheck %s --check-prefix=CHECK-NGM
+
+ at m = internal global i32 0, align 4
+ at n = internal global i32 0, align 4
+
+define void @f1(i32 %a1, i32 %a2) {
+ store i32 %a1, i32* @m, align 4
+ store i32 %a2, i32* @n, align 4
+ ret void
+}
+
+!0 = !{ i32 1, !"Global Merge", i32 1 }
+!llvm.module.flags = !{ !0 }
+
+;CHECK-GM: .type _MergedGlobals, at object // @_MergedGlobals
+;CHECK-GM: .local _MergedGlobals
+;CHECK-GM: .comm _MergedGlobals,8,8
+
+;CHECK-NGM-NOT: MergedGlobals
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7969.21061.patch
Type: text/x-patch
Size: 3427 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150303/e09b4a66/attachment.bin>
More information about the llvm-commits
mailing list