/home/arjun/llvm-project/mlir/include/mlir/IR/MLIRContext.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===- MLIRContext.h - MLIR Global Context Class ----------------*- 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 | | #ifndef MLIR_IR_MLIRCONTEXT_H |
10 | | #define MLIR_IR_MLIRCONTEXT_H |
11 | | |
12 | | #include "mlir/Support/LLVM.h" |
13 | | #include <functional> |
14 | | #include <memory> |
15 | | #include <vector> |
16 | | |
17 | | namespace mlir { |
18 | | class AbstractOperation; |
19 | | class DiagnosticEngine; |
20 | | class Dialect; |
21 | | class InFlightDiagnostic; |
22 | | class Location; |
23 | | class MLIRContextImpl; |
24 | | class StorageUniquer; |
25 | | |
26 | | /// MLIRContext is the top-level object for a collection of MLIR modules. It |
27 | | /// holds immortal uniqued objects like types, and the tables used to unique |
28 | | /// them. |
29 | | /// |
30 | | /// MLIRContext gets a redundant "MLIR" prefix because otherwise it ends up with |
31 | | /// a very generic name ("Context") and because it is uncommon for clients to |
32 | | /// interact with it. |
33 | | /// |
34 | | class MLIRContext { |
35 | | public: |
36 | | explicit MLIRContext(); |
37 | | ~MLIRContext(); |
38 | | |
39 | | /// Return information about all registered IR dialects. |
40 | | std::vector<Dialect *> getRegisteredDialects(); |
41 | | |
42 | | /// Get a registered IR dialect with the given namespace. If an exact match is |
43 | | /// not found, then return nullptr. |
44 | | Dialect *getRegisteredDialect(StringRef name); |
45 | | |
46 | | /// Get a registered IR dialect for the given derived dialect type. The |
47 | | /// derived type must provide a static 'getDialectNamespace' method. |
48 | | template <typename T> T *getRegisteredDialect() { |
49 | | return static_cast<T *>(getRegisteredDialect(T::getDialectNamespace())); |
50 | | } |
51 | | |
52 | | /// Return true if we allow to create operation for unregistered dialects. |
53 | | bool allowsUnregisteredDialects(); |
54 | | |
55 | | /// Enables creating operations in unregistered dialects. |
56 | | void allowUnregisteredDialects(bool allow = true); |
57 | | |
58 | | /// Return true if multi-threading is enabled by the context. |
59 | | bool isMultithreadingEnabled(); |
60 | | |
61 | | /// Set the flag specifying if multi-threading is disabled by the context. |
62 | | void disableMultithreading(bool disable = true); |
63 | 0 | void enableMultithreading(bool enable = true) { |
64 | 0 | disableMultithreading(!enable); |
65 | 0 | } |
66 | | |
67 | | /// Return true if we should attach the operation to diagnostics emitted via |
68 | | /// Operation::emit. |
69 | | bool shouldPrintOpOnDiagnostic(); |
70 | | |
71 | | /// Set the flag specifying if we should attach the operation to diagnostics |
72 | | /// emitted via Operation::emit. |
73 | | void printOpOnDiagnostic(bool enable); |
74 | | |
75 | | /// Return true if we should attach the current stacktrace to diagnostics when |
76 | | /// emitted. |
77 | | bool shouldPrintStackTraceOnDiagnostic(); |
78 | | |
79 | | /// Set the flag specifying if we should attach the current stacktrace when |
80 | | /// emitting diagnostics. |
81 | | void printStackTraceOnDiagnostic(bool enable); |
82 | | |
83 | | /// Return information about all registered operations. This isn't very |
84 | | /// efficient: typically you should ask the operations about their properties |
85 | | /// directly. |
86 | | std::vector<AbstractOperation *> getRegisteredOperations(); |
87 | | |
88 | | /// Return true if this operation name is registered in this context. |
89 | | bool isOperationRegistered(StringRef name); |
90 | | |
91 | | // This is effectively private given that only MLIRContext.cpp can see the |
92 | | // MLIRContextImpl type. |
93 | 0 | MLIRContextImpl &getImpl() { return *impl; } |
94 | | |
95 | | /// Returns the diagnostic engine for this context. |
96 | | DiagnosticEngine &getDiagEngine(); |
97 | | |
98 | | /// Returns the storage uniquer used for creating affine constructs. |
99 | | StorageUniquer &getAffineUniquer(); |
100 | | |
101 | | /// Returns the storage uniquer used for constructing type storage instances. |
102 | | /// This should not be used directly. |
103 | | StorageUniquer &getTypeUniquer(); |
104 | | |
105 | | /// Returns the storage uniquer used for constructing attribute storage |
106 | | /// instances. This should not be used directly. |
107 | | StorageUniquer &getAttributeUniquer(); |
108 | | |
109 | | private: |
110 | | const std::unique_ptr<MLIRContextImpl> impl; |
111 | | |
112 | | MLIRContext(const MLIRContext &) = delete; |
113 | | void operator=(const MLIRContext &) = delete; |
114 | | }; |
115 | | |
116 | | //===----------------------------------------------------------------------===// |
117 | | // MLIRContext CommandLine Options |
118 | | //===----------------------------------------------------------------------===// |
119 | | |
120 | | /// Register a set of useful command-line options that can be used to configure |
121 | | /// various flags within the MLIRContext. These flags are used when constructing |
122 | | /// an MLIR context for initialization. |
123 | | void registerMLIRContextCLOptions(); |
124 | | |
125 | | } // end namespace mlir |
126 | | |
127 | | #endif // MLIR_IR_MLIRCONTEXT_H |