llvm.org GIT mirror llvm / 06ec721
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 Chandler Carruth 6 years ago
1 changed file(s) with 14 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
35123512 const DataLayout *TD,
35133513 const TargetTransformInfo *TTI,
35143514 const SmallDenseMap& ResultTypes) {
3515 // The table density should be at least 40%. This is the same criterion as for
3516 // jump tables, see SelectionDAGBuilder::handleJTSwitchCase.
3517 // FIXME: Find the best cut-off.
35183515 if (SI->getNumCases() > TableSize || TableSize >= UINT64_MAX / 10)
35193516 return false; // TableSize overflowed, or mul below might overflow.
35203517
3521 // If each table would fit in a register, we should build it anyway.
3522 bool AllFit = true;
3518 bool AllTablesFitInRegister = true;
35233519 bool HasIllegalType = false;
35243520 for (SmallDenseMap::const_iterator I = ResultTypes.begin(),
35253521 E = ResultTypes.end(); I != E; ++I) {
35273523 if (!TTI->getScalarTargetTransformInfo()->isTypeLegal(Ty))
35283524 HasIllegalType = true;
35293525 if (!SwitchLookupTable::WouldFitInRegister(TD, TableSize, Ty)) {
3530 AllFit = false;
3526 AllTablesFitInRegister = false;
35313527 break;
35323528 }
35333529 }
35343530
3535 return AllFit || (!HasIllegalType && (SI->getNumCases() * 10 >= TableSize * 4));
3531 // If each table would fit in a register, we should build it anyway.
3532 if (AllTablesFitInRegister)
3533 return true;
3534
3535 // Don't build a table that doesn't fit in-register if it has illegal types.
3536 if (HasIllegalType)
3537 return false;
3538
3539 // The table density should be at least 40%. This is the same criterion as for
3540 // jump tables, see SelectionDAGBuilder::handleJTSwitchCase.
3541 // FIXME: Find the best cut-off.
3542 return SI->getNumCases() * 10 >= TableSize * 4;
35363543 }
35373544
35383545 /// SwitchToLookupTable - If the switch is only used to initialize one or more