[PATCH] D43192: [GlobalMerge] Allow merging of dllexported variables

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 12 07:05:49 PST 2018


mstorsjo created this revision.
mstorsjo added reviewers: compnerd, john.brawn, rnk, smeenai.
Herald added a subscriber: javed.absar.

If merging them, the dllexport attribute needs to be brought along to the new GlobalAlias.

This is a follow-up to https://reviews.llvm.org/D42127 (which just turned off merging of dllexported variables). Handling it properly turned out to be very straightforward after all. I hadn't noticed before that GlobalAlias handily was a GlobalValue subclass - otherwise this would have end up as a much larger change.


Repository:
  rL LLVM

https://reviews.llvm.org/D43192

Files:
  lib/CodeGen/GlobalMerge.cpp
  test/CodeGen/ARM/global-merge-dllexport.ll


Index: test/CodeGen/ARM/global-merge-dllexport.ll
===================================================================
--- test/CodeGen/ARM/global-merge-dllexport.ll
+++ test/CodeGen/ARM/global-merge-dllexport.ll
@@ -5,11 +5,17 @@
 
 define void @f1(i32 %a1, i32 %a2) {
 ; CHECK: f1:
-; CHECK: movw [[REG1:r[0-9]+]], :lower16:x
-; CHECK: movt [[REG1]], :upper16:x
+; CHECK: movw [[REG1:r[0-9]+]], :lower16:.L_MergedGlobals
+; CHECK: movt [[REG1]], :upper16:.L_MergedGlobals
   store i32 %a1, i32* @x, align 4
   store i32 %a2, i32* @y, align 4
   ret void
 }
 
-; CHECK-NOT: .L_MergedGlobals
+; CHECK: .lcomm .L_MergedGlobals,8,4
+; CHECK: .globl x
+; CHECK: x = .L_MergedGlobals
+; CHECK: .globl y
+; CHECK: y = .L_MergedGlobals+4
+; CHECK: .section .drectve,"yn"
+; CHECK: .ascii " /EXPORT:y,DATA"
Index: lib/CodeGen/GlobalMerge.cpp
===================================================================
--- lib/CodeGen/GlobalMerge.cpp
+++ lib/CodeGen/GlobalMerge.cpp
@@ -497,6 +497,8 @@
     for (ssize_t k = i, idx = 0; k != j; k = GlobalSet.find_next(k), ++idx) {
       GlobalValue::LinkageTypes Linkage = Globals[k]->getLinkage();
       std::string Name = Globals[k]->getName();
+      GlobalValue::DLLStorageClassTypes DLLStorage =
+          Globals[k]->getDLLStorageClass();
 
       // Copy metadata while adjusting any debug info metadata by the original
       // global's offset within the merged global.
@@ -517,7 +519,9 @@
       // It's not safe on Mach-O as the alias (and thus the portion of the
       // MergedGlobals variable) may be dead stripped at link time.
       if (Linkage != GlobalValue::InternalLinkage || !IsMachO) {
-        GlobalAlias::create(Tys[idx], AddrSpace, Linkage, Name, GEP, &M);
+        GlobalAlias *GA =
+            GlobalAlias::create(Tys[idx], AddrSpace, Linkage, Name, GEP, &M);
+        GA->setDLLStorageClass(DLLStorage);
       }
 
       NumMerged++;
@@ -577,8 +581,7 @@
   for (auto &GV : M.globals()) {
     // Merge is safe for "normal" internal or external globals only
     if (GV.isDeclaration() || GV.isThreadLocal() ||
-        GV.hasSection() || GV.hasImplicitSection() ||
-        GV.hasDLLExportStorageClass())
+        GV.hasSection() || GV.hasImplicitSection())
       continue;
 
     // It's not safe to merge globals that may be preempted


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43192.133856.patch
Type: text/x-patch
Size: 2308 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180212/42b076fc/attachment.bin>


More information about the llvm-commits mailing list