Teresa Johnson | a081145 | 2016-11-10 16:57:32 +0000 | [diff] [blame] | 1 | ; 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 Johnson | e0ee5cf | 2016-12-27 17:45:09 +0000 | [diff] [blame] | 7 | ; 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 Johnson | a081145 | 2016-11-10 16:57:32 +0000 | [diff] [blame] | 10 | |
Peter Collingbourne | 7faa60c | 2017-04-11 18:12:00 +0000 | [diff] [blame] | 11 | ; RUN: llvm-lto2 run %t1.bc %t2.bc -o %t.o -save-temps \ |
Teresa Johnson | a081145 | 2016-11-10 16:57:32 +0000 | [diff] [blame] | 12 | ; RUN: -r=%t1.bc,foo,plx \ |
Teresa Johnson | e0ee5cf | 2016-12-27 17:45:09 +0000 | [diff] [blame] | 13 | ; 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 Johnson | a081145 | 2016-11-10 16:57:32 +0000 | [diff] [blame] | 17 | ; 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 Johnson | e0ee5cf | 2016-12-27 17:45:09 +0000 | [diff] [blame] | 22 | ; RUN: -r=%t1.bc,callglobalfunc,plx \ |
| 23 | ; RUN: -r=%t1.bc,callweakfunc,plx \ |
Teresa Johnson | a081145 | 2016-11-10 16:57:32 +0000 | [diff] [blame] | 24 | ; RUN: -r=%t2.bc,main,plx \ |
| 25 | ; RUN: -r=%t2.bc,func1,l \ |
| 26 | ; RUN: -r=%t2.bc,func2,l \ |
Teresa Johnson | e0ee5cf | 2016-12-27 17:45:09 +0000 | [diff] [blame] | 27 | ; RUN: -r=%t2.bc,func3,l \ |
| 28 | ; RUN: -r=%t2.bc,callglobalfunc,l \ |
| 29 | ; RUN: -r=%t2.bc,callweakfunc,l |
Teresa Johnson | a081145 | 2016-11-10 16:57:32 +0000 | [diff] [blame] | 30 | ; 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 Johnson | e0ee5cf | 2016-12-27 17:45:09 +0000 | [diff] [blame] | 36 | ; promoted. |
Teresa Johnson | a081145 | 2016-11-10 16:57:32 +0000 | [diff] [blame] | 37 | ; 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 Johnson | e0ee5cf | 2016-12-27 17:45:09 +0000 | [diff] [blame] | 43 | ; NM0-DAG: T callglobalfunc |
| 44 | ; NM0-DAG: T callweakfunc |
| 45 | ; NM0-DAG: T globalfunc |
| 46 | ; NM0-DAG: W weakfunc |
Teresa Johnson | a081145 | 2016-11-10 16:57:32 +0000 | [diff] [blame] | 47 | |
Teresa Johnson | 3624bdf | 2016-11-14 17:12:32 +0000 | [diff] [blame] | 48 | ; Ensure that foo, b and x are likewise not exported (imported as refs |
Teresa Johnson | a081145 | 2016-11-10 16:57:32 +0000 | [diff] [blame] | 49 | ; into the other module), since they can't be promoted. Additionally, |
| 50 | ; referencing functions func2 and func3 should not have been |
Teresa Johnson | e0ee5cf | 2016-12-27 17:45:09 +0000 | [diff] [blame] | 51 | ; 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 Johnson | 3624bdf | 2016-11-14 17:12:32 +0000 | [diff] [blame] | 54 | ; NM1-NOT: foo |
Teresa Johnson | a081145 | 2016-11-10 16:57:32 +0000 | [diff] [blame] | 55 | ; NM1-NOT: b |
| 56 | ; NM1-NOT: x |
Teresa Johnson | 3624bdf | 2016-11-14 17:12:32 +0000 | [diff] [blame] | 57 | ; NM1-DAG: U func1 |
Teresa Johnson | a081145 | 2016-11-10 16:57:32 +0000 | [diff] [blame] | 58 | ; NM1-DAG: U func2 |
| 59 | ; NM1-DAG: U func3 |
Teresa Johnson | e0ee5cf | 2016-12-27 17:45:09 +0000 | [diff] [blame] | 60 | ; NM1-DAG: U globalfunc |
| 61 | ; NM1-DAG: U weakfunc |
Teresa Johnson | a081145 | 2016-11-10 16:57:32 +0000 | [diff] [blame] | 62 | ; NM1-DAG: T main |
Teresa Johnson | 3624bdf | 2016-11-14 17:12:32 +0000 | [diff] [blame] | 63 | ; NM1-NOT: foo |
Teresa Johnson | a081145 | 2016-11-10 16:57:32 +0000 | [diff] [blame] | 64 | ; NM1-NOT: b |
| 65 | ; NM1-NOT: x |
| 66 | |
Eric Christopher | 0824096 | 2017-02-10 04:35:32 +0000 | [diff] [blame] | 67 | target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
Teresa Johnson | a081145 | 2016-11-10 16:57:32 +0000 | [diff] [blame] | 68 | target 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 | |
| 76 | module asm "\09.text" |
| 77 | module asm "\09.type\09foo,@function" |
| 78 | module asm "foo:" |
| 79 | module asm "\09movl b, %eax" |
| 80 | module asm "\09movl x, %edx" |
| 81 | module asm "\09ret " |
| 82 | module asm "\09.size\09foo, .-foo" |
| 83 | module asm "" |
Teresa Johnson | e0ee5cf | 2016-12-27 17:45:09 +0000 | [diff] [blame] | 84 | module asm "\09.globl\09globalfunc" |
| 85 | module asm "\09.type\09globalfunc,@function" |
| 86 | module asm "globalfunc:" |
| 87 | module asm "\09movl b, %eax" |
| 88 | module asm "\09movl x, %edx" |
| 89 | module asm "\09ret " |
| 90 | module asm "\09.size\09globalfunc, .-globalfunc" |
| 91 | module asm "" |
| 92 | module asm "\09.weak\09weakfunc" |
| 93 | module asm "\09.type\09weakfunc,@function" |
| 94 | module asm "weakfunc:" |
| 95 | module asm "\09movl b, %eax" |
| 96 | module asm "\09movl x, %edx" |
| 97 | module asm "\09ret " |
| 98 | module asm "\09.size\09weakfunc, .-weakfunc" |
| 99 | module asm "" |
Teresa Johnson | a081145 | 2016-11-10 16:57:32 +0000 | [diff] [blame] | 100 | |
| 101 | declare i16 @foo() #0 |
Teresa Johnson | e0ee5cf | 2016-12-27 17:45:09 +0000 | [diff] [blame] | 102 | declare i16 @globalfunc() #0 |
| 103 | declare i16 @weakfunc() #0 |
Teresa Johnson | a081145 | 2016-11-10 16:57:32 +0000 | [diff] [blame] | 104 | |
| 105 | define i32 @func1() #1 { |
| 106 | call i16 @foo() |
| 107 | ret i32 1 |
| 108 | } |
| 109 | |
| 110 | define i32 @func2() #1 { |
| 111 | %1 = load i32, i32* @b, align 4 |
| 112 | ret i32 %1 |
| 113 | } |
| 114 | |
| 115 | define i32 @func3() #1 { |
| 116 | %1 = load i32, i32* @x, align 4 |
| 117 | ret i32 %1 |
| 118 | } |
Teresa Johnson | e0ee5cf | 2016-12-27 17:45:09 +0000 | [diff] [blame] | 119 | |
| 120 | define i32 @callglobalfunc() #1 { |
| 121 | call i16 @globalfunc() |
| 122 | ret i32 1 |
| 123 | } |
| 124 | |
| 125 | define i32 @callweakfunc() #1 { |
| 126 | call i16 @weakfunc() |
| 127 | ret i32 1 |
| 128 | } |