forked from OSchip/llvm-project
Convert several parts of the ScalarEvolution framework to use
SmallVector instead of std::vector. llvm-svn: 73357
This commit is contained in:
parent
1cf2536d6c
commit
0652fd59ff
|
@ -394,24 +394,24 @@ namespace llvm {
|
|||
SCEVHandle getZeroExtendExpr(const SCEVHandle &Op, const Type *Ty);
|
||||
SCEVHandle getSignExtendExpr(const SCEVHandle &Op, const Type *Ty);
|
||||
SCEVHandle getAnyExtendExpr(const SCEVHandle &Op, const Type *Ty);
|
||||
SCEVHandle getAddExpr(std::vector<SCEVHandle> &Ops);
|
||||
SCEVHandle getAddExpr(SmallVectorImpl<SCEVHandle> &Ops);
|
||||
SCEVHandle getAddExpr(const SCEVHandle &LHS, const SCEVHandle &RHS) {
|
||||
std::vector<SCEVHandle> Ops;
|
||||
SmallVector<SCEVHandle, 2> Ops;
|
||||
Ops.push_back(LHS);
|
||||
Ops.push_back(RHS);
|
||||
return getAddExpr(Ops);
|
||||
}
|
||||
SCEVHandle getAddExpr(const SCEVHandle &Op0, const SCEVHandle &Op1,
|
||||
const SCEVHandle &Op2) {
|
||||
std::vector<SCEVHandle> Ops;
|
||||
SmallVector<SCEVHandle, 3> Ops;
|
||||
Ops.push_back(Op0);
|
||||
Ops.push_back(Op1);
|
||||
Ops.push_back(Op2);
|
||||
return getAddExpr(Ops);
|
||||
}
|
||||
SCEVHandle getMulExpr(std::vector<SCEVHandle> &Ops);
|
||||
SCEVHandle getMulExpr(SmallVectorImpl<SCEVHandle> &Ops);
|
||||
SCEVHandle getMulExpr(const SCEVHandle &LHS, const SCEVHandle &RHS) {
|
||||
std::vector<SCEVHandle> Ops;
|
||||
SmallVector<SCEVHandle, 2> Ops;
|
||||
Ops.push_back(LHS);
|
||||
Ops.push_back(RHS);
|
||||
return getMulExpr(Ops);
|
||||
|
@ -419,17 +419,17 @@ namespace llvm {
|
|||
SCEVHandle getUDivExpr(const SCEVHandle &LHS, const SCEVHandle &RHS);
|
||||
SCEVHandle getAddRecExpr(const SCEVHandle &Start, const SCEVHandle &Step,
|
||||
const Loop *L);
|
||||
SCEVHandle getAddRecExpr(std::vector<SCEVHandle> &Operands,
|
||||
SCEVHandle getAddRecExpr(SmallVectorImpl<SCEVHandle> &Operands,
|
||||
const Loop *L);
|
||||
SCEVHandle getAddRecExpr(const std::vector<SCEVHandle> &Operands,
|
||||
SCEVHandle getAddRecExpr(const SmallVectorImpl<SCEVHandle> &Operands,
|
||||
const Loop *L) {
|
||||
std::vector<SCEVHandle> NewOp(Operands);
|
||||
SmallVector<SCEVHandle, 4> NewOp(Operands.begin(), Operands.end());
|
||||
return getAddRecExpr(NewOp, L);
|
||||
}
|
||||
SCEVHandle getSMaxExpr(const SCEVHandle &LHS, const SCEVHandle &RHS);
|
||||
SCEVHandle getSMaxExpr(std::vector<SCEVHandle> Operands);
|
||||
SCEVHandle getSMaxExpr(SmallVectorImpl<SCEVHandle> &Operands);
|
||||
SCEVHandle getUMaxExpr(const SCEVHandle &LHS, const SCEVHandle &RHS);
|
||||
SCEVHandle getUMaxExpr(std::vector<SCEVHandle> Operands);
|
||||
SCEVHandle getUMaxExpr(SmallVectorImpl<SCEVHandle> &Operands);
|
||||
SCEVHandle getUnknown(Value *V);
|
||||
SCEVHandle getCouldNotCompute();
|
||||
|
||||
|
|
|
@ -199,10 +199,10 @@ namespace llvm {
|
|||
///
|
||||
class SCEVNAryExpr : public SCEV {
|
||||
protected:
|
||||
std::vector<SCEVHandle> Operands;
|
||||
SmallVector<SCEVHandle, 8> Operands;
|
||||
|
||||
SCEVNAryExpr(enum SCEVTypes T, const std::vector<SCEVHandle> &ops)
|
||||
: SCEV(T), Operands(ops) {}
|
||||
SCEVNAryExpr(enum SCEVTypes T, const SmallVectorImpl<SCEVHandle> &ops)
|
||||
: SCEV(T), Operands(ops.begin(), ops.end()) {}
|
||||
virtual ~SCEVNAryExpr() {}
|
||||
|
||||
public:
|
||||
|
@ -212,8 +212,8 @@ namespace llvm {
|
|||
return Operands[i];
|
||||
}
|
||||
|
||||
const std::vector<SCEVHandle> &getOperands() const { return Operands; }
|
||||
typedef std::vector<SCEVHandle>::const_iterator op_iterator;
|
||||
const SmallVectorImpl<SCEVHandle> &getOperands() const { return Operands; }
|
||||
typedef SmallVectorImpl<SCEVHandle>::const_iterator op_iterator;
|
||||
op_iterator op_begin() const { return Operands.begin(); }
|
||||
op_iterator op_end() const { return Operands.end(); }
|
||||
|
||||
|
@ -259,7 +259,7 @@ namespace llvm {
|
|||
///
|
||||
class SCEVCommutativeExpr : public SCEVNAryExpr {
|
||||
protected:
|
||||
SCEVCommutativeExpr(enum SCEVTypes T, const std::vector<SCEVHandle> &ops)
|
||||
SCEVCommutativeExpr(enum SCEVTypes T, const SmallVectorImpl<SCEVHandle> &ops)
|
||||
: SCEVNAryExpr(T, ops) {}
|
||||
~SCEVCommutativeExpr();
|
||||
|
||||
|
@ -289,7 +289,7 @@ namespace llvm {
|
|||
class SCEVAddExpr : public SCEVCommutativeExpr {
|
||||
friend class ScalarEvolution;
|
||||
|
||||
explicit SCEVAddExpr(const std::vector<SCEVHandle> &ops)
|
||||
explicit SCEVAddExpr(const SmallVectorImpl<SCEVHandle> &ops)
|
||||
: SCEVCommutativeExpr(scAddExpr, ops) {
|
||||
}
|
||||
|
||||
|
@ -309,7 +309,7 @@ namespace llvm {
|
|||
class SCEVMulExpr : public SCEVCommutativeExpr {
|
||||
friend class ScalarEvolution;
|
||||
|
||||
explicit SCEVMulExpr(const std::vector<SCEVHandle> &ops)
|
||||
explicit SCEVMulExpr(const SmallVectorImpl<SCEVHandle> &ops)
|
||||
: SCEVCommutativeExpr(scMulExpr, ops) {
|
||||
}
|
||||
|
||||
|
@ -387,7 +387,7 @@ namespace llvm {
|
|||
|
||||
const Loop *L;
|
||||
|
||||
SCEVAddRecExpr(const std::vector<SCEVHandle> &ops, const Loop *l)
|
||||
SCEVAddRecExpr(const SmallVectorImpl<SCEVHandle> &ops, const Loop *l)
|
||||
: SCEVNAryExpr(scAddRecExpr, ops), L(l) {
|
||||
for (size_t i = 0, e = Operands.size(); i != e; ++i)
|
||||
assert(Operands[i]->isLoopInvariant(l) &&
|
||||
|
@ -404,7 +404,7 @@ namespace llvm {
|
|||
/// of degree N, it returns a chrec of degree N-1.
|
||||
SCEVHandle getStepRecurrence(ScalarEvolution &SE) const {
|
||||
if (isAffine()) return getOperand(1);
|
||||
return SE.getAddRecExpr(std::vector<SCEVHandle>(op_begin()+1,op_end()),
|
||||
return SE.getAddRecExpr(SmallVector<SCEVHandle, 3>(op_begin()+1,op_end()),
|
||||
getLoop());
|
||||
}
|
||||
|
||||
|
@ -463,7 +463,7 @@ namespace llvm {
|
|||
class SCEVSMaxExpr : public SCEVCommutativeExpr {
|
||||
friend class ScalarEvolution;
|
||||
|
||||
explicit SCEVSMaxExpr(const std::vector<SCEVHandle> &ops)
|
||||
explicit SCEVSMaxExpr(const SmallVectorImpl<SCEVHandle> &ops)
|
||||
: SCEVCommutativeExpr(scSMaxExpr, ops) {
|
||||
}
|
||||
|
||||
|
@ -484,7 +484,7 @@ namespace llvm {
|
|||
class SCEVUMaxExpr : public SCEVCommutativeExpr {
|
||||
friend class ScalarEvolution;
|
||||
|
||||
explicit SCEVUMaxExpr(const std::vector<SCEVHandle> &ops)
|
||||
explicit SCEVUMaxExpr(const SmallVectorImpl<SCEVHandle> &ops)
|
||||
: SCEVCommutativeExpr(scUMaxExpr, ops) {
|
||||
}
|
||||
|
||||
|
|
|
@ -293,7 +293,7 @@ replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
|||
SCEVHandle H =
|
||||
getOperand(i)->replaceSymbolicValuesWithConcrete(Sym, Conc, SE);
|
||||
if (H != getOperand(i)) {
|
||||
std::vector<SCEVHandle> NewOps;
|
||||
SmallVector<SCEVHandle, 8> NewOps;
|
||||
NewOps.reserve(getNumOperands());
|
||||
for (unsigned j = 0; j != i; ++j)
|
||||
NewOps.push_back(getOperand(j));
|
||||
|
@ -373,7 +373,7 @@ replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
|||
SCEVHandle H =
|
||||
getOperand(i)->replaceSymbolicValuesWithConcrete(Sym, Conc, SE);
|
||||
if (H != getOperand(i)) {
|
||||
std::vector<SCEVHandle> NewOps;
|
||||
SmallVector<SCEVHandle, 8> NewOps;
|
||||
NewOps.reserve(getNumOperands());
|
||||
for (unsigned j = 0; j != i; ++j)
|
||||
NewOps.push_back(getOperand(j));
|
||||
|
@ -558,7 +558,7 @@ namespace {
|
|||
/// this to depend on where the addresses of various SCEV objects happened to
|
||||
/// land in memory.
|
||||
///
|
||||
static void GroupByComplexity(std::vector<SCEVHandle> &Ops,
|
||||
static void GroupByComplexity(SmallVectorImpl<SCEVHandle> &Ops,
|
||||
LoopInfo *LI) {
|
||||
if (Ops.size() < 2) return; // Noop
|
||||
if (Ops.size() == 2) {
|
||||
|
@ -766,7 +766,7 @@ SCEVHandle ScalarEvolution::getTruncateExpr(const SCEVHandle &Op,
|
|||
// If the input value is a chrec scev made out of constants, truncate
|
||||
// all of the constants.
|
||||
if (const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(Op)) {
|
||||
std::vector<SCEVHandle> Operands;
|
||||
SmallVector<SCEVHandle, 4> Operands;
|
||||
for (unsigned i = 0, e = AddRec->getNumOperands(); i != e; ++i)
|
||||
Operands.push_back(getTruncateExpr(AddRec->getOperand(i), Ty));
|
||||
return getAddRecExpr(Operands, AddRec->getLoop());
|
||||
|
@ -981,7 +981,7 @@ SCEVHandle ScalarEvolution::getAnyExtendExpr(const SCEVHandle &Op,
|
|||
|
||||
/// getAddExpr - Get a canonical add expression, or something simpler if
|
||||
/// possible.
|
||||
SCEVHandle ScalarEvolution::getAddExpr(std::vector<SCEVHandle> &Ops) {
|
||||
SCEVHandle ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVHandle> &Ops) {
|
||||
assert(!Ops.empty() && "Cannot get empty add!");
|
||||
if (Ops.size() == 1) return Ops[0];
|
||||
#ifndef NDEBUG
|
||||
|
@ -1001,9 +1001,8 @@ SCEVHandle ScalarEvolution::getAddExpr(std::vector<SCEVHandle> &Ops) {
|
|||
assert(Idx < Ops.size());
|
||||
while (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
|
||||
// We found two constants, fold them together!
|
||||
ConstantInt *Fold = ConstantInt::get(LHSC->getValue()->getValue() +
|
||||
Ops[0] = getConstant(LHSC->getValue()->getValue() +
|
||||
RHSC->getValue()->getValue());
|
||||
Ops[0] = getConstant(Fold);
|
||||
Ops.erase(Ops.begin()+1); // Erase the folded element
|
||||
if (Ops.size() == 1) return Ops[0];
|
||||
LHSC = cast<SCEVConstant>(Ops[0]);
|
||||
|
@ -1043,7 +1042,7 @@ SCEVHandle ScalarEvolution::getAddExpr(std::vector<SCEVHandle> &Ops) {
|
|||
const SCEVTruncateExpr *Trunc = cast<SCEVTruncateExpr>(Ops[Idx]);
|
||||
const Type *DstType = Trunc->getType();
|
||||
const Type *SrcType = Trunc->getOperand()->getType();
|
||||
std::vector<SCEVHandle> LargeOps;
|
||||
SmallVector<SCEVHandle, 8> LargeOps;
|
||||
bool Ok = true;
|
||||
// Check all the operands to see if they can be represented in the
|
||||
// source type of the truncate.
|
||||
|
@ -1059,7 +1058,7 @@ SCEVHandle ScalarEvolution::getAddExpr(std::vector<SCEVHandle> &Ops) {
|
|||
// is much more likely to be foldable here.
|
||||
LargeOps.push_back(getSignExtendExpr(C, SrcType));
|
||||
} else if (const SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(Ops[i])) {
|
||||
std::vector<SCEVHandle> LargeMulOps;
|
||||
SmallVector<SCEVHandle, 8> LargeMulOps;
|
||||
for (unsigned j = 0, f = M->getNumOperands(); j != f && Ok; ++j) {
|
||||
if (const SCEVTruncateExpr *T =
|
||||
dyn_cast<SCEVTruncateExpr>(M->getOperand(j))) {
|
||||
|
@ -1128,13 +1127,13 @@ SCEVHandle ScalarEvolution::getAddExpr(std::vector<SCEVHandle> &Ops) {
|
|||
for (unsigned MulOp = 0, e = Mul->getNumOperands(); MulOp != e; ++MulOp) {
|
||||
const SCEV *MulOpSCEV = Mul->getOperand(MulOp);
|
||||
for (unsigned AddOp = 0, e = Ops.size(); AddOp != e; ++AddOp)
|
||||
if (MulOpSCEV == Ops[AddOp] && !isa<SCEVConstant>(MulOpSCEV)) {
|
||||
if (MulOpSCEV == Ops[AddOp] && !isa<SCEVConstant>(Ops[AddOp])) {
|
||||
// Fold W + X + (X * Y * Z) --> W + (X * ((Y*Z)+1))
|
||||
SCEVHandle InnerMul = Mul->getOperand(MulOp == 0);
|
||||
if (Mul->getNumOperands() != 2) {
|
||||
// If the multiply has more than two operands, we must get the
|
||||
// Y*Z term.
|
||||
std::vector<SCEVHandle> MulOps(Mul->op_begin(), Mul->op_end());
|
||||
SmallVector<SCEVHandle, 4> MulOps(Mul->op_begin(), Mul->op_end());
|
||||
MulOps.erase(MulOps.begin()+MulOp);
|
||||
InnerMul = getMulExpr(MulOps);
|
||||
}
|
||||
|
@ -1166,13 +1165,13 @@ SCEVHandle ScalarEvolution::getAddExpr(std::vector<SCEVHandle> &Ops) {
|
|||
// Fold X + (A*B*C) + (A*D*E) --> X + (A*(B*C+D*E))
|
||||
SCEVHandle InnerMul1 = Mul->getOperand(MulOp == 0);
|
||||
if (Mul->getNumOperands() != 2) {
|
||||
std::vector<SCEVHandle> MulOps(Mul->op_begin(), Mul->op_end());
|
||||
SmallVector<SCEVHandle, 4> MulOps(Mul->op_begin(), Mul->op_end());
|
||||
MulOps.erase(MulOps.begin()+MulOp);
|
||||
InnerMul1 = getMulExpr(MulOps);
|
||||
}
|
||||
SCEVHandle InnerMul2 = OtherMul->getOperand(OMulOp == 0);
|
||||
if (OtherMul->getNumOperands() != 2) {
|
||||
std::vector<SCEVHandle> MulOps(OtherMul->op_begin(),
|
||||
SmallVector<SCEVHandle, 4> MulOps(OtherMul->op_begin(),
|
||||
OtherMul->op_end());
|
||||
MulOps.erase(MulOps.begin()+OMulOp);
|
||||
InnerMul2 = getMulExpr(MulOps);
|
||||
|
@ -1199,7 +1198,7 @@ SCEVHandle ScalarEvolution::getAddExpr(std::vector<SCEVHandle> &Ops) {
|
|||
for (; Idx < Ops.size() && isa<SCEVAddRecExpr>(Ops[Idx]); ++Idx) {
|
||||
// Scan all of the other operands to this add and add them to the vector if
|
||||
// they are loop invariant w.r.t. the recurrence.
|
||||
std::vector<SCEVHandle> LIOps;
|
||||
SmallVector<SCEVHandle, 8> LIOps;
|
||||
const SCEVAddRecExpr *AddRec = cast<SCEVAddRecExpr>(Ops[Idx]);
|
||||
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
|
||||
if (Ops[i]->isLoopInvariant(AddRec->getLoop())) {
|
||||
|
@ -1213,7 +1212,8 @@ SCEVHandle ScalarEvolution::getAddExpr(std::vector<SCEVHandle> &Ops) {
|
|||
// NLI + LI + {Start,+,Step} --> NLI + {LI+Start,+,Step}
|
||||
LIOps.push_back(AddRec->getStart());
|
||||
|
||||
std::vector<SCEVHandle> AddRecOps(AddRec->op_begin(), AddRec->op_end());
|
||||
SmallVector<SCEVHandle, 4> AddRecOps(AddRec->op_begin(),
|
||||
AddRec->op_end());
|
||||
AddRecOps[0] = getAddExpr(LIOps);
|
||||
|
||||
SCEVHandle NewRec = getAddRecExpr(AddRecOps, AddRec->getLoop());
|
||||
|
@ -1238,7 +1238,7 @@ SCEVHandle ScalarEvolution::getAddExpr(std::vector<SCEVHandle> &Ops) {
|
|||
const SCEVAddRecExpr *OtherAddRec = cast<SCEVAddRecExpr>(Ops[OtherIdx]);
|
||||
if (AddRec->getLoop() == OtherAddRec->getLoop()) {
|
||||
// Other + {A,+,B} + {C,+,D} --> Other + {A+C,+,B+D}
|
||||
std::vector<SCEVHandle> NewOps(AddRec->op_begin(), AddRec->op_end());
|
||||
SmallVector<SCEVHandle, 4> NewOps(AddRec->op_begin(), AddRec->op_end());
|
||||
for (unsigned i = 0, e = OtherAddRec->getNumOperands(); i != e; ++i) {
|
||||
if (i >= NewOps.size()) {
|
||||
NewOps.insert(NewOps.end(), OtherAddRec->op_begin()+i,
|
||||
|
@ -1274,7 +1274,7 @@ SCEVHandle ScalarEvolution::getAddExpr(std::vector<SCEVHandle> &Ops) {
|
|||
|
||||
/// getMulExpr - Get a canonical multiply expression, or something simpler if
|
||||
/// possible.
|
||||
SCEVHandle ScalarEvolution::getMulExpr(std::vector<SCEVHandle> &Ops) {
|
||||
SCEVHandle ScalarEvolution::getMulExpr(SmallVectorImpl<SCEVHandle> &Ops) {
|
||||
assert(!Ops.empty() && "Cannot get empty mul!");
|
||||
#ifndef NDEBUG
|
||||
for (unsigned i = 1, e = Ops.size(); i != e; ++i)
|
||||
|
@ -1355,7 +1355,7 @@ SCEVHandle ScalarEvolution::getMulExpr(std::vector<SCEVHandle> &Ops) {
|
|||
for (; Idx < Ops.size() && isa<SCEVAddRecExpr>(Ops[Idx]); ++Idx) {
|
||||
// Scan all of the other operands to this mul and add them to the vector if
|
||||
// they are loop invariant w.r.t. the recurrence.
|
||||
std::vector<SCEVHandle> LIOps;
|
||||
SmallVector<SCEVHandle, 8> LIOps;
|
||||
const SCEVAddRecExpr *AddRec = cast<SCEVAddRecExpr>(Ops[Idx]);
|
||||
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
|
||||
if (Ops[i]->isLoopInvariant(AddRec->getLoop())) {
|
||||
|
@ -1367,7 +1367,7 @@ SCEVHandle ScalarEvolution::getMulExpr(std::vector<SCEVHandle> &Ops) {
|
|||
// If we found some loop invariants, fold them into the recurrence.
|
||||
if (!LIOps.empty()) {
|
||||
// NLI * LI * {Start,+,Step} --> NLI * {LI*Start,+,LI*Step}
|
||||
std::vector<SCEVHandle> NewOps;
|
||||
SmallVector<SCEVHandle, 4> NewOps;
|
||||
NewOps.reserve(AddRec->getNumOperands());
|
||||
if (LIOps.size() == 1) {
|
||||
const SCEV *Scale = LIOps[0];
|
||||
|
@ -1375,7 +1375,7 @@ SCEVHandle ScalarEvolution::getMulExpr(std::vector<SCEVHandle> &Ops) {
|
|||
NewOps.push_back(getMulExpr(Scale, AddRec->getOperand(i)));
|
||||
} else {
|
||||
for (unsigned i = 0, e = AddRec->getNumOperands(); i != e; ++i) {
|
||||
std::vector<SCEVHandle> MulOps(LIOps);
|
||||
SmallVector<SCEVHandle, 4> MulOps(LIOps.begin(), LIOps.end());
|
||||
MulOps.push_back(AddRec->getOperand(i));
|
||||
NewOps.push_back(getMulExpr(MulOps));
|
||||
}
|
||||
|
@ -1473,14 +1473,14 @@ SCEVHandle ScalarEvolution::getUDivExpr(const SCEVHandle &LHS,
|
|||
getAddRecExpr(getZeroExtendExpr(AR->getStart(), ExtTy),
|
||||
getZeroExtendExpr(Step, ExtTy),
|
||||
AR->getLoop())) {
|
||||
std::vector<SCEVHandle> Operands;
|
||||
SmallVector<SCEVHandle, 4> Operands;
|
||||
for (unsigned i = 0, e = AR->getNumOperands(); i != e; ++i)
|
||||
Operands.push_back(getUDivExpr(AR->getOperand(i), RHS));
|
||||
return getAddRecExpr(Operands, AR->getLoop());
|
||||
}
|
||||
// (A*B)/C --> A*(B/C) if safe and B/C can be folded.
|
||||
if (const SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(LHS)) {
|
||||
std::vector<SCEVHandle> Operands;
|
||||
SmallVector<SCEVHandle, 4> Operands;
|
||||
for (unsigned i = 0, e = M->getNumOperands(); i != e; ++i)
|
||||
Operands.push_back(getZeroExtendExpr(M->getOperand(i), ExtTy));
|
||||
if (getZeroExtendExpr(M, ExtTy) == getMulExpr(Operands))
|
||||
|
@ -1489,7 +1489,9 @@ SCEVHandle ScalarEvolution::getUDivExpr(const SCEVHandle &LHS,
|
|||
SCEVHandle Op = M->getOperand(i);
|
||||
SCEVHandle Div = getUDivExpr(Op, RHSC);
|
||||
if (!isa<SCEVUDivExpr>(Div) && getMulExpr(Div, RHSC) == Op) {
|
||||
Operands = M->getOperands();
|
||||
const SmallVectorImpl<SCEVHandle> &MOperands = M->getOperands();
|
||||
Operands = SmallVector<SCEVHandle, 4>(MOperands.begin(),
|
||||
MOperands.end());
|
||||
Operands[i] = Div;
|
||||
return getMulExpr(Operands);
|
||||
}
|
||||
|
@ -1497,7 +1499,7 @@ SCEVHandle ScalarEvolution::getUDivExpr(const SCEVHandle &LHS,
|
|||
}
|
||||
// (A+B)/C --> (A/C + B/C) if safe and A/C and B/C can be folded.
|
||||
if (const SCEVAddRecExpr *A = dyn_cast<SCEVAddRecExpr>(LHS)) {
|
||||
std::vector<SCEVHandle> Operands;
|
||||
SmallVector<SCEVHandle, 4> Operands;
|
||||
for (unsigned i = 0, e = A->getNumOperands(); i != e; ++i)
|
||||
Operands.push_back(getZeroExtendExpr(A->getOperand(i), ExtTy));
|
||||
if (getZeroExtendExpr(A, ExtTy) == getAddExpr(Operands)) {
|
||||
|
@ -1531,7 +1533,7 @@ SCEVHandle ScalarEvolution::getUDivExpr(const SCEVHandle &LHS,
|
|||
/// Simplify the expression as much as possible.
|
||||
SCEVHandle ScalarEvolution::getAddRecExpr(const SCEVHandle &Start,
|
||||
const SCEVHandle &Step, const Loop *L) {
|
||||
std::vector<SCEVHandle> Operands;
|
||||
SmallVector<SCEVHandle, 4> Operands;
|
||||
Operands.push_back(Start);
|
||||
if (const SCEVAddRecExpr *StepChrec = dyn_cast<SCEVAddRecExpr>(Step))
|
||||
if (StepChrec->getLoop() == L) {
|
||||
|
@ -1546,7 +1548,7 @@ SCEVHandle ScalarEvolution::getAddRecExpr(const SCEVHandle &Start,
|
|||
|
||||
/// getAddRecExpr - Get an add recurrence expression for the specified loop.
|
||||
/// Simplify the expression as much as possible.
|
||||
SCEVHandle ScalarEvolution::getAddRecExpr(std::vector<SCEVHandle> &Operands,
|
||||
SCEVHandle ScalarEvolution::getAddRecExpr(SmallVectorImpl<SCEVHandle> &Operands,
|
||||
const Loop *L) {
|
||||
if (Operands.size() == 1) return Operands[0];
|
||||
#ifndef NDEBUG
|
||||
|
@ -1565,7 +1567,7 @@ SCEVHandle ScalarEvolution::getAddRecExpr(std::vector<SCEVHandle> &Operands,
|
|||
if (const SCEVAddRecExpr *NestedAR = dyn_cast<SCEVAddRecExpr>(Operands[0])) {
|
||||
const Loop* NestedLoop = NestedAR->getLoop();
|
||||
if (L->getLoopDepth() < NestedLoop->getLoopDepth()) {
|
||||
std::vector<SCEVHandle> NestedOperands(NestedAR->op_begin(),
|
||||
SmallVector<SCEVHandle, 4> NestedOperands(NestedAR->op_begin(),
|
||||
NestedAR->op_end());
|
||||
SCEVHandle NestedARHandle(NestedAR);
|
||||
Operands[0] = NestedAR->getStart();
|
||||
|
@ -1582,13 +1584,14 @@ SCEVHandle ScalarEvolution::getAddRecExpr(std::vector<SCEVHandle> &Operands,
|
|||
|
||||
SCEVHandle ScalarEvolution::getSMaxExpr(const SCEVHandle &LHS,
|
||||
const SCEVHandle &RHS) {
|
||||
std::vector<SCEVHandle> Ops;
|
||||
SmallVector<SCEVHandle, 2> Ops;
|
||||
Ops.push_back(LHS);
|
||||
Ops.push_back(RHS);
|
||||
return getSMaxExpr(Ops);
|
||||
}
|
||||
|
||||
SCEVHandle ScalarEvolution::getSMaxExpr(std::vector<SCEVHandle> Ops) {
|
||||
SCEVHandle
|
||||
ScalarEvolution::getSMaxExpr(SmallVectorImpl<SCEVHandle> &Ops) {
|
||||
assert(!Ops.empty() && "Cannot get empty smax!");
|
||||
if (Ops.size() == 1) return Ops[0];
|
||||
#ifndef NDEBUG
|
||||
|
@ -1668,13 +1671,14 @@ SCEVHandle ScalarEvolution::getSMaxExpr(std::vector<SCEVHandle> Ops) {
|
|||
|
||||
SCEVHandle ScalarEvolution::getUMaxExpr(const SCEVHandle &LHS,
|
||||
const SCEVHandle &RHS) {
|
||||
std::vector<SCEVHandle> Ops;
|
||||
SmallVector<SCEVHandle, 2> Ops;
|
||||
Ops.push_back(LHS);
|
||||
Ops.push_back(RHS);
|
||||
return getUMaxExpr(Ops);
|
||||
}
|
||||
|
||||
SCEVHandle ScalarEvolution::getUMaxExpr(std::vector<SCEVHandle> Ops) {
|
||||
SCEVHandle
|
||||
ScalarEvolution::getUMaxExpr(SmallVectorImpl<SCEVHandle> &Ops) {
|
||||
assert(!Ops.empty() && "Cannot get empty umax!");
|
||||
if (Ops.size() == 1) return Ops[0];
|
||||
#ifndef NDEBUG
|
||||
|
@ -2040,7 +2044,7 @@ SCEVHandle ScalarEvolution::createNodeForPHI(PHINode *PN) {
|
|||
|
||||
if (FoundIndex != Add->getNumOperands()) {
|
||||
// Create an add with everything but the specified operand.
|
||||
std::vector<SCEVHandle> Ops;
|
||||
SmallVector<SCEVHandle, 8> Ops;
|
||||
for (unsigned i = 0, e = Add->getNumOperands(); i != e; ++i)
|
||||
if (i != FoundIndex)
|
||||
Ops.push_back(Add->getOperand(i));
|
||||
|
@ -3074,7 +3078,7 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(const SCEV *V, const Loop *L) {
|
|||
if (OpAtScope != Comm->getOperand(i)) {
|
||||
// Okay, at least one of these operands is loop variant but might be
|
||||
// foldable. Build a new instance of the folded commutative expression.
|
||||
std::vector<SCEVHandle> NewOps(Comm->op_begin(), Comm->op_begin()+i);
|
||||
SmallVector<SCEVHandle, 8> NewOps(Comm->op_begin(), Comm->op_begin()+i);
|
||||
NewOps.push_back(OpAtScope);
|
||||
|
||||
for (++i; i != e; ++i) {
|
||||
|
@ -3611,7 +3615,7 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
|
|||
// If the start is a non-zero constant, shift the range to simplify things.
|
||||
if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(getStart()))
|
||||
if (!SC->getValue()->isZero()) {
|
||||
std::vector<SCEVHandle> Operands(op_begin(), op_end());
|
||||
SmallVector<SCEVHandle, 4> Operands(op_begin(), op_end());
|
||||
Operands[0] = SE.getIntegerSCEV(0, SC->getType());
|
||||
SCEVHandle Shifted = SE.getAddRecExpr(Operands, getLoop());
|
||||
if (const SCEVAddRecExpr *ShiftedAddRec =
|
||||
|
@ -3672,7 +3676,7 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
|
|||
// quadratic equation to solve it. To do this, we must frame our problem in
|
||||
// terms of figuring out when zero is crossed, instead of when
|
||||
// Range.getUpper() is crossed.
|
||||
std::vector<SCEVHandle> NewOps(op_begin(), op_end());
|
||||
SmallVector<SCEVHandle, 4> NewOps(op_begin(), op_end());
|
||||
NewOps[0] = SE.getNegativeSCEV(SE.getConstant(Range.getUpper()));
|
||||
SCEVHandle NewAddRec = SE.getAddRecExpr(NewOps, getLoop());
|
||||
|
||||
|
|
|
@ -182,7 +182,8 @@ static bool FactorOutConstant(SCEVHandle &S,
|
|||
if (const SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(S))
|
||||
if (const SCEVConstant *C = dyn_cast<SCEVConstant>(M->getOperand(0)))
|
||||
if (!C->getValue()->getValue().srem(Factor)) {
|
||||
std::vector<SCEVHandle> NewMulOps(M->getOperands());
|
||||
const SmallVectorImpl<SCEVHandle> &MOperands = M->getOperands();
|
||||
SmallVector<SCEVHandle, 4> NewMulOps(MOperands.begin(), MOperands.end());
|
||||
NewMulOps[0] =
|
||||
SE.getConstant(C->getValue()->getValue().sdiv(Factor));
|
||||
S = SE.getMulExpr(NewMulOps);
|
||||
|
@ -239,7 +240,7 @@ Value *SCEVExpander::expandAddToGEP(const SCEVHandle *op_begin,
|
|||
Value *V) {
|
||||
const Type *ElTy = PTy->getElementType();
|
||||
SmallVector<Value *, 4> GepIndices;
|
||||
std::vector<SCEVHandle> Ops(op_begin, op_end);
|
||||
SmallVector<SCEVHandle, 8> Ops(op_begin, op_end);
|
||||
bool AnyNonZeroIndices = false;
|
||||
|
||||
// Decend down the pointer's type and attempt to convert the other
|
||||
|
@ -250,8 +251,8 @@ Value *SCEVExpander::expandAddToGEP(const SCEVHandle *op_begin,
|
|||
for (;;) {
|
||||
APInt ElSize = APInt(SE.getTypeSizeInBits(Ty),
|
||||
ElTy->isSized() ? SE.TD->getTypeAllocSize(ElTy) : 0);
|
||||
std::vector<SCEVHandle> NewOps;
|
||||
std::vector<SCEVHandle> ScaledOps;
|
||||
SmallVector<SCEVHandle, 8> NewOps;
|
||||
SmallVector<SCEVHandle, 8> ScaledOps;
|
||||
for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
|
||||
// Split AddRecs up into parts as either of the parts may be usable
|
||||
// without the other.
|
||||
|
@ -365,7 +366,7 @@ Value *SCEVExpander::visitAddExpr(const SCEVAddExpr *S) {
|
|||
// comments on expandAddToGEP for details.
|
||||
if (SE.TD)
|
||||
if (const PointerType *PTy = dyn_cast<PointerType>(V->getType())) {
|
||||
const std::vector<SCEVHandle> &Ops = S->getOperands();
|
||||
const SmallVectorImpl<SCEVHandle> &Ops = S->getOperands();
|
||||
return expandAddToGEP(&Ops[0], &Ops[Ops.size() - 1],
|
||||
PTy, Ty, V);
|
||||
}
|
||||
|
@ -432,7 +433,7 @@ static void ExposePointerBase(SCEVHandle &Base, SCEVHandle &Rest,
|
|||
}
|
||||
if (const SCEVAddExpr *A = dyn_cast<SCEVAddExpr>(Base)) {
|
||||
Base = A->getOperand(A->getNumOperands()-1);
|
||||
std::vector<SCEVHandle> NewAddOps(A->op_begin(), A->op_end());
|
||||
SmallVector<SCEVHandle, 8> NewAddOps(A->op_begin(), A->op_end());
|
||||
NewAddOps.back() = Rest;
|
||||
Rest = SE.getAddExpr(NewAddOps);
|
||||
ExposePointerBase(Base, Rest, SE);
|
||||
|
@ -473,7 +474,8 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
|
|||
|
||||
// {X,+,F} --> X + {0,+,F}
|
||||
if (!S->getStart()->isZero()) {
|
||||
std::vector<SCEVHandle> NewOps(S->getOperands());
|
||||
const SmallVectorImpl<SCEVHandle> &SOperands = S->getOperands();
|
||||
SmallVector<SCEVHandle, 4> NewOps(SOperands.begin(), SOperands.end());
|
||||
NewOps[0] = SE.getIntegerSCEV(0, Ty);
|
||||
SCEVHandle Rest = SE.getAddRecExpr(NewOps, L);
|
||||
|
||||
|
|
|
@ -592,7 +592,7 @@ static void MoveLoopVariantsToImmediateField(SCEVHandle &Val, SCEVHandle &Imm,
|
|||
if (Val->isLoopInvariant(L)) return; // Nothing to do.
|
||||
|
||||
if (const SCEVAddExpr *SAE = dyn_cast<SCEVAddExpr>(Val)) {
|
||||
std::vector<SCEVHandle> NewOps;
|
||||
SmallVector<SCEVHandle, 4> NewOps;
|
||||
NewOps.reserve(SAE->getNumOperands());
|
||||
|
||||
for (unsigned i = 0; i != SAE->getNumOperands(); ++i)
|
||||
|
@ -613,7 +613,7 @@ static void MoveLoopVariantsToImmediateField(SCEVHandle &Val, SCEVHandle &Imm,
|
|||
SCEVHandle Start = SARE->getStart();
|
||||
MoveLoopVariantsToImmediateField(Start, Imm, L, SE);
|
||||
|
||||
std::vector<SCEVHandle> Ops(SARE->op_begin(), SARE->op_end());
|
||||
SmallVector<SCEVHandle, 4> Ops(SARE->op_begin(), SARE->op_end());
|
||||
Ops[0] = Start;
|
||||
Val = SE->getAddRecExpr(Ops, SARE->getLoop());
|
||||
} else {
|
||||
|
@ -633,7 +633,7 @@ static void MoveImmediateValues(const TargetLowering *TLI,
|
|||
bool isAddress, Loop *L,
|
||||
ScalarEvolution *SE) {
|
||||
if (const SCEVAddExpr *SAE = dyn_cast<SCEVAddExpr>(Val)) {
|
||||
std::vector<SCEVHandle> NewOps;
|
||||
SmallVector<SCEVHandle, 4> NewOps;
|
||||
NewOps.reserve(SAE->getNumOperands());
|
||||
|
||||
for (unsigned i = 0; i != SAE->getNumOperands(); ++i) {
|
||||
|
@ -660,7 +660,7 @@ static void MoveImmediateValues(const TargetLowering *TLI,
|
|||
MoveImmediateValues(TLI, AccessTy, Start, Imm, isAddress, L, SE);
|
||||
|
||||
if (Start != SARE->getStart()) {
|
||||
std::vector<SCEVHandle> Ops(SARE->op_begin(), SARE->op_end());
|
||||
SmallVector<SCEVHandle, 4> Ops(SARE->op_begin(), SARE->op_end());
|
||||
Ops[0] = Start;
|
||||
Val = SE->getAddRecExpr(Ops, SARE->getLoop());
|
||||
}
|
||||
|
@ -717,7 +717,7 @@ static void MoveImmediateValues(const TargetLowering *TLI,
|
|||
/// SeparateSubExprs - Decompose Expr into all of the subexpressions that are
|
||||
/// added together. This is used to reassociate common addition subexprs
|
||||
/// together for maximal sharing when rewriting bases.
|
||||
static void SeparateSubExprs(std::vector<SCEVHandle> &SubExprs,
|
||||
static void SeparateSubExprs(SmallVector<SCEVHandle, 16> &SubExprs,
|
||||
SCEVHandle Expr,
|
||||
ScalarEvolution *SE) {
|
||||
if (const SCEVAddExpr *AE = dyn_cast<SCEVAddExpr>(Expr)) {
|
||||
|
@ -729,7 +729,7 @@ static void SeparateSubExprs(std::vector<SCEVHandle> &SubExprs,
|
|||
SubExprs.push_back(Expr);
|
||||
} else {
|
||||
// Compute the addrec with zero as its base.
|
||||
std::vector<SCEVHandle> Ops(SARE->op_begin(), SARE->op_end());
|
||||
SmallVector<SCEVHandle, 4> Ops(SARE->op_begin(), SARE->op_end());
|
||||
Ops[0] = Zero; // Start with zero base.
|
||||
SubExprs.push_back(SE->getAddRecExpr(Ops, SARE->getLoop()));
|
||||
|
||||
|
@ -783,9 +783,9 @@ RemoveCommonExpressionsFromUseBases(std::vector<BasedUser> &Uses,
|
|||
|
||||
// UniqueSubExprs - Keep track of all of the subexpressions we see in the
|
||||
// order we see them.
|
||||
std::vector<SCEVHandle> UniqueSubExprs;
|
||||
SmallVector<SCEVHandle, 16> UniqueSubExprs;
|
||||
|
||||
std::vector<SCEVHandle> SubExprs;
|
||||
SmallVector<SCEVHandle, 16> SubExprs;
|
||||
unsigned NumUsesInsideLoop = 0;
|
||||
for (unsigned i = 0; i != NumUses; ++i) {
|
||||
// If the user is outside the loop, just ignore it for base computation.
|
||||
|
|
Loading…
Reference in New Issue