[Mlir-commits] [mlir] f8faf23 - [mlir] Default `mlir-query` input to stdin (#156324)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Sep 1 07:04:28 PDT 2025
Author: Denzel-Brian Budii
Date: 2025-09-01T14:04:24Z
New Revision: f8faf23d92a6bf931bad6104bace62be7182724c
URL: https://github.com/llvm/llvm-project/commit/f8faf23d92a6bf931bad6104bace62be7182724c
DIFF: https://github.com/llvm/llvm-project/commit/f8faf23d92a6bf931bad6104bace62be7182724c.diff
LOG: [mlir] Default `mlir-query` input to stdin (#156324)
This allows piping without an explicit `-` :
```shell
./mlir-opt input.mlir -canonicalize | ./mlir-query -c "<your_query_1>" -c "<your_query_2>" ... -c "<your_query_N>"
```
Added:
Modified:
mlir/lib/Tools/mlir-query/MlirQueryMain.cpp
Removed:
################################################################################
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);
More information about the Mlir-commits
mailing list