[PATCH] D20643: Move whole-program virtual call optimization pass after function attribute inference in LTO pipeline.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Wed May 25 14:04:34 PDT 2016
pcc created this revision.
pcc added reviewers: pete, mehdi_amini, chandlerc.
pcc added subscribers: llvm-commits, krasin.
Herald added a subscriber: mehdi_amini.
As a result of D18634 we no longer infer certain attributes on linkonce_odr
functions at compile time, and may only infer them at LTO time. The readnone
attribute in particular is required for virtual constant propagation (part
of whole-program virtual call optimization) to work correctly.
This change moves the whole-program virtual call optimization pass after
the function attribute inference passes, and enables the attribute inference
passes at opt level 1, so that virtual constant propagation has a chance to
work correctly for linkonce_odr functions.
http://reviews.llvm.org/D20643
Files:
lib/Transforms/IPO/PassManagerBuilder.cpp
Index: lib/Transforms/IPO/PassManagerBuilder.cpp
===================================================================
--- lib/Transforms/IPO/PassManagerBuilder.cpp
+++ lib/Transforms/IPO/PassManagerBuilder.cpp
@@ -567,6 +567,10 @@
}
void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
+ // Remove unused virtual tables to improve the quality of code generated by
+ // whole-program devirtualization and bitset lowering.
+ PM.add(createGlobalDCEPass());
+
// Provide AliasAnalysis services for optimizations.
addInitialAliasAnalysisPasses(PM);
@@ -585,14 +589,26 @@
// produce the same result as if we only do promotion here.
PM.add(createPGOIndirectCallPromotionLegacyPass(true));
- // Propagate constants at call sites into the functions they call. This
- // opens opportunities for globalopt (and inlining) by substituting function
- // pointers passed as arguments to direct uses of functions.
- PM.add(createIPSCCPPass());
+ if (OptLevel > 1) {
+ // Propagate constants at call sites into the functions they call. This
+ // opens opportunities for globalopt (and inlining) by substituting function
+ // pointers passed as arguments to direct uses of functions.
+ PM.add(createIPSCCPPass());
+ }
- // Now that we internalized some globals, see if we can hack on them!
+ // Infer attributes about definitions. The readnone attribute in particular is
+ // required for virtual constant propagation.
PM.add(createPostOrderFunctionAttrsLegacyPass());
PM.add(createReversePostOrderFunctionAttrsPass());
+
+ // Apply whole-program devirtualization and virtual constant propagation.
+ PM.add(createWholeProgramDevirtPass());
+
+ // That's all we need at opt level 1.
+ if (OptLevel == 1)
+ return;
+
+ // Now that we internalized some globals, see if we can hack on them!
PM.add(createGlobalOptimizerPass());
// Promote any localized global vars.
PM.add(createPromoteMemoryToRegisterPass());
@@ -694,16 +710,6 @@
PM.add(createJumpThreadingPass());
}
-void PassManagerBuilder::addEarlyLTOOptimizationPasses(
- legacy::PassManagerBase &PM) {
- // Remove unused virtual tables to improve the quality of code generated by
- // whole-program devirtualization and bitset lowering.
- PM.add(createGlobalDCEPass());
-
- // Apply whole-program devirtualization and virtual constant propagation.
- PM.add(createWholeProgramDevirtPass());
-}
-
void PassManagerBuilder::addLateLTOOptimizationPasses(
legacy::PassManagerBase &PM) {
// Delete basic blocks, which optimization passes may have killed.
@@ -746,9 +752,6 @@
PM.add(createVerifierPass());
if (OptLevel != 0)
- addEarlyLTOOptimizationPasses(PM);
-
- if (OptLevel > 1)
addLTOOptimizationPasses(PM);
// Create a function that performs CFI checks for cross-DSO calls with targets
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20643.58503.patch
Type: text/x-patch
Size: 2865 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160525/961f931a/attachment.bin>
More information about the llvm-commits
mailing list