2015-11-21 22:55:48 +01:00
|
|
|
; First ensure that the ThinLTO handling in llvm-link and llvm-lto handles
|
2016-03-15 01:04:37 +01:00
|
|
|
; bitcode without summary sections gracefully.
|
2016-04-12 23:35:18 +02:00
|
|
|
; RUN: opt %s -o %t.bc
|
|
|
|
; RUN: opt %p/Inputs/funcimport.ll -o %t2.bc
|
2016-03-15 01:04:37 +01:00
|
|
|
; RUN: llvm-link %t.bc -summary-index=%t.bc -S
|
2015-11-21 22:55:48 +01:00
|
|
|
; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc
|
|
|
|
|
2015-11-03 01:14:15 +01:00
|
|
|
; Do setup work for all below tests: generate bitcode and combined index
|
2016-04-12 23:35:18 +02:00
|
|
|
; RUN: opt -module-summary %s -o %t.bc
|
|
|
|
; RUN: opt -module-summary %p/Inputs/funcimport.ll -o %t2.bc
|
2015-11-03 01:14:15 +01:00
|
|
|
; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc
|
|
|
|
|
|
|
|
; Ensure statics are promoted/renamed correctly from this file (all but
|
|
|
|
; constant variable need promotion).
|
2016-03-15 01:04:37 +01:00
|
|
|
; RUN: llvm-link %t.bc -summary-index=%t3.thinlto.bc -S | FileCheck %s --check-prefix=EXPORTSTATIC
|
2018-01-18 03:08:23 +01:00
|
|
|
; EXPORTSTATIC-DAG: @staticvar.llvm.{{.*}} = hidden global
|
2016-12-02 02:02:30 +01:00
|
|
|
; Eventually @staticconstvar can be exported as a copy and not promoted
|
2018-01-18 03:08:23 +01:00
|
|
|
; EXPORTSTATIC-DAG: @staticconstvar.llvm.0 = hidden unnamed_addr constant
|
|
|
|
; EXPORTSTATIC-DAG: @P.llvm.{{.*}} = hidden global void ()* null
|
|
|
|
; EXPORTSTATIC-DAG: define hidden i32 @staticfunc.llvm.
|
|
|
|
; EXPORTSTATIC-DAG: define hidden void @staticfunc2.llvm.
|
2015-11-03 01:14:15 +01:00
|
|
|
|
|
|
|
; Ensure that both weak alias to an imported function and strong alias to a
|
|
|
|
; non-imported function are correctly turned into declarations.
|
2015-11-04 17:01:16 +01:00
|
|
|
; Also ensures that alias to a linkonce function is turned into a declaration
|
|
|
|
; and that the associated linkonce function is not in the output, as it is
|
|
|
|
; lazily linked and never referenced/materialized.
|
2016-03-15 01:04:37 +01:00
|
|
|
; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=globalfunc1:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB1
|
2015-11-12 20:31:46 +01:00
|
|
|
; IMPORTGLOB1-DAG: define available_externally void @globalfunc1
|
2015-12-02 23:22:24 +01:00
|
|
|
; IMPORTGLOB1-DAG: declare void @weakalias
|
2015-11-12 20:31:46 +01:00
|
|
|
; IMPORTGLOB1-DAG: declare void @analias
|
2015-12-02 23:59:04 +01:00
|
|
|
; IMPORTGLOB1-NOT: @linkoncealias
|
2015-11-04 17:01:16 +01:00
|
|
|
; IMPORTGLOB1-NOT: @linkoncefunc
|
2015-12-02 23:59:04 +01:00
|
|
|
; IMPORTGLOB1-NOT: declare void @globalfunc2
|
2015-11-03 01:14:15 +01:00
|
|
|
|
|
|
|
; Ensure that weak alias to a non-imported function is correctly
|
|
|
|
; turned into a declaration, but that strong alias to an imported function
|
|
|
|
; is imported as alias.
|
2016-03-15 01:04:37 +01:00
|
|
|
; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=globalfunc2:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB2
|
2015-12-02 23:22:24 +01:00
|
|
|
; IMPORTGLOB2-DAG: declare void @analias
|
2015-11-12 20:31:46 +01:00
|
|
|
; IMPORTGLOB2-DAG: define available_externally void @globalfunc2
|
2015-12-02 23:22:24 +01:00
|
|
|
; IMPORTGLOB2-DAG: declare void @weakalias
|
2015-12-02 23:59:04 +01:00
|
|
|
; IMPORTGLOB2-NOT: declare void @globalfunc1
|
2015-11-03 01:14:15 +01:00
|
|
|
|
|
|
|
; Ensure that strong alias imported in second pass of importing ends up
|
|
|
|
; as an alias.
|
2016-03-15 01:04:37 +01:00
|
|
|
; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=globalfunc1:%t.bc -import=globalfunc2:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB3
|
2015-12-02 23:22:24 +01:00
|
|
|
; IMPORTGLOB3-DAG: declare void @analias
|
2015-11-12 20:31:46 +01:00
|
|
|
; IMPORTGLOB3-DAG: define available_externally void @globalfunc1
|
|
|
|
; IMPORTGLOB3-DAG: define available_externally void @globalfunc2
|
2015-12-02 23:22:24 +01:00
|
|
|
; IMPORTGLOB3-DAG: declare void @weakalias
|
2015-11-03 01:14:15 +01:00
|
|
|
|
|
|
|
; Ensure that strong alias imported in first pass of importing ends up
|
|
|
|
; as an alias, and that seeing the alias definition during a second inlining
|
|
|
|
; pass is handled correctly.
|
2016-03-15 01:04:37 +01:00
|
|
|
; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=globalfunc2:%t.bc -import=globalfunc1:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB4
|
2015-12-02 23:22:24 +01:00
|
|
|
; IMPORTGLOB4-DAG: declare void @analias
|
2015-11-12 20:31:46 +01:00
|
|
|
; IMPORTGLOB4-DAG: define available_externally void @globalfunc2
|
|
|
|
; IMPORTGLOB4-DAG: define available_externally void @globalfunc1
|
2015-12-02 23:22:24 +01:00
|
|
|
; IMPORTGLOB4-DAG: declare void @weakalias
|
2015-11-03 01:14:15 +01:00
|
|
|
|
2017-07-27 17:09:06 +02:00
|
|
|
; An alias is never imported.
|
2016-03-15 01:04:37 +01:00
|
|
|
; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=linkoncefunc:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB5
|
2017-07-27 17:09:06 +02:00
|
|
|
; IMPORTGLOB5-NOT: @linkoncealias
|
|
|
|
; IMPORTGLOB5-DAG: define available_externally void @linkoncefunc()
|
2015-11-26 20:22:59 +01:00
|
|
|
|
2015-11-03 01:14:15 +01:00
|
|
|
; Ensure that imported static variable and function references are correctly
|
|
|
|
; promoted and renamed (including static constant variable).
|
2016-03-15 01:04:37 +01:00
|
|
|
; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=referencestatics:%t.bc -S | FileCheck %s --check-prefix=IMPORTSTATIC
|
2018-01-18 03:08:23 +01:00
|
|
|
; IMPORTSTATIC-DAG: @staticvar.llvm.{{.*}} = external hidden global
|
2016-12-02 02:02:30 +01:00
|
|
|
; Eventually @staticconstvar can be imported as a copy
|
2018-01-18 03:08:23 +01:00
|
|
|
; IMPORTSTATIC-DAG: @staticconstvar.llvm.{{.*}} = external hidden unnamed_addr constant
|
2015-11-12 20:31:46 +01:00
|
|
|
; IMPORTSTATIC-DAG: define available_externally i32 @referencestatics
|
2016-04-12 01:26:46 +02:00
|
|
|
; IMPORTSTATIC-DAG: %call = call i32 @staticfunc.llvm.
|
|
|
|
; IMPORTSTATIC-DAG: %0 = load i32, i32* @staticvar.llvm.
|
2018-01-18 03:08:23 +01:00
|
|
|
; IMPORTSTATIC-DAG: declare hidden i32 @staticfunc.llvm.
|
2015-11-03 01:14:15 +01:00
|
|
|
|
|
|
|
; Ensure that imported global (external) function and variable references
|
|
|
|
; are handled correctly (including referenced variable imported as
|
|
|
|
; available_externally definition)
|
2016-03-15 01:04:37 +01:00
|
|
|
; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=referenceglobals:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOBALS
|
2016-03-19 01:40:31 +01:00
|
|
|
; IMPORTGLOBALS-DAG: @globalvar = external global
|
2015-11-12 20:31:46 +01:00
|
|
|
; IMPORTGLOBALS-DAG: declare void @globalfunc1()
|
|
|
|
; IMPORTGLOBALS-DAG: define available_externally i32 @referenceglobals
|
2015-11-03 01:14:15 +01:00
|
|
|
|
|
|
|
; Ensure that common variable correctly imported as common defition.
|
2016-03-15 01:04:37 +01:00
|
|
|
; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=referencecommon:%t.bc -S | FileCheck %s --check-prefix=IMPORTCOMMON
|
2016-03-19 01:40:31 +01:00
|
|
|
; IMPORTCOMMON-DAG: @commonvar = external global
|
2015-11-12 20:31:46 +01:00
|
|
|
; IMPORTCOMMON-DAG: define available_externally i32 @referencecommon
|
2015-11-03 01:14:15 +01:00
|
|
|
|
|
|
|
; Ensure that imported static function pointer correctly promoted and renamed.
|
2016-03-15 01:04:37 +01:00
|
|
|
; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=callfuncptr:%t.bc -S | FileCheck %s --check-prefix=IMPORTFUNCPTR
|
2018-01-18 03:08:23 +01:00
|
|
|
; IMPORTFUNCPTR-DAG: @P.llvm.{{.*}} = external hidden global void ()*
|
2015-11-12 20:31:46 +01:00
|
|
|
; IMPORTFUNCPTR-DAG: define available_externally void @callfuncptr
|
2016-04-12 01:26:46 +02:00
|
|
|
; IMPORTFUNCPTR-DAG: %0 = load void ()*, void ()** @P.llvm.
|
2015-11-03 01:14:15 +01:00
|
|
|
|
|
|
|
; Ensure that imported weak function reference/definition handled properly.
|
|
|
|
; Imported weak_any definition should be skipped with warning, and imported
|
|
|
|
; reference should turned into an external_weak declaration.
|
2016-03-15 01:04:37 +01:00
|
|
|
; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=callweakfunc:%t.bc -import=weakfunc:%t.bc -S 2>&1 | FileCheck %s --check-prefix=IMPORTWEAKFUNC
|
2015-11-12 20:31:46 +01:00
|
|
|
; IMPORTWEAKFUNC-DAG: Ignoring import request for weak-any function weakfunc
|
2016-04-20 06:18:11 +02:00
|
|
|
; IMPORTWEAKFUNC-DAG: declare void @weakfunc
|
2015-11-12 20:31:46 +01:00
|
|
|
; IMPORTWEAKFUNC-DAG: define available_externally void @callweakfunc
|
2015-12-02 23:59:04 +01:00
|
|
|
; IMPORTWEAKFUNC-NOT: @weakvar = extern_weak global i32, align 4
|
2015-11-03 01:14:15 +01:00
|
|
|
|
|
|
|
@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 (...)*)
|
2015-11-04 17:01:16 +01:00
|
|
|
@linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc to void (...)*)
|
2015-11-03 01:14:15 +01:00
|
|
|
|
|
|
|
define void @globalfunc1() #0 {
|
|
|
|
entry:
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @globalfunc2() #0 {
|
|
|
|
entry:
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2015-11-04 17:01:16 +01:00
|
|
|
define linkonce_odr void @linkoncefunc() #0 {
|
|
|
|
entry:
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2015-11-03 01:14:15 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2015-11-10 19:20:11 +01:00
|
|
|
@weakvar = weak global i32 1, align 4
|
2015-11-03 01:14:15 +01:00
|
|
|
define weak void @weakfunc() #0 {
|
|
|
|
entry:
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @callweakfunc() #0 {
|
|
|
|
entry:
|
|
|
|
call void @weakfunc()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define internal i32 @staticfunc() #0 {
|
|
|
|
entry:
|
|
|
|
ret i32 1
|
|
|
|
}
|
|
|
|
|
|
|
|
define internal void @staticfunc2() #0 {
|
|
|
|
entry:
|
|
|
|
ret void
|
|
|
|
}
|