[Mlir-commits] [mlir] 4a1682e - [mlir][Linalg] Add some depedence query methods to LinalgDependenceGraph.

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Oct 8 10:29:04 PDT 2020


Author: MaheshRavishankar
Date: 2020-10-08T10:17:18-07:00
New Revision: 4a1682e931c1b4bfed77194fa43d18435f88d092

URL: https://github.com/llvm/llvm-project/commit/4a1682e931c1b4bfed77194fa43d18435f88d092
DIFF: https://github.com/llvm/llvm-project/commit/4a1682e931c1b4bfed77194fa43d18435f88d092.diff

LOG: [mlir][Linalg] Add some depedence query methods to LinalgDependenceGraph.

The methods allow to check
- if an operation has dependencies,
- if there is a dependence from one operation to another.

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

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Linalg/Analysis/DependenceAnalysis.h
    mlir/lib/Dialect/Linalg/Analysis/DependenceAnalysis.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Linalg/Analysis/DependenceAnalysis.h b/mlir/include/mlir/Dialect/Linalg/Analysis/DependenceAnalysis.h
index e40d63661b77..057b1bc657fa 100644
--- a/mlir/include/mlir/Dialect/Linalg/Analysis/DependenceAnalysis.h
+++ b/mlir/include/mlir/Dialect/Linalg/Analysis/DependenceAnalysis.h
@@ -98,6 +98,18 @@ class LinalgDependenceGraph {
                                                  LinalgOp dstLinalgOp,
                                                  Value view) const;
 
+  /// Returns true if the two operations have the specified dependence from
+  /// `srcLinalgOp` to `dstLinalgOp`.
+  bool hasDependenceFrom(LinalgOp srcLinalgOp, LinalgOp dstLinalgOp,
+                         ArrayRef<DependenceType> depTypes = {
+                             DependenceType::RAW, DependenceType::WAW}) const;
+
+  /// Returns true if the `linalgOp` has dependences into or from it.
+  bool hasDependentOperations(LinalgOp linalgOp,
+                              ArrayRef<DependenceType> depTypes = {
+                                  DependenceType::RAW,
+                                  DependenceType::WAW}) const;
+
 private:
   // Keep dependences in both directions, this is not just a performance gain
   // but it also reduces usage errors.

diff  --git a/mlir/lib/Dialect/Linalg/Analysis/DependenceAnalysis.cpp b/mlir/lib/Dialect/Linalg/Analysis/DependenceAnalysis.cpp
index 292a3268cf88..bffd9bd1bd0c 100644
--- a/mlir/lib/Dialect/Linalg/Analysis/DependenceAnalysis.cpp
+++ b/mlir/lib/Dialect/Linalg/Analysis/DependenceAnalysis.cpp
@@ -162,7 +162,7 @@ void LinalgDependenceGraph::addDependencesBetween(LinalgOp src, LinalgOp dst) {
     }
     // WAW graph
     for (auto dstView : dst.getOutputBuffers()) { // W
-      if (aliases.alias(srcView, dstView)) { // if alias, fill WAW
+      if (aliases.alias(srcView, dstView)) {      // if alias, fill WAW
         addDependenceElem(DependenceType::WAW,
                           LinalgOpView{src.getOperation(), srcView},
                           LinalgOpView{dst.getOperation(), dstView});
@@ -180,7 +180,7 @@ void LinalgDependenceGraph::addDependencesBetween(LinalgOp src, LinalgOp dst) {
     }
     // WAR graph
     for (auto dstView : dst.getOutputBuffers()) { // W
-      if (aliases.alias(srcView, dstView)) { // if alias, fill WAR
+      if (aliases.alias(srcView, dstView)) {      // if alias, fill WAR
         addDependenceElem(DependenceType::WAR,
                           LinalgOpView{src.getOperation(), srcView},
                           LinalgOpView{dst.getOperation(), dstView});
@@ -242,3 +242,26 @@ LinalgDependenceGraph::findOperationsWithCoveringDependences(
   }
   return res;
 }
+
+bool LinalgDependenceGraph::hasDependenceFrom(
+    LinalgOp srcLinalgOp, LinalgOp dstLinalgOp,
+    ArrayRef<LinalgDependenceGraph::DependenceType> depTypes) const {
+  for (auto dep : depTypes) {
+    for (auto dependence : getDependencesInto(dstLinalgOp, dep)) {
+      if (dependence.dependentOpView.op == srcLinalgOp)
+        return true;
+    }
+  }
+  return false;
+}
+
+bool LinalgDependenceGraph::hasDependentOperations(
+    LinalgOp linalgOp,
+    ArrayRef<LinalgDependenceGraph::DependenceType> depTypes) const {
+  for (auto dep : depTypes) {
+    if (!getDependencesFrom(linalgOp, dep).empty() ||
+        !getDependencesInto(linalgOp, dep).empty())
+      return true;
+  }
+  return false;
+}


        


More information about the Mlir-commits mailing list