• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "mlir/Support/LLVM.h"
17 
18 #include <memory>
19 
20 namespace mlir {
21 class Operation;
22 
23 namespace detail {
24 class AsmStateImpl;
25 } // end namespace detail
26 
27 /// This class provides management for the lifetime of the state used when
28 /// printing the IR. It allows for alleviating the cost of recomputing the
29 /// internal state of the asm printer.
30 ///
31 /// The IR should not be mutated in-between invocations using this state, and
32 /// the IR being printed must not be an parent of the IR originally used to
33 /// initialize this state. This means that if a child operation is provided, a
34 /// parent operation cannot reuse this state.
35 class AsmState {
36 public:
37   /// This map represents the raw locations of operations within the output
38   /// stream. This maps the original pointer to the operation, to a pair of line
39   /// and column in the output stream.
40   using LocationMap = DenseMap<Operation *, std::pair<unsigned, unsigned>>;
41 
42   /// Initialize the asm state at the level of the given operation. A location
43   /// map may optionally be provided to be populated when printing.
44   AsmState(Operation *op, LocationMap *locationMap = nullptr);
45   ~AsmState();
46 
47   /// Return an instance of the internal implementation. Returns nullptr if the
48   /// state has not been initialized.
getImpl()49   detail::AsmStateImpl &getImpl() { return *impl; }
50 
51 private:
52   AsmState() = delete;
53 
54   /// A pointer to allocated storage for the impl state.
55   std::unique_ptr<detail::AsmStateImpl> impl;
56 };
57 
58 //===----------------------------------------------------------------------===//
59 // AsmPrinter CommandLine Options
60 //===----------------------------------------------------------------------===//
61 
62 /// Register a set of useful command-line options that can be used to configure
63 /// various flags within the AsmPrinter.
64 void registerAsmPrinterCLOptions();
65 
66 } // end namespace mlir
67 
68 #endif // MLIR_IR_ASMSTATE_H_
69