• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- MlirOptMain.h - MLIR Optimizer Driver main ---------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Main entry function for mlir-opt for when built as standalone binary.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "mlir/Support/LogicalResult.h"
14 #include "llvm/ADT/StringRef.h"
15 
16 #include <memory>
17 
18 namespace llvm {
19 class raw_ostream;
20 class MemoryBuffer;
21 } // end namespace llvm
22 
23 namespace mlir {
24 class DialectRegistry;
25 class PassPipelineCLParser;
26 
27 /// Perform the core processing behind `mlir-opt`:
28 /// - outputStream is the stream where the resulting IR is printed.
29 /// - buffer is the in-memory file to parser and process.
30 /// - passPipeline is the specification of the pipeline that will be applied.
31 /// - registry should contain all the dialects that can be parsed in the source.
32 /// - splitInputFile will look for a "-----" marker in the input file, and load
33 /// each chunk in an individual ModuleOp processed separately.
34 /// - verifyDiagnostics enables a verification mode where comments starting with
35 /// "expected-(error|note|remark|warning)" are parsed in the input and matched
36 /// against emitted diagnostics.
37 /// - verifyPasses enables the IR verifier in-between each pass in the pipeline.
38 /// - allowUnregisteredDialects allows to parse and create operation without
39 /// registering the Dialect in the MLIRContext.
40 /// - preloadDialectsInContext will trigger the upfront loading of all
41 ///   dialects from the global registry in the MLIRContext. This option is
42 ///   deprecated and will be removed soon.
43 LogicalResult MlirOptMain(llvm::raw_ostream &outputStream,
44                           std::unique_ptr<llvm::MemoryBuffer> buffer,
45                           const PassPipelineCLParser &passPipeline,
46                           DialectRegistry &registry, bool splitInputFile,
47                           bool verifyDiagnostics, bool verifyPasses,
48                           bool allowUnregisteredDialects,
49                           bool preloadDialectsInContext = true);
50 
51 /// Implementation for tools like `mlir-opt`.
52 /// - toolName is used for the header displayed by `--help`.
53 /// - registry should contain all the dialects that can be parsed in the source.
54 /// - preloadDialectsInContext will trigger the upfront loading of all
55 ///   dialects from the global registry in the MLIRContext. This option is
56 ///   deprecated and will be removed soon.
57 LogicalResult MlirOptMain(int argc, char **argv, llvm::StringRef toolName,
58                           DialectRegistry &registry,
59                           bool preloadDialectsInContext = true);
60 
61 } // end namespace mlir
62