[llvm] [ThinLTO] Do not duplicate import a function that is actually defined in the current module #110064 (PR #111933)
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 10 20:28:18 PDT 2024
================
@@ -0,0 +1,92 @@
+; https://github.com/llvm/llvm-project/pull/110064
+; This test case checks if thinLTO correctly links metadata values in a specific
+; situation. Assume we are linking module B into module A, where an extern
+; function used in A is defined in B, but the function body has a
+; DITemplateValueParameter referring to another function back in A. The
+; compiler must check this other function is actually coming from A, thus
+; already materialized and does not require remapping. The IR here is modified
+; from the following source code.
+;
+; // A.h
+; template <void (*Func)()>
+; struct S {
+; void Impl() {
+; Func();
+; }
+; };
+;
+; void func1();
+;
+; // A.cpp
+; #include "A.h"
+; __attribute__((weak)) void func1() {}
+; extern void thinlto1();
+; void bar() {
+; S<func1> s; // Force instantiation of S<func1> in this compilation unit.
+; s.Impl();
+; thinlto1();
+; }
+;
+; // B.cpp
+; #include "A.h"
+; void thinlto1() {
+; S<func1> s;
+; }
+;
+; RUN: opt -module-summary -o %t1.bc %s
+; RUN: opt -module-summary -o %t2.bc %S/Inputs/ditemplatevalueparameter-remap.ll
+; RUN: llvm-lto2 run %t1.bc %t2.bc -o %t3.o -save-temps \
+; RUN: -r=%t1.bc,_Z5func1v,p \
+; RUN: -r=%t1.bc,_Z3bazv, \
+; RUN: -r=%t1.bc,_Z8thinlto1v, \
+; RUN: -r=%t1.bc,_Z3barv,px \
+; RUN: -r=%t2.bc,_Z8thinlto1v,p
+; RUN: clang -O3 -fthinlto-index=%t3.o.index.bc -x ir %t1.bc -S -emit-llvm -o - | FileCheck %s
----------------
teresajohnson wrote:
I think you will run into trouble with invoking clang here as well. I usually use opt to simulate a distributed ThinLTO backend. Take a look at some of the other test cases in this directory that use llvm-lto2 with -thinlto-distributed-indexes, in particular distributed_import.ll.
https://github.com/llvm/llvm-project/pull/111933
More information about the llvm-commits
mailing list