1
0
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:
Michael Liao 2021-06-29 11:03:52 -04:00
parent 9296dfb97c
commit 36ed673592
2 changed files with 13 additions and 0 deletions

View File

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

View 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