MLIR  14.0.0git
AsmState.h
Go to the documentation of this file.
1 //===- AsmState.h - State class for AsmPrinter ------------------*- 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 // This file defines the AsmState class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_IR_ASMSTATE_H_
14 #define MLIR_IR_ASMSTATE_H_
15 
17 #include "mlir/Support/LLVM.h"
18 
19 #include <memory>
20 
21 namespace mlir {
22 class Operation;
23 
24 namespace detail {
25 class AsmStateImpl;
26 } // namespace detail
27 
28 /// This class provides management for the lifetime of the state used when
29 /// printing the IR. It allows for alleviating the cost of recomputing the
30 /// internal state of the asm printer.
31 ///
32 /// The IR should not be mutated in-between invocations using this state, and
33 /// the IR being printed must not be an parent of the IR originally used to
34 /// initialize this state. This means that if a child operation is provided, a
35 /// parent operation cannot reuse this state.
36 class AsmState {
37 public:
38  /// This map represents the raw locations of operations within the output
39  /// stream. This maps the original pointer to the operation, to a pair of line
40  /// and column in the output stream.
42 
43  /// Initialize the asm state at the level of the given operation. A location
44  /// map may optionally be provided to be populated when printing.
45  AsmState(Operation *op,
46  const OpPrintingFlags &printerFlags = OpPrintingFlags(),
47  LocationMap *locationMap = nullptr);
48  ~AsmState();
49 
50  /// Return an instance of the internal implementation. Returns nullptr if the
51  /// state has not been initialized.
53 
54 private:
55  AsmState() = delete;
56 
57  /// A pointer to allocated storage for the impl state.
58  std::unique_ptr<detail::AsmStateImpl> impl;
59 };
60 
61 //===----------------------------------------------------------------------===//
62 // AsmPrinter CommandLine Options
63 //===----------------------------------------------------------------------===//
64 
65 /// Register a set of useful command-line options that can be used to configure
66 /// various flags within the AsmPrinter.
68 
69 } // namespace mlir
70 
71 #endif // MLIR_IR_ASMSTATE_H_
Include the generated interface declarations.
Operation is a basic unit of execution within MLIR.
Definition: Operation.h:28
detail::AsmStateImpl & getImpl()
Return an instance of the internal implementation.
Definition: AsmState.h:52
void registerAsmPrinterCLOptions()
Register a set of useful command-line options that can be used to configure various flags within the ...
Definition: AsmPrinter.cpp:155
Set of flags used to control the behavior of the various IR print methods (e.g.
This class provides management for the lifetime of the state used when printing the IR...
Definition: AsmState.h:36