[polly] r261791 - Introduce Scop::getStmtFor. NFC.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 24 14:08:19 PST 2016


Author: meinersbur
Date: Wed Feb 24 16:08:19 2016
New Revision: 261791

URL: http://llvm.org/viewvc/llvm-project?rev=261791&view=rev
Log:
Introduce Scop::getStmtFor. NFC.

Replace Scop::getStmtForBasicBlock and Scop::getStmtForRegionNode, and
add overloads for llvm::Instruction and llvm::RegionNode.

getStmtFor and overloads become the common interface to get the Stmt
that contains something. Named after LoopInfo::getLoopFor and
RegionInfo::getRegionFor.

Modified:
    polly/trunk/include/polly/ScopInfo.h
    polly/trunk/lib/Analysis/ScopInfo.cpp
    polly/trunk/lib/CodeGen/IslNodeBuilder.cpp

Modified: polly/trunk/include/polly/ScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopInfo.h?rev=261791&r1=261790&r2=261791&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Wed Feb 24 16:08:19 2016
@@ -1859,13 +1859,24 @@ public:
   /// @brief Get an isl string representing the boundary context.
   std::string getBoundaryContextStr() const;
 
-  /// @brief Return the stmt for the given @p BB or nullptr if none.
-  ScopStmt *getStmtForBasicBlock(BasicBlock *BB) const;
+  /// @brief Return the ScopStmt for the given @p BB or nullptr if there is
+  ///        none.
+  ScopStmt *getStmtFor(BasicBlock *BB) const;
+
+  /// @brief Return the ScopStmt that represents the Region @p R, or nullptr if
+  ///        it is not represented by any statement in this Scop.
+  ScopStmt *getStmtFor(Region *R) const;
 
   /// @brief Return the ScopStmt that represents @p RN; can return nullptr if
-  /// the RegionNode is not within the SCoP or has been removed due to
-  /// simplifications.
-  ScopStmt *getStmtForRegionNode(RegionNode *RN) const;
+  ///        the RegionNode is not within the SCoP or has been removed due to
+  ///        simplifications.
+  ScopStmt *getStmtFor(RegionNode *RN) const;
+
+  /// @brief Return the ScopStmt an instruction belongs to, or nullptr if it
+  ///        does not belong to any statement in this Scop.
+  ScopStmt *getStmtFor(Instruction *Inst) const {
+    return getStmtFor(Inst->getParent());
+  }
 
   /// @brief Return the number of statements in the SCoP.
   size_t getSize() const { return Stmts.size(); }

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=261791&r1=261790&r2=261791&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Wed Feb 24 16:08:19 2016
@@ -1006,7 +1006,7 @@ void ScopStmt::addAccess(MemoryAccess *A
     MAL.emplace_front(Access);
   } else if (Access->isValueKind() && Access->isWrite()) {
     Instruction *AccessVal = cast<Instruction>(Access->getAccessValue());
-    assert(Parent.getStmtForBasicBlock(AccessVal->getParent()) == this);
+    assert(Parent.getStmtFor(AccessVal) == this);
     assert(!ValueWrites.lookup(AccessVal));
 
     ValueWrites[AccessVal] = Access;
@@ -3032,7 +3032,7 @@ bool Scop::isHoistableAccess(MemoryAcces
     assert(BasePtrInst && R.contains(BasePtrInst));
     if (!isa<LoadInst>(BasePtrInst))
       return false;
-    auto *BasePtrStmt = getStmtForBasicBlock(BasePtrInst->getParent());
+    auto *BasePtrStmt = getStmtFor(BasePtrInst);
     assert(BasePtrStmt);
     auto *BasePtrMA = BasePtrStmt->getArrayAccessOrNULLFor(BasePtrInst);
     if (BasePtrMA && !isHoistableAccess(BasePtrMA, Writes))
@@ -3079,7 +3079,7 @@ void Scop::verifyInvariantLoads(ScopDete
   auto &RIL = *SD.getRequiredInvariantLoads(&getRegion());
   for (LoadInst *LI : RIL) {
     assert(LI && getRegion().contains(LI));
-    ScopStmt *Stmt = getStmtForBasicBlock(LI->getParent());
+    ScopStmt *Stmt = getStmtFor(LI);
     if (Stmt && Stmt->getArrayAccessOrNULLFor(LI)) {
       invalidate(INVARIANTLOAD, LI->getDebugLoc());
       return;
@@ -3479,7 +3479,7 @@ ScalarEvolution *Scop::getSE() const { r
 
 bool Scop::isIgnored(RegionNode *RN, DominatorTree &DT, LoopInfo &LI) {
   BasicBlock *BB = getRegionNodeBasicBlock(RN);
-  ScopStmt *Stmt = getStmtForRegionNode(RN);
+  ScopStmt *Stmt = getStmtFor(RN);
 
   // If there is no stmt, then it already has been removed.
   if (!Stmt)
@@ -3675,7 +3675,7 @@ void Scop::buildSchedule(RegionNode *RN,
   auto &LoopData = LoopStack.back();
   LoopData.NumBlocksProcessed += getNumBlocksInRegionNode(RN);
 
-  if (auto *Stmt = getStmtForRegionNode(RN)) {
+  if (auto *Stmt = getStmtFor(RN)) {
     auto *UDomain = isl_union_set_from_set(Stmt->getDomain());
     auto *StmtSchedule = isl_schedule_from_domain(UDomain);
     LoopData.Schedule = combineInSequence(LoopData.Schedule, StmtSchedule);
@@ -3711,15 +3711,23 @@ void Scop::buildSchedule(RegionNode *RN,
   }
 }
 
-ScopStmt *Scop::getStmtForBasicBlock(BasicBlock *BB) const {
+ScopStmt *Scop::getStmtFor(BasicBlock *BB) const {
   auto StmtMapIt = StmtMap.find(BB);
   if (StmtMapIt == StmtMap.end())
     return nullptr;
   return StmtMapIt->second;
 }
 
-ScopStmt *Scop::getStmtForRegionNode(RegionNode *RN) const {
-  return getStmtForBasicBlock(getRegionNodeBasicBlock(RN));
+ScopStmt *Scop::getStmtFor(RegionNode *RN) const {
+  if (RN->isSubRegion())
+    return getStmtFor(RN->getNodeAs<Region>());
+  return getStmtFor(RN->getNodeAs<BasicBlock>());
+}
+
+ScopStmt *Scop::getStmtFor(Region *R) const {
+  ScopStmt *Stmt = getStmtFor(R->getEntry());
+  assert(!Stmt || Stmt->getRegion() == R);
+  return Stmt;
 }
 
 int Scop::getRelativeLoopDepth(const Loop *L) const {
@@ -4077,7 +4085,7 @@ MemoryAccess *ScopInfo::addMemoryAccess(
                                         ArrayRef<const SCEV *> Subscripts,
                                         ArrayRef<const SCEV *> Sizes,
                                         ScopArrayInfo::MemoryKind Kind) {
-  ScopStmt *Stmt = scop->getStmtForBasicBlock(BB);
+  ScopStmt *Stmt = scop->getStmtFor(BB);
 
   // Do not create a memory access for anything not in the SCoP. It would be
   // ignored anyway.
@@ -4130,7 +4138,7 @@ void ScopInfo::addArrayAccess(MemAccInst
 }
 
 void ScopInfo::ensureValueWrite(Instruction *Inst) {
-  ScopStmt *Stmt = scop->getStmtForBasicBlock(Inst->getParent());
+  ScopStmt *Stmt = scop->getStmtFor(Inst);
 
   // Inst not defined within this SCoP.
   if (!Stmt)
@@ -4168,10 +4176,9 @@ void ScopInfo::ensureValueRead(Value *V,
   // no defining ScopStmt if the value is a function argument, a global value,
   // or defined outside the SCoP.
   Instruction *ValueInst = dyn_cast<Instruction>(V);
-  ScopStmt *ValueStmt =
-      ValueInst ? scop->getStmtForBasicBlock(ValueInst->getParent()) : nullptr;
+  ScopStmt *ValueStmt = ValueInst ? scop->getStmtFor(ValueInst) : nullptr;
 
-  ScopStmt *UserStmt = scop->getStmtForBasicBlock(UserBB);
+  ScopStmt *UserStmt = scop->getStmtFor(UserBB);
 
   // We do not model uses outside the scop.
   if (!UserStmt)
@@ -4199,7 +4206,7 @@ void ScopInfo::ensureValueRead(Value *V,
 
 void ScopInfo::ensurePHIWrite(PHINode *PHI, BasicBlock *IncomingBlock,
                               Value *IncomingValue, bool IsExitBlock) {
-  ScopStmt *IncomingStmt = scop->getStmtForBasicBlock(IncomingBlock);
+  ScopStmt *IncomingStmt = scop->getStmtFor(IncomingBlock);
   if (!IncomingStmt)
     return;
 

Modified: polly/trunk/lib/CodeGen/IslNodeBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslNodeBuilder.cpp?rev=261791&r1=261790&r2=261791&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslNodeBuilder.cpp (original)
+++ polly/trunk/lib/CodeGen/IslNodeBuilder.cpp Wed Feb 24 16:08:19 2016
@@ -863,7 +863,7 @@ bool IslNodeBuilder::materializeValue(is
           if (Address &&
               SE.getUnknown(UndefValue::get(Address->getType())) ==
                   SE.getPointerBase(SE.getSCEV(Address))) {
-          } else if (S.getStmtForBasicBlock(Inst->getParent())) {
+          } else if (S.getStmtFor(Inst)) {
             IsDead = false;
           } else {
             auto *Domain = S.getDomainConditions(Inst->getParent());




More information about the llvm-commits mailing list