[llvm] r228312 - LowerSwitch: Use ConstantInt for CaseRange::{Low, High}
Hans Wennborg
hans at hanshq.net
Thu Feb 5 08:58:10 PST 2015
Author: hans
Date: Thu Feb 5 10:58:10 2015
New Revision: 228312
URL: http://llvm.org/viewvc/llvm-project?rev=228312&view=rev
Log:
LowerSwitch: Use ConstantInt for CaseRange::{Low,High}
Case values are always ConstantInt. This allows us to remove
a bunch of casts. NFC.
Modified:
llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp
Modified: llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp?rev=228312&r1=228311&r2=228312&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp Thu Feb 5 10:58:10 2015
@@ -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
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
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
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(Ca
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(Ca
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(CaseVec
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(Swit
// 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(Swit
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) {
More information about the llvm-commits
mailing list