[Mlir-commits] [mlir] 554e40d - Add a message to mlir-opt when reading from stdin to avoid being waiting for nothing
Mehdi Amini
llvmlistbot at llvm.org
Mon Mar 13 06:28:31 PDT 2023
Author: Mehdi Amini
Date: 2023-03-13T14:28:11+01:00
New Revision: 554e40d6ba1cdeef1c0b82469bce3978fabc84a9
URL: https://github.com/llvm/llvm-project/commit/554e40d6ba1cdeef1c0b82469bce3978fabc84a9
DIFF: https://github.com/llvm/llvm-project/commit/554e40d6ba1cdeef1c0b82469bce3978fabc84a9.diff
LOG: Add a message to mlir-opt when reading from stdin to avoid being waiting for nothing
It happens from time to time that one may run mlir-opt expecting something to
happen, but the process is waiting on stdin. Print a message when reading from
stdin to warn developers.
Reviewed By: rriddle
Differential Revision: https://reviews.llvm.org/D145469
Added:
Modified:
mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
index d1c56375e3fda..a9d165b117b48 100644
--- a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
+++ b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
@@ -32,6 +32,7 @@
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/Process.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/StringSaver.h"
@@ -338,6 +339,14 @@ LogicalResult mlir::MlirOptMain(int argc, char **argv, llvm::StringRef toolName,
MlirOptMainConfig config = MlirOptMainConfig::createFromCLOptions();
config.preloadDialectsInContext(preloadDialectsInContext);
+ // When reading from stdin and the input is a tty, it is often a user mistak
+ // and the process "appears to be stuck". Print a message to let the user know
+ // about it!
+ if (inputFilename == "-" &&
+ 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