llvm/lib/Transforms/IPO
James Molloy fb7bc35602 [GlobalOpt] Demote globals to locals more aggressively
Global to local demotion can speed up programs that use globals a lot. It is particularly useful with LTO, when the entire call graph is known and most functions have been internalized.

For a global to be demoted, it must only be accessed by one function and that function:
  1. Must never recurse directly or indirectly, else the GV would be clobbered.
  2. Must never rely on the value in GV at the start of the function (apart from the initializer).

GlobalOpt can already do this, but it is hamstrung and only ever tries to demote globals inside "main", because C++ gives extra guarantees about how main is called - once and only once.

In LTO mode, we can often prove the first property (if the function is internal by this point, we know enough about the callgraph to determine if it could possibly recurse). FunctionAttrs now infers the "norecurse" attribute for this reason.

The second property can be proven for a subset of functions by proving that all loads from GV are dominated by a store to GV. This is conservative in the name of compile time - this only requires a DominatorTree which is fairly cheap in the grand scheme of things. We could do more fancy stuff with MemoryDependenceAnalysis too to catch more cases but this appears to catch most of the useful ones in my testing.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253168 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-15 14:21:37 +00:00
..
ArgumentPromotion.cpp DI: Reverse direction of subprogram -> function edge. 2015-11-05 22:03:56 +00:00
BarrierNoopPass.cpp Revert r240137 (Fixed/added namespace ending comments using clang-tidy. NFC) 2015-06-23 09:49:53 +00:00
CMakeLists.txt Convert SampleProfile pass into a Module pass. 2015-08-25 15:25:11 +00:00
ConstantMerge.cpp IPO: Remove implicit ilist iterator conversions, NFC 2015-10-13 17:51:03 +00:00
DeadArgumentElimination.cpp DI: Reverse direction of subprogram -> function edge. 2015-11-05 22:03:56 +00:00
ElimAvailExtern.cpp Restore "Support for ThinLTO function importing and symbol linking." 2015-11-03 00:14:15 +00:00
ExtractGV.cpp IPO: Remove implicit ilist iterator conversions, NFC 2015-10-13 17:51:03 +00:00
FunctionAttrs.cpp Revert "Revert "[FunctionAttrs] Identify norecurse functions"" 2015-11-12 10:55:20 +00:00
GlobalDCE.cpp Rangify for loops in GlobalDCE, NFC. 2015-07-18 19:57:34 +00:00
GlobalOpt.cpp [GlobalOpt] Demote globals to locals more aggressively 2015-11-15 14:21:37 +00:00
InlineAlways.cpp [PM/AA] Rebuild LLVM's alias analysis infrastructure in a way compatible 2015-09-09 17:55:00 +00:00
Inliner.cpp Revert r252990. 2015-11-13 01:44:32 +00:00
InlineSimple.cpp [PM/AA] Rebuild LLVM's alias analysis infrastructure in a way compatible 2015-09-09 17:55:00 +00:00
Internalize.cpp IPO: Remove implicit ilist iterator conversions, NFC 2015-10-13 17:51:03 +00:00
IPConstantPropagation.cpp Revert r240137 (Fixed/added namespace ending comments using clang-tidy. NFC) 2015-06-23 09:49:53 +00:00
IPO.cpp [PM] Port StripDeadPrototypes to the new pass manager 2015-10-30 23:28:12 +00:00
LLVMBuild.txt Update libdeps in LLVMipo and LLVMScalarOpts, corresponding to r245940. 2015-08-25 17:11:17 +00:00
LoopExtractor.cpp IPO: Remove implicit ilist iterator conversions, NFC 2015-10-13 17:51:03 +00:00
LowerBitSets.cpp Fix Clang-tidy modernize-use-nullptr warnings in source directories and generated files; other minor cleanups. 2015-10-06 23:24:35 +00:00
Makefile
MergeFunctions.cpp [IR] Add support for empty tokens 2015-11-11 21:57:16 +00:00
PartialInlining.cpp IPO: Remove implicit ilist iterator conversions, NFC 2015-10-13 17:51:03 +00:00
PassManagerBuilder.cpp LLE 6/6: Add LoopLoadElimination pass 2015-11-03 23:50:08 +00:00
PruneEH.cpp IPO: Remove implicit ilist iterator conversions, NFC 2015-10-13 17:51:03 +00:00
SampleProfile.cpp StringRef-ify DiagnosticInfoSampleProfile::Filename 2015-11-02 20:01:13 +00:00
StripDeadPrototypes.cpp [PM] Port StripDeadPrototypes to the new pass manager 2015-10-30 23:28:12 +00:00
StripSymbols.cpp DI: Reverse direction of subprogram -> function edge. 2015-11-05 22:03:56 +00:00