1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00
llvm-mirror/include/llvm/Analysis
Jun Bum Lim 93f61e6588 [InlineCost] Improve the cost heuristic for Switch
Summary:
The motivation example is like below which has 13 cases but only 2 distinct targets

```
lor.lhs.false2:                                   ; preds = %if.then
  switch i32 %Status, label %if.then27 [
    i32 -7012, label %if.end35
    i32 -10008, label %if.end35
    i32 -10016, label %if.end35
    i32 15000, label %if.end35
    i32 14013, label %if.end35
    i32 10114, label %if.end35
    i32 10107, label %if.end35
    i32 10105, label %if.end35
    i32 10013, label %if.end35
    i32 10011, label %if.end35
    i32 7008, label %if.end35
    i32 7007, label %if.end35
    i32 5002, label %if.end35
  ]
```
which is compiled into a balanced binary tree like this on AArch64 (similar on X86)

```
.LBB853_9:                              // %lor.lhs.false2
        mov     w8, #10012
        cmp             w19, w8
        b.gt    .LBB853_14
// BB#10:                               // %lor.lhs.false2
        mov     w8, #5001
        cmp             w19, w8
        b.gt    .LBB853_18
// BB#11:                               // %lor.lhs.false2
        mov     w8, #-10016
        cmp             w19, w8
        b.eq    .LBB853_23
// BB#12:                               // %lor.lhs.false2
        mov     w8, #-10008
        cmp             w19, w8
        b.eq    .LBB853_23
// BB#13:                               // %lor.lhs.false2
        mov     w8, #-7012
        cmp             w19, w8
        b.eq    .LBB853_23
        b       .LBB853_3
.LBB853_14:                             // %lor.lhs.false2
        mov     w8, #14012
        cmp             w19, w8
        b.gt    .LBB853_21
// BB#15:                               // %lor.lhs.false2
        mov     w8, #-10105
        add             w8, w19, w8
        cmp             w8, #9          // =9
        b.hi    .LBB853_17
// BB#16:                               // %lor.lhs.false2
        orr     w9, wzr, #0x1
        lsl     w8, w9, w8
        mov     w9, #517
        and             w8, w8, w9
        cbnz    w8, .LBB853_23
.LBB853_17:                             // %lor.lhs.false2
        mov     w8, #10013
        cmp             w19, w8
        b.eq    .LBB853_23
        b       .LBB853_3
.LBB853_18:                             // %lor.lhs.false2
        mov     w8, #-7007
        add             w8, w19, w8
        cmp             w8, #2          // =2
        b.lo    .LBB853_23
// BB#19:                               // %lor.lhs.false2
        mov     w8, #5002
        cmp             w19, w8
        b.eq    .LBB853_23
// BB#20:                               // %lor.lhs.false2
        mov     w8, #10011
        cmp             w19, w8
        b.eq    .LBB853_23
        b       .LBB853_3
.LBB853_21:                             // %lor.lhs.false2
        mov     w8, #14013
        cmp             w19, w8
        b.eq    .LBB853_23
// BB#22:                               // %lor.lhs.false2
        mov     w8, #15000
        cmp             w19, w8
        b.ne    .LBB853_3
```
However, the inline cost model estimates the cost to be linear with the number
of distinct targets and the cost of the above switch is just 2 InstrCosts.
The function containing this switch is then inlined about 900 times.

This change use the general way of switch lowering for the inline heuristic. It
etimate the number of case clusters with the suitability check for a jump table
or bit test. Considering the binary search tree built for the clusters, this
change modifies the model to be linear with the size of the balanced binary
tree. The model is off by default for now :
  -inline-generic-switch-cost=false

This change was originally proposed by Haicheng in D29870.

Reviewers: hans, bmakam, chandlerc, eraman, haicheng, mcrosier

Reviewed By: hans

Subscribers: joerg, aemerson, llvm-commits, rengolin

Differential Revision: https://reviews.llvm.org/D31085

llvm-svn: 301649
2017-04-28 16:04:03 +00:00
..
AliasAnalysis.h AliasAnalysis: Be less conservative about volatile than atomic. 2017-04-07 01:28:36 +00:00
AliasAnalysisEvaluator.h
AliasSetTracker.h Use WeakVH instead of WeakTrackingVH in AliasSetTracker's UnkownInsts 2017-04-26 16:21:02 +00:00
AssumptionCache.h Reverts commit r301424, r301425 and r301426 2017-04-26 16:37:05 +00:00
BasicAliasAnalysis.h De-duplicate some code for creating an AARGetter suitable for the legacy PM. 2017-02-09 23:11:52 +00:00
BlockFrequencyInfo.h
BlockFrequencyInfoImpl.h Cleanup some GraphTraits iteration code 2017-04-19 03:22:50 +00:00
BranchProbabilityInfo.h [BPI] Refactor post domination calculation and simple fix for ColdCall 2017-04-12 05:42:14 +00:00
CallGraph.h Reverts commit r301424, r301425 and r301426 2017-04-26 16:37:05 +00:00
CallGraphSCCPass.h
CallPrinter.h
CaptureTracking.h
CFG.h
CFGPrinter.h [IR] Redesign the case iterator in SwitchInst to actually be an iterator 2017-04-12 07:27:28 +00:00
CFLAndersAliasAnalysis.h
CFLSteensAliasAnalysis.h
CGSCCPassManager.h Reverts commit r301424, r301425 and r301426 2017-04-26 16:37:05 +00:00
CodeMetrics.h
ConstantFolding.h InstSimplify: Add a hook for shufflevector 2017-04-03 22:05:30 +00:00
DemandedBits.h [ValueTracking] Introduce a KnownBits struct to wrap the two APInts for computeKnownBits 2017-04-26 16:39:58 +00:00
DependenceAnalysis.h
DivergenceAnalysis.h
DominanceFrontier.h
DominanceFrontierImpl.h Cleanup some GraphTraits iteration code 2017-04-19 03:22:50 +00:00
DomPrinter.h
DOTGraphTraitsPass.h
EHPersonalities.h
GlobalsModRef.h
IndirectCallPromotionAnalysis.h
IndirectCallSiteVisitor.h
InlineCost.h
InstructionSimplify.h Kill the old Simplify* APIs, leave SimplifyInstruction for the moment 2017-04-26 20:56:17 +00:00
Interval.h
IntervalIterator.h
IntervalPartition.h
IteratedDominanceFrontier.h
IVUsers.h Reverts commit r301424, r301425 and r301426 2017-04-26 16:37:05 +00:00
LazyBlockFrequencyInfo.h [LazyBFI] Fix typos 2017-02-14 17:21:12 +00:00
LazyBranchProbabilityInfo.h Add new pass LazyMachineBlockFrequencyInfo 2017-02-14 17:21:09 +00:00
LazyCallGraph.h [PM/LCG] Teach the LazyCallGraph how to replace a function without 2017-02-09 23:24:13 +00:00
LazyValueInfo.h [LVI] Add an LVI printer pass to capture test LVI cache after transformations 2017-03-22 19:27:12 +00:00
Lint.h
Loads.h Extract FindAvailablePtrLoadStore out of FindAvailableLoadedValue. NFCI 2017-03-19 15:27:52 +00:00
LoopAccessAnalysis.h [SLP] Revert everything that has to do with memory access sorting. 2017-03-10 18:59:07 +00:00
LoopAnalysisManager.h Revert r293017 and fix the actual underlying issue. 2017-02-07 01:50:48 +00:00
LoopInfo.h Avoid unnecessary copies in some for loops 2017-04-24 20:01:03 +00:00
LoopInfoImpl.h Avoid unnecessary copies in some for loops 2017-04-24 20:01:03 +00:00
LoopIterator.h
LoopPass.h
LoopUnrollAnalyzer.h
MemoryBuiltins.h Reverts commit r301424, r301425 and r301426 2017-04-26 16:37:05 +00:00
MemoryDependenceAnalysis.h
MemoryLocation.h
MemorySSA.h MemorySSA: Move to Analysis, from Transforms/Utils. It's used as 2017-04-11 20:06:36 +00:00
MemorySSAUpdater.h MemorySSA: Move to Analysis, from Transforms/Utils. It's used as 2017-04-11 20:06:36 +00:00
ModuleSummaryAnalysis.h
ObjCARCAliasAnalysis.h
ObjCARCAnalysisUtils.h
ObjCARCInstKind.h
ObjectUtils.h Move llvm::canBeOmittedFromSymbolTable() to Analysis. 2017-03-31 04:46:31 +00:00
OptimizationDiagnosticInfo.h [ORE] Remove ORE.emit{{.+}} functions 2017-02-23 21:32:53 +00:00
OrderedBasicBlock.h
Passes.h
PHITransAddr.h
PostDominators.h
ProfileSummaryInfo.h Use isFunctionHotInCallGraph to set the function section prefix. 2017-03-23 23:14:11 +00:00
PtrUseVisitor.h [IR/Analysis] Defend against getting slightly wrong template arguments 2017-02-07 03:17:30 +00:00
RegionInfo.h [RegionInfo] Fix dangling references created by moving RegionInfo objects 2017-04-24 11:54:37 +00:00
RegionInfoImpl.h
RegionIterator.h
RegionPass.h
RegionPrinter.h
ScalarEvolution.h [SCEV] Fix exponential time complexity by caching 2017-04-24 00:09:46 +00:00
ScalarEvolutionAliasAnalysis.h
ScalarEvolutionExpander.h Reverts commit r301424, r301425 and r301426 2017-04-26 16:37:05 +00:00
ScalarEvolutionExpressions.h Use range-for in a few places 2017-04-14 17:42:12 +00:00
ScalarEvolutionNormalization.h Add missing #include 2017-04-14 17:25:23 +00:00
ScopedNoAliasAA.h
SparsePropagation.h
TargetFolder.h
TargetLibraryInfo.def
TargetLibraryInfo.h
TargetTransformInfo.h [InlineCost] Improve the cost heuristic for Switch 2017-04-28 16:04:03 +00:00
TargetTransformInfoImpl.h [InlineCost] Improve the cost heuristic for Switch 2017-04-28 16:04:03 +00:00
Trace.h
TypeBasedAliasAnalysis.h
TypeMetadataUtils.h
ValueTracking.h [ValueTracking] Convert computeKnownBitsFromRangeMetadata to use KnownBits struct. 2017-04-28 06:28:56 +00:00
VectorUtils.h