[PATCH] D50426: [NFC][MustExecute] Rework API to start making better analysis, part 2

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 14 02:11:53 PDT 2018


mkazantsev updated this revision to Diff 160535.
mkazantsev retitled this revision from "[NFC][MustExecute] Rework API to start making better analysis" to "[NFC][MustExecute] Rework API to start making better analysis, part 2".

https://reviews.llvm.org/D50426

Files:
  include/llvm/Analysis/MustExecute.h
  lib/Analysis/MustExecute.cpp
  lib/Transforms/Scalar/LoopIdiomRecognize.cpp
  lib/Transforms/Utils/LoopUnrollAndJam.cpp


Index: lib/Transforms/Utils/LoopUnrollAndJam.cpp
===================================================================
--- lib/Transforms/Utils/LoopUnrollAndJam.cpp
+++ lib/Transforms/Utils/LoopUnrollAndJam.cpp
@@ -761,8 +761,7 @@
   }
 
   // Check the loop safety info for exceptions.
-  LoopSafetyInfo LSI;
-  LSI.computeLoopSafetyInfo(L);
+  LoopSafetyInfo LSI(L);
   if (LSI.anyBlockMayThrow()) {
     LLVM_DEBUG(dbgs() << "Won't unroll-and-jam; Something may throw\n");
     return false;
Index: lib/Transforms/Scalar/LoopIdiomRecognize.cpp
===================================================================
--- lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ lib/Transforms/Scalar/LoopIdiomRecognize.cpp
@@ -319,8 +319,7 @@
 
   // The following transforms hoist stores/memsets into the loop pre-header.
   // Give up if the loop has instructions may throw.
-  LoopSafetyInfo SafetyInfo;
-  SafetyInfo.computeLoopSafetyInfo(CurLoop);
+  LoopSafetyInfo SafetyInfo(CurLoop);
   if (SafetyInfo.anyBlockMayThrow())
     return MadeChange;
 
Index: lib/Analysis/MustExecute.cpp
===================================================================
--- lib/Analysis/MustExecute.cpp
+++ lib/Analysis/MustExecute.cpp
@@ -23,14 +23,17 @@
 using namespace llvm;
 
 bool LoopSafetyInfo::headerMayThrow() const {
+  assert(CurLoop && "Should calculate the info first!");
   return HeaderMayThrow;
 }
 
 bool LoopSafetyInfo::anyBlockMayThrow() const {
+  assert(CurLoop && "Should calculate the info first!");
   return MayThrow;
 }
 
-void LoopSafetyInfo::computeLoopSafetyInfo(Loop *CurLoop) {
+void LoopSafetyInfo::computeLoopSafetyInfo(Loop *L) {
+  CurLoop = L;
   assert(CurLoop != nullptr && "CurLoop can't be null");
   BasicBlock *Header = CurLoop->getHeader();
   // Iterate over header and compute safety info.
Index: include/llvm/Analysis/MustExecute.h
===================================================================
--- include/llvm/Analysis/MustExecute.h
+++ include/llvm/Analysis/MustExecute.h
@@ -48,6 +48,8 @@
   bool MayThrow = false;       // The current loop contains an instruction which
                                // may throw.
   bool HeaderMayThrow = false; // Same as previous, but specific to loop header
+  // The current loop for which this info is calculated.
+  Loop *CurLoop = nullptr;
 
 public:
   // Used to update funclet bundle operands.
@@ -70,6 +72,10 @@
   void computeLoopSafetyInfo(Loop *);
 
   LoopSafetyInfo() = default;
+
+  LoopSafetyInfo(Loop *L) {
+    computeLoopSafetyInfo(L);
+  }
 };
 
 /// Returns true if the instruction in a loop is guaranteed to execute at least


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50426.160535.patch
Type: text/x-patch
Size: 2620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180814/3dd5ce46/attachment-0001.bin>


More information about the llvm-commits mailing list