[ThinLTO] Only import for non-prevailing interposable global variables
authorShoaib Meenai <smeenai@fb.com>
Sat, 25 Mar 2023 00:34:14 +0000 (17:34 -0700)
committerShoaib Meenai <smeenai@fb.com>
Sun, 26 Mar 2023 04:37:42 +0000 (21:37 -0700)
commit377e1311d50c7e5b5aab3db081938e0d0ceebdfc
tree42695adc7a9504adff62416306a1a19664de54f4
parent943df86c82b1450bde45678757b7c39e459bc6ad
[ThinLTO] Only import for non-prevailing interposable global variables

This logic was added in https://reviews.llvm.org/D95943 specifically to
handle an issue for non-prevailing global variables. It turns out that
it adds a new issue for prevailing glboal variables, since those could
be replaced by an available_externally definition and hence incorrectly
omitted from the output object file. Limit the import to non-prevailing
global variables to fix this, as suggested by @tejohnson.

The bulk of the diff is mechanical changes to thread isPrevailing
through to where it's needed and ensure it's available before the
relevant calls; the actual logic change itself is straightforward.

Fixes https://github.com/llvm/llvm-project/issues/61677

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D146876
llvm/include/llvm/Transforms/IPO/FunctionImport.h
llvm/lib/LTO/LTO.cpp
llvm/lib/LTO/ThinLTOCodeGenerator.cpp
llvm/lib/Transforms/IPO/FunctionImport.cpp
llvm/test/ThinLTO/X86/nonprevailing_weak_globals_import.ll [moved from llvm/test/ThinLTO/X86/weak_globals_import.ll with 100% similarity]
llvm/test/ThinLTO/X86/prevailing_weak_globals_import.ll [new file with mode: 0644]