-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[mlir] Default mlir-query input to stdin
#156324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
@llvm/pr-subscribers-mlir-core @llvm/pr-subscribers-mlir Author: Denzel-Brian Budii (chios202) ChangesCurrently ,when piping a pass pipeline into ./mlir-opt input.mlir -canonicalize | ./mlir-query - -c "<your_query_1>" -c "<your_query_2>" ... -c "<your_query_N>"With this PR, the explicit ./mlir-opt input.mlir -canonicalize | ./mlir-query -c "<your_query_1>" -c "<your_query_2>" ... -c "<your_query_N>"Full diff: https://github.com/llvm/llvm-project/pull/156324.diff 2 Files Affected:
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
reviewed
Sep 1, 2025
joker-eph
approved these changes
Sep 1, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently ,when piping a pass pipeline into
mlir-query, you must explicitly pass-to read from the standard input:With this PR, the explicit
-is no longer required: