Skip to content

Commit f8faf23

Browse files
authored
[mlir] Default mlir-query input to stdin (llvm#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>" ```
1 parent 78e3a58 commit f8faf23

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

mlir/lib/Tools/mlir-query/MlirQueryMain.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/LineEditor/LineEditor.h"
2222
#include "llvm/Support/CommandLine.h"
2323
#include "llvm/Support/InitLLVM.h"
24+
#include "llvm/Support/Process.h"
2425
#include "llvm/Support/SourceMgr.h"
2526

2627
//===----------------------------------------------------------------------===//
@@ -43,7 +44,7 @@ mlir::mlirQueryMain(int argc, char **argv, MLIRContext &context,
4344
llvm::cl::value_desc("command"), llvm::cl::cat(mlirQueryCategory));
4445

4546
static llvm::cl::opt<std::string> inputFilename(
46-
llvm::cl::Positional, llvm::cl::desc("<input file>"),
47+
llvm::cl::Positional, llvm::cl::desc("<input file>"), llvm::cl::init("-"),
4748
llvm::cl::cat(mlirQueryCategory));
4849

4950
static llvm::cl::opt<bool> noImplicitModule{
@@ -68,6 +69,14 @@ mlir::mlirQueryMain(int argc, char **argv, MLIRContext &context,
6869
return mlir::success();
6970
}
7071

72+
// When reading from stdin and the input is a tty, it is often a user mistake
73+
// and the process "appears to be stuck". Print a message to let the user
74+
// know!
75+
if (inputFilename == "-" &&
76+
llvm::sys::Process::FileDescriptorIsDisplayed(fileno(stdin)))
77+
llvm::errs() << "(processing input from stdin now, hit ctrl-c/ctrl-d to "
78+
"interrupt)\n";
79+
7180
// Set up the input file.
7281
std::string errorMessage;
7382
auto file = openInputFile(inputFilename, &errorMessage);

0 commit comments

Comments
 (0)