From 2cdfb4b5da7939e1af4cee44fd541af08d1d47b0 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Thu, 5 Feb 2015 16:58:10 +0000 Subject: [PATCH] LowerSwitch: Use ConstantInt for CaseRange::{Low,High} Case values are always ConstantInt. This allows us to remove a bunch of casts. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228312 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/LowerSwitch.cpp | 40 ++++++++++++++-------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/Transforms/Utils/LowerSwitch.cpp b/lib/Transforms/Utils/LowerSwitch.cpp index 8141049a817..b3bdae47d94 100644 --- a/lib/Transforms/Utils/LowerSwitch.cpp +++ b/lib/Transforms/Utils/LowerSwitch.cpp @@ -67,11 +67,11 @@ namespace { } struct CaseRange { - Constant* Low; - Constant* High; + ConstantInt* Low; + ConstantInt* High; BasicBlock* BB; - CaseRange(Constant *low, Constant *high, BasicBlock *bb) + CaseRange(ConstantInt *low, ConstantInt *high, BasicBlock *bb) : Low(low), High(high), BB(bb) {} }; @@ -220,14 +220,14 @@ LowerSwitch::switchConvert(CaseItr Begin, CaseItr End, ConstantInt *LowerBound, CaseRange &Pivot = *(Begin + Mid); DEBUG(dbgs() << "Pivot ==> " - << cast(Pivot.Low)->getValue() - << " -" << cast(Pivot.High)->getValue() << "\n"); + << Pivot.Low->getValue() + << " -" << Pivot.High->getValue() << "\n"); // NewLowerBound here should never be the integer minimal value. // This is because it is computed from a case range that is never // the smallest, so there is always a case range that has at least // a smaller value. - ConstantInt *NewLowerBound = cast(Pivot.Low); + ConstantInt *NewLowerBound = Pivot.Low; // Because NewLowerBound is never the smallest representable integer // it is safe here to subtract one. @@ -236,16 +236,16 @@ LowerSwitch::switchConvert(CaseItr Begin, CaseItr End, ConstantInt *LowerBound, if (!UnreachableRanges.empty()) { // Check if the gap between LHS's highest and NewLowerBound is unreachable. - int64_t GapLow = cast(LHS.back().High)->getSExtValue() + 1; + int64_t GapLow = LHS.back().High->getSExtValue() + 1; int64_t GapHigh = NewLowerBound->getSExtValue() - 1; IntRange Gap = { GapLow, GapHigh }; if (GapHigh >= GapLow && IsInRanges(Gap, UnreachableRanges)) - NewUpperBound = cast(LHS.back().High); + NewUpperBound = LHS.back().High; } DEBUG(dbgs() << "LHS Bounds ==> "; if (LowerBound) { - dbgs() << cast(LowerBound)->getSExtValue(); + dbgs() << LowerBound->getSExtValue(); } else { dbgs() << "NONE"; } @@ -253,7 +253,7 @@ LowerSwitch::switchConvert(CaseItr Begin, CaseItr End, ConstantInt *LowerBound, dbgs() << "RHS Bounds ==> "; dbgs() << NewLowerBound->getSExtValue() << " - "; if (UpperBound) { - dbgs() << cast(UpperBound)->getSExtValue() << "\n"; + dbgs() << UpperBound->getSExtValue() << "\n"; } else { dbgs() << "NONE\n"; }); @@ -304,11 +304,11 @@ BasicBlock* LowerSwitch::newLeafBlock(CaseRange& Leaf, Value* Val, Leaf.Low, "SwitchLeaf"); } else { // Make range comparison - if (cast(Leaf.Low)->isMinValue(true /*isSigned*/)) { + if (Leaf.Low->isMinValue(true /*isSigned*/)) { // Val >= Min && Val <= Hi --> Val <= Hi Comp = new ICmpInst(*NewLeaf, ICmpInst::ICMP_SLE, Val, Leaf.High, "SwitchLeaf"); - } else if (cast(Leaf.Low)->isZero()) { + } else if (Leaf.Low->isZero()) { // Val >= 0 && Val <= Hi --> Val <=u Hi Comp = new ICmpInst(*NewLeaf, ICmpInst::ICMP_ULE, Val, Leaf.High, "SwitchLeaf"); @@ -333,8 +333,8 @@ BasicBlock* LowerSwitch::newLeafBlock(CaseRange& Leaf, Value* Val, for (BasicBlock::iterator I = Succ->begin(); isa(I); ++I) { PHINode* PN = cast(I); // Remove all but one incoming entries from the cluster - uint64_t Range = cast(Leaf.High)->getSExtValue() - - cast(Leaf.Low)->getSExtValue(); + uint64_t Range = Leaf.High->getSExtValue() - + Leaf.Low->getSExtValue(); for (uint64_t j = 0; j < Range; ++j) { PN->removeIncomingValue(OrigBlock); } @@ -362,8 +362,8 @@ unsigned LowerSwitch::Clusterify(CaseVector& Cases, SwitchInst *SI) { if (Cases.size()>=2) for (CaseItr I = Cases.begin(), J = std::next(Cases.begin()); J != Cases.end();) { - int64_t nextValue = cast(J->Low)->getSExtValue(); - int64_t currentValue = cast(I->High)->getSExtValue(); + int64_t nextValue = J->Low->getSExtValue(); + int64_t currentValue = I->High->getSExtValue(); BasicBlock* nextBB = J->BB; BasicBlock* currentBB = I->BB; @@ -420,8 +420,8 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI) { // know that the value passed to the switch must be exactly one of the case // values. assert(!Cases.empty()); - LowerBound = cast(Cases.front().Low); - UpperBound = cast(Cases.back().High); + LowerBound = Cases.front().Low; + UpperBound = Cases.back().High; DenseMap Popularity; unsigned MaxPop = 0; @@ -430,8 +430,8 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI) { IntRange R = { INT64_MIN, INT64_MAX }; UnreachableRanges.push_back(R); for (const auto &I : Cases) { - int64_t Low = cast(I.Low)->getSExtValue(); - int64_t High = cast(I.High)->getSExtValue(); + int64_t Low = I.Low->getSExtValue(); + int64_t High = I.High->getSExtValue(); IntRange &LastRange = UnreachableRanges.back(); if (LastRange.Low == Low) { -- 2.34.1