[polly] r221015 - [Refactor][NFC] Map basic blocks to SCoP statements.

Johannes Doerfert doerfert at cs.uni-saarland.de
Fri Oct 31 16:13:39 PDT 2014


Author: jdoerfert
Date: Fri Oct 31 18:13:39 2014
New Revision: 221015

URL: http://llvm.org/viewvc/llvm-project?rev=221015&view=rev
Log:
[Refactor][NFC] Map basic blocks to SCoP statements.

  This will simplify the construction of domains and the modeling of
  PHI's.


Modified:
    polly/trunk/include/polly/ScopInfo.h
    polly/trunk/lib/Analysis/ScopInfo.cpp
    polly/trunk/lib/Support/ScopHelper.cpp

Modified: polly/trunk/include/polly/ScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopInfo.h?rev=221015&r1=221014&r2=221015&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Fri Oct 31 18:13:39 2014
@@ -621,6 +621,9 @@ private:
   /// Isl context.
   isl_ctx *IslCtx;
 
+  /// @brief A map from basic blocks to SCoP statements.
+  DenseMap<BasicBlock *, ScopStmt *> StmtMap;
+
   /// Constraints on parameters.
   isl_set *Context;
 
@@ -800,6 +803,9 @@ public:
   /// @brief Get an isl string representing the assumed context.
   std::string getAssumedContextStr() const;
 
+  /// @brief Return the stmt for the given @p BB or nullptr if none.
+  ScopStmt *getStmtForBasicBlock(BasicBlock *BB) const;
+
   /// @name Statements Iterators
   ///
   /// These iterators iterate over all statements of this Scop.

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=221015&r1=221014&r2=221015&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Fri Oct 31 18:13:39 2014
@@ -1722,8 +1722,12 @@ void Scop::buildScop(TempScop &tempScop,
       if (isTrivialBB(BB, tempScop))
         continue;
 
-      Stmts.push_back(
-          new ScopStmt(*this, tempScop, CurRegion, *BB, NestLoops, Scatter));
+      ScopStmt *Stmt =
+          new ScopStmt(*this, tempScop, CurRegion, *BB, NestLoops, Scatter);
+
+      // Insert all statements into the statement map and the statement vector.
+      StmtMap[BB] = Stmt;
+      Stmts.push_back(Stmt);
 
       // Increasing the Scattering function is OK for the moment, because
       // we are using a depth first iterator and the program is well structured.
@@ -1739,6 +1743,13 @@ void Scop::buildScop(TempScop &tempScop,
   ++Scatter[loopDepth - 1];
 }
 
+ScopStmt *Scop::getStmtForBasicBlock(BasicBlock *BB) const {
+  const auto &StmtMapIt = StmtMap.find(BB);
+  if (StmtMapIt == StmtMap.end())
+    return nullptr;
+  return StmtMapIt->second;
+}
+
 //===----------------------------------------------------------------------===//
 ScopInfo::ScopInfo() : RegionPass(ID), scop(0) {
   ctx = isl_ctx_alloc();

Modified: polly/trunk/lib/Support/ScopHelper.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/ScopHelper.cpp?rev=221015&r1=221014&r2=221015&view=diff
==============================================================================
--- polly/trunk/lib/Support/ScopHelper.cpp (original)
+++ polly/trunk/lib/Support/ScopHelper.cpp Fri Oct 31 18:13:39 2014
@@ -88,11 +88,8 @@ BasicBlock *polly::createSingleExitEdge(
 
 static void replaceScopAndRegionEntry(polly::Scop *S, BasicBlock *OldEntry,
                                       BasicBlock *NewEntry) {
-  for (polly::ScopStmt *Stmt : *S)
-    if (Stmt->getBasicBlock() == OldEntry) {
-      Stmt->setBasicBlock(NewEntry);
-      break;
-    }
+  if (polly::ScopStmt *Stmt = S->getStmtForBasicBlock(OldEntry))
+    Stmt->setBasicBlock(NewEntry);
 
   S->getRegion().replaceEntryRecursive(NewEntry);
 }





More information about the llvm-commits mailing list