[Mlir-commits] [mlir] 9f7d801 - [MLIR] NFC. Clean up logic of hasSingleEffect

Uday Bondhugula llvmlistbot at llvm.org
Sat Jul 16 00:20:38 PDT 2022


Author: Uday Bondhugula
Date: 2022-07-16T12:39:32+05:30
New Revision: 9f7d80145a356b20f6a70e3929b3f5d7f1bb948b

URL: https://github.com/llvm/llvm-project/commit/9f7d80145a356b20f6a70e3929b3f5d7f1bb948b
DIFF: https://github.com/llvm/llvm-project/commit/9f7d80145a356b20f6a70e3929b3f5d7f1bb948b.diff

LOG: [MLIR] NFC. Clean up logic of hasSingleEffect

Clean up conditional logic of hasSingleEffect. NFC.

Reviewed By: rriddle

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

Added: 
    

Modified: 
    mlir/include/mlir/Interfaces/SideEffectInterfaces.h
    mlir/lib/Interfaces/SideEffectInterfaces.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Interfaces/SideEffectInterfaces.h b/mlir/include/mlir/Interfaces/SideEffectInterfaces.h
index e5f4f2bf63fdb..a2e55f36671ce 100644
--- a/mlir/include/mlir/Interfaces/SideEffectInterfaces.h
+++ b/mlir/include/mlir/Interfaces/SideEffectInterfaces.h
@@ -250,7 +250,8 @@ struct Write : public Effect::Base<Write> {};
 // SideEffect Utilities
 //===----------------------------------------------------------------------===//
 
-/// Returns true if this operation only has the given effect on `value`.
+/// Returns true if `op` has only an effect of type `EffectTy` (and of no other
+/// type) on `value`.
 template <typename EffectTy>
 bool hasSingleEffect(Operation *op, Value value);
 

diff  --git a/mlir/lib/Interfaces/SideEffectInterfaces.cpp b/mlir/lib/Interfaces/SideEffectInterfaces.cpp
index 82d4f9edb9830..563d86432f7b9 100644
--- a/mlir/lib/Interfaces/SideEffectInterfaces.cpp
+++ b/mlir/lib/Interfaces/SideEffectInterfaces.cpp
@@ -97,25 +97,24 @@ bool mlir::hasSingleEffect(Operation *op, Value value) {
     return false;
   SmallVector<SideEffects::EffectInstance<MemoryEffects::Effect>, 4> effects;
   memOp.getEffects(effects);
-  bool doesOpOnlyHaveSingleEffectOnVal = false;
-  // Iterate through `effects` and check if and only if effect of type
-  // `EffectTy` is present.
+  bool hasSingleEffectOnVal = false;
+  // Iterate through `effects` and check if an effect of type `EffectTy` and
+  // only of that type is present.
   for (auto &effect : effects) {
-    if (effect.getValue() == value && isa<EffectTy>(effect.getEffect()))
-      doesOpOnlyHaveSingleEffectOnVal = true;
-    if (effect.getValue() == value && !isa<EffectTy>(effect.getEffect())) {
-      doesOpOnlyHaveSingleEffectOnVal = false;
-      break;
-    }
+    if (effect.getValue() != value)
+      continue;
+    hasSingleEffectOnVal = isa<EffectTy>(effect.getEffect());
+    if (!hasSingleEffectOnVal)
+      return false;
   }
-  return doesOpOnlyHaveSingleEffectOnVal;
+  return hasSingleEffectOnVal;
 }
 
 template bool mlir::hasSingleEffect<MemoryEffects::Allocate>(Operation *,
                                                              Value);
 template bool mlir::hasSingleEffect<MemoryEffects::Free>(Operation *, Value);
-template bool mlir::hasSingleEffect<MemoryEffects::Write>(Operation *, Value);
 template bool mlir::hasSingleEffect<MemoryEffects::Read>(Operation *, Value);
+template bool mlir::hasSingleEffect<MemoryEffects::Write>(Operation *, Value);
 
 bool mlir::wouldOpBeTriviallyDead(Operation *op) {
   if (op->mightHaveTrait<OpTrait::IsTerminator>())


        


More information about the Mlir-commits mailing list