Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/Analysis/ScalarEvolution.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 1,928 Lines • ▼ Show 20 Lines | |||||
ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) { | ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) { | ||||
assert(getTypeSizeInBits(Op->getType()) < getTypeSizeInBits(Ty) && | assert(getTypeSizeInBits(Op->getType()) < getTypeSizeInBits(Ty) && | ||||
"This is not an extending conversion!"); | "This is not an extending conversion!"); | ||||
assert(isSCEVable(Ty) && | assert(isSCEVable(Ty) && | ||||
"This is not a conversion to a SCEVable type!"); | "This is not a conversion to a SCEVable type!"); | ||||
assert(!Op->getType()->isPointerTy() && "Can't extend pointer!"); | assert(!Op->getType()->isPointerTy() && "Can't extend pointer!"); | ||||
Ty = getEffectiveSCEVType(Ty); | Ty = getEffectiveSCEVType(Ty); | ||||
FoldID ID; | |||||
ID.addInteger(scSignExtend); | |||||
ID.addPointer(Op); | |||||
ID.addPointer(Ty); | |||||
auto Iter = FoldCache.find(ID); | |||||
if (Iter != FoldCache.end()) | |||||
return Iter->second; | |||||
const SCEV *S = getSignExtendExprImpl(Op, Ty, Depth); | |||||
if (!isa<SCEVSignExtendExpr>(S)) { | |||||
FoldCache.insert({ID, S}); | |||||
auto R = FoldCacheUser.insert({S, {}}); | |||||
R.first->second.push_back(ID); | |||||
} | |||||
return S; | |||||
} | |||||
const SCEV *ScalarEvolution::getSignExtendExprImpl(const SCEV *Op, Type *Ty, | |||||
unsigned Depth) { | |||||
assert(getTypeSizeInBits(Op->getType()) < getTypeSizeInBits(Ty) && | |||||
"This is not an extending conversion!"); | |||||
assert(isSCEVable(Ty) && "This is not a conversion to a SCEVable type!"); | |||||
assert(!Op->getType()->isPointerTy() && "Can't extend pointer!"); | |||||
Ty = getEffectiveSCEVType(Ty); | |||||
// Fold if the operand is constant. | // Fold if the operand is constant. | ||||
if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(Op)) | if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(Op)) | ||||
return getConstant( | return getConstant( | ||||
cast<ConstantInt>(ConstantExpr::getSExt(SC->getValue(), Ty))); | cast<ConstantInt>(ConstantExpr::getSExt(SC->getValue(), Ty))); | ||||
// sext(sext(x)) --> sext(x) | // sext(sext(x)) --> sext(x) | ||||
if (const SCEVSignExtendExpr *SS = dyn_cast<SCEVSignExtendExpr>(Op)) | if (const SCEVSignExtendExpr *SS = dyn_cast<SCEVSignExtendExpr>(Op)) | ||||
return getSignExtendExpr(SS->getOperand(), Ty, Depth + 1); | return getSignExtendExpr(SS->getOperand(), Ty, Depth + 1); | ||||
▲ Show 20 Lines • Show All 13,178 Lines • Show Last 20 Lines |