xref: /llvm-project/llvm/test/Transforms/FunctionImport/funcimport_cutoff.ll (revision a9af1b9a307780a39facd016c7329990d6cc5508)
1cee313d2SEric Christopher; Test to ensure that thin linking with -import-cutoff stops importing when
2cee313d2SEric Christopher; expected.
3cee313d2SEric Christopher
4cee313d2SEric Christopher; "-stats" and "-debug-only" require +Asserts.
5cee313d2SEric Christopher; REQUIRES: asserts
6cee313d2SEric Christopher
7cee313d2SEric Christopher; RUN: opt -module-summary %s -o %t.bc
8cee313d2SEric Christopher; RUN: opt -module-summary %p/Inputs/funcimport_cutoff.ll -o %t2.bc
9cee313d2SEric Christopher; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc
10cee313d2SEric Christopher
11cee313d2SEric Christopher; First do with default options, which should import both foo and bar
12*a9af1b9aSFangrui Song; RUN: opt -passes=function-import -stats -print-imports -summary-file %t3.thinlto.bc %t.bc -S 2>&1 | FileCheck %s --check-prefix=IMPORT
13cee313d2SEric Christopher
14cee313d2SEric Christopher; Next try to restrict to 1 import. This should import just foo.
15*a9af1b9aSFangrui Song; RUN: opt -import-cutoff=1 -passes=function-import -stats -print-imports -summary-file %t3.thinlto.bc %t.bc -S 2>&1 | FileCheck %s --check-prefix=IMPORT1
16cee313d2SEric Christopher
17cee313d2SEric Christopher; Next try to restrict to 0 imports. This should not import.
18*a9af1b9aSFangrui Song; RUN: opt -import-cutoff=0 -passes=function-import -stats -print-imports -summary-file %t3.thinlto.bc %t.bc -S 2>&1 | FileCheck %s --check-prefix=NOIMPORT
19cee313d2SEric Christopher
20cee313d2SEric Christopherdefine i32 @main() {
21cee313d2SEric Christopherentry:
22cee313d2SEric Christopher  call void @foo()
23cee313d2SEric Christopher  call void @bar()
24cee313d2SEric Christopher  ret i32 0
25cee313d2SEric Christopher}
26cee313d2SEric Christopher
27cee313d2SEric Christopherdeclare void @foo()
28cee313d2SEric Christopherdeclare void @bar()
29cee313d2SEric Christopher
30cee313d2SEric Christopher; Check -print-imports output
31cee313d2SEric Christopher; IMPORT: Import foo
32cee313d2SEric Christopher; IMPORT: Import bar
33cee313d2SEric Christopher; IMPORT1: Import foo
34cee313d2SEric Christopher; IMPORT1-NOT: Import bar
35cee313d2SEric Christopher; NOIMPORT-NOT: Import foo
36cee313d2SEric Christopher; NOIMPORT-NOT: Import bar
37cee313d2SEric Christopher
38cee313d2SEric Christopher; Check -S output
39cee313d2SEric Christopher; IMPORT-DAG: define available_externally void @foo()
40cee313d2SEric Christopher; IMPORT-DAG: define available_externally void @bar()
41cee313d2SEric Christopher; NOIMPORT-DAG: declare void @foo()
42cee313d2SEric Christopher; NOIMPORT-DAG: declare void @bar()
43cee313d2SEric Christopher; IMPORT1-DAG: define available_externally void @foo()
44cee313d2SEric Christopher; IMPORT1-DAG: declare void @bar()
45cee313d2SEric Christopher
46cee313d2SEric Christopher; Check -stats output
47cee313d2SEric Christopher; IMPORT: 2 function-import - Number of functions imported
48cee313d2SEric Christopher; IMPORT1: 1 function-import - Number of functions imported
49cee313d2SEric Christopher; NOIMPORT-NOT: function-import - Number of functions imported
50