[polly] r369972 - [ScopBuilder] Simplify main statement flag in buildEqivClassBlockStmts. NFC.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 26 14:31:47 PDT 2019


Author: meinersbur
Date: Mon Aug 26 14:31:47 2019
New Revision: 369972

URL: http://llvm.org/viewvc/llvm-project?rev=369972&view=rev
Log:
[ScopBuilder] Simplify main statement flag in buildEqivClassBlockStmts. NFC.

When reading code in ScopBuilder::buildEqivClassBlockStmts, I think the
main statement flag computation can be simplified, here is the patch.
It's based on two simple facts that:

  1. Instruction won't be removed once it's inserted into UnionFind.
  2. Main statement must be set if there is non-trivial statement besides the last one.

The patch also saves std::find call.

Patch by bin.narwal <bin.narwal at gmail.com>

Differential Revision: https://reviews.llvm.org/D66477

Modified:
    polly/trunk/lib/Analysis/ScopBuilder.cpp

Modified: polly/trunk/lib/Analysis/ScopBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopBuilder.cpp?rev=369972&r1=369971&r2=369972&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopBuilder.cpp (original)
+++ polly/trunk/lib/Analysis/ScopBuilder.cpp Mon Aug 26 14:31:47 2019
@@ -2095,7 +2095,7 @@ void ScopBuilder::buildEqivClassBlockStm
   // shouldModelInst() repeatedly.
   SmallVector<Instruction *, 32> ModeledInsts;
   EquivalenceClasses<Instruction *> UnionFind;
-  Instruction *MainInst = nullptr;
+  Instruction *MainInst = nullptr, *MainLeader = nullptr;
   for (Instruction &Inst : *BB) {
     if (!shouldModelInst(&Inst, L))
       continue;
@@ -2129,6 +2129,8 @@ void ScopBuilder::buildEqivClassBlockStm
     if (LeaderIt == UnionFind.member_end())
       continue;
 
+    if (&Inst == MainInst)
+      MainLeader = *LeaderIt;
     std::vector<Instruction *> &InstList = LeaderToInstList[*LeaderIt];
     InstList.push_back(&Inst);
   }
@@ -2136,19 +2138,11 @@ void ScopBuilder::buildEqivClassBlockStm
   // Finally build the statements.
   int Count = 0;
   long BBIdx = scop->getNextStmtIdx();
-  bool MainFound = false;
   for (auto &Instructions : reverse(LeaderToInstList)) {
     std::vector<Instruction *> &InstList = Instructions.second;
 
     // If there is no main instruction, make the first statement the main.
-    bool IsMain;
-    if (MainInst)
-      IsMain = std::find(InstList.begin(), InstList.end(), MainInst) !=
-               InstList.end();
-    else
-      IsMain = (Count == 0);
-    if (IsMain)
-      MainFound = true;
+    bool IsMain = (MainInst ? MainLeader == Instructions.first : Count == 0);
 
     std::reverse(InstList.begin(), InstList.end());
     std::string Name = makeStmtName(BB, BBIdx, Count, IsMain);
@@ -2159,8 +2153,10 @@ void ScopBuilder::buildEqivClassBlockStm
   // Unconditionally add an epilogue (last statement). It contains no
   // instructions, but holds the PHI write accesses for successor basic blocks,
   // if the incoming value is not defined in another statement if the same BB.
+  // The epilogue becomes the main statement only if there is no other
+  // statement that could become main.
   // The epilogue will be removed if no PHIWrite is added to it.
-  std::string EpilogueName = makeStmtName(BB, BBIdx, Count, !MainFound, true);
+  std::string EpilogueName = makeStmtName(BB, BBIdx, Count, Count == 0, true);
   scop->addScopStmt(BB, EpilogueName, L, {});
 }
 




More information about the llvm-commits mailing list