Refactor: Move the IRAccess building code to a new function.

llvm-svn: 183635
This commit is contained in:
Hongbin Zheng 2013-06-10 02:52:30 +00:00
parent c04341bb34
commit d1fdf0b180
2 changed files with 39 additions and 30 deletions

View File

@ -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);

View File

@ -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<LoadInst>(Inst)) {
Size = TD->getTypeStoreSize(Load->getType());
Type = IRAccess::READ;
} else {
StoreInst *Store = cast<StoreInst>(Inst);
Size = TD->getTypeStoreSize(Store->getValueOperand()->getType());
Type = IRAccess::WRITE;
}
const SCEV *AccessFunction =
SE->getSCEVAtScope(getPointerOperand(*Inst), L);
const SCEVUnknown *BasePointer =
dyn_cast<SCEVUnknown>(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<LoadInst>(&Inst) || isa<StoreInst>(&Inst)) {
unsigned Size;
enum IRAccess::TypeKind Type;
if (LoadInst *Load = dyn_cast<LoadInst>(&Inst)) {
Size = TD->getTypeStoreSize(Load->getType());
Type = IRAccess::READ;
} else {
StoreInst *Store = cast<StoreInst>(&Inst);
Size = TD->getTypeStoreSize(Store->getValueOperand()->getType());
Type = IRAccess::WRITE;
}
const SCEV *AccessFunction =
SE->getSCEVAtScope(getPointerOperand(Inst), L);
const SCEVUnknown *BasePointer =
dyn_cast<SCEVUnknown>(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<LoadInst>(Inst) || isa<StoreInst>(Inst))
Functions.push_back(std::make_pair(buildIRAccess(Inst, L, &R), Inst));
}
if (Functions.empty())