diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2012-11-30 09:26:25 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2012-11-30 09:26:25 +0000 |
commit | 06ec7211c17a4b45a943c36e0fb3d6715aa2453d (patch) | |
tree | 0e94e2169c89c4b65ed0c48ae3e2d99b01d7dbc2 /lib/Transforms/Utils/SimplifyCFG.cpp | |
parent | 67587f462e746e538322fbf7929b8db5de25ced7 (diff) |
Rearrange the comments, control flow, and variable names; no
functionality changed.
Evan's commit r168970 moved the code that the primary comment in this
function referred to to the other end of the function without moving the
comment, and there has been a steady creep of "boolean" logic in it that
is simpler if handled via early exit. That way each special case can
have its own comments. I've also made the variable name a bit more
explanatory than "AllFit". This is in preparation to fix the
non-deterministic output of this function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168988 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r-- | lib/Transforms/Utils/SimplifyCFG.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 611e466719..5a1b21025c 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -3513,14 +3513,10 @@ static bool ShouldBuildLookupTable(SwitchInst *SI, const DataLayout *TD, const TargetTransformInfo *TTI, const SmallDenseMap<PHINode*, Type*>& ResultTypes) { - // The table density should be at least 40%. This is the same criterion as for - // jump tables, see SelectionDAGBuilder::handleJTSwitchCase. - // FIXME: Find the best cut-off. if (SI->getNumCases() > TableSize || TableSize >= UINT64_MAX / 10) return false; // TableSize overflowed, or mul below might overflow. - // If each table would fit in a register, we should build it anyway. - bool AllFit = true; + bool AllTablesFitInRegister = true; bool HasIllegalType = false; for (SmallDenseMap<PHINode*, Type*>::const_iterator I = ResultTypes.begin(), E = ResultTypes.end(); I != E; ++I) { @@ -3528,12 +3524,23 @@ static bool ShouldBuildLookupTable(SwitchInst *SI, if (!TTI->getScalarTargetTransformInfo()->isTypeLegal(Ty)) HasIllegalType = true; if (!SwitchLookupTable::WouldFitInRegister(TD, TableSize, Ty)) { - AllFit = false; + AllTablesFitInRegister = false; break; } } - return AllFit || (!HasIllegalType && (SI->getNumCases() * 10 >= TableSize * 4)); + // If each table would fit in a register, we should build it anyway. + if (AllTablesFitInRegister) + return true; + + // Don't build a table that doesn't fit in-register if it has illegal types. + if (HasIllegalType) + return false; + + // The table density should be at least 40%. This is the same criterion as for + // jump tables, see SelectionDAGBuilder::handleJTSwitchCase. + // FIXME: Find the best cut-off. + return SI->getNumCases() * 10 >= TableSize * 4; } /// SwitchToLookupTable - If the switch is only used to initialize one or more |