Skip to content

Conversation

chios202
Copy link
Contributor

@chios202 chios202 commented Sep 1, 2025

Currently ,when piping a pass pipeline into mlir-query , you must explicitly pass - to read from the standard input:

./mlir-opt input.mlir -canonicalize | ./mlir-query - -c "<your_query_1>" -c "<your_query_2>" ... -c "<your_query_N>"

With this PR, the explicit - is no longer required:

./mlir-opt input.mlir -canonicalize | ./mlir-query -c "<your_query_1>" -c "<your_query_2>" ... -c "<your_query_N>"

@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Sep 1, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 1, 2025

@llvm/pr-subscribers-mlir-core

@llvm/pr-subscribers-mlir

Author: Denzel-Brian Budii (chios202)

Changes

Currently ,when piping a pass pipeline into mlir-query , you must explicitly pass - to read from the standard input:

./mlir-opt input.mlir -canonicalize | ./mlir-query - -c "&lt;your_query_1&gt;" -c "&lt;your_query_2&gt;" ... -c "&lt;your_query_N&gt;"

With this PR, the explicit - is no longer required:

./mlir-opt input.mlir -canonicalize | ./mlir-query -c "&lt;your_query_1&gt;" -c "&lt;your_query_2&gt;" ... -c "&lt;your_query_N&gt;"

Full diff: https://github.com/llvm/llvm-project/pull/156324.diff

2 Files Affected:

  • (modified) mlir/lib/Tools/mlir-query/MlirQueryMain.cpp (+10-1)
  • (added) mlir/test/mlir-query/slice-reproducer.mlir (+27)
diff --git a/mlir/lib/Tools/mlir-query/MlirQueryMain.cpp b/mlir/lib/Tools/mlir-query/MlirQueryMain.cpp
index 99500508ef045..6945c096124fd 100644
--- a/mlir/lib/Tools/mlir-query/MlirQueryMain.cpp
+++ b/mlir/lib/Tools/mlir-query/MlirQueryMain.cpp
@@ -21,6 +21,7 @@
 #include "llvm/LineEditor/LineEditor.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/InitLLVM.h"
+#include "llvm/Support/Process.h"
 #include "llvm/Support/SourceMgr.h"
 
 //===----------------------------------------------------------------------===//
@@ -43,7 +44,7 @@ mlir::mlirQueryMain(int argc, char **argv, MLIRContext &context,
       llvm::cl::value_desc("command"), llvm::cl::cat(mlirQueryCategory));
 
   static llvm::cl::opt<std::string> inputFilename(
-      llvm::cl::Positional, llvm::cl::desc("<input file>"),
+      llvm::cl::Positional, llvm::cl::desc("<input file>"), llvm::cl::init("-"),
       llvm::cl::cat(mlirQueryCategory));
 
   static llvm::cl::opt<bool> noImplicitModule{
@@ -68,6 +69,14 @@ mlir::mlirQueryMain(int argc, char **argv, MLIRContext &context,
     return mlir::success();
   }
 
+  // When reading from stdin and the input is a tty, it is often a user mistake
+  // and the process "appears to be stuck". Print a message to let the user
+  // know!
+  if (inputFilename == "-" &&
+      llvm::sys::Process::FileDescriptorIsDisplayed(fileno(stdin)))
+    llvm::errs() << "(processing input from stdin now, hit ctrl-c/ctrl-d to "
+                    "interrupt)\n";
+
   // Set up the input file.
   std::string errorMessage;
   auto file = openInputFile(inputFilename, &errorMessage);
diff --git a/mlir/test/mlir-query/slice-reproducer.mlir b/mlir/test/mlir-query/slice-reproducer.mlir
new file mode 100644
index 0000000000000..126d9a71b57c9
--- /dev/null
+++ b/mlir/test/mlir-query/slice-reproducer.mlir
@@ -0,0 +1,27 @@
+// RUN: mlir-opt %s -slice-analysis-test -split-input-file | mlir-query -c "match getDefinitions(hasOpName(\"memref.dealloc\"), 2, false, true, true).extract(\"backward_slice\")" | FileCheck %s
+
+func.func @slicing_linalg_op(%arg0 : index, %arg1 : index, %arg2 : index) {
+  %a = memref.alloc(%arg0, %arg2) : memref<?x?xf32>
+  %b = memref.alloc(%arg2, %arg1) : memref<?x?xf32>
+  %c = memref.alloc(%arg0, %arg1) : memref<?x?xf32>
+  %d = memref.alloc(%arg0, %arg1) : memref<?x?xf32>
+  linalg.matmul ins(%a, %b : memref<?x?xf32>, memref<?x?xf32>)
+               outs(%c : memref<?x?xf32>)
+  linalg.matmul ins(%a, %b : memref<?x?xf32>, memref<?x?xf32>)
+               outs(%d : memref<?x?xf32>)
+  memref.dealloc %c : memref<?x?xf32>
+  memref.dealloc %b : memref<?x?xf32>
+  memref.dealloc %a : memref<?x?xf32>
+  memref.dealloc %d : memref<?x?xf32>
+  return
+}
+
+// CHECK: func.func @backward_slice(
+// CHECK-SAME:    %[[ARG0:[a-zA-Z0-9_]+]]: index, 
+// CHECK-SAME:    %[[ARG1:[a-zA-Z0-9_]+]]: index, 
+// CHECK-SAME:    %[[ARG2:[a-zA-Z0-9_]+]]: index) -> (memref<?x?xf32>, memref<?x?xf32>, memref<?x?xf32>, memref<?x?xf32>) {
+// CHECK:        %[[ALLOC:.*]] = memref.alloc(%[[ARG1]], %[[ARG2]]) : memref<?x?xf32>
+// CHECK-NEXT:   %[[ALLOC_0:.*]] = memref.alloc(%[[ARG0]], %[[ARG2]]) : memref<?x?xf32>
+// CHECK-NEXT:   %[[ALLOC_1:.*]] = memref.alloc(%[[ARG1]], %[[ARG0]]) : memref<?x?xf32> 
+// CHECK-NEXT:   %[[ALLOC_2:.*]] = memref.alloc(%[[ARG1]], %[[ARG2]]) : memref<?x?xf32>
+// CHECK-NEXT:   return %[[ALLOC]], %[[ALLOC_0]], %[[ALLOC_1]], %[[ALLOC_2]] : memref<?x?xf32>, memref<?x?xf32>, memref<?x?xf32>, memref<?x?xf32>

@joker-eph joker-eph enabled auto-merge (squash) September 1, 2025 13:57
@joker-eph joker-eph merged commit f8faf23 into llvm:main Sep 1, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:core MLIR Core Infrastructure mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants