diff options
author | Teresa Johnson <tejohnson@google.com> | 2018-07-13 21:35:51 +0000 |
---|---|---|
committer | Teresa Johnson <tejohnson@google.com> | 2018-07-13 21:35:51 +0000 |
commit | d94c0594d966e9ee11aeb05e2917098bd584361e (patch) | |
tree | 3beb1a7b38a03356fe7471f465adddff3bc0f824 /llvm/test/Transforms/FunctionImport | |
parent | d66941fab9b562296e956274bf225ade97e7b3de (diff) | |
download | bcm5719-llvm-d94c0594d966e9ee11aeb05e2917098bd584361e.tar.gz bcm5719-llvm-d94c0594d966e9ee11aeb05e2917098bd584361e.zip |
[ThinLTO] Ensure we always select the same function copy to import
In order to always import the same copy of a linkonce function,
even when encountering it with different thresholds (a higher one then a
lower one), keep track of the summary we decided to import.
This ensures that the backend only gets a single definition to import
for each GUID, so that it doesn't need to choose one.
Move the largest threshold the GUID was considered for import into the
current module out of the ImportMap (which is part of a larger map
maintained across the whole index), and into a new map just maintained
for the current module we are computing imports for. This saves some
memory since we no longer have the thresholds maintained across the
whole index (and throughout the in-process backends when doing a normal
non-distributed ThinLTO build), at the cost of some additional
information being maintained for each invocation of ComputeImportForModule
(the selected summary pointer for each import).
There is an additional map lookup for each callee being considered for
importing, however, this was able to subsume a map lookup in the
Worklist iteration that invokes computeImportForFunction. We also are
able to avoid calling selectCallee if we already failed to import at the
same or higher threshold.
I compared the run time and peak memory for the SPEC2006 471.omnetpp
benchmark (running in-process ThinLTO backends), as well as for a large
internal benchmark with a distributed ThinLTO build (so just looking at
the thin link time/memory). Across a number of runs with and without
this change there was no significant change in the time and memory.
(I tried a few other variations of the change but they also didn't
improve time or peak memory).
Reviewers: davidxl
Subscribers: mehdi_amini, inglorion, llvm-commits
Differential Revision: https://reviews.llvm.org/D48670
llvm-svn: 337050
Diffstat (limited to 'llvm/test/Transforms/FunctionImport')
3 files changed, 90 insertions, 0 deletions
diff --git a/llvm/test/Transforms/FunctionImport/Inputs/funcimport_resolved1.ll b/llvm/test/Transforms/FunctionImport/Inputs/funcimport_resolved1.ll new file mode 100644 index 00000000000..2b2443c96af --- /dev/null +++ b/llvm/test/Transforms/FunctionImport/Inputs/funcimport_resolved1.ll @@ -0,0 +1,34 @@ +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.11.0" + +define void @foo() { + call void @linkonceodrfunc() + call void @linkonceodrfunc2() + ret void +} + +define linkonce_odr void @linkonceodrfunc() { + call void @f() + call void @f() + call void @f() + call void @f() + call void @f() + call void @f() + call void @f() + ret void +} + +define linkonce_odr void @linkonceodrfunc2() { + call void @f() + call void @f() + call void @f() + call void @f() + call void @f() + call void @f() + call void @f() + ret void +} + +define internal void @f() { + ret void +} diff --git a/llvm/test/Transforms/FunctionImport/Inputs/funcimport_resolved2.ll b/llvm/test/Transforms/FunctionImport/Inputs/funcimport_resolved2.ll new file mode 100644 index 00000000000..278a7f4553f --- /dev/null +++ b/llvm/test/Transforms/FunctionImport/Inputs/funcimport_resolved2.ll @@ -0,0 +1,6 @@ +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.11.0" + +define linkonce_odr void @linkonceodrfunc() { + ret void +} diff --git a/llvm/test/Transforms/FunctionImport/funcimport_resolved.ll b/llvm/test/Transforms/FunctionImport/funcimport_resolved.ll new file mode 100644 index 00000000000..d9989c6aa52 --- /dev/null +++ b/llvm/test/Transforms/FunctionImport/funcimport_resolved.ll @@ -0,0 +1,50 @@ +; Test to ensure that we always select the same copy of a linkonce function +; when it is encountered with different thresholds. When we encounter the +; copy in funcimport_resolved1.ll with a higher threshold via the direct call +; from main(), it will be selected for importing. When we encounter it with a +; lower threshold by reaching it from the deeper call chain via foo(), it +; won't be selected for importing. We don't want to select both the copy from +; funcimport_resolved1.ll and the smaller one from funcimport_resolved2.ll, +; leaving it up to the backend to figure out which one to actually import. +; The linkonce_odr may have different instruction counts in practice due to +; different inlines in the compile step. + +; Require asserts so we can use -debug-only +; REQUIRES: asserts + +; RUN: opt -module-summary %s -o %t.bc +; RUN: opt -module-summary %p/Inputs/funcimport_resolved1.ll -o %t2.bc +; RUN: opt -module-summary %p/Inputs/funcimport_resolved2.ll -o %t3.bc + +; First do a sanity check that all callees are imported with the default +; instruction limit +; RUN: llvm-lto2 run %t.bc %t2.bc %t3.bc -o %t4 -r=%t.bc,_main,pl -r=%t.bc,_linkonceodrfunc,l -r=%t.bc,_foo,l -r=%t2.bc,_foo,pl -r=%t2.bc,_linkonceodrfunc,pl -r=%t2.bc,_linkonceodrfunc2,pl -r=%t3.bc,_linkonceodrfunc,l -thinlto-threads=1 -debug-only=function-import 2>&1 | FileCheck %s --check-prefix=INSTLIMDEFAULT +; INSTLIMDEFAULT: Is importing function {{.*}} foo from {{.*}}funcimport_resolved1.ll +; INSTLIMDEFAULT: Is importing function {{.*}} linkonceodrfunc from {{.*}}funcimport_resolved1.ll +; INSTLIMDEFAULT: Is importing function {{.*}} linkonceodrfunc2 from {{.*}}funcimport_resolved1.ll +; INSTLIMDEFAULT: Is importing function {{.*}} f from {{.*}}funcimport_resolved1.ll +; INSTLIMDEFAULT-NOT: Is importing function {{.*}} linkonceodrfunc from {{.*}}funcimport_resolved2.ll + +; Now run with the lower threshold that will only allow linkonceodrfunc to be +; imported from funcimport_resolved1.ll when encountered via the direct call +; from main(). Ensure we don't also select the copy in funcimport_resolved2.ll +; when it is encountered via the deeper call chain. +; RUN: llvm-lto2 run %t.bc %t2.bc %t3.bc -o %t4 -r=%t.bc,_main,pl -r=%t.bc,_linkonceodrfunc,l -r=%t.bc,_foo,l -r=%t2.bc,_foo,pl -r=%t2.bc,_linkonceodrfunc,pl -r=%t2.bc,_linkonceodrfunc2,pl -r=%t3.bc,_linkonceodrfunc,l -thinlto-threads=1 -debug-only=function-import -import-instr-limit=8 2>&1 | FileCheck %s --check-prefix=INSTLIM8 +; INSTLIM8: Is importing function {{.*}} foo from {{.*}}funcimport_resolved1.ll +; INSTLIM8: Is importing function {{.*}} linkonceodrfunc from {{.*}}funcimport_resolved1.ll +; INSTLIM8: Not importing function {{.*}} linkonceodrfunc2 from {{.*}}funcimport_resolved1.ll +; INSTLIM8: Is importing function {{.*}} f from {{.*}}funcimport_resolved1.ll +; INSTLIM8-NOT: Is importing function {{.*}} linkonceodrfunc from {{.*}}funcimport_resolved2.ll + +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.11.0" + +define i32 @main() #0 { +entry: + call void (...) @foo() + call void (...) @linkonceodrfunc() + ret i32 0 +} + +declare void @foo(...) #1 +declare void @linkonceodrfunc(...) #1 |