@@ -85,6 +85,64 @@ if (DialectInlinerInterface *interface = dyn_cast<DialectInlinerInterface>(diale
8585}
8686```
8787
88+ #### Utilizing the ODS framework
89+
90+ Note: Before reading this section, the reader should have some familiarity with
91+ the concepts described in the
92+ [`Operation Definition Specification`](DefiningDialects/Operations.md) documentation.
93+
94+ MLIR also supports defining dialect interfaces directly in **TableGen**.
95+ This reduces boilerplate and allows authors to specify high-level interface
96+ structure declaratively.
97+
98+ For example, the above interface can be defined using ODS as follows:
99+ ```tablegen
100+ def DialectInlinerInterface : DialectInterface<" DialectInlinerInterface" > {
101+ let description = [ {
102+ Define a base inlining interface class to allow for dialects to opt-in to
103+ the inliner.
104+ }] ;
105+
106+ let methods = [
107+ InterfaceMethod<
108+ /* desc=* / [ {
109+ Returns true if the given region 'src' can be inlined into the region
110+ 'dest' that is attached to an operation registered to the current dialect.
111+ 'valueMapping' contains any remapped values from within the 'src' region.
112+ This can be used to examine what values will replace entry arguments into
113+ the 'src' region, for example.
114+ }] ,
115+ /* returnType=* / "bool",
116+ /* methodName=* / "isLegalToInline",
117+ /* args=* / (ins "Region * ":$dest, "Region * ":$src,
118+ "IRMapping &":$valueMapping),
119+ /* methodBody=* / [ {
120+ return false;
121+ }]
122+ >
123+ ] ;
124+ }
125+ ```
126+
127+ ` DialectInterfaces ` class make use of the following components:
128+
129+ * C++ Class Name (Provided via template parameter)
130+ - The name of the C++ interface class.
131+ * Description (` description ` )
132+ - A string description of the interface, its invariants, example usages,
133+ etc.
134+ * C++ Namespace (` cppNamespace ` )
135+ - The C++ namespace that the interface class should be generated in.
136+ * Methods (` methods ` )
137+ - The list of interface hook methods that are defined by the IR object.
138+ - The structure of these methods is defined [ here] ( #interface-methods ) .
139+
140+ The header file can be generated via the following command:
141+ ``` bash
142+ mlir-tblgen gen-dialect-interface-decls DialectInterface.td
143+
144+ ```
145+
88146#### DialectInterfaceCollection
89147
90148An additional utility is provided via ` DialectInterfaceCollection ` . This class
@@ -364,10 +422,6 @@ void *TestDialect::getRegisteredInterfaceForOp(TypeID typeID,
364422
365423#### Utilizing the ODS Framework
366424
367- Note: Before reading this section, the reader should have some familiarity with
368- the concepts described in the
369- [`Operation Definition Specification`](DefiningDialects/Operations.md) documentation.
370-
371425As detailed above, [Interfaces](#attributeoperationtype-interfaces) allow for
372426attributes, operations, and types to expose method calls without requiring that
373427the caller know the specific derived type. The downside to this infrastructure,
0 commit comments