mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-04 08:16:49 +00:00
[SCEV] Add an expandAddToGEP overload for a single operand. NFC.
Only wanting to pass a single SCEV operand to use as the offset of the GEP is a common operation. Right now this requires creating a temporary stack array at every call site. Add an overload that encapsulates that pattern and simplify the call sites. Suggested-By: sanjoy (in https://reviews.llvm.org/D49832) llvm-svn: 338072
This commit is contained in:
parent
0f81faed05
commit
259ea987f5
@ -335,6 +335,7 @@ namespace llvm {
|
|||||||
Value *expandAddToGEP(const SCEV *const *op_begin,
|
Value *expandAddToGEP(const SCEV *const *op_begin,
|
||||||
const SCEV *const *op_end,
|
const SCEV *const *op_end,
|
||||||
PointerType *PTy, Type *Ty, Value *V);
|
PointerType *PTy, Type *Ty, Value *V);
|
||||||
|
Value *expandAddToGEP(const SCEV *Op, PointerType *PTy, Type *Ty, Value *V);
|
||||||
|
|
||||||
/// Find a previous Value in ExprValueMap for expand.
|
/// Find a previous Value in ExprValueMap for expand.
|
||||||
ScalarEvolution::ValueOffsetPair
|
ScalarEvolution::ValueOffsetPair
|
||||||
|
@ -589,6 +589,12 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin,
|
|||||||
return expand(SE.getAddExpr(Ops));
|
return expand(SE.getAddExpr(Ops));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value *SCEVExpander::expandAddToGEP(const SCEV *Op, PointerType *PTy, Type *Ty,
|
||||||
|
Value *V) {
|
||||||
|
const SCEV *const Ops[1] = {Op};
|
||||||
|
return expandAddToGEP(Ops, Ops + 1, PTy, Ty, V);
|
||||||
|
}
|
||||||
|
|
||||||
/// PickMostRelevantLoop - Given two loops pick the one that's most relevant for
|
/// PickMostRelevantLoop - Given two loops pick the one that's most relevant for
|
||||||
/// SCEV expansion. If they are nested, this is the most nested. If they are
|
/// SCEV expansion. If they are nested, this is the most nested. If they are
|
||||||
/// neighboring, pick the later.
|
/// neighboring, pick the later.
|
||||||
@ -1036,8 +1042,7 @@ Value *SCEVExpander::expandIVInc(PHINode *PN, Value *StepV, const Loop *L,
|
|||||||
if (!isa<ConstantInt>(StepV))
|
if (!isa<ConstantInt>(StepV))
|
||||||
GEPPtrTy = PointerType::get(Type::getInt1Ty(SE.getContext()),
|
GEPPtrTy = PointerType::get(Type::getInt1Ty(SE.getContext()),
|
||||||
GEPPtrTy->getAddressSpace());
|
GEPPtrTy->getAddressSpace());
|
||||||
const SCEV *const StepArray[1] = { SE.getSCEV(StepV) };
|
IncV = expandAddToGEP(SE.getSCEV(StepV), GEPPtrTy, IntTy, PN);
|
||||||
IncV = expandAddToGEP(StepArray, StepArray+1, GEPPtrTy, IntTy, PN);
|
|
||||||
if (IncV->getType() != PN->getType()) {
|
if (IncV->getType() != PN->getType()) {
|
||||||
IncV = Builder.CreateBitCast(IncV, PN->getType());
|
IncV = Builder.CreateBitCast(IncV, PN->getType());
|
||||||
rememberInstruction(IncV);
|
rememberInstruction(IncV);
|
||||||
@ -1443,12 +1448,9 @@ Value *SCEVExpander::expandAddRecExprLiterally(const SCEVAddRecExpr *S) {
|
|||||||
if (PointerType *PTy = dyn_cast<PointerType>(ExpandTy)) {
|
if (PointerType *PTy = dyn_cast<PointerType>(ExpandTy)) {
|
||||||
if (Result->getType()->isIntegerTy()) {
|
if (Result->getType()->isIntegerTy()) {
|
||||||
Value *Base = expandCodeFor(PostLoopOffset, ExpandTy);
|
Value *Base = expandCodeFor(PostLoopOffset, ExpandTy);
|
||||||
const SCEV *const OffsetArray[1] = {SE.getUnknown(Result)};
|
Result = expandAddToGEP(SE.getUnknown(Result), PTy, IntTy, Base);
|
||||||
Result = expandAddToGEP(OffsetArray, OffsetArray + 1, PTy, IntTy, Base);
|
|
||||||
} else {
|
} else {
|
||||||
const SCEV *const OffsetArray[1] = {PostLoopOffset};
|
Result = expandAddToGEP(PostLoopOffset, PTy, IntTy, Result);
|
||||||
Result =
|
|
||||||
expandAddToGEP(OffsetArray, OffsetArray + 1, PTy, IntTy, Result);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Result = InsertNoopCastOfTo(Result, IntTy);
|
Result = InsertNoopCastOfTo(Result, IntTy);
|
||||||
@ -1500,9 +1502,9 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
|
|||||||
// Turn things like ptrtoint+arithmetic+inttoptr into GEP. See the
|
// Turn things like ptrtoint+arithmetic+inttoptr into GEP. See the
|
||||||
// comments on expandAddToGEP for details.
|
// comments on expandAddToGEP for details.
|
||||||
const SCEV *Base = S->getStart();
|
const SCEV *Base = S->getStart();
|
||||||
const SCEV *RestArray[1] = { Rest };
|
|
||||||
// Dig into the expression to find the pointer base for a GEP.
|
// Dig into the expression to find the pointer base for a GEP.
|
||||||
ExposePointerBase(Base, RestArray[0], SE);
|
const SCEV *ExposedRest = Rest;
|
||||||
|
ExposePointerBase(Base, ExposedRest, SE);
|
||||||
// If we found a pointer, expand the AddRec with a GEP.
|
// If we found a pointer, expand the AddRec with a GEP.
|
||||||
if (PointerType *PTy = dyn_cast<PointerType>(Base->getType())) {
|
if (PointerType *PTy = dyn_cast<PointerType>(Base->getType())) {
|
||||||
// Make sure the Base isn't something exotic, such as a multiplied
|
// Make sure the Base isn't something exotic, such as a multiplied
|
||||||
@ -1511,7 +1513,7 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
|
|||||||
if (!isa<SCEVMulExpr>(Base) && !isa<SCEVUDivExpr>(Base)) {
|
if (!isa<SCEVMulExpr>(Base) && !isa<SCEVUDivExpr>(Base)) {
|
||||||
Value *StartV = expand(Base);
|
Value *StartV = expand(Base);
|
||||||
assert(StartV->getType() == PTy && "Pointer type mismatch for GEP!");
|
assert(StartV->getType() == PTy && "Pointer type mismatch for GEP!");
|
||||||
return expandAddToGEP(RestArray, RestArray+1, PTy, Ty, StartV);
|
return expandAddToGEP(ExposedRest, PTy, Ty, StartV);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user