| OLD | NEW |
| 1 //===- subzero/src/IceSwitchLowering.cpp - Switch lowering -----------------==// | 1 //===- subzero/src/IceSwitchLowering.cpp - Switch lowering -----------------==// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 /// | 9 /// |
| 10 /// \file | 10 /// \file |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 if (NumCases * 2 <= TotalRange) | 68 if (NumCases * 2 <= TotalRange) |
| 69 return CaseClusters; | 69 return CaseClusters; |
| 70 // Unlikely. Would mean can't store size of jump table. | 70 // Unlikely. Would mean can't store size of jump table. |
| 71 if (TotalRange == UINT64_MAX) | 71 if (TotalRange == UINT64_MAX) |
| 72 return CaseClusters; | 72 return CaseClusters; |
| 73 ++TotalRange; | 73 ++TotalRange; |
| 74 | 74 |
| 75 // Replace everything with a jump table | 75 // Replace everything with a jump table |
| 76 InstJumpTable *JumpTable = | 76 InstJumpTable *JumpTable = |
| 77 InstJumpTable::create(Func, TotalRange, Inst->getLabelDefault()); | 77 InstJumpTable::create(Func, TotalRange, Inst->getLabelDefault()); |
| 78 for (const CaseCluster &Case : CaseClusters) | 78 for (const CaseCluster &Case : CaseClusters) { |
| 79 for (uint64_t I = Case.Low; I <= Case.High; ++I) | 79 // Case.High could be UINT64_MAX which makes the loop awkward. Unwrap the |
| 80 // last iteration to avoid wrap around problems. |
| 81 for (uint64_t I = Case.Low; I < Case.High; ++I) |
| 80 JumpTable->addTarget(I - MinValue, Case.Label); | 82 JumpTable->addTarget(I - MinValue, Case.Label); |
| 83 JumpTable->addTarget(Case.High - MinValue, Case.Label); |
| 84 } |
| 81 | 85 |
| 82 CaseClusters.clear(); | 86 CaseClusters.clear(); |
| 83 CaseClusters.emplace_back(MinValue, MaxValue, JumpTable); | 87 CaseClusters.emplace_back(MinValue, MaxValue, JumpTable); |
| 84 | 88 |
| 85 return CaseClusters; | 89 return CaseClusters; |
| 86 } | 90 } |
| 87 | 91 |
| 88 bool CaseCluster::tryAppend(const CaseCluster &New) { | 92 bool CaseCluster::tryAppend(const CaseCluster &New) { |
| 89 // Can only append ranges with the same target and are adjacent | 93 // Can only append ranges with the same target and are adjacent |
| 90 bool CanAppend = this->Label == New.Label && this->High + 1 == New.Low; | 94 bool CanAppend = this->Label == New.Label && this->High + 1 == New.Low; |
| 91 if (CanAppend) | 95 if (CanAppend) |
| 92 this->High = New.High; | 96 this->High = New.High; |
| 93 return CanAppend; | 97 return CanAppend; |
| 94 } | 98 } |
| 95 | 99 |
| 96 } // end of namespace Ice | 100 } // end of namespace Ice |
| OLD | NEW |