diff options
author | Hans Wennborg <hans@hanshq.net> | 2015-02-05 16:58:10 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2015-02-05 16:58:10 +0000 |
commit | 8b4dbdf15db77f1ed848e65cf524a57eb685895d (patch) | |
tree | c589644bc01c8a1a56781a04f741fdd245f35d54 /llvm/lib/Transforms/Utils/LowerSwitch.cpp | |
parent | 8c82fbcb73507cdd37ade64464382a8395f80612 (diff) | |
download | bcm5719-llvm-8b4dbdf15db77f1ed848e65cf524a57eb685895d.tar.gz bcm5719-llvm-8b4dbdf15db77f1ed848e65cf524a57eb685895d.zip |
LowerSwitch: Use ConstantInt for CaseRange::{Low,High}
Case values are always ConstantInt. This allows us to remove
a bunch of casts. NFC.
llvm-svn: 228312
Diffstat (limited to 'llvm/lib/Transforms/Utils/LowerSwitch.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LowerSwitch.cpp | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/llvm/lib/Transforms/Utils/LowerSwitch.cpp b/llvm/lib/Transforms/Utils/LowerSwitch.cpp index 8141049a817..b3bdae47d94 100644 --- a/llvm/lib/Transforms/Utils/LowerSwitch.cpp +++ b/llvm/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<ConstantInt>(Pivot.Low)->getValue() - << " -" << cast<ConstantInt>(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<ConstantInt>(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<ConstantInt>(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<ConstantInt>(LHS.back().High); + NewUpperBound = LHS.back().High; } DEBUG(dbgs() << "LHS Bounds ==> "; if (LowerBound) { - dbgs() << cast<ConstantInt>(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<ConstantInt>(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<ConstantInt>(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<ConstantInt>(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<PHINode>(I); ++I) { PHINode* PN = cast<PHINode>(I); // Remove all but one incoming entries from the cluster - uint64_t Range = cast<ConstantInt>(Leaf.High)->getSExtValue() - - cast<ConstantInt>(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<ConstantInt>(J->Low)->getSExtValue(); - int64_t currentValue = cast<ConstantInt>(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<ConstantInt>(Cases.front().Low); - UpperBound = cast<ConstantInt>(Cases.back().High); + LowerBound = Cases.front().Low; + UpperBound = Cases.back().High; DenseMap<BasicBlock *, unsigned> 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<ConstantInt>(I.Low)->getSExtValue(); - int64_t High = cast<ConstantInt>(I.High)->getSExtValue(); + int64_t Low = I.Low->getSExtValue(); + int64_t High = I.High->getSExtValue(); IntRange &LastRange = UnreachableRanges.back(); if (LastRange.Low == Low) { |