llvm-6502/lib/Transforms/Scalar
Diego Novillo 0de8cecb84 Propagation of profile samples through the CFG.
This adds a propagation heuristic to convert instruction samples
into branch weights. It implements a similar heuristic to the one
implemented by Dehao Chen on GCC.

The propagation proceeds in 3 phases:

1- Assignment of block weights. All the basic blocks in the function
   are initial assigned the same weight as their most frequently
   executed instruction.

2- Creation of equivalence classes. Since samples may be missing from
   blocks, we can fill in the gaps by setting the weights of all the
   blocks in the same equivalence class to the same weight. To compute
   the concept of equivalence, we use dominance and loop information.
   Two blocks B1 and B2 are in the same equivalence class if B1
   dominates B2, B2 post-dominates B1 and both are in the same loop.

3- Propagation of block weights into edges. This uses a simple
   propagation heuristic. The following rules are applied to every
   block B in the CFG:

   - If B has a single predecessor/successor, then the weight
     of that edge is the weight of the block.

   - If all the edges are known except one, and the weight of the
     block is already known, the weight of the unknown edge will
     be the weight of the block minus the sum of all the known
     edges. If the sum of all the known edges is larger than B's weight,
     we set the unknown edge weight to zero.

   - If there is a self-referential edge, and the weight of the block is
     known, the weight for that edge is set to the weight of the block
     minus the weight of the other incoming edges to that block (if
     known).

Since this propagation is not guaranteed to finalize for every CFG, we
only allow it to proceed for a limited number of iterations (controlled
by -sample-profile-max-propagate-iterations). It currently uses the same
GCC default of 100.

Before propagation starts, the pass builds (for each block) a list of
unique predecessors and successors. This is necessary to handle
identical edges in multiway branches. Since we visit all blocks and all
edges of the CFG, it is cleaner to build these lists once at the start
of the pass.

Finally, the patch fixes the computation of relative line locations.
The profiler emits lines relative to the function header. To discover
it, we traverse the compilation unit looking for the subprogram
corresponding to the function. The line number of that subprogram is the
line where the function begins. That becomes line zero for all the
relative locations.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198972 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-10 23:23:46 +00:00
..
ADCE.cpp Use SmallVectorImpl::iterator/const_iterator instead of SmallVector to avoid specifying the vector size. 2013-07-04 01:31:24 +00:00
CMakeLists.txt Add a Scalarizer pass. 2013-11-22 16:58:05 +00:00
CodeGenPrepare.cpp Put the functionality for printing a value to a raw_ostream as an 2014-01-09 02:29:41 +00:00
ConstantProp.cpp Move all of the header files which are involved in modelling the LLVM IR 2013-01-02 11:36:10 +00:00
CorrelatedValuePropagation.cpp CVP: If we have a PHI with an incoming select, try to skip the select. 2013-02-24 15:34:43 +00:00
DCE.cpp Move all of the header files which are involved in modelling the LLVM IR 2013-01-02 11:36:10 +00:00
DeadStoreElimination.cpp Change GetPointerBaseWithConstantOffset's DataLayout argument from a 2013-01-31 02:00:45 +00:00
EarlyCSE.cpp Change std::deque => std::vector. No functionality change. 2013-12-05 18:42:12 +00:00
FlattenCFGPass.cpp Factor FlattenCFG out from SimplifyCFG 2013-08-06 02:43:45 +00:00
GlobalMerge.cpp Change tabs to spaces. 2013-07-22 21:11:30 +00:00
GVN.cpp Put the functionality for printing a value to a raw_ostream as an 2014-01-09 02:29:41 +00:00
IndVarSimplify.cpp Reapply r198654 "indvars: sink truncates outside the loop." 2014-01-07 06:59:12 +00:00
JumpThreading.cpp Don't eliminate a partially redundant load if it's in a landing pad. 2013-10-21 04:09:17 +00:00
LICM.cpp LICM: Hoist insertvalue/extractvalue out of loops. 2013-01-09 18:12:03 +00:00
LLVMBuild.txt Add proper dependencies to LLVMBuild.txt in llvm/lib. 2013-12-10 05:39:34 +00:00
LoopDeletion.cpp Use SmallVectorImpl& instead of SmallVector to avoid repeating small vector size. 2013-07-14 04:42:23 +00:00
LoopIdiomRecognize.cpp Don't #include heavy Dominators.h file in LoopInfo.h. This change reduces 2013-12-07 21:20:17 +00:00
LoopInstSimplify.cpp Re-sort all of the includes with ./utils/sort_includes.py so that 2014-01-07 11:48:04 +00:00
LoopRerollPass.cpp Re-sort all of the includes with ./utils/sort_includes.py so that 2014-01-07 11:48:04 +00:00
LoopRotation.cpp Don't #include heavy Dominators.h file in LoopInfo.h. This change reduces 2013-12-07 21:20:17 +00:00
LoopStrengthReduce.cpp Put the functionality for printing a value to a raw_ostream as an 2014-01-09 02:29:41 +00:00
LoopUnrollPass.cpp Don't #include heavy Dominators.h file in LoopInfo.h. This change reduces 2013-12-07 21:20:17 +00:00
LoopUnswitch.cpp Remove dead code from LoopUnswitch 2013-11-08 19:58:21 +00:00
LowerAtomic.cpp Move all of the header files which are involved in modelling the LLVM IR 2013-01-02 11:36:10 +00:00
Makefile
MemCpyOptimizer.cpp MemCpyOptimizer: Use max legal int size instead of pointer size 2013-09-16 22:43:16 +00:00
PartiallyInlineLibCalls.cpp Turn MipsOptimizeMathLibCalls into a target-independent scalar transform 2013-08-23 10:27:02 +00:00
Reassociate.cpp Put the functionality for printing a value to a raw_ostream as an 2014-01-09 02:29:41 +00:00
Reg2Mem.cpp Move all of the header files which are involved in modelling the LLVM IR 2013-01-02 11:36:10 +00:00
SampleProfile.cpp Propagation of profile samples through the CFG. 2014-01-10 23:23:46 +00:00
Scalar.cpp Add a Scalarizer pass. 2013-11-22 16:58:05 +00:00
Scalarizer.cpp Fix Scalarizer insertion point when replacing PHIs with insertelements 2013-12-23 14:51:56 +00:00
ScalarReplAggregates.cpp Correct word hyphenations 2013-12-05 05:44:44 +00:00
SCCP.cpp Use SmallVectorImpl& instead of SmallVector to avoid repeating small vector size. 2013-07-14 04:42:23 +00:00
SimplifyCFGPass.cpp Reapply r188119 now that the bug it exposed is fixed. 2013-08-12 22:38:43 +00:00
Sink.cpp Put the functionality for printing a value to a raw_ostream as an 2014-01-09 02:29:41 +00:00
SROA.cpp Add missed cleanup from r198456 2014-01-04 22:47:48 +00:00
StructurizeCFG.cpp StructurizeCFG: Fix verification failure with some loops. 2013-11-22 19:24:39 +00:00
TailRecursionElimination.cpp TRE: Move class into anonymous namespace. 2013-07-24 16:12:08 +00:00