blob: 02404062163deb5eac5237b2439eb62b287a8329 [file] [log] [blame]
Teresa Johnsona0811452016-11-10 16:57:32 +00001; Test to ensure that uses and defs in module level asm are handled
2; appropriately. Specifically, we should conservatively block importing
3; of any references to these values, as they can't be renamed.
4; RUN: opt -module-summary %s -o %t1.bc
5; RUN: opt -module-summary %p/Inputs/module_asm2.ll -o %t2.bc
6
Teresa Johnsone0ee5cf2016-12-27 17:45:09 +00007; RUN: llvm-lto -thinlto-action=run -exported-symbol=main -exported-symbol=func1 -exported-symbol=func2 -exported-symbol=func3 -exported-symbol=callglobalfunc -exported-symbol=callweakfunc %t1.bc %t2.bc
8; RUN: llvm-nm %t1.bc.thinlto.o | FileCheck %s --check-prefix=NM0
9; RUN: llvm-nm %t2.bc.thinlto.o | FileCheck %s --check-prefix=NM1
Teresa Johnsona0811452016-11-10 16:57:32 +000010
11; RUN: llvm-lto2 %t1.bc %t2.bc -o %t.o -save-temps \
12; RUN: -r=%t1.bc,foo,plx \
Teresa Johnsone0ee5cf2016-12-27 17:45:09 +000013; RUN: -r=%t1.bc,globalfunc,plx \
14; RUN: -r=%t1.bc,globalfunc,plx \
15; RUN: -r=%t1.bc,weakfunc,plx \
16; RUN: -r=%t1.bc,weakfunc,plx \
Teresa Johnsona0811452016-11-10 16:57:32 +000017; RUN: -r=%t1.bc,b,pl \
18; RUN: -r=%t1.bc,x,pl \
19; RUN: -r=%t1.bc,func1,pl \
20; RUN: -r=%t1.bc,func2,pl \
21; RUN: -r=%t1.bc,func3,pl \
Teresa Johnsone0ee5cf2016-12-27 17:45:09 +000022; RUN: -r=%t1.bc,callglobalfunc,plx \
23; RUN: -r=%t1.bc,callweakfunc,plx \
Teresa Johnsona0811452016-11-10 16:57:32 +000024; RUN: -r=%t2.bc,main,plx \
25; RUN: -r=%t2.bc,func1,l \
26; RUN: -r=%t2.bc,func2,l \
Teresa Johnsone0ee5cf2016-12-27 17:45:09 +000027; RUN: -r=%t2.bc,func3,l \
28; RUN: -r=%t2.bc,callglobalfunc,l \
29; RUN: -r=%t2.bc,callweakfunc,l
Teresa Johnsona0811452016-11-10 16:57:32 +000030; RUN: llvm-nm %t.o.0 | FileCheck %s --check-prefix=NM0
31; RUN: llvm-nm %t.o.1 | FileCheck %s --check-prefix=NM1
32
33; Check that local values b and x, which are referenced on
34; llvm.used and llvm.compiler.used, respectively, are not promoted.
35; Similarly, foo which is defined in module level asm should not be
Teresa Johnsone0ee5cf2016-12-27 17:45:09 +000036; promoted.
Teresa Johnsona0811452016-11-10 16:57:32 +000037; NM0-DAG: d b
38; NM0-DAG: d x
39; NM0-DAG: t foo
40; NM0-DAG: T func1
41; NM0-DAG: T func2
42; NM0-DAG: T func3
Teresa Johnsone0ee5cf2016-12-27 17:45:09 +000043; NM0-DAG: T callglobalfunc
44; NM0-DAG: T callweakfunc
45; NM0-DAG: T globalfunc
46; NM0-DAG: W weakfunc
Teresa Johnsona0811452016-11-10 16:57:32 +000047
Teresa Johnson3624bdf2016-11-14 17:12:32 +000048; Ensure that foo, b and x are likewise not exported (imported as refs
Teresa Johnsona0811452016-11-10 16:57:32 +000049; into the other module), since they can't be promoted. Additionally,
50; referencing functions func2 and func3 should not have been
Teresa Johnsone0ee5cf2016-12-27 17:45:09 +000051; imported. However, we should have been able to import callglobalfunc
52; and callweakfunc (leaving undefined symbols globalfunc and weakfunc)
53; since globalfunc and weakfunc were defined but not local in module asm.
Teresa Johnson3624bdf2016-11-14 17:12:32 +000054; NM1-NOT: foo
Teresa Johnsona0811452016-11-10 16:57:32 +000055; NM1-NOT: b
56; NM1-NOT: x
Teresa Johnson3624bdf2016-11-14 17:12:32 +000057; NM1-DAG: U func1
Teresa Johnsona0811452016-11-10 16:57:32 +000058; NM1-DAG: U func2
59; NM1-DAG: U func3
Teresa Johnsone0ee5cf2016-12-27 17:45:09 +000060; NM1-DAG: U globalfunc
61; NM1-DAG: U weakfunc
Teresa Johnsona0811452016-11-10 16:57:32 +000062; NM1-DAG: T main
Teresa Johnson3624bdf2016-11-14 17:12:32 +000063; NM1-NOT: foo
Teresa Johnsona0811452016-11-10 16:57:32 +000064; NM1-NOT: b
65; NM1-NOT: x
66
67target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
68target triple = "x86_64-unknown-linux-gnu"
69
70@b = internal global i32 1, align 4
71@x = internal global i32 1, align 4
72
73@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32* @b to i8*)], section "llvm.metadata"
74@llvm.used = appending global [1 x i8*] [i8* bitcast (i32* @x to i8*)], section "llvm.metadata"
75
76module asm "\09.text"
77module asm "\09.type\09foo,@function"
78module asm "foo:"
79module asm "\09movl b, %eax"
80module asm "\09movl x, %edx"
81module asm "\09ret "
82module asm "\09.size\09foo, .-foo"
83module asm ""
Teresa Johnsone0ee5cf2016-12-27 17:45:09 +000084module asm "\09.globl\09globalfunc"
85module asm "\09.type\09globalfunc,@function"
86module asm "globalfunc:"
87module asm "\09movl b, %eax"
88module asm "\09movl x, %edx"
89module asm "\09ret "
90module asm "\09.size\09globalfunc, .-globalfunc"
91module asm ""
92module asm "\09.weak\09weakfunc"
93module asm "\09.type\09weakfunc,@function"
94module asm "weakfunc:"
95module asm "\09movl b, %eax"
96module asm "\09movl x, %edx"
97module asm "\09ret "
98module asm "\09.size\09weakfunc, .-weakfunc"
99module asm ""
Teresa Johnsona0811452016-11-10 16:57:32 +0000100
101declare i16 @foo() #0
Teresa Johnsone0ee5cf2016-12-27 17:45:09 +0000102declare i16 @globalfunc() #0
103declare i16 @weakfunc() #0
Teresa Johnsona0811452016-11-10 16:57:32 +0000104
105define i32 @func1() #1 {
106 call i16 @foo()
107 ret i32 1
108}
109
110define i32 @func2() #1 {
111 %1 = load i32, i32* @b, align 4
112 ret i32 %1
113}
114
115define i32 @func3() #1 {
116 %1 = load i32, i32* @x, align 4
117 ret i32 %1
118}
Teresa Johnsone0ee5cf2016-12-27 17:45:09 +0000119
120define i32 @callglobalfunc() #1 {
121 call i16 @globalfunc()
122 ret i32 1
123}
124
125define i32 @callweakfunc() #1 {
126 call i16 @weakfunc()
127 ret i32 1
128}