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

River Riddle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 28 11:22:26 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG60b884208427: [mlir] Optimize OpResult use case for single result operations. (authored by rriddle).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73430/new/

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.240951.patch
Type: text/x-patch
Size: 2785 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200128/9c85f984/attachment.bin>


More information about the llvm-commits mailing list