[llvm] a40b0c3 - [WPD] Update llvm.public.type.test after importing functions

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Thu May 11 09:10:50 PDT 2023


Author: Teresa Johnson
Date: 2023-05-11T09:10:32-07:00
New Revision: a40b0c3e77a28b8dee5af7f9d9cdc9ad5919077e

URL: https://github.com/llvm/llvm-project/commit/a40b0c3e77a28b8dee5af7f9d9cdc9ad5919077e
DIFF: https://github.com/llvm/llvm-project/commit/a40b0c3e77a28b8dee5af7f9d9cdc9ad5919077e.diff

LOG: [WPD] Update llvm.public.type.test after importing functions

I noticed that we are converting llvm.public.type.test to regular
llvm.type.test too early, and thus not updating those in imported
functions. This would result in losing out on WPD opportunities. Move
the update to after function importing, and improve test to cover this
case.

Differential Revision: https://reviews.llvm.org/D150326

Added: 
    

Modified: 
    clang/test/CodeGenCXX/thinlto_public_type_test_distributed.ll
    lld/test/ELF/lto/update_public_type_test.ll
    llvm/lib/LTO/LTOBackend.cpp
    llvm/lib/LTO/ThinLTOCodeGenerator.cpp
    llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
    llvm/test/ThinLTO/X86/public-type-test.ll

Removed: 
    


################################################################################
diff  --git a/clang/test/CodeGenCXX/thinlto_public_type_test_distributed.ll b/clang/test/CodeGenCXX/thinlto_public_type_test_distributed.ll
index 1d175962e3602..ce3447384adbe 100644
--- 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
index 037e7b9089d02..285085e0b5299 100644
--- 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
index a089cbe63963e..667ebb0c43320 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -565,8 +565,6 @@ Error lto::thinBackend(const Config &Conf, unsigned Task, AddStreamFn AddStream,
   // 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 @@ Error lto::thinBackend(const Config &Conf, unsigned Task, AddStreamFn AddStream,
 
   // 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
index 0549098f10209..d113e119c4ad7 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -452,11 +452,6 @@ ProcessThinLTOModule(Module &TheModule, ModuleSummaryIndex &Index,
                      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 @@ ProcessThinLTOModule(Module &TheModule, ModuleSummaryIndex &Index,
   // 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
index 7f8e6121669e7..10dda3fab0baa 100644
--- 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
index 5a4e19edca590..fbba2a4eea406 100644
--- 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 @@ define i32 @main(ptr %vtable) {
 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)


        


More information about the llvm-commits mailing list