[llvm] r324937 - [GlobalMerge] Allow merging of dllexported variables
Martin Storsjo via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 12 13:14:22 PST 2018
Author: mstorsjo
Date: Mon Feb 12 13:14:21 2018
New Revision: 324937
URL: http://llvm.org/viewvc/llvm-project?rev=324937&view=rev
Log:
[GlobalMerge] Allow merging of dllexported variables
If merging them, the dllexport attribute needs to be brought along
to the new GlobalAlias.
Differential Revision: https://reviews.llvm.org/D43192
Modified:
llvm/trunk/lib/CodeGen/GlobalMerge.cpp
llvm/trunk/test/CodeGen/ARM/global-merge-dllexport.ll
Modified: llvm/trunk/lib/CodeGen/GlobalMerge.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalMerge.cpp?rev=324937&r1=324936&r2=324937&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalMerge.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalMerge.cpp Mon Feb 12 13:14:21 2018
@@ -497,6 +497,8 @@ bool GlobalMerge::doMerge(const SmallVec
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 @@ bool GlobalMerge::doMerge(const SmallVec
// 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 @@ bool GlobalMerge::doInitialization(Modul
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
Modified: llvm/trunk/test/CodeGen/ARM/global-merge-dllexport.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/global-merge-dllexport.ll?rev=324937&r1=324936&r2=324937&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/global-merge-dllexport.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/global-merge-dllexport.ll Mon Feb 12 13:14:21 2018
@@ -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"
More information about the llvm-commits
mailing list