Index: include/polly/ScopDetection.h =================================================================== --- include/polly/ScopDetection.h +++ include/polly/ScopDetection.h @@ -220,6 +220,10 @@ /// @returns The number of regions erased regions. unsigned removeCachedResultsRecursively(const Region &R); + /// @brief Map to memory access description for the corresponding LLVM + /// instructions. + mutable MapInsnToMemAcc InsnToMemAcc; + /// @brief Add the region @p AR as over approximated sub-region in @p Context. /// /// @param AR The non-affine subregion. @@ -514,6 +518,10 @@ /// @return The error or "" if no error appeared. std::string regionIsInvalidBecause(const Region *R) const; + /// @brief Get the instruction to memory access mapping of the current + /// function + MapInsnToMemAcc &getInsnToMemAccMap() const { return InsnToMemAcc; } + /// @name Maximum Region In Scops Iterators /// /// These iterators iterator over all maximum region in Scops of this Index: include/polly/ScopInfo.h =================================================================== --- include/polly/ScopInfo.h +++ include/polly/ScopInfo.h @@ -2040,11 +2040,13 @@ /// @param R The region on which to build the data access dictionary. /// @param BoxedLoops The set of loops that are overapproximated in @p R. /// @param ScopRIL The required invariant loads equivalence classes. + /// @param InsnToMemAcc The Instruction to MemoryAccess mapping /// @returns True if the access could be built, False otherwise. bool buildAccessMultiDimParam(MemAccInst Inst, Loop *L, Region *R, const ScopDetection::BoxedLoopsSetTy *BoxedLoops, - const InvariantLoadsSetTy &ScopRIL); + const InvariantLoadsSetTy &ScopRIL, + const MapInsnToMemAcc &InsnToMemAcc); /// @brief Build a single-dimensional parameteric sized MemoryAccess /// from the Load/Store instruction. @@ -2065,9 +2067,11 @@ /// @param R The region on which to build the data access dictionary. /// @param BoxedLoops The set of loops that are overapproximated in @p R. /// @param ScopRIL The required invariant loads equivalence classes. + /// @param InsnToMemAcc The Instruction to MemoryAccess mapping. void buildMemoryAccess(MemAccInst Inst, Loop *L, Region *R, const ScopDetection::BoxedLoopsSetTy *BoxedLoops, - const InvariantLoadsSetTy &ScopRIL); + const InvariantLoadsSetTy &ScopRIL, + const MapInsnToMemAcc &InsnToMemAcc); /// @brief Analyze and extract the cross-BB scalar dependences (or, /// dataflow dependencies) of an instruction. @@ -2093,9 +2097,11 @@ /// @brief Build the access functions for the subregion @p SR. /// - /// @param R The SCoP region. - /// @param SR A subregion of @p R. - void buildAccessFunctions(Region &R, Region &SR); + /// @param R The SCoP region. + /// @param SR A subregion of @p R. + /// @param InsnToMemAcc The Instruction to MemoryAccess mapping. + void buildAccessFunctions(Region &R, Region &SR, + const MapInsnToMemAcc &InsnToMemAcc); /// @brief Create ScopStmt for all BBs and non-affine subregions of @p SR. /// @@ -2110,9 +2116,11 @@ /// /// @param R The SCoP region. /// @param BB A basic block in @p R. + /// @param InsnToMemAcc The Instruction to MemoryAccess mapping. /// @param NonAffineSubRegion The non affine sub-region @p BB is in. /// @param IsExitBlock Flag to indicate that @p BB is in the exit BB. void buildAccessFunctions(Region &R, BasicBlock &BB, + const MapInsnToMemAcc &InsnToMemAcc, Region *NonAffineSubRegion = nullptr, bool IsExitBlock = false); Index: lib/Analysis/ScopDetection.cpp =================================================================== --- lib/Analysis/ScopDetection.cpp +++ lib/Analysis/ScopDetection.cpp @@ -501,8 +501,6 @@ return true; } -MapInsnToMemAcc InsnToMemAcc; - /// @brief Remove smax of smax(0, size) expressions from a SCEV expression and /// register the '...' components. /// Index: lib/Analysis/ScopInfo.cpp =================================================================== --- lib/Analysis/ScopInfo.cpp +++ lib/Analysis/ScopInfo.cpp @@ -3734,8 +3734,6 @@ } } -extern MapInsnToMemAcc InsnToMemAcc; - bool ScopInfo::buildAccessMultiDimFixed( MemAccInst Inst, Loop *L, Region *R, const ScopDetection::BoxedLoopsSetTy *BoxedLoops, @@ -3795,7 +3793,7 @@ bool ScopInfo::buildAccessMultiDimParam( MemAccInst Inst, Loop *L, Region *R, const ScopDetection::BoxedLoopsSetTy *BoxedLoops, - const InvariantLoadsSetTy &ScopRIL) { + const InvariantLoadsSetTy &ScopRIL, const MapInsnToMemAcc &InsnToMemAcc) { Value *Address = Inst.getPointerOperand(); Value *Val = Inst.getValueOperand(); Type *SizeType = Val->getType(); @@ -3881,30 +3879,31 @@ void ScopInfo::buildMemoryAccess( MemAccInst Inst, Loop *L, Region *R, const ScopDetection::BoxedLoopsSetTy *BoxedLoops, - const InvariantLoadsSetTy &ScopRIL) { + const InvariantLoadsSetTy &ScopRIL, const MapInsnToMemAcc &InsnToMemAcc) { if (buildAccessMultiDimFixed(Inst, L, R, BoxedLoops, ScopRIL)) return; - if (buildAccessMultiDimParam(Inst, L, R, BoxedLoops, ScopRIL)) + if (buildAccessMultiDimParam(Inst, L, R, BoxedLoops, ScopRIL, InsnToMemAcc)) return; buildAccessSingleDim(Inst, L, R, BoxedLoops, ScopRIL); } -void ScopInfo::buildAccessFunctions(Region &R, Region &SR) { +void ScopInfo::buildAccessFunctions(Region &R, Region &SR, + const MapInsnToMemAcc &InsnToMemAcc) { if (SD->isNonAffineSubRegion(&SR, &R)) { for (BasicBlock *BB : SR.blocks()) - buildAccessFunctions(R, *BB, &SR); + buildAccessFunctions(R, *BB, InsnToMemAcc, &SR); return; } for (auto I = SR.element_begin(), E = SR.element_end(); I != E; ++I) if (I->isSubRegion()) - buildAccessFunctions(R, *I->getNodeAs()); + buildAccessFunctions(R, *I->getNodeAs(), InsnToMemAcc); else - buildAccessFunctions(R, *I->getNodeAs()); + buildAccessFunctions(R, *I->getNodeAs(), InsnToMemAcc); } void ScopInfo::buildStmts(Region &R, Region &SR) { @@ -3922,6 +3921,7 @@ } void ScopInfo::buildAccessFunctions(Region &R, BasicBlock &BB, + const MapInsnToMemAcc &InsnToMemAcc, Region *NonAffineSubRegion, bool IsExitBlock) { // We do not build access functions for error blocks, as they may contain @@ -3951,7 +3951,7 @@ // there might be other invariant accesses that will be hoisted and // that would allow to make a non-affine access affine. if (auto MemInst = MemAccInst::dyn_cast(Inst)) - buildMemoryAccess(MemInst, L, &R, BoxedLoops, ScopRIL); + buildMemoryAccess(MemInst, L, &R, BoxedLoops, ScopRIL, InsnToMemAcc); if (isIgnoredIntrinsic(&Inst)) continue; @@ -4129,7 +4129,7 @@ scop = new Scop(R, *SE, ctx, MaxLoopDepth); buildStmts(R, R); - buildAccessFunctions(R, R); + buildAccessFunctions(R, R, SD->getInsnToMemAccMap()); // 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 @@ -4139,7 +4139,8 @@ // 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. if (!R.getExitingBlock()) - buildAccessFunctions(R, *R.getExit(), nullptr, /* IsExitBlock */ true); + buildAccessFunctions(R, *R.getExit(), SD->getInsnToMemAccMap(), nullptr, + /* IsExitBlock */ true); scop->init(*AA, AC, *SD, *DT, *LI); }