|
17 | 17 |
|
18 | 18 | namespace mlir { |
19 | 19 | class Operation; |
20 | | -class DialectBytecodeWriter; |
21 | | - |
22 | | -/// A class to interact with the attributes and types printer when emitting MLIR |
23 | | -/// bytecode. |
24 | | -template <class T> |
25 | | -class AttrTypeBytecodeWriter { |
26 | | -public: |
27 | | - AttrTypeBytecodeWriter() = default; |
28 | | - virtual ~AttrTypeBytecodeWriter() = default; |
29 | | - |
30 | | - /// Callback writer API used in IRNumbering, where groups are created and |
31 | | - /// type/attribute components are numbered. At this stage, writer is expected |
32 | | - /// to be a `NumberingDialectWriter`. |
33 | | - virtual LogicalResult write(T entry, std::optional<StringRef> &name, |
34 | | - DialectBytecodeWriter &writer) = 0; |
35 | | - |
36 | | - /// Callback writer API used in BytecodeWriter, where groups are created and |
37 | | - /// type/attribute components are numbered. Here, DialectBytecodeWriter is |
38 | | - /// expected to be an actual writer. The optional stringref specified by |
39 | | - /// the user is ignored, since the group was already specified when numbering |
40 | | - /// the IR. |
41 | | - LogicalResult write(T entry, DialectBytecodeWriter &writer) { |
42 | | - std::optional<StringRef> dummy; |
43 | | - return write(entry, dummy, writer); |
44 | | - } |
45 | | - |
46 | | - /// Return an Attribute/Type printer implemented via the given callable, whose |
47 | | - /// form should match that of the `write` function above. |
48 | | - template <typename CallableT, |
49 | | - std::enable_if_t<std::is_convertible_v< |
50 | | - CallableT, std::function<LogicalResult( |
51 | | - T, std::optional<StringRef> &, |
52 | | - DialectBytecodeWriter &)>>, |
53 | | - bool> = true> |
54 | | - static std::unique_ptr<AttrTypeBytecodeWriter<T>> |
55 | | - fromCallable(CallableT &&writeFn) { |
56 | | - struct Processor : public AttrTypeBytecodeWriter<T> { |
57 | | - Processor(CallableT &&writeFn) |
58 | | - : AttrTypeBytecodeWriter(), writeFn(std::move(writeFn)) {} |
59 | | - LogicalResult write(T entry, std::optional<StringRef> &name, |
60 | | - DialectBytecodeWriter &writer) override { |
61 | | - return writeFn(entry, name, writer); |
62 | | - } |
63 | | - |
64 | | - std::decay_t<CallableT> writeFn; |
65 | | - }; |
66 | | - return std::make_unique<Processor>(std::forward<CallableT>(writeFn)); |
67 | | - } |
68 | | -}; |
69 | 20 |
|
70 | 21 | /// This class contains the configuration used for the bytecode writer. It |
71 | 22 | /// controls various aspects of bytecode generation, and contains all of the |
@@ -97,43 +48,6 @@ class BytecodeWriterConfig { |
97 | 48 | /// Get the set desired bytecode version to emit. |
98 | 49 | int64_t getDesiredBytecodeVersion() const; |
99 | 50 |
|
100 | | - //===--------------------------------------------------------------------===// |
101 | | - // Types and Attributes encoding |
102 | | - //===--------------------------------------------------------------------===// |
103 | | - |
104 | | - /// Retrieve the callbacks. |
105 | | - ArrayRef<std::unique_ptr<AttrTypeBytecodeWriter<Attribute>>> |
106 | | - getAttributeWriterCallbacks() const; |
107 | | - ArrayRef<std::unique_ptr<AttrTypeBytecodeWriter<Type>>> |
108 | | - getTypeWriterCallbacks() const; |
109 | | - |
110 | | - /// Attach a custom bytecode printer callback to the configuration for the |
111 | | - /// emission of custom type/attributes encodings. |
112 | | - void attachAttributeCallback( |
113 | | - std::unique_ptr<AttrTypeBytecodeWriter<Attribute>> callback); |
114 | | - void |
115 | | - attachTypeCallback(std::unique_ptr<AttrTypeBytecodeWriter<Type>> callback); |
116 | | - |
117 | | - /// Attach a custom bytecode printer callback to the configuration for the |
118 | | - /// emission of custom type/attributes encodings. |
119 | | - template <typename CallableT> |
120 | | - std::enable_if_t<std::is_convertible_v< |
121 | | - CallableT, |
122 | | - std::function<LogicalResult(Attribute, std::optional<StringRef> &, |
123 | | - DialectBytecodeWriter &)>>> |
124 | | - attachAttributeCallback(CallableT &&emitFn) { |
125 | | - attachAttributeCallback(AttrTypeBytecodeWriter<Attribute>::fromCallable( |
126 | | - std::forward<CallableT>(emitFn))); |
127 | | - } |
128 | | - template <typename CallableT> |
129 | | - std::enable_if_t<std::is_convertible_v< |
130 | | - CallableT, std::function<LogicalResult(Type, std::optional<StringRef> &, |
131 | | - DialectBytecodeWriter &)>>> |
132 | | - attachTypeCallback(CallableT &&emitFn) { |
133 | | - attachTypeCallback(AttrTypeBytecodeWriter<Type>::fromCallable( |
134 | | - std::forward<CallableT>(emitFn))); |
135 | | - } |
136 | | - |
137 | 51 | //===--------------------------------------------------------------------===// |
138 | 52 | // Resources |
139 | 53 | //===--------------------------------------------------------------------===// |
|
0 commit comments