Simplify ScopInfo function interfaces [NFC]

llvm-svn: 270428
This commit is contained in:
Johannes Doerfert 2016-05-23 12:45:17 +00:00
parent e0b08077bf
commit 57a7317fb8
2 changed files with 43 additions and 52 deletions

View File

@ -2292,53 +2292,47 @@ class ScopInfo : public RegionPass {
/// ///
/// @param Inst The Load/Store instruction that access the memory /// @param Inst The Load/Store instruction that access the memory
/// @param L The parent loop of the instruction /// @param L The parent loop of the instruction
/// @param R The region on which to build the data access dictionary.
/// ///
/// @returns True if the access could be built, False otherwise. /// @returns True if the access could be built, False otherwise.
bool buildAccessMultiDimFixed(MemAccInst Inst, Loop *L, Region *R); bool buildAccessMultiDimFixed(MemAccInst Inst, Loop *L);
/// @brief Try to build a multi-dimensional parameteric sized MemoryAccess /// @brief Try to build a multi-dimensional parameteric sized MemoryAccess
/// from the Load/Store instruction. /// from the Load/Store instruction.
/// ///
/// @param Inst The Load/Store instruction that access the memory /// @param Inst The Load/Store instruction that access the memory
/// @param L The parent loop of the instruction /// @param L The parent loop of the instruction
/// @param R The region on which to build the data access dictionary.
/// ///
/// @returns True if the access could be built, False otherwise. /// @returns True if the access could be built, False otherwise.
bool buildAccessMultiDimParam(MemAccInst Inst, Loop *L, Region *R); bool buildAccessMultiDimParam(MemAccInst Inst, Loop *L);
/// @brief Try to build a MemoryAccess for a memory intrinsic. /// @brief Try to build a MemoryAccess for a memory intrinsic.
/// ///
/// @param Inst The instruction that access the memory /// @param Inst The instruction that access the memory
/// @param L The parent loop of the instruction /// @param L The parent loop of the instruction
/// @param R The region on which to build the data access dictionary.
/// ///
/// @returns True if the access could be built, False otherwise. /// @returns True if the access could be built, False otherwise.
bool buildAccessMemIntrinsic(MemAccInst Inst, Loop *L, Region *R); bool buildAccessMemIntrinsic(MemAccInst Inst, Loop *L);
/// @brief Try to build a MemoryAccess for a call instruction. /// @brief Try to build a MemoryAccess for a call instruction.
/// ///
/// @param Inst The call instruction that access the memory /// @param Inst The call instruction that access the memory
/// @param L The parent loop of the instruction /// @param L The parent loop of the instruction
/// @param R The region on which to build the data access dictionary.
/// ///
/// @returns True if the access could be built, False otherwise. /// @returns True if the access could be built, False otherwise.
bool buildAccessCallInst(MemAccInst Inst, Loop *L, Region *R); bool buildAccessCallInst(MemAccInst Inst, Loop *L);
/// @brief Build a single-dimensional parameteric sized MemoryAccess /// @brief Build a single-dimensional parameteric sized MemoryAccess
/// from the Load/Store instruction. /// from the Load/Store instruction.
/// ///
/// @param Inst The Load/Store instruction that access the memory /// @param Inst The Load/Store instruction that access the memory
/// @param L The parent loop of the instruction /// @param L The parent loop of the instruction
/// @param R The region on which to build the data access dictionary. void buildAccessSingleDim(MemAccInst Inst, Loop *L);
void buildAccessSingleDim(MemAccInst Inst, Loop *L, Region *R);
/// @brief Build an instance of MemoryAccess from the Load/Store instruction. /// @brief Build an instance of MemoryAccess from the Load/Store instruction.
/// ///
/// @param Inst The Load/Store instruction that access the memory /// @param Inst The Load/Store instruction that access the memory
/// @param L The parent loop of the instruction /// @param L The parent loop of the instruction
/// @param R The region on which to build the data access dictionary. void buildMemoryAccess(MemAccInst Inst, Loop *L);
void buildMemoryAccess(MemAccInst Inst, Loop *L, Region *R);
/// @brief Analyze and extract the cross-BB scalar dependences (or, /// @brief Analyze and extract the cross-BB scalar dependences (or,
/// dataflow dependencies) of an instruction. /// dataflow dependencies) of an instruction.
@ -2356,35 +2350,31 @@ class ScopInfo : public RegionPass {
/// @brief Create MemoryAccesses for the given PHI node in the given region. /// @brief Create MemoryAccesses for the given PHI node in the given region.
/// ///
/// @param PHI The PHI node to be handled /// @param PHI The PHI node to be handled
/// @param R The SCoP region
/// @param NonAffineSubRegion The non affine sub-region @p PHI is in. /// @param NonAffineSubRegion The non affine sub-region @p PHI is in.
/// @param IsExitBlock Flag to indicate that @p PHI is in the exit BB. /// @param IsExitBlock Flag to indicate that @p PHI is in the exit BB.
void buildPHIAccesses(PHINode *PHI, Region &R, Region *NonAffineSubRegion, void buildPHIAccesses(PHINode *PHI, Region *NonAffineSubRegion,
bool IsExitBlock = false); bool IsExitBlock = false);
/// @brief Build the access functions for the subregion @p SR. /// @brief Build the access functions for the subregion @p SR.
/// ///
/// @param R The SCoP region.
/// @param SR A subregion of @p R. /// @param SR A subregion of @p R.
/// @param InsnToMemAcc The Instruction to MemoryAccess mapping. /// @param InsnToMemAcc The Instruction to MemoryAccess mapping.
void buildAccessFunctions(Region &R, Region &SR); void buildAccessFunctions(Region &SR);
/// @brief Create ScopStmt for all BBs and non-affine subregions of @p SR. /// @brief Create ScopStmt for all BBs and non-affine subregions of @p SR.
/// ///
/// @param R The SCoP region.
/// @param SR A subregion of @p R. /// @param SR A subregion of @p R.
/// ///
/// Some of the statments might be optimized away later when they do not /// Some of the statments might be optimized away later when they do not
/// access any memory and thus have no effect. /// access any memory and thus have no effect.
void buildStmts(Region &R, Region &SR); void buildStmts(Region &SR);
/// @brief Build the access functions for the basic block @p BB /// @brief Build the access functions for the basic block @p BB
/// ///
/// @param R The SCoP region.
/// @param BB A basic block in @p R. /// @param BB A basic block in @p R.
/// @param NonAffineSubRegion The non affine sub-region @p BB is in. /// @param NonAffineSubRegion The non affine sub-region @p BB is in.
/// @param IsExitBlock Flag to indicate that @p BB is in the exit BB. /// @param IsExitBlock Flag to indicate that @p BB is in the exit BB.
void buildAccessFunctions(Region &R, BasicBlock &BB, void buildAccessFunctions(BasicBlock &BB,
Region *NonAffineSubRegion = nullptr, Region *NonAffineSubRegion = nullptr,
bool IsExitBlock = false); bool IsExitBlock = false);

View File

@ -4243,8 +4243,8 @@ int Scop::getRelativeLoopDepth(const Loop *L) const {
return L->getLoopDepth() - OuterLoop->getLoopDepth(); return L->getLoopDepth() - OuterLoop->getLoopDepth();
} }
void ScopInfo::buildPHIAccesses(PHINode *PHI, Region &R, void ScopInfo::buildPHIAccesses(PHINode *PHI, Region *NonAffineSubRegion,
Region *NonAffineSubRegion, bool IsExitBlock) { bool IsExitBlock) {
// PHI nodes that are in the exit block of the region, hence if IsExitBlock is // PHI nodes that are in the exit block of the region, hence if IsExitBlock is
// true, are not modeled as ordinary PHI nodes as they are not part of the // true, are not modeled as ordinary PHI nodes as they are not part of the
@ -4255,7 +4255,7 @@ void ScopInfo::buildPHIAccesses(PHINode *PHI, Region &R,
// the region. If it is not it can only be in the exit block of the region. // the region. If it is not it can only be in the exit block of the region.
// In this case we model the operands but not the PHI itself. // In this case we model the operands but not the PHI itself.
auto *Scope = LI->getLoopFor(PHI->getParent()); auto *Scope = LI->getLoopFor(PHI->getParent());
if (!IsExitBlock && canSynthesize(PHI, LI, SE, &R, Scope)) if (!IsExitBlock && canSynthesize(PHI, LI, SE, &scop->getRegion(), Scope))
return; return;
// PHI nodes are modeled as if they had been demoted prior to the SCoP // PHI nodes are modeled as if they had been demoted prior to the SCoP
@ -4314,7 +4314,7 @@ void ScopInfo::buildEscapingDependences(Instruction *Inst) {
} }
} }
bool ScopInfo::buildAccessMultiDimFixed(MemAccInst Inst, Loop *L, Region *R) { bool ScopInfo::buildAccessMultiDimFixed(MemAccInst Inst, Loop *L) {
Value *Val = Inst.getValueOperand(); Value *Val = Inst.getValueOperand();
Type *ElementType = Val->getType(); Type *ElementType = Val->getType();
Value *Address = Inst.getPointerOperand(); Value *Address = Inst.getPointerOperand();
@ -4361,7 +4361,7 @@ bool ScopInfo::buildAccessMultiDimFixed(MemAccInst Inst, Loop *L, Region *R) {
const InvariantLoadsSetTy &ScopRIL = scop->getRequiredInvariantLoads(); const InvariantLoadsSetTy &ScopRIL = scop->getRequiredInvariantLoads();
for (auto *Subscript : Subscripts) { for (auto *Subscript : Subscripts) {
InvariantLoadsSetTy AccessILS; InvariantLoadsSetTy AccessILS;
if (!isAffineExpr(R, L, Subscript, *SE, &AccessILS)) if (!isAffineExpr(&scop->getRegion(), L, Subscript, *SE, &AccessILS))
return false; return false;
for (LoadInst *LInst : AccessILS) for (LoadInst *LInst : AccessILS)
@ -4381,7 +4381,7 @@ bool ScopInfo::buildAccessMultiDimFixed(MemAccInst Inst, Loop *L, Region *R) {
return true; return true;
} }
bool ScopInfo::buildAccessMultiDimParam(MemAccInst Inst, Loop *L, Region *R) { bool ScopInfo::buildAccessMultiDimParam(MemAccInst Inst, Loop *L) {
if (!PollyDelinearize) if (!PollyDelinearize)
return false; return false;
@ -4424,7 +4424,7 @@ bool ScopInfo::buildAccessMultiDimParam(MemAccInst Inst, Loop *L, Region *R) {
return true; return true;
} }
bool ScopInfo::buildAccessMemIntrinsic(MemAccInst Inst, Loop *L, Region *R) { bool ScopInfo::buildAccessMemIntrinsic(MemAccInst Inst, Loop *L) {
auto *MemIntr = dyn_cast_or_null<MemIntrinsic>(Inst); auto *MemIntr = dyn_cast_or_null<MemIntrinsic>(Inst);
if (MemIntr == nullptr) if (MemIntr == nullptr)
@ -4436,7 +4436,8 @@ bool ScopInfo::buildAccessMemIntrinsic(MemAccInst Inst, Loop *L, Region *R) {
// Check if the length val is actually affine or if we overapproximate it // Check if the length val is actually affine or if we overapproximate it
InvariantLoadsSetTy AccessILS; InvariantLoadsSetTy AccessILS;
const InvariantLoadsSetTy &ScopRIL = scop->getRequiredInvariantLoads(); const InvariantLoadsSetTy &ScopRIL = scop->getRequiredInvariantLoads();
bool LengthIsAffine = isAffineExpr(R, L, LengthVal, *SE, &AccessILS); bool LengthIsAffine =
isAffineExpr(&scop->getRegion(), L, LengthVal, *SE, &AccessILS);
for (LoadInst *LInst : AccessILS) for (LoadInst *LInst : AccessILS)
if (!ScopRIL.count(LInst)) if (!ScopRIL.count(LInst))
LengthIsAffine = false; LengthIsAffine = false;
@ -4487,7 +4488,7 @@ bool ScopInfo::buildAccessMemIntrinsic(MemAccInst Inst, Loop *L, Region *R) {
return true; return true;
} }
bool ScopInfo::buildAccessCallInst(MemAccInst Inst, Loop *L, Region *R) { bool ScopInfo::buildAccessCallInst(MemAccInst Inst, Loop *L) {
auto *CI = dyn_cast_or_null<CallInst>(Inst); auto *CI = dyn_cast_or_null<CallInst>(Inst);
if (CI == nullptr) if (CI == nullptr)
@ -4530,7 +4531,7 @@ bool ScopInfo::buildAccessCallInst(MemAccInst Inst, Loop *L, Region *R) {
return true; return true;
} }
void ScopInfo::buildAccessSingleDim(MemAccInst Inst, Loop *L, Region *R) { void ScopInfo::buildAccessSingleDim(MemAccInst Inst, Loop *L) {
Value *Address = Inst.getPointerOperand(); Value *Address = Inst.getPointerOperand();
Value *Val = Inst.getValueOperand(); Value *Val = Inst.getValueOperand();
Type *ElementType = Val->getType(); Type *ElementType = Val->getType();
@ -4554,8 +4555,9 @@ void ScopInfo::buildAccessSingleDim(MemAccInst Inst, Loop *L, Region *R) {
isVariantInNonAffineLoop = true; isVariantInNonAffineLoop = true;
InvariantLoadsSetTy AccessILS; InvariantLoadsSetTy AccessILS;
bool IsAffine = !isVariantInNonAffineLoop && bool IsAffine =
isAffineExpr(R, L, AccessFunction, *SE, &AccessILS); !isVariantInNonAffineLoop &&
isAffineExpr(&scop->getRegion(), L, AccessFunction, *SE, &AccessILS);
const InvariantLoadsSetTy &ScopRIL = scop->getRequiredInvariantLoads(); const InvariantLoadsSetTy &ScopRIL = scop->getRequiredInvariantLoads();
for (LoadInst *LInst : AccessILS) for (LoadInst *LInst : AccessILS)
@ -4569,39 +4571,39 @@ void ScopInfo::buildAccessSingleDim(MemAccInst Inst, Loop *L, Region *R) {
{AccessFunction}, {}, Val); {AccessFunction}, {}, Val);
} }
void ScopInfo::buildMemoryAccess(MemAccInst Inst, Loop *L, Region *R) { void ScopInfo::buildMemoryAccess(MemAccInst Inst, Loop *L) {
if (buildAccessMemIntrinsic(Inst, L, R)) if (buildAccessMemIntrinsic(Inst, L))
return; return;
if (buildAccessCallInst(Inst, L, R)) if (buildAccessCallInst(Inst, L))
return; return;
if (buildAccessMultiDimFixed(Inst, L, R)) if (buildAccessMultiDimFixed(Inst, L))
return; return;
if (buildAccessMultiDimParam(Inst, L, R)) if (buildAccessMultiDimParam(Inst, L))
return; return;
buildAccessSingleDim(Inst, L, R); buildAccessSingleDim(Inst, L);
} }
void ScopInfo::buildAccessFunctions(Region &R, Region &SR) { void ScopInfo::buildAccessFunctions(Region &SR) {
if (scop->isNonAffineSubRegion(&SR)) { if (scop->isNonAffineSubRegion(&SR)) {
for (BasicBlock *BB : SR.blocks()) for (BasicBlock *BB : SR.blocks())
buildAccessFunctions(R, *BB, &SR); buildAccessFunctions(*BB, &SR);
return; return;
} }
for (auto I = SR.element_begin(), E = SR.element_end(); I != E; ++I) for (auto I = SR.element_begin(), E = SR.element_end(); I != E; ++I)
if (I->isSubRegion()) if (I->isSubRegion())
buildAccessFunctions(R, *I->getNodeAs<Region>()); buildAccessFunctions(*I->getNodeAs<Region>());
else else
buildAccessFunctions(R, *I->getNodeAs<BasicBlock>()); buildAccessFunctions(*I->getNodeAs<BasicBlock>());
} }
void ScopInfo::buildStmts(Region &R, Region &SR) { void ScopInfo::buildStmts(Region &SR) {
if (scop->isNonAffineSubRegion(&SR)) { if (scop->isNonAffineSubRegion(&SR)) {
scop->addScopStmt(nullptr, &SR); scop->addScopStmt(nullptr, &SR);
@ -4610,17 +4612,16 @@ void ScopInfo::buildStmts(Region &R, Region &SR) {
for (auto I = SR.element_begin(), E = SR.element_end(); I != E; ++I) for (auto I = SR.element_begin(), E = SR.element_end(); I != E; ++I)
if (I->isSubRegion()) if (I->isSubRegion())
buildStmts(R, *I->getNodeAs<Region>()); buildStmts(*I->getNodeAs<Region>());
else else
scop->addScopStmt(I->getNodeAs<BasicBlock>(), nullptr); scop->addScopStmt(I->getNodeAs<BasicBlock>(), nullptr);
} }
void ScopInfo::buildAccessFunctions(Region &R, BasicBlock &BB, void ScopInfo::buildAccessFunctions(BasicBlock &BB, Region *NonAffineSubRegion,
Region *NonAffineSubRegion,
bool IsExitBlock) { bool IsExitBlock) {
// We do not build access functions for error blocks, as they may contain // We do not build access functions for error blocks, as they may contain
// instructions we can not model. // instructions we can not model.
if (isErrorBlock(BB, R, *LI, *DT) && !IsExitBlock) if (isErrorBlock(BB, scop->getRegion(), *LI, *DT) && !IsExitBlock)
return; return;
Loop *L = LI->getLoopFor(&BB); Loop *L = LI->getLoopFor(&BB);
@ -4628,14 +4629,14 @@ void ScopInfo::buildAccessFunctions(Region &R, BasicBlock &BB,
for (Instruction &Inst : BB) { for (Instruction &Inst : BB) {
PHINode *PHI = dyn_cast<PHINode>(&Inst); PHINode *PHI = dyn_cast<PHINode>(&Inst);
if (PHI) if (PHI)
buildPHIAccesses(PHI, R, NonAffineSubRegion, IsExitBlock); buildPHIAccesses(PHI, NonAffineSubRegion, IsExitBlock);
// For the exit block we stop modeling after the last PHI node. // For the exit block we stop modeling after the last PHI node.
if (!PHI && IsExitBlock) if (!PHI && IsExitBlock)
break; break;
if (auto MemInst = MemAccInst::dyn_cast(Inst)) if (auto MemInst = MemAccInst::dyn_cast(Inst))
buildMemoryAccess(MemInst, L, &R); buildMemoryAccess(MemInst, L);
if (isIgnoredIntrinsic(&Inst)) if (isIgnoredIntrinsic(&Inst))
continue; continue;
@ -4829,8 +4830,8 @@ void ScopInfo::addPHIReadAccess(PHINode *PHI) {
void ScopInfo::buildScop(Region &R, AssumptionCache &AC) { void ScopInfo::buildScop(Region &R, AssumptionCache &AC) {
scop.reset(new Scop(R, *SE, *LI, *SD->getDetectionContext(&R))); scop.reset(new Scop(R, *SE, *LI, *SD->getDetectionContext(&R)));
buildStmts(R, R); buildStmts(R);
buildAccessFunctions(R, R); buildAccessFunctions(R);
// In case the region does not have an exiting block we will later (during // In case the region does not have an exiting block we will later (during
// code generation) split the exit block. This will move potential PHI nodes // code generation) split the exit block. This will move potential PHI nodes
@ -4840,7 +4841,7 @@ void ScopInfo::buildScop(Region &R, AssumptionCache &AC) {
// accesses. Note that we do not model anything in the exit block if we have // accesses. Note that we do not model anything in the exit block if we have
// an exiting block in the region, as there will not be any splitting later. // an exiting block in the region, as there will not be any splitting later.
if (!scop->hasSingleExitEdge()) if (!scop->hasSingleExitEdge())
buildAccessFunctions(R, *R.getExit(), nullptr, buildAccessFunctions(*R.getExit(), nullptr,
/* IsExitBlock */ true); /* IsExitBlock */ true);
// Create memory accesses for global reads since all arrays are now known. // Create memory accesses for global reads since all arrays are now known.