mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 10:42:39 +01:00
[Internalize] Preserve variables externally initialized.
- ``externally_initialized`` variables would be initialized or modified elsewhere. Particularly, CUDA or HIP may have host code to initialize or modify ``externally_initialized`` device variables, which may not be explicitly referenced on the device side but may still be used through the host side interfaces. Not preserving them triggers the elimination of them in the GlobalDCE and breaks the user code. Reviewed By: yaxunl Differential Revision: https://reviews.llvm.org/D105135
This commit is contained in:
parent
9296dfb97c
commit
36ed673592
@ -101,6 +101,12 @@ bool InternalizePass::shouldPreserveGV(const GlobalValue &GV) {
|
||||
if (GV.hasDLLExportStorageClass())
|
||||
return true;
|
||||
|
||||
// As the name suggests, externally initialized variables need preserving as
|
||||
// they would be initialized elsewhere externally.
|
||||
if (const auto *G = dyn_cast<GlobalVariable>(&GV))
|
||||
if (G->isExternallyInitialized())
|
||||
return true;
|
||||
|
||||
// Already local, has nothing to do.
|
||||
if (GV.hasLocalLinkage())
|
||||
return false;
|
||||
|
7
test/Transforms/Internalize/externally-initialized.ll
Normal file
7
test/Transforms/Internalize/externally-initialized.ll
Normal file
@ -0,0 +1,7 @@
|
||||
; RUN: opt < %s -internalize -S | FileCheck %s
|
||||
; RUN: opt < %s -passes=internalize -S | FileCheck %s
|
||||
|
||||
; CHECK: @G0
|
||||
; CHECK-NOT: internal
|
||||
; CHECK-SAME: global i32
|
||||
@G0 = protected externally_initialized global i32 0, align 4
|
Loading…
Reference in New Issue
Block a user