llvm.org GIT mirror llvm / 03ef7f1
Move whole-program virtual call optimization pass after function attribute inference in LTO pipeline. 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. Differential Revision: http://reviews.llvm.org/D20643 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270765 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 3 years ago
2 changed file(s) with 28 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
160160 legacy::PassManagerBase &PM) const;
161161 void addInitialAliasAnalysisPasses(legacy::PassManagerBase &PM) const;
162162 void addLTOOptimizationPasses(legacy::PassManagerBase &PM);
163 void addEarlyLTOOptimizationPasses(legacy::PassManagerBase &PM);
164163 void addLateLTOOptimizationPasses(legacy::PassManagerBase &PM);
165164 void addPGOInstrPasses(legacy::PassManagerBase &MPM);
166165 void addFunctionSimplificationPasses(legacy::PassManagerBase &MPM);
566566 }
567567
568568 void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
569 // Remove unused virtual tables to improve the quality of code generated by
570 // whole-program devirtualization and bitset lowering.
571 PM.add(createGlobalDCEPass());
572
569573 // Provide AliasAnalysis services for optimizations.
570574 addInitialAliasAnalysisPasses(PM);
571575
578582 // Infer attributes about declarations if possible.
579583 PM.add(createInferFunctionAttrsLegacyPass());
580584
581 // Indirect call promotion. This should promote all the targets that are left
582 // by the earlier promotion pass that promotes intra-module targets.
583 // This two-step promotion is to save the compile time. For LTO, it should
584 // produce the same result as if we only do promotion here.
585 PM.add(createPGOIndirectCallPromotionLegacyPass(true));
586
587 // Propagate constants at call sites into the functions they call. This
588 // opens opportunities for globalopt (and inlining) by substituting function
589 // pointers passed as arguments to direct uses of functions.
590 PM.add(createIPSCCPPass());
591
592 // Now that we internalized some globals, see if we can hack on them!
585 if (OptLevel > 1) {
586 // Indirect call promotion. This should promote all the targets that are
587 // left by the earlier promotion pass that promotes intra-module targets.
588 // This two-step promotion is to save the compile time. For LTO, it should
589 // produce the same result as if we only do promotion here.
590 PM.add(createPGOIndirectCallPromotionLegacyPass(true));
591
592 // Propagate constants at call sites into the functions they call. This
593 // opens opportunities for globalopt (and inlining) by substituting function
594 // pointers passed as arguments to direct uses of functions.
595 PM.add(createIPSCCPPass());
596 }
597
598 // Infer attributes about definitions. The readnone attribute in particular is
599 // required for virtual constant propagation.
593600 PM.add(createPostOrderFunctionAttrsLegacyPass());
594601 PM.add(createReversePostOrderFunctionAttrsPass());
602
603 // Apply whole-program devirtualization and virtual constant propagation.
604 PM.add(createWholeProgramDevirtPass());
605
606 // That's all we need at opt level 1.
607 if (OptLevel == 1)
608 return;
609
610 // Now that we internalized some globals, see if we can hack on them!
595611 PM.add(createGlobalOptimizerPass());
596612 // Promote any localized global vars.
597613 PM.add(createPromoteMemoryToRegisterPass());
693709 PM.add(createJumpThreadingPass());
694710 }
695711
696 void PassManagerBuilder::addEarlyLTOOptimizationPasses(
697 legacy::PassManagerBase &PM) {
698 // Remove unused virtual tables to improve the quality of code generated by
699 // whole-program devirtualization and bitset lowering.
700 PM.add(createGlobalDCEPass());
701
702 // Apply whole-program devirtualization and virtual constant propagation.
703 PM.add(createWholeProgramDevirtPass());
704 }
705
706712 void PassManagerBuilder::addLateLTOOptimizationPasses(
707713 legacy::PassManagerBase &PM) {
708714 // Delete basic blocks, which optimization passes may have killed.
745751 PM.add(createVerifierPass());
746752
747753 if (OptLevel != 0)
748 addEarlyLTOOptimizationPasses(PM);
749
750 if (OptLevel > 1)
751754 addLTOOptimizationPasses(PM);
752755
753756 // Create a function that performs CFI checks for cross-DSO calls with targets