1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

[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

llvm-svn: 324937
This commit is contained in:
Martin Storsjo 2018-02-12 21:14:21 +00:00
parent d52f3268e8
commit 546bc69235
2 changed files with 15 additions and 6 deletions

View File

@ -497,6 +497,8 @@ bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals,
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 SmallVectorImpl<GlobalVariable *> &Globals,
// 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(Module &M) {
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

View File

@ -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"