Revert "[mlirTranslateMain] Add a customization callback."

This reverts commit f18d6af7e9.
This patch is a more controversial than I expected, it is
better to revert while the discussion continues.  xref this
thread:
https://discourse.llvm.org/t/doc-mlir-translate-mlir-opt/60751/

xref this phab patch: https://reviews.llvm.org/D120970

Differential Revision: https://reviews.llvm.org/D121668
This commit is contained in:
Chris Lattner 2022-03-14 21:56:14 -07:00
parent 6d007e0278
commit 2ef95efb41
2 changed files with 5 additions and 35 deletions

View file

@ -13,30 +13,16 @@
#ifndef MLIR_TOOLS_MLIRTRANSLATE_MLIRTRANSLATEMAIN_H
#define MLIR_TOOLS_MLIRTRANSLATE_MLIRTRANSLATEMAIN_H
#include "mlir/IR/Dialect.h"
#include "mlir/Support/LogicalResult.h"
#include "llvm/ADT/STLFunctionalExtras.h"
#include "llvm/ADT/StringRef.h"
namespace mlir {
/// Translate to/from an MLIR module from/to an external representation (e.g.
/// LLVM IR, SPIRV binary, ...). This is the entry point for the implementation
/// of tools like `mlir-translate`. The translation to perform is parsed from
/// the command line. The `toolName` argument is used for the header displayed
/// by `--help`.
///
/// Dialect translation typically registers the dialects produced or returned
/// by the translation itself, but some translation testing tools may want
/// additional dialects registered so the .mlir parser can read them. In this
/// case, `extraDialects` may be specified with additional dialects to use.
///
/// The client may specify a "customization" function if they'd like, which
/// is invoked when an MLIRContext is set up, allowing custom settings.
LogicalResult
mlirTranslateMain(int argc, char **argv, StringRef toolName,
const DialectRegistry &extraDialects = DialectRegistry(),
function_ref<void(MLIRContext &)> customization = {});
LogicalResult mlirTranslateMain(int argc, char **argv, StringRef toolName);
} // namespace mlir
#endif // MLIR_TOOLS_MLIRTRANSLATE_MLIRTRANSLATEMAIN_H

View file

@ -22,13 +22,11 @@
using namespace mlir;
//===----------------------------------------------------------------------===//
// mlir-translate tool driver
// Translation Parser
//===----------------------------------------------------------------------===//
LogicalResult
mlir::mlirTranslateMain(int argc, char **argv, llvm::StringRef toolName,
const DialectRegistry &extraDialects,
llvm::function_ref<void(MLIRContext &)> customization) {
LogicalResult mlir::mlirTranslateMain(int argc, char **argv,
llvm::StringRef toolName) {
static llvm::cl::opt<std::string> inputFilename(
llvm::cl::Positional, llvm::cl::desc("<input file>"),
@ -82,22 +80,8 @@ mlir::mlirTranslateMain(int argc, char **argv, llvm::StringRef toolName,
auto processBuffer = [&](std::unique_ptr<llvm::MemoryBuffer> ownedBuffer,
raw_ostream &os) {
MLIRContext context;
// If the client wanted to register additional dialects, go ahead and add
// them to our context.
context.appendDialectRegistry(extraDialects);
// If a customization callback was provided, apply it to the MLIRContext.
// This could add dialects to the registry or change context defaults.
if (customization)
customization(context);
// If command line flags were used to customize the context, apply their
// settings.
if (allowUnregisteredDialects.getNumOccurrences())
context.allowUnregisteredDialects(allowUnregisteredDialects);
context.allowUnregisteredDialects(allowUnregisteredDialects);
context.printOpOnDiagnostic(!verifyDiagnostics);
llvm::SourceMgr sourceMgr;
sourceMgr.AddNewSourceBuffer(std::move(ownedBuffer), SMLoc());