[PATCH] D49056: [Dominators] Add isUpdateLazy() method to the DomTreeUpdater

Chijun Sima via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 7 22:32:31 PDT 2018


NutshellySima created this revision.
NutshellySima added reviewers: kuhar, brzycki, dmgreen.
Herald added a subscriber: llvm-commits.

Previously, when people need to deal with DTU with different UpdateStrategy using different actions, they need to

  if (DTU.getUpdateStrategy() == DomTreeUpdater::UpdateStrategy::Lazy) {
    ...
  }
  if (DTU.getUpdateStrategy() == DomTreeUpdater::UpdateStrategy::Eager) {
    ...
  }

After the patch, they can avoid code patterns above

  if (DTU.isUpdateLazy()){
    ...
  }
  if (!DTU.isUpdateLazy()){
    ...
  }


Repository:
  rL LLVM

https://reviews.llvm.org/D49056

Files:
  include/llvm/IR/DomTreeUpdater.h
  unittests/IR/DomTreeUpdaterTest.cpp


Index: unittests/IR/DomTreeUpdaterTest.cpp
===================================================================
--- unittests/IR/DomTreeUpdaterTest.cpp
+++ unittests/IR/DomTreeUpdaterTest.cpp
@@ -58,7 +58,7 @@
 
   ASSERT_TRUE(DTU.hasDomTree());
   ASSERT_TRUE(DTU.hasPostDomTree());
-  ASSERT_EQ(DTU.getUpdateStrategy(), DomTreeUpdater::UpdateStrategy::Eager);
+  ASSERT_FALSE(DTU.isUpdateLazy());
   ASSERT_TRUE(DTU.getDomTree().verify());
   ASSERT_TRUE(DTU.getPostDomTree().verify());
   ASSERT_FALSE(DTU.hasPendingUpdates());
@@ -166,7 +166,7 @@
   DomTreeUpdater DTU(DT, PDT, DomTreeUpdater::UpdateStrategy::Eager);
   ASSERT_TRUE(DTU.hasDomTree());
   ASSERT_TRUE(DTU.hasPostDomTree());
-  ASSERT_EQ(DTU.getUpdateStrategy(), DomTreeUpdater::UpdateStrategy::Eager);
+  ASSERT_FALSE(DTU.isUpdateLazy());
   ASSERT_TRUE(DT.verify());
   ASSERT_TRUE(PDT.verify());
 
@@ -239,7 +239,7 @@
   DomTreeUpdater DTU(&DT, PDT, DomTreeUpdater::UpdateStrategy::Lazy);
   ASSERT_TRUE(DTU.hasDomTree());
   ASSERT_FALSE(DTU.hasPostDomTree());
-  ASSERT_EQ(DTU.getUpdateStrategy(), DomTreeUpdater::UpdateStrategy::Lazy);
+  ASSERT_TRUE(DTU.isUpdateLazy());
   ASSERT_TRUE(DTU.getDomTree().verify());
 
   Function::iterator FI = F->begin();
@@ -327,7 +327,7 @@
   DomTreeUpdater DTU(&DT, PDT, DomTreeUpdater::UpdateStrategy::Lazy);
   ASSERT_TRUE(DTU.hasDomTree());
   ASSERT_FALSE(DTU.hasPostDomTree());
-  ASSERT_EQ(DTU.getUpdateStrategy(), DomTreeUpdater::UpdateStrategy::Lazy);
+  ASSERT_TRUE(DTU.isUpdateLazy());
   ASSERT_TRUE(DTU.getDomTree().verify());
 
   Function::iterator FI = F->begin();
@@ -453,7 +453,7 @@
   DomTreeUpdater DTU(&DT, &PDT, DomTreeUpdater::UpdateStrategy::Lazy);
   ASSERT_TRUE(DTU.hasDomTree());
   ASSERT_TRUE(DTU.hasPostDomTree());
-  ASSERT_EQ(DTU.getUpdateStrategy(), DomTreeUpdater::UpdateStrategy::Lazy);
+  ASSERT_TRUE(DTU.isUpdateLazy());
   ASSERT_TRUE(DTU.getDomTree().verify());
   ASSERT_TRUE(DTU.getPostDomTree().verify());
 
@@ -535,7 +535,7 @@
   DomTreeUpdater DTU(DT, PDT, DomTreeUpdater::UpdateStrategy::Lazy);
   ASSERT_TRUE(DTU.hasDomTree());
   ASSERT_TRUE(DTU.hasPostDomTree());
-  ASSERT_EQ(DTU.getUpdateStrategy(), DomTreeUpdater::UpdateStrategy::Lazy);
+  ASSERT_TRUE(DTU.isUpdateLazy());
   ASSERT_TRUE(DTU.getDomTree().verify());
   ASSERT_TRUE(DTU.getPostDomTree().verify());
 
@@ -624,7 +624,7 @@
 
   ASSERT_TRUE(DTU.hasDomTree());
   ASSERT_TRUE(DTU.hasPostDomTree());
-  ASSERT_EQ(DTU.getUpdateStrategy(), DomTreeUpdater::UpdateStrategy::Lazy);
+  ASSERT_TRUE(DTU.isUpdateLazy());
   ASSERT_TRUE(DTU.getDomTree().verify());
   ASSERT_TRUE(DTU.getPostDomTree().verify());
   ASSERT_FALSE(DTU.hasPendingUpdates());
Index: include/llvm/IR/DomTreeUpdater.h
===================================================================
--- include/llvm/IR/DomTreeUpdater.h
+++ include/llvm/IR/DomTreeUpdater.h
@@ -46,8 +46,8 @@
 
   ~DomTreeUpdater() { flush(); }
 
-  /// Returns the UpdateStrategy of the class instance.
-  UpdateStrategy getUpdateStrategy() const { return Strategy; };
+  /// Returns true if the class instance works under the Lazy UpdateStrategy.
+  bool isUpdateLazy() const { return Strategy == UpdateStrategy::Lazy; };
 
   /// Returns true if it holds a DominatorTree.
   bool hasDomTree() const { return DT != nullptr; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49056.154509.patch
Type: text/x-patch
Size: 3285 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180708/1037b3c1/attachment.bin>


More information about the llvm-commits mailing list