
The motivating use case is to support import the function declaration across modules to construct call graph edges for indirect calls [1] when importing the function definition costs too much compile time (e.g., the function is too large has no `noinline` attribute). 1. Currently, when the compiled IR module doesn't have a function definition but its postlink combined summary contains the function summary or a global alias summary with this function as aliasee, the function definition will be imported from source module by IRMover. The implementation is in FunctionImporter::importFunctions [2] 2. In order for FunctionImporter to import a declaration of a function, both function summary and alias summary need to carry the def / decl state. Specifically, all existing summary fields doesn't differ across import modules, but the def / decl state of is decided by `<ImportModule, Function>`. This change encodes the def/decl state in `GlobalValueSummary::GVFlags`. In the subsequent changes 1. The indexing step `computeImportForModule` [3] will compute the set of definitions and the set of declarations for each module, and passing on the information to bitcode writer. 2. Bitcode writer will look up the def/decl state and sets the state when it writes out the flag value. This is demonstrated in https://github.com/llvm/llvm-project/pull/87600 3. Function importer will read the def/decl state when reading the combined summary to figure out two sets of global values, and IRMover will be updated to import the declaration (aka linkGlobalValuePrototype [4]) into the destination module. - The next change is https://github.com/llvm/llvm-project/pull/87600 [1] mentioned in rfc https://discourse.llvm.org/t/rfc-for-better-call-graph-sort-build-a-more-complete-call-graph-by-adding-more-indirect-call-edges/74029#support-cross-module-function-declaration-import-5 [2]3b337242ee/llvm/lib/Transforms/IPO/FunctionImport.cpp (L1608-L1764)
[3]3b337242ee/llvm/lib/Transforms/IPO/FunctionImport.cpp (L856)
[4]3b337242ee/llvm/lib/Linker/IRMover.cpp (L605)
113 lines
4.2 KiB
LLVM
113 lines
4.2 KiB
LLVM
; Test that we correctly import an indir resolution for type identifier "typeid1".
|
|
; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-indir.yaml -wholeprogramdevirt-write-summary=%t < %s | FileCheck %s
|
|
; RUN: FileCheck --check-prefix=SUMMARY %s < %t
|
|
|
|
; SUMMARY: GlobalValueMap:
|
|
; SUMMARY-NEXT: 42:
|
|
; SUMMARY-NEXT: - Linkage: 0
|
|
; SUMMARY-NEXT: Visibility: 0
|
|
; SUMMARY-NEXT: NotEligibleToImport: false
|
|
; SUMMARY-NEXT: Live: true
|
|
; SUMMARY-NEXT: Local: false
|
|
; SUMMARY-NEXT: CanAutoHide: false
|
|
; SUMMARY-NEXT: ImportType: 0
|
|
; SUMMARY-NEXT: TypeTestAssumeVCalls:
|
|
; SUMMARY-NEXT: - GUID: 123
|
|
; SUMMARY-NEXT: Offset: 0
|
|
; SUMMARY-NEXT: - GUID: 456
|
|
; SUMMARY-NEXT: Offset: 4
|
|
; SUMMARY-NEXT: TypeCheckedLoadVCalls:
|
|
; SUMMARY-NEXT: - GUID: 789
|
|
; SUMMARY-NEXT: Offset: 8
|
|
; SUMMARY-NEXT: - GUID: 1234
|
|
; SUMMARY-NEXT: Offset: 16
|
|
; SUMMARY-NEXT: TypeTestAssumeConstVCalls:
|
|
; SUMMARY-NEXT: - VFunc:
|
|
; SUMMARY-NEXT: GUID: 123
|
|
; SUMMARY-NEXT: Offset: 4
|
|
; SUMMARY-NEXT: Args: [ 12, 24 ]
|
|
; SUMMARY-NEXT: TypeCheckedLoadConstVCalls:
|
|
; SUMMARY-NEXT: - VFunc:
|
|
; SUMMARY-NEXT: GUID: 456
|
|
; SUMMARY-NEXT: Offset: 8
|
|
; SUMMARY-NEXT: Args: [ 24, 12 ]
|
|
; SUMMARY-NEXT: 43:
|
|
; SUMMARY-NEXT: - Linkage: 0
|
|
; SUMMARY-NEXT: Visibility: 0
|
|
; SUMMARY-NEXT: NotEligibleToImport: false
|
|
; SUMMARY-NEXT: Live: true
|
|
; SUMMARY-NEXT: Local: false
|
|
; SUMMARY-NEXT: CanAutoHide: false
|
|
; SUMMARY-NEXT: ImportType: 1
|
|
; SUMMARY-NEXT: TypeIdMap:
|
|
; SUMMARY-NEXT: typeid1:
|
|
; SUMMARY-NEXT: TTRes:
|
|
; SUMMARY-NEXT: Kind: Unknown
|
|
; SUMMARY-NEXT: SizeM1BitWidth: 0
|
|
; SUMMARY-NEXT: AlignLog2: 0
|
|
; SUMMARY-NEXT: SizeM1: 0
|
|
; SUMMARY-NEXT: BitMask: 0
|
|
; SUMMARY-NEXT: InlineBits: 0
|
|
; SUMMARY-NEXT: WPDRes:
|
|
; SUMMARY-NEXT: 0:
|
|
; SUMMARY-NEXT: Kind: Indir
|
|
; SUMMARY-NEXT: SingleImplName: ''
|
|
; SUMMARY-NEXT: ResByArg:
|
|
; SUMMARY-NEXT: 4:
|
|
; SUMMARY-NEXT: Kind: Indir
|
|
; SUMMARY-NEXT: SingleImplName: ''
|
|
; SUMMARY-NEXT: ResByArg:
|
|
; SUMMARY-NEXT: :
|
|
; SUMMARY-NEXT: Kind: UniformRetVal
|
|
; SUMMARY-NEXT: Info: 12
|
|
; SUMMARY-NEXT: Byte: 0
|
|
; SUMMARY-NEXT: Bit: 0
|
|
; SUMMARY-NEXT: 12:
|
|
; SUMMARY-NEXT: Kind: UniformRetVal
|
|
; SUMMARY-NEXT: Info: 24
|
|
; SUMMARY-NEXT: Byte: 0
|
|
; SUMMARY-NEXT: Bit: 0
|
|
; SUMMARY-NEXT: 12,24:
|
|
; SUMMARY-NEXT: Kind: UniformRetVal
|
|
; SUMMARY-NEXT: Info: 48
|
|
; SUMMARY-NEXT: Byte: 0
|
|
; SUMMARY-NEXT: Bit: 0
|
|
|
|
target datalayout = "e-p:32:32"
|
|
|
|
declare void @llvm.assume(i1)
|
|
declare void @llvm.trap()
|
|
declare {ptr, i1} @llvm.type.checked.load(ptr, i32, metadata)
|
|
declare i1 @llvm.type.test(ptr, metadata)
|
|
|
|
; CHECK: define i1 @f1
|
|
define i1 @f1(ptr %obj) {
|
|
%vtable = load ptr, ptr %obj
|
|
%p = call i1 @llvm.type.test(ptr %vtable, metadata !"typeid1")
|
|
call void @llvm.assume(i1 %p)
|
|
%fptr = load ptr, ptr %vtable
|
|
; CHECK: call i1 %
|
|
%result = call i1 %fptr(ptr %obj, i32 5)
|
|
ret i1 %result
|
|
}
|
|
|
|
; CHECK: define i1 @f2
|
|
define i1 @f2(ptr %obj) {
|
|
%vtable = load ptr, ptr %obj
|
|
%pair = call {ptr, i1} @llvm.type.checked.load(ptr %vtable, i32 4, metadata !"typeid1")
|
|
%fptr = extractvalue {ptr, i1} %pair, 0
|
|
%p = extractvalue {ptr, i1} %pair, 1
|
|
; CHECK: [[P:%.*]] = call i1 @llvm.type.test
|
|
; CHECK: br i1 [[P]]
|
|
br i1 %p, label %cont, label %trap
|
|
|
|
cont:
|
|
; CHECK: call i1 %
|
|
%result = call i1 %fptr(ptr %obj, i32 undef)
|
|
ret i1 %result
|
|
|
|
trap:
|
|
call void @llvm.trap()
|
|
unreachable
|
|
}
|