[PATCH] D73430: [mlir] Optimize OpResult use case for single result operations.

River Riddle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 26 03:08:05 PST 2020


rriddle created this revision.
rriddle added a reviewer: mehdi_amini.
Herald added subscribers: llvm-commits, liufengdb, lucyrfox, mgester, arpith-jacob, antiagainst, shauheen, burmako, jpienaar.
Herald added a reviewer: nicolasvasilache.
Herald added a project: LLVM.

Operation represents all of the uses of each result with one use list, so manipulating the use list of a specific result requires filtering the main use list. This revision adds an optimization for the case of single result operations to avoid this filtering.

Depends On D73429 <https://reviews.llvm.org/D73429>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73430

Files:
  mlir/include/mlir/IR/UseDefLists.h
  mlir/lib/IR/Value.cpp


Index: mlir/lib/IR/Value.cpp
===================================================================
--- mlir/lib/IR/Value.cpp
+++ mlir/lib/IR/Value.cpp
@@ -102,7 +102,10 @@
 void Value::dropAllUses() const {
   if (BlockArgument arg = dyn_cast<BlockArgument>())
     return arg.getImpl()->dropAllUses();
-  return cast<OpResult>().getOwner()->dropAllUses(*this);
+  Operation *owner = cast<OpResult>().getOwner();
+  if (owner->hasSingleResult)
+    return owner->dropAllUses();
+  return owner->dropAllUses(*this);
 }
 
 /// Replace all uses of 'this' value with the new value, updating anything in
@@ -111,7 +114,10 @@
 void Value::replaceAllUsesWith(Value newValue) const {
   if (BlockArgument arg = dyn_cast<BlockArgument>())
     return arg.getImpl()->replaceAllUsesWith(newValue);
-  IRMultiObjectWithUseList<OpOperand> *useList = cast<OpResult>().getOwner();
+  Operation *owner = cast<OpResult>().getOwner();
+  IRMultiObjectWithUseList<OpOperand> *useList = owner;
+  if (owner->hasSingleResult)
+    return useList->replaceAllUsesWith(newValue);
   useList->replaceAllUsesWith(*this, newValue);
 }
 
@@ -121,21 +127,25 @@
 auto Value::use_begin() const -> use_iterator {
   if (BlockArgument arg = dyn_cast<BlockArgument>())
     return arg.getImpl()->use_begin();
-  return cast<OpResult>().getOwner()->use_begin(*this);
+  Operation *owner = cast<OpResult>().getOwner();
+  return owner->hasSingleResult ? use_iterator(owner->use_begin())
+                                : owner->use_begin(*this);
 }
 
 /// Returns true if this value has exactly one use.
 bool Value::hasOneUse() const {
   if (BlockArgument arg = dyn_cast<BlockArgument>())
     return arg.getImpl()->hasOneUse();
-  return cast<OpResult>().getOwner()->hasOneUse(*this);
+  Operation *owner = cast<OpResult>().getOwner();
+  return owner->hasSingleResult ? owner->hasOneUse() : owner->hasOneUse(*this);
 }
 
 /// Returns true if this value has no uses.
 bool Value::use_empty() const {
   if (BlockArgument arg = dyn_cast<BlockArgument>())
     return arg.getImpl()->use_empty();
-  return cast<OpResult>().getOwner()->use_empty(*this);
+  Operation *owner = cast<OpResult>().getOwner();
+  return owner->hasSingleResult ? owner->use_empty() : owner->use_empty(*this);
 }
 
 //===----------------------------------------------------------------------===//
Index: mlir/include/mlir/IR/UseDefLists.h
===================================================================
--- mlir/include/mlir/IR/UseDefLists.h
+++ mlir/include/mlir/IR/UseDefLists.h
@@ -131,6 +131,7 @@
     for (OperandType &use : llvm::make_early_inc_range(getUses(oldValue)))
       use.set(newValue);
   }
+  using BaseType::replaceAllUsesWith;
 
   //===--------------------------------------------------------------------===//
   // Uses


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73430.240426.patch
Type: text/x-patch
Size: 2785 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200126/94a042c8/attachment.bin>


More information about the llvm-commits mailing list