Skip to content

Commit 1fe7309

Browse files
committed
convert external globals with no usage to internal linkage to be removed by globaldce, fix tests
1 parent 245854b commit 1fe7309

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ using namespace llvm;
2020
static bool finalizeLinkage(Module &M) {
2121
bool MadeChange = false;
2222

23-
// Convert private global variables to internal linkage.
24-
for (GlobalVariable &GV : M.globals()) {
25-
if (GV.hasPrivateLinkage()) {
23+
// Convert private globals and external globals with no usage to internal
24+
// linkage.
25+
for (GlobalVariable &GV : M.globals())
26+
if (GV.hasPrivateLinkage() || (GV.hasExternalLinkage() && GV.use_empty())) {
2627
GV.setLinkage(GlobalValue::InternalLinkage);
2728
MadeChange = true;
2829
}
29-
}
3030

3131
SmallVector<Function *> Funcs;
3232

llvm/test/CodeGen/DirectX/finalize_linkage.ll

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
target triple = "dxilv1.5-pc-shadermodel6.5-compute"
55

66
; DXILFinalizeLinkage changes linkage of all functions that are hidden to
7-
; internal, and converts private global variables to internal linkage.
7+
; internal, converts private global variables to internal linkage, and removes
8+
; unused global variables.
9+
10+
; CHECK-NOT: @aTile
11+
@aTile = hidden addrspace(3) global [4 x [1 x i32]] zeroinitializer, align 4
12+
13+
; CHECK-NOT: @bTile
14+
@bTile = hidden addrspace(3) global [1 x <1 x i32>] zeroinitializer, align 4
815

916
; CHECK: @switch.table = internal unnamed_addr constant [4 x i32]
1017
@switch.table = private unnamed_addr constant [4 x i32] [i32 1, i32 257, i32 65793, i32 16843009], align 4
@@ -27,6 +34,17 @@ target triple = "dxilv1.5-pc-shadermodel6.5-compute"
2734
; CHECK: @hidden_var = hidden global i32
2835
@hidden_var = hidden global i32 1, align 4
2936

37+
define void @anchor_function() #0 {
38+
entry:
39+
%0 = load i32, ptr @switch.table, align 4
40+
%1 = load [3 x float], ptr @private_array, align 4
41+
%2 = load i32, ptr @private_var, align 4
42+
%3 = load i32, ptr @internal_var, align 4
43+
%4 = load i32, ptr @external_var, align 4
44+
%5 = load i32, ptr @hidden_var, align 4
45+
ret void
46+
}
47+
3048
; CHECK-NOT: define internal void @"?f1@@YAXXZ"()
3149
define void @"?f1@@YAXXZ"() #0 {
3250
entry:

llvm/test/CodeGen/DirectX/scalar-data.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llc %s -mtriple=dxil-pc-shadermodel6.3-library --filetype=asm -o - | FileCheck %s
1+
; RUN: opt -S -passes='dxil-data-scalarization,dxil-flatten-arrays' -mtriple=dxil-unknown-shadermodel6.5-compute %s | FileCheck %s
22

33
; Make sure we don't touch arrays without vectors and that can recurse and flatten multiple-dimension arrays of vectors
44

llvm/test/tools/dxil-dis/opaque-value_as_metadata.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ target triple = "dxil-unknown-shadermodel6.7-library"
77
@CBV = external constant %"$Globals"
88

99
define void @main() #0 {
10+
%1 = load float, ptr @CBV, align 4
1011
ret void
1112
}
1213

0 commit comments

Comments
 (0)