From ca7edc4867b510168ed79a3afcc81cfa64050c81 Mon Sep 17 00:00:00 2001 From: Denzel-Brian Budii Date: Mon, 1 Sep 2025 10:48:47 +0000 Subject: [PATCH 1/2] Default input to stdin --- mlir/lib/Tools/mlir-query/MlirQueryMain.cpp | 11 ++++++++- mlir/test/mlir-query/slice-reproducer.mlir | 27 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 mlir/test/mlir-query/slice-reproducer.mlir 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 inputFilename( - llvm::cl::Positional, llvm::cl::desc(""), + llvm::cl::Positional, llvm::cl::desc(""), llvm::cl::init("-"), llvm::cl::cat(mlirQueryCategory)); static llvm::cl::opt 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 + %b = memref.alloc(%arg2, %arg1) : memref + %c = memref.alloc(%arg0, %arg1) : memref + %d = memref.alloc(%arg0, %arg1) : memref + linalg.matmul ins(%a, %b : memref, memref) + outs(%c : memref) + linalg.matmul ins(%a, %b : memref, memref) + outs(%d : memref) + memref.dealloc %c : memref + memref.dealloc %b : memref + memref.dealloc %a : memref + memref.dealloc %d : memref + 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, memref, memref, memref) { +// CHECK: %[[ALLOC:.*]] = memref.alloc(%[[ARG1]], %[[ARG2]]) : memref +// CHECK-NEXT: %[[ALLOC_0:.*]] = memref.alloc(%[[ARG0]], %[[ARG2]]) : memref +// CHECK-NEXT: %[[ALLOC_1:.*]] = memref.alloc(%[[ARG1]], %[[ARG0]]) : memref +// CHECK-NEXT: %[[ALLOC_2:.*]] = memref.alloc(%[[ARG1]], %[[ARG2]]) : memref +// CHECK-NEXT: return %[[ALLOC]], %[[ALLOC_0]], %[[ALLOC_1]], %[[ALLOC_2]] : memref, memref, memref, memref From 89b51dc599c9238e4dec65ab098025e6d62e5686 Mon Sep 17 00:00:00 2001 From: Denzel-Brian Budii Date: Mon, 1 Sep 2025 13:52:24 +0000 Subject: [PATCH 2/2] Remove unnecessary test --- mlir/test/mlir-query/slice-reproducer.mlir | 27 ---------------------- 1 file changed, 27 deletions(-) delete mode 100644 mlir/test/mlir-query/slice-reproducer.mlir diff --git a/mlir/test/mlir-query/slice-reproducer.mlir b/mlir/test/mlir-query/slice-reproducer.mlir deleted file mode 100644 index 126d9a71b57c9..0000000000000 --- a/mlir/test/mlir-query/slice-reproducer.mlir +++ /dev/null @@ -1,27 +0,0 @@ -// 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 - %b = memref.alloc(%arg2, %arg1) : memref - %c = memref.alloc(%arg0, %arg1) : memref - %d = memref.alloc(%arg0, %arg1) : memref - linalg.matmul ins(%a, %b : memref, memref) - outs(%c : memref) - linalg.matmul ins(%a, %b : memref, memref) - outs(%d : memref) - memref.dealloc %c : memref - memref.dealloc %b : memref - memref.dealloc %a : memref - memref.dealloc %d : memref - 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, memref, memref, memref) { -// CHECK: %[[ALLOC:.*]] = memref.alloc(%[[ARG1]], %[[ARG2]]) : memref -// CHECK-NEXT: %[[ALLOC_0:.*]] = memref.alloc(%[[ARG0]], %[[ARG2]]) : memref -// CHECK-NEXT: %[[ALLOC_1:.*]] = memref.alloc(%[[ARG1]], %[[ARG0]]) : memref -// CHECK-NEXT: %[[ALLOC_2:.*]] = memref.alloc(%[[ARG1]], %[[ARG2]]) : memref -// CHECK-NEXT: return %[[ALLOC]], %[[ALLOC_0]], %[[ALLOC_1]], %[[ALLOC_2]] : memref, memref, memref, memref