diff --git a/clang/test/CodeGenCXX/thinlto_public_type_test_distributed.ll b/clang/test/CodeGenCXX/thinlto_public_type_test_distributed.ll --- a/clang/test/CodeGenCXX/thinlto_public_type_test_distributed.ll +++ b/clang/test/CodeGenCXX/thinlto_public_type_test_distributed.ll @@ -11,7 +11,7 @@ ; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \ ; RUN: -emit-obj -fthinlto-index=%t.o.thinlto.bc \ ; RUN: -o %t.native.o -x ir %t.o --save-temps=obj -; RUN: llvm-dis %t.native.o.0.preopt.bc -o - | FileCheck %s --check-prefix=PUBLIC +; RUN: llvm-dis %t.native.o.3.import.bc -o - | FileCheck %s --check-prefix=PUBLIC ; RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o --whole-program-visibility \ ; RUN: -o %t2.index \ @@ -20,7 +20,7 @@ ; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \ ; RUN: -emit-obj -fthinlto-index=%t.o.thinlto.bc \ ; RUN: -o %t.native.o -x ir %t.o --save-temps=obj -; RUN: llvm-dis %t.native.o.0.preopt.bc -o - | FileCheck %s --check-prefix=HIDDEN +; RUN: llvm-dis %t.native.o.3.import.bc -o - | FileCheck %s --check-prefix=HIDDEN ; PUBLIC-NOT: call {{.*}}@llvm.public.type.test ; PUBLIC-NOT: call {{.*}}@llvm.type.test diff --git a/lld/test/ELF/lto/update_public_type_test.ll b/lld/test/ELF/lto/update_public_type_test.ll --- a/lld/test/ELF/lto/update_public_type_test.ll +++ b/lld/test/ELF/lto/update_public_type_test.ll @@ -4,9 +4,9 @@ ; RUN: opt --thinlto-bc -o %t.o %s ; RUN: ld.lld %t.o -o %t2.o --save-temps -; RUN: llvm-dis %t.o.0.preopt.bc -o - | FileCheck %s --check-prefix=PUB +; RUN: llvm-dis %t.o.3.import.bc -o - | FileCheck %s --check-prefix=PUB ; RUN: ld.lld %t.o -o %t3.o --save-temps --lto-whole-program-visibility -; RUN: llvm-dis %t.o.0.preopt.bc -o - | FileCheck %s --check-prefix=WPV +; RUN: llvm-dis %t.o.3.import.bc -o - | FileCheck %s --check-prefix=WPV target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-grtev4-linux-gnu" diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -565,8 +565,6 @@ // the module, if applicable. Mod.setPartialSampleProfileRatio(CombinedIndex); - updatePublicTypeTestCalls(Mod, CombinedIndex.withWholeProgramVisibility()); - if (Conf.CodeGenOnly) { codegen(Conf, TM.get(), AddStream, Task, Mod, CombinedIndex); return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile)); @@ -653,6 +651,7 @@ // Do this after any importing so that imported code is updated. updateMemProfAttributes(Mod, CombinedIndex); + updatePublicTypeTestCalls(Mod, CombinedIndex.withWholeProgramVisibility()); if (Conf.PostImportModuleHook && !Conf.PostImportModuleHook(Task, Mod)) return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile)); diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp --- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -452,11 +452,6 @@ bool DisableCodeGen, StringRef SaveTempsDir, bool Freestanding, unsigned OptLevel, unsigned count, bool DebugPassManager) { - // See comment at call to updateVCallVisibilityInIndex() for why - // WholeProgramVisibilityEnabledInLTO is false. - updatePublicTypeTestCalls(TheModule, - /* WholeProgramVisibilityEnabledInLTO */ false); - // "Benchmark"-like optimization: single-source case bool SingleModule = (ModuleMap.size() == 1); @@ -487,13 +482,18 @@ // Save internalized bitcode saveTempBitcode(TheModule, SaveTempsDir, count, ".2.internalized.bc"); - if (!SingleModule) { + if (!SingleModule) crossImportIntoModule(TheModule, Index, ModuleMap, ImportList, ClearDSOLocalOnDeclarations); - // Save temps: after cross-module import. - saveTempBitcode(TheModule, SaveTempsDir, count, ".3.imported.bc"); - } + // Do this after any importing so that imported code is updated. + // See comment at call to updateVCallVisibilityInIndex() for why + // WholeProgramVisibilityEnabledInLTO is false. + updatePublicTypeTestCalls(TheModule, + /* WholeProgramVisibilityEnabledInLTO */ false); + + // Save temps: after cross-module import. + saveTempBitcode(TheModule, SaveTempsDir, count, ".3.imported.bc"); optimizeModule(TheModule, TM, OptLevel, Freestanding, DebugPassManager, &Index); diff --git a/llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll b/llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll --- a/llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll +++ b/llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll @@ -18,7 +18,7 @@ ; RUN: -r=%t2.o,_ZTV1B,px \ ; RUN: -r=%t2.o,_ZTV1C,px \ ; RUN: -r=%t2.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK -; RUN: llvm-dis %t3.1.0.preopt.bc -o - | FileCheck %s --check-prefix=CHECK-TT +; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=CHECK-TT ; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR ; Hybrid WPD @@ -43,7 +43,7 @@ ; RUN: -r=%t.o,_ZTV1B,px \ ; RUN: -r=%t.o,_ZTV1C,px \ ; RUN: -r=%t.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK --dump-input=fail -; RUN: llvm-dis %t3.1.0.preopt.bc -o - | FileCheck %s --check-prefix=CHECK-TT +; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=CHECK-TT ; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR ; Regular LTO WPD @@ -83,7 +83,7 @@ ; RUN: -r=%t2.o,_ZTV1B,px \ ; RUN: -r=%t2.o,_ZTV1C,px \ ; RUN: -r=%t2.o,_ZTV1D,px 2>&1 | FileCheck %s --implicit-check-not single-impl --allow-empty -; RUN: llvm-dis %t3.1.0.preopt.bc -o - | FileCheck %s --check-prefix=CHECK-TT +; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=CHECK-TT ; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR ; Hybrid WPD @@ -105,7 +105,7 @@ ; RUN: -r=%t.o,_ZTV1B,px \ ; RUN: -r=%t.o,_ZTV1C,px \ ; RUN: -r=%t.o,_ZTV1D,px 2>&1 | FileCheck %s --implicit-check-not single-impl --allow-empty -; RUN: llvm-dis %t3.1.0.preopt.bc -o - | FileCheck %s --check-prefix=CHECK-TT +; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=CHECK-TT ; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR ; Regular LTO WPD @@ -139,7 +139,7 @@ ; RUN: -r=%t2.o,_ZTV1B,px \ ; RUN: -r=%t2.o,_ZTV1C,px \ ; RUN: -r=%t2.o,_ZTV1D,px 2>&1 | FileCheck %s --implicit-check-not single-impl --allow-empty -; RUN: llvm-dis %t3.1.0.preopt.bc -o - | FileCheck %s --check-prefix=CHECK-TT +; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=CHECK-TT ; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR ; CHECK-TT-NOT: call {{.*}}@llvm.public.type.test diff --git a/llvm/test/ThinLTO/X86/public-type-test.ll b/llvm/test/ThinLTO/X86/public-type-test.ll --- a/llvm/test/ThinLTO/X86/public-type-test.ll +++ b/llvm/test/ThinLTO/X86/public-type-test.ll @@ -1,16 +1,40 @@ -; Test to ensure that the legacy LTO API lowers @llvm.public.type.test. +; Test to ensure that the LTO API (legacy and new) lowers @llvm.public.type.test. -; RUN: opt -module-summary %s -o %t.bc -; RUN: llvm-lto --thinlto-action=run -exported-symbol=_main %t.bc --thinlto-save-temps=%t2 -; RUN: llvm-dis -o - %t20.2.internalized.bc | FileCheck %s --check-prefix=PUBLIC -; RUN: llvm-lto --thinlto-action=run -exported-symbol=_main %t.bc --thinlto-save-temps=%t2 --whole-program-visibility -; RUN: llvm-dis -o - %t20.2.internalized.bc | FileCheck %s --check-prefix=HIDDEN +; RUN: split-file %s %t + +; RUN: opt -module-summary %t/main.ll -o %t/main.bc +; RUN: opt -module-summary %t/foo.ll -o %t/foo.bc +; RUN: llvm-lto --thinlto-action=run -exported-symbol=_main %t/main.bc %t/foo.bc --thinlto-save-temps=%t2. +; RUN: llvm-dis -o - %t2.0.3.imported.bc | FileCheck %s --check-prefix=PUBLIC +; RUN: llvm-lto --thinlto-action=run -exported-symbol=_main %t/main.bc %t/foo.bc --thinlto-save-temps=%t2. --whole-program-visibility +; RUN: llvm-dis -o - %t2.0.3.imported.bc | FileCheck %s --check-prefix=HIDDEN + +; RUN: llvm-lto2 run %t/main.bc %t/foo.bc -save-temps -pass-remarks=. \ +; RUN: -whole-program-visibility \ +; RUN: -o %t3 \ +; RUN: -r=%t/main.bc,_main,px \ +; RUN: -r=%t/main.bc,_bar,px \ +; RUN: -r=%t/main.bc,_foo, \ +; RUN: -r=%t/foo.bc,_foo,px +; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=HIDDEN +; RUN: llvm-lto2 run %t/main.bc %t/foo.bc -save-temps -pass-remarks=. \ +; RUN: -o %t3 \ +; RUN: -r=%t/main.bc,_main,px \ +; RUN: -r=%t/main.bc,_bar,px \ +; RUN: -r=%t/main.bc,_foo, \ +; RUN: -r=%t/foo.bc,_foo,px +; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=PUBLIC ; PUBLIC-NOT: call {{.*}}@llvm.public.type.test ; PUBLIC-NOT: call {{.*}}@llvm.type.test +;; We should have converted the type tests from both main and the imported +;; copy of foo to non-public. +; HIDDEN-NOT: call {{.*}}@llvm.public.type.test +; HIDDEN: call {{.*}}@llvm.type.test ; HIDDEN-NOT: call {{.*}}@llvm.public.type.test ; HIDDEN: call {{.*}}@llvm.type.test +;--- main.ll target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.9" @@ -18,8 +42,31 @@ entry: %p = call i1 @llvm.public.type.test(ptr %vtable, metadata !"_ZTS1A") call void @llvm.assume(i1 %p) + call void @bar(ptr %vtable) ret i32 0 } +define void @bar(ptr %vtable) { +entry: + call void @foo(ptr %vtable) + ret void +} + +declare void @foo(ptr %vtable) + +declare void @llvm.assume(i1) +declare i1 @llvm.public.type.test(ptr, metadata) + +;--- foo.ll +target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.9" + +define void @foo(ptr %vtable) { +entry: + %p = call i1 @llvm.public.type.test(ptr %vtable, metadata !"_ZTS1A") + call void @llvm.assume(i1 %p) + ret void +} + declare void @llvm.assume(i1) declare i1 @llvm.public.type.test(ptr, metadata)