llvm-project/llvm/lib/Transforms/IPO
Teresa Johnson bed4d9c897 [ThinLTO] More efficient export computation (NFC)
Summary:
A recent change to enable more importing of global variables with
references exposed some efficiency issues with export computation.
See D73724 for more information and detailed analysis.

The first was specific to variable importing. The code was marking every
copy of a referenced value (from possibly thousands of files in the case
of linkonce_odr) as exported, and we only need to mark the copy in the
module containing the variable def being imported as exported. The
reason is that this is tracking what values are newly exported as a
result of importing. Anything that was defined in another module and
simply used in the exporting module is already exported, and would have
been identified by the caller (e.g. the LTO API implementations).

The second issue is that the code was re-adding previously exported
values (along with all references). It is easy to identify when a
variable was already imported into the same module (via the
import list insert call return value), and we already did this for
function importing. However, what we weren't doing for either function
or variable importing was avoiding a re-insertion when it was previously
exported into a different importing module. The reason we couldn't do
this is there was no way of telling from the export list whether it was
previously inserted there because its definition was exported (in which
case we already marked all its references as exported) from when it was
inserted there because it was referenced by another exported value (in
which case we haven't yet inserted its own references).

To address this we can restructure the way the export list is
constructed. This patch only adds the actual imported definitions
(variable or function) to the export list for its module during the
import computation. After import computation is complete, where we were
already post-processing the export list we go ahead and add all
references made by those exported values to the export list.

These changes speed up the thin link not only with constant variable
importing enabled, but also without (due to the efficiency improvement
in function importing).

Some thin link user time measurements for one large application, average
of 5 runs:

With constant variable importing enabled:
- without this patch: 479.5s
- with this patch: 74.6s

Without constant variable importing enabled:
- without this patch: 80.6s
- with this patch: 70.3s

Note I have not re-enabled constant variable importing here, as I would
like to do additional compile time measurements with these fixes first.

Reviewers: evgeny777

Subscribers: mehdi_amini, inglorion, hiraditya, dexonsmith, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73851
2020-02-03 09:15:33 -08:00
..
AlwaysInliner.cpp [NFC] Refactor InlineResult for readability 2020-01-15 13:34:20 -08:00
ArgumentPromotion.cpp [Attributor] Pointer privatization attribute (argument promotion) 2020-01-29 21:31:04 -06:00
Attributor.cpp [Attributor] AANoRecurse check all call sites for `norecurse` 2020-02-02 23:57:17 -06:00
BarrierNoopPass.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
BlockExtractor.cpp Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
CMakeLists.txt [cmake] Explicitly mark libraries defined in lib/ as "Component Libraries" 2019-11-21 10:48:08 -08:00
CalledValuePropagation.cpp Add missing includes needed to prune LLVMContext.h include, NFC 2019-11-14 15:23:15 -08:00
ConstantMerge.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
CrossDSOCFI.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
DeadArgumentElimination.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
ElimAvailExtern.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
ExtractGV.cpp [llvm-extract] Add -keep-const-init commandline option 2020-02-03 14:30:28 +09:00
ForceFunctionAttrs.cpp Add missing includes needed to prune LLVMContext.h include, NFC 2019-11-14 15:23:15 -08:00
FunctionAttrs.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
FunctionImport.cpp [ThinLTO] More efficient export computation (NFC) 2020-02-03 09:15:33 -08:00
GlobalDCE.cpp [WPD/VFE] Always emit vcall_visibility metadata for -fwhole-program-vtables 2020-01-23 11:36:01 -08:00
GlobalOpt.cpp Revert "Recommit "[GlobalOpt] Pass DTU to removeUnreachableBlocks instead of recomputing."" 2020-01-14 14:50:07 +00:00
GlobalSplit.cpp [WPD/VFE] Always emit vcall_visibility metadata for -fwhole-program-vtables 2020-01-23 11:36:01 -08:00
HotColdSplitting.cpp HotColdSplitting: Do not outline within noreturn functions 2019-12-19 14:06:24 -08:00
IPConstantPropagation.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
IPO.cpp [NewPM] Port MergeFunctions pass 2020-01-14 20:55:41 +01:00
InferFunctionAttrs.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
InlineSimple.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
Inliner.cpp [NFC] Refactor InlineResult for readability 2020-01-15 13:34:20 -08:00
Internalize.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
LLVMBuild.txt Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
LoopExtractor.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
LowerTypeTests.cpp Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
MergeFunctions.cpp [NewPM] Port MergeFunctions pass 2020-01-14 20:55:41 +01:00
PartialInlining.cpp [NFC] Refactor InlineResult for readability 2020-01-15 13:34:20 -08:00
PassManagerBuilder.cpp [PassManagerBuilder] Remove global extension when a plugin is unloaded 2020-01-29 16:15:45 +00:00
PruneEH.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
SCCP.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
SampleProfile.cpp Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
StripDeadPrototypes.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
StripSymbols.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
SyntheticCountsPropagation.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ThinLTOBitcodeWriter.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
WholeProgramDevirt.cpp Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00