diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:46:15 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:46:15 +0000 |
| commit | dd58ef019b700900793a1eb48b52123db01b654e (patch) | |
| tree | fcfbb4df56a744f4ddc6122c50521dd3f1c5e196 /test/Transforms/FunctionImport | |
| parent | 2fe5752e3a7c345cdb59e869278d36af33c13fa4 (diff) | |
Notes
Diffstat (limited to 'test/Transforms/FunctionImport')
| -rw-r--r-- | test/Transforms/FunctionImport/Inputs/funcimport.ll | 87 | ||||
| -rw-r--r-- | test/Transforms/FunctionImport/Inputs/funcimport_debug.ll | 27 | ||||
| -rw-r--r-- | test/Transforms/FunctionImport/funcimport.ll | 75 | ||||
| -rw-r--r-- | test/Transforms/FunctionImport/funcimport_debug.ll | 45 |
4 files changed, 234 insertions, 0 deletions
diff --git a/test/Transforms/FunctionImport/Inputs/funcimport.ll b/test/Transforms/FunctionImport/Inputs/funcimport.ll new file mode 100644 index 000000000000..96555892fe3c --- /dev/null +++ b/test/Transforms/FunctionImport/Inputs/funcimport.ll @@ -0,0 +1,87 @@ +@globalvar = global i32 1, align 4 +@staticvar = internal global i32 1, align 4 +@staticconstvar = internal unnamed_addr constant [2 x i32] [i32 10, i32 20], align 4 +@commonvar = common global i32 0, align 4 +@P = internal global void ()* null, align 8 + +@weakalias = weak alias void (...), bitcast (void ()* @globalfunc1 to void (...)*) +@analias = alias void (...), bitcast (void ()* @globalfunc2 to void (...)*) +@linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc to void (...)*) + +define void @globalfunc1() #0 { +entry: + ret void +} + +define void @globalfunc2() #0 { +entry: + ret void +} + +define linkonce_odr void @linkoncefunc() #0 { +entry: + ret void +} + +define i32 @referencestatics(i32 %i) #0 { +entry: + %i.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + %call = call i32 @staticfunc() + %0 = load i32, i32* @staticvar, align 4 + %add = add nsw i32 %call, %0 + %1 = load i32, i32* %i.addr, align 4 + %idxprom = sext i32 %1 to i64 + %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* @staticconstvar, i64 0, i64 %idxprom + %2 = load i32, i32* %arrayidx, align 4 + %add1 = add nsw i32 %add, %2 + ret i32 %add1 +} + +define i32 @referenceglobals(i32 %i) #0 { +entry: + %i.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + call void @globalfunc1() + %0 = load i32, i32* @globalvar, align 4 + ret i32 %0 +} + +define i32 @referencecommon(i32 %i) #0 { +entry: + %i.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + %0 = load i32, i32* @commonvar, align 4 + ret i32 %0 +} + +define void @setfuncptr() #0 { +entry: + store void ()* @staticfunc2, void ()** @P, align 8 + ret void +} + +define void @callfuncptr() #0 { +entry: + %0 = load void ()*, void ()** @P, align 8 + call void %0() + ret void +} + +@weakvar = weak global i32 1, align 4 +define weak void @weakfunc() #0 { +entry: + ret void +} + +define internal i32 @staticfunc() #0 { +entry: + ret i32 1 +} + +define internal void @staticfunc2() #0 { +entry: + ret void +} + + diff --git a/test/Transforms/FunctionImport/Inputs/funcimport_debug.ll b/test/Transforms/FunctionImport/Inputs/funcimport_debug.ll new file mode 100644 index 000000000000..35c62a262903 --- /dev/null +++ b/test/Transforms/FunctionImport/Inputs/funcimport_debug.ll @@ -0,0 +1,27 @@ +; ModuleID = 'funcimport_debug.o' +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; Function Attrs: nounwind uwtable +define void @func() #0 !dbg !4 { +entry: + ret void, !dbg !10 +} + +attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!7, !8} +!llvm.ident = !{!9} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.8.0 (trunk 255685) (llvm/trunk 255682)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3) +!1 = !DIFile(filename: "funcimport_debug.c", directory: ".") +!2 = !{} +!3 = !{!4} +!4 = distinct !DISubprogram(name: "func", scope: !1, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, variables: !2) +!5 = !DISubroutineType(types: !6) +!6 = !{null} +!7 = !{i32 2, !"Dwarf Version", i32 4} +!8 = !{i32 2, !"Debug Info Version", i32 3} +!9 = !{!"clang version 3.8.0 (trunk 255685) (llvm/trunk 255682)"} +!10 = !DILocation(line: 2, column: 1, scope: !4) diff --git a/test/Transforms/FunctionImport/funcimport.ll b/test/Transforms/FunctionImport/funcimport.ll new file mode 100644 index 000000000000..c099b9766477 --- /dev/null +++ b/test/Transforms/FunctionImport/funcimport.ll @@ -0,0 +1,75 @@ +; Do setup work for all below tests: generate bitcode and combined index +; RUN: llvm-as -function-summary %s -o %t.bc +; RUN: llvm-as -function-summary %p/Inputs/funcimport.ll -o %t2.bc +; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc + +; Do the import now +; RUN: opt -function-import -summary-file %t3.thinlto.bc %s -S | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIMDEF + +; Test import with smaller instruction limit +; RUN: opt -function-import -summary-file %t3.thinlto.bc %s -import-instr-limit=5 -S | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIM5 +; INSTLIM5-NOT: @staticfunc.llvm.2 + +define i32 @main() #0 { +entry: + call void (...) @weakalias() + call void (...) @analias() + call void (...) @linkoncealias() + %call = call i32 (...) @referencestatics() + %call1 = call i32 (...) @referenceglobals() + %call2 = call i32 (...) @referencecommon() + call void (...) @setfuncptr() + call void (...) @callfuncptr() + call void (...) @weakfunc() + ret i32 0 +} + +; Won't import weak alias +; CHECK-DAG: declare void @weakalias +declare void @weakalias(...) #1 + +; Cannot create an alias to available_externally +; CHECK-DAG: declare void @analias +declare void @analias(...) #1 + +; Aliases import the aliasee function +declare void @linkoncealias(...) #1 +; CHECK-DAG: define linkonce_odr void @linkoncefunc() +; CHECK-DAG: @linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc to void (...)* + +; INSTLIMDEF-DAG: define available_externally i32 @referencestatics(i32 %i) +; INSTLIM5-DAG: declare i32 @referencestatics(...) +declare i32 @referencestatics(...) #1 + +; The import of referencestatics will expose call to staticfunc that +; should in turn be imported as a promoted/renamed and hidden function. +; Ensure that the call is to the properly-renamed function. +; INSTLIMDEF-DAG: %call = call i32 @staticfunc.llvm.2() +; INSTLIMDEF-DAG: define available_externally hidden i32 @staticfunc.llvm.2() + +; CHECK-DAG: define available_externally i32 @referenceglobals(i32 %i) +declare i32 @referenceglobals(...) #1 + +; The import of referenceglobals will expose call to globalfunc1 that +; should in turn be imported. +; CHECK-DAG: define available_externally void @globalfunc1() + +; CHECK-DAG: define available_externally i32 @referencecommon(i32 %i) +declare i32 @referencecommon(...) #1 + +; CHECK-DAG: define available_externally void @setfuncptr() +declare void @setfuncptr(...) #1 + +; CHECK-DAG: define available_externally void @callfuncptr() +declare void @callfuncptr(...) #1 + +; Ensure that all uses of local variable @P which has used in setfuncptr +; and callfuncptr are to the same promoted/renamed global. +; CHECK-DAG: @P.llvm.2 = available_externally hidden global void ()* null +; CHECK-DAG: %0 = load void ()*, void ()** @P.llvm.2, +; CHECK-DAG: store void ()* @staticfunc2.llvm.2, void ()** @P.llvm.2, + +; Won't import weak func +; CHECK-DAG: declare void @weakfunc(...) +declare void @weakfunc(...) #1 + diff --git a/test/Transforms/FunctionImport/funcimport_debug.ll b/test/Transforms/FunctionImport/funcimport_debug.ll new file mode 100644 index 000000000000..c57b5e14af1b --- /dev/null +++ b/test/Transforms/FunctionImport/funcimport_debug.ll @@ -0,0 +1,45 @@ +; Do setup work for all below tests: generate bitcode and combined index +; RUN: llvm-as -function-summary %s -o %t.bc +; RUN: llvm-as -function-summary %p/Inputs/funcimport_debug.ll -o %t2.bc +; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc + +; Do the import now and confirm that metadata is linked for imported function. +; RUN: opt -function-import -summary-file %t3.thinlto.bc %s -S | FileCheck %s + +; CHECK: define available_externally void @func() +; CHECK: distinct !DISubprogram(name: "main" +; CHECK: distinct !DISubprogram(name: "func" + +; ModuleID = 'funcimport_debug.o' +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; Function Attrs: nounwind uwtable +define i32 @main() #0 !dbg !4 { +entry: + call void (...) @func(), !dbg !11 + ret i32 0, !dbg !12 +} + +declare void @func(...) #1 + +attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!8, !9} +!llvm.ident = !{!10} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.8.0 (trunk 255685) (llvm/trunk 255682)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3) +!1 = !DIFile(filename: "funcimport_debug.c", directory: ".") +!2 = !{} +!3 = !{!4} +!4 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: false, variables: !2) +!5 = !DISubroutineType(types: !6) +!6 = !{!7} +!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) +!8 = !{i32 2, !"Dwarf Version", i32 4} +!9 = !{i32 2, !"Debug Info Version", i32 3} +!10 = !{!"clang version 3.8.0 (trunk 255685) (llvm/trunk 255682)"} +!11 = !DILocation(line: 3, column: 3, scope: !4) +!12 = !DILocation(line: 4, column: 1, scope: !4) |
