Analysis: Simplify the ScalarEvolution::getGEPExpr() interface. NFCI.

All existing callers were manually extracting information out of an existing
GEP instruction and passing it to getGEPExpr(). Simplify the interface by
changing it to take a GEPOperator instead.

llvm-svn: 286751
This commit is contained in:
Peter Collingbourne 2016-11-13 06:59:50 +00:00
parent 9ef5a8c501
commit 8dff03911c
4 changed files with 14 additions and 20 deletions

View File

@ -1188,13 +1188,11 @@ public:
} }
/// Returns an expression for a GEP /// Returns an expression for a GEP
/// ///
/// \p PointeeType The type used as the basis for the pointer arithmetics /// \p GEP The GEP. The indices contained in the GEP itself are ignored,
/// \p BaseExpr The expression for the pointer operand. /// instead we use IndexExprs.
/// \p IndexExprs The expressions for the indices. /// \p IndexExprs The expressions for the indices.
/// \p InBounds Whether the GEP is in bounds. const SCEV *getGEPExpr(GEPOperator *GEP,
const SCEV *getGEPExpr(Type *PointeeType, const SCEV *BaseExpr, const SmallVectorImpl<const SCEV *> &IndexExprs);
const SmallVectorImpl<const SCEV *> &IndexExprs,
bool InBounds = false);
const SCEV *getSMaxExpr(const SCEV *LHS, const SCEV *RHS); const SCEV *getSMaxExpr(const SCEV *LHS, const SCEV *RHS);
const SCEV *getSMaxExpr(SmallVectorImpl<const SCEV *> &Operands); const SCEV *getSMaxExpr(SmallVectorImpl<const SCEV *> &Operands);
const SCEV *getUMaxExpr(const SCEV *LHS, const SCEV *RHS); const SCEV *getUMaxExpr(const SCEV *LHS, const SCEV *RHS);

View File

@ -3015,9 +3015,9 @@ ScalarEvolution::getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
} }
const SCEV * const SCEV *
ScalarEvolution::getGEPExpr(Type *PointeeType, const SCEV *BaseExpr, ScalarEvolution::getGEPExpr(GEPOperator *GEP,
const SmallVectorImpl<const SCEV *> &IndexExprs, const SmallVectorImpl<const SCEV *> &IndexExprs) {
bool InBounds) { const SCEV *BaseExpr = getSCEV(GEP->getPointerOperand());
// getSCEV(Base)->getType() has the same address space as Base->getType() // getSCEV(Base)->getType() has the same address space as Base->getType()
// because SCEV::getType() preserves the address space. // because SCEV::getType() preserves the address space.
Type *IntPtrTy = getEffectiveSCEVType(BaseExpr->getType()); Type *IntPtrTy = getEffectiveSCEVType(BaseExpr->getType());
@ -3026,12 +3026,13 @@ ScalarEvolution::getGEPExpr(Type *PointeeType, const SCEV *BaseExpr,
// flow and the no-overflow bits may not be valid for the expression in any // flow and the no-overflow bits may not be valid for the expression in any
// context. This can be fixed similarly to how these flags are handled for // context. This can be fixed similarly to how these flags are handled for
// adds. // adds.
SCEV::NoWrapFlags Wrap = InBounds ? SCEV::FlagNSW : SCEV::FlagAnyWrap; SCEV::NoWrapFlags Wrap = GEP->isInBounds() ? SCEV::FlagNSW
: SCEV::FlagAnyWrap;
const SCEV *TotalOffset = getZero(IntPtrTy); const SCEV *TotalOffset = getZero(IntPtrTy);
// The address space is unimportant. The first thing we do on CurTy is getting // The address space is unimportant. The first thing we do on CurTy is getting
// its element type. // its element type.
Type *CurTy = PointerType::getUnqual(PointeeType); Type *CurTy = PointerType::getUnqual(GEP->getSourceElementType());
for (const SCEV *IndexExpr : IndexExprs) { for (const SCEV *IndexExpr : IndexExprs) {
// Compute the (potentially symbolic) offset in bytes for this index. // Compute the (potentially symbolic) offset in bytes for this index.
if (StructType *STy = dyn_cast<StructType>(CurTy)) { if (StructType *STy = dyn_cast<StructType>(CurTy)) {
@ -4373,9 +4374,7 @@ const SCEV *ScalarEvolution::createNodeForGEP(GEPOperator *GEP) {
SmallVector<const SCEV *, 4> IndexExprs; SmallVector<const SCEV *, 4> IndexExprs;
for (auto Index = GEP->idx_begin(); Index != GEP->idx_end(); ++Index) for (auto Index = GEP->idx_begin(); Index != GEP->idx_end(); ++Index)
IndexExprs.push_back(getSCEV(*Index)); IndexExprs.push_back(getSCEV(*Index));
return getGEPExpr(GEP->getSourceElementType(), return getGEPExpr(GEP, IndexExprs);
getSCEV(GEP->getPointerOperand()),
IndexExprs, GEP->isInBounds());
} }
uint32_t uint32_t

View File

@ -354,9 +354,8 @@ NaryReassociatePass::tryReassociateGEPAtIndex(GetElementPtrInst *GEP,
IndexExprs[I] = IndexExprs[I] =
SE->getZeroExtendExpr(IndexExprs[I], GEP->getOperand(I)->getType()); SE->getZeroExtendExpr(IndexExprs[I], GEP->getOperand(I)->getType());
} }
const SCEV *CandidateExpr = SE->getGEPExpr( const SCEV *CandidateExpr = SE->getGEPExpr(cast<GEPOperator>(GEP),
GEP->getSourceElementType(), SE->getSCEV(GEP->getPointerOperand()), IndexExprs);
IndexExprs, GEP->isInBounds());
Value *Candidate = findClosestMatchingDominator(CandidateExpr, GEP); Value *Candidate = findClosestMatchingDominator(CandidateExpr, GEP);
if (Candidate == nullptr) if (Candidate == nullptr)

View File

@ -499,9 +499,7 @@ void StraightLineStrengthReduce::allocateCandidatesAndFindBasisForGEP(
// The base of this candidate is GEP's base plus the offsets of all // The base of this candidate is GEP's base plus the offsets of all
// indices except this current one. // indices except this current one.
const SCEV *BaseExpr = SE->getGEPExpr(GEP->getSourceElementType(), const SCEV *BaseExpr = SE->getGEPExpr(cast<GEPOperator>(GEP), IndexExprs);
SE->getSCEV(GEP->getPointerOperand()),
IndexExprs, GEP->isInBounds());
Value *ArrayIdx = GEP->getOperand(I); Value *ArrayIdx = GEP->getOperand(I);
uint64_t ElementSize = DL->getTypeAllocSize(*GTI); uint64_t ElementSize = DL->getTypeAllocSize(*GTI);
if (ArrayIdx->getType()->getIntegerBitWidth() <= if (ArrayIdx->getType()->getIntegerBitWidth() <=