[LTO/WPD] Enable aggressive WPD under LTO option
authorTeresa Johnson <tejohnson@google.com>
Thu, 26 Dec 2019 19:40:18 +0000 (11:40 -0800)
committerTeresa Johnson <tejohnson@google.com>
Fri, 24 Jan 2020 00:09:44 +0000 (16:09 -0800)
commit59733525d37cf9ad88b5021b33ecdbaf2e18911c
treef69939a1a10d827519574d710a71617df758684c
parent9e66c4ec127ef6e73f1bafe06fe3fba45d59feee
[LTO/WPD] Enable aggressive WPD under LTO option

Summary:
Third part in series to support Safe Whole Program Devirtualization
Enablement, see RFC here:
http://lists.llvm.org/pipermail/llvm-dev/2019-December/137543.html

This patch adds type test metadata under -fwhole-program-vtables,
even for classes without hidden visibility. It then changes WPD to skip
devirtualization for a virtual function call when any of the compatible
vtables has public vcall visibility.

Additionally, internal LLVM options as well as lld and gold-plugin
options are added which enable upgrading all public vcall visibility
to linkage unit (hidden) visibility during LTO. This enables the more
aggressive WPD to kick in based on LTO time knowledge of the visibility
guarantees.

Support was added to all flavors of LTO WPD (regular, hybrid and
index-only), and to both the new and old LTO APIs.

Unfortunately it was not simple to split the first and second parts of
this part of the change (the unconditional emission of type tests and
the upgrading of the vcall visiblity) as I needed a way to upgrade the
public visibility on legacy WPD llvm assembly tests that don't include
linkage unit vcall visibility specifiers, to avoid a lot of test churn.

I also added a mechanism to LowerTypeTests that allows dropping type
test assume sequences we now aggressively insert when we invoke
distributed ThinLTO backends with null indexes, which is used in testing
mode, and which doesn't invoke the normal ThinLTO backend pipeline.

Depends on D71907 and D71911.

Reviewers: pcc, evgeny777, steven_wu, espindola

Subscribers: emaste, Prazek, inglorion, arichardson, hiraditya, MaskRay, dexonsmith, dang, davidxl, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D71913
71 files changed:
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/CodeGen/CGClass.cpp
clang/lib/CodeGen/CGVTables.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
clang/test/CodeGenCXX/cfi-mfcall.cpp
clang/test/CodeGenCXX/lto-visibility-inference.cpp
clang/test/CodeGenCXX/thinlto-distributed-type-metadata.cpp [new file with mode: 0644]
clang/test/CodeGenCXX/type-metadata.cpp
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/LTO.cpp
lld/ELF/Options.td
lld/test/ELF/lto/devirt_vcall_vis_public.ll [new file with mode: 0644]
llvm/include/llvm/LTO/Config.h
llvm/include/llvm/Transforms/IPO.h
llvm/include/llvm/Transforms/IPO/LowerTypeTests.h
llvm/include/llvm/Transforms/IPO/WholeProgramDevirt.h
llvm/lib/LTO/LTO.cpp
llvm/lib/LTO/LTOCodeGenerator.cpp
llvm/lib/LTO/ThinLTOCodeGenerator.cpp
llvm/lib/Transforms/IPO/LowerTypeTests.cpp
llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
llvm/test/ThinLTO/X86/cache-typeid-resolutions.ll
llvm/test/ThinLTO/X86/cfi-devirt.ll
llvm/test/ThinLTO/X86/devirt-after-icp.ll
llvm/test/ThinLTO/X86/devirt.ll
llvm/test/ThinLTO/X86/devirt2.ll
llvm/test/ThinLTO/X86/devirt_alias.ll
llvm/test/ThinLTO/X86/devirt_available_externally.ll
llvm/test/ThinLTO/X86/devirt_external_comdat_same_guid.ll
llvm/test/ThinLTO/X86/devirt_promote.ll
llvm/test/ThinLTO/X86/devirt_promote_legacy.ll
llvm/test/ThinLTO/X86/devirt_single_hybrid.ll
llvm/test/ThinLTO/X86/devirt_vcall_vis_hidden.ll [new file with mode: 0644]
llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll [new file with mode: 0644]
llvm/test/Transforms/WholeProgramDevirt/bad-read-from-vtable.ll
llvm/test/Transforms/WholeProgramDevirt/branch-funnel-threshold.ll
llvm/test/Transforms/WholeProgramDevirt/branch-funnel.ll
llvm/test/Transforms/WholeProgramDevirt/constant-arg.ll
llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl-check.ll
llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl.ll
llvm/test/Transforms/WholeProgramDevirt/expand-check.ll
llvm/test/Transforms/WholeProgramDevirt/export-nothing.ll
llvm/test/Transforms/WholeProgramDevirt/export-single-impl.ll
llvm/test/Transforms/WholeProgramDevirt/export-uniform-ret-val.ll
llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll
llvm/test/Transforms/WholeProgramDevirt/export-unsuccessful-checked.ll
llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
llvm/test/Transforms/WholeProgramDevirt/non-constant-vtable.ll
llvm/test/Transforms/WholeProgramDevirt/pointer-vtable.ll
llvm/test/Transforms/WholeProgramDevirt/soa-vtable.ll
llvm/test/Transforms/WholeProgramDevirt/struct-vtable.ll
llvm/test/Transforms/WholeProgramDevirt/uniform-retval-invoke.ll
llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll
llvm/test/Transforms/WholeProgramDevirt/unique-retval.ll
llvm/test/Transforms/WholeProgramDevirt/vcp-accesses-memory.ll
llvm/test/Transforms/WholeProgramDevirt/vcp-decl.ll
llvm/test/Transforms/WholeProgramDevirt/vcp-no-this.ll
llvm/test/Transforms/WholeProgramDevirt/vcp-non-constant-arg.ll
llvm/test/Transforms/WholeProgramDevirt/vcp-too-wide-ints.ll
llvm/test/Transforms/WholeProgramDevirt/vcp-type-mismatch.ll
llvm/test/Transforms/WholeProgramDevirt/vcp-uses-this.ll
llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-begin.ll
llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-check.ll
llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-end.ll
llvm/test/Transforms/WholeProgramDevirt/vtable-decl.ll
llvm/test/tools/gold/X86/devirt_vcall_vis_public.ll [new file with mode: 0644]
llvm/tools/gold/gold-plugin.cpp
llvm/tools/opt/opt.cpp