diff --git a/polly/include/polly/TempScopInfo.h b/polly/include/polly/TempScopInfo.h index 7b8564d0d3d9..1e9ce4773ce0 100755 --- a/polly/include/polly/TempScopInfo.h +++ b/polly/include/polly/TempScopInfo.h @@ -264,6 +264,16 @@ class TempScopInfo : public FunctionPass { // of Scop. TempScop *buildTempScop(Region &R); + /// @brief Build an instance of IRAccess from the Load/Store instruction. + /// + /// @param Inst The Load/Store instruction that access the memory + /// @param L The parent loop of the instruction + /// @param R The region on which we are going to build a TempScop + /// + /// @return The IRAccess to describe the access function of the + /// instruction. + IRAccess buildIRAccess(Instruction *Inst, Loop *L, Region *R); + void buildAccessFunctions(Region &RefRegion, BasicBlock &BB); void buildLoopBounds(TempScop &Scop); diff --git a/polly/lib/Analysis/TempScopInfo.cpp b/polly/lib/Analysis/TempScopInfo.cpp index fe8edb1f00f6..78210a532f6d 100644 --- a/polly/lib/Analysis/TempScopInfo.cpp +++ b/polly/lib/Analysis/TempScopInfo.cpp @@ -73,41 +73,40 @@ void TempScop::printDetail(llvm::raw_ostream &OS, ScalarEvolution *SE, LoopInfo *LI, const Region *CurR, unsigned ind) const {} +IRAccess TempScopInfo::buildIRAccess(Instruction *Inst, Loop *L, Region *R) { + unsigned Size; + enum IRAccess::TypeKind Type; + + if (LoadInst *Load = dyn_cast(Inst)) { + Size = TD->getTypeStoreSize(Load->getType()); + Type = IRAccess::READ; + } else { + StoreInst *Store = cast(Inst); + Size = TD->getTypeStoreSize(Store->getValueOperand()->getType()); + Type = IRAccess::WRITE; + } + + const SCEV *AccessFunction = + SE->getSCEVAtScope(getPointerOperand(*Inst), L); + const SCEVUnknown *BasePointer = + dyn_cast(SE->getPointerBase(AccessFunction)); + + assert(BasePointer && "Could not find base pointer"); + AccessFunction = SE->getMinusSCEV(AccessFunction, BasePointer); + + bool IsAffine = isAffineExpr(R, AccessFunction, *SE, BasePointer->getValue()); + + return IRAccess(Type, BasePointer->getValue(), AccessFunction, Size, IsAffine); +} + void TempScopInfo::buildAccessFunctions(Region &R, BasicBlock &BB) { AccFuncSetType Functions; Loop *L = LI->getLoopFor(&BB); for (BasicBlock::iterator I = BB.begin(), E = --BB.end(); I != E; ++I) { - Instruction &Inst = *I; - if (isa(&Inst) || isa(&Inst)) { - unsigned Size; - enum IRAccess::TypeKind Type; - - if (LoadInst *Load = dyn_cast(&Inst)) { - Size = TD->getTypeStoreSize(Load->getType()); - Type = IRAccess::READ; - } else { - StoreInst *Store = cast(&Inst); - Size = TD->getTypeStoreSize(Store->getValueOperand()->getType()); - Type = IRAccess::WRITE; - } - - const SCEV *AccessFunction = - SE->getSCEVAtScope(getPointerOperand(Inst), L); - const SCEVUnknown *BasePointer = - dyn_cast(SE->getPointerBase(AccessFunction)); - - assert(BasePointer && "Could not find base pointer"); - AccessFunction = SE->getMinusSCEV(AccessFunction, BasePointer); - - bool IsAffine = - isAffineExpr(&R, AccessFunction, *SE, BasePointer->getValue()); - - Functions.push_back( - std::make_pair(IRAccess(Type, BasePointer->getValue(), AccessFunction, - Size, IsAffine), - &Inst)); - } + Instruction *Inst = I; + if (isa(Inst) || isa(Inst)) + Functions.push_back(std::make_pair(buildIRAccess(Inst, L, &R), Inst)); } if (Functions.empty())