Skip to content

Commit e3cfa7f

Browse files
committed
Addressing review comments
1. Use ODS framework for all of DLTI attrs 2. Removing need of MLIRContext in APIs 3. Removing canonicalizer heuristics from this PR
1 parent d3811d8 commit e3cfa7f

File tree

10 files changed

+388
-814
lines changed

10 files changed

+388
-814
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
add_mlir_dialect(DLTI dlti)
22
add_mlir_doc(DLTI DLTIDialect Dialects/ -gen-dialect-doc)
3+
4+
set(LLVM_TARGET_DEFINITIONS DLTIAttrs.td)
5+
mlir_tablegen(DLTIAttrs.h.inc -gen-attrdef-decls -attrdefs-dialect=dlti)
6+
mlir_tablegen(DLTIAttrs.cpp.inc -gen-attrdef-defs -attrdefs-dialect=dlti)
7+
add_public_tablegen_target(MLIRDLTIAttrsIncGen)
8+
add_dependencies(mlir-headers MLIRDLTIAttrsIncGen)

mlir/include/mlir/Dialect/DLTI/DLTI.h

Lines changed: 5 additions & 252 deletions
Original file line numberDiff line numberDiff line change
@@ -18,260 +18,13 @@
1818
#include "mlir/Interfaces/DataLayoutInterfaces.h"
1919

2020
namespace mlir {
21-
namespace impl {
22-
class DataLayoutEntryStorage;
23-
class DataLayoutSpecStorage;
24-
class TargetSystemDescSpecAttrStorage;
25-
class TargetDeviceDescSpecAttrStorage;
26-
} // namespace impl
27-
28-
//===----------------------------------------------------------------------===//
29-
// DataLayoutEntryAttr
30-
//===----------------------------------------------------------------------===//
31-
32-
/// A data layout entry attribute is a key-value pair where the key is a type or
33-
/// an identifier and the value is another attribute. These entries form a data
34-
/// layout specification.
35-
class DataLayoutEntryAttr
36-
: public Attribute::AttrBase<DataLayoutEntryAttr, Attribute,
37-
impl::DataLayoutEntryStorage,
38-
DataLayoutEntryInterface::Trait> {
39-
public:
40-
using Base::Base;
41-
42-
/// The keyword used for this attribute in custom syntax.
43-
constexpr const static llvm::StringLiteral kAttrKeyword = "dl_entry";
44-
45-
/// Returns the entry with the given key and value.
46-
static DataLayoutEntryAttr get(StringAttr key, Attribute value);
47-
static DataLayoutEntryAttr get(Type key, Attribute value);
48-
49-
/// Returns the key of this entry.
50-
DataLayoutEntryKey getKey() const;
51-
52-
/// Returns the value of this entry.
53-
Attribute getValue() const;
54-
55-
/// Parses an instance of this attribute.
56-
static DataLayoutEntryAttr parse(AsmParser &parser);
57-
58-
/// Prints this attribute.
59-
void print(AsmPrinter &os) const;
60-
61-
static constexpr StringLiteral name = "builtin.data_layout_entry";
62-
};
63-
64-
//===----------------------------------------------------------------------===//
65-
// DataLayoutSpecAttr
66-
//===----------------------------------------------------------------------===//
67-
68-
/// A data layout specification is a list of entries that specify (partial) data
69-
/// layout information. It is expected to be attached to operations that serve
70-
/// as scopes for data layout requests.
71-
class DataLayoutSpecAttr
72-
: public Attribute::AttrBase<DataLayoutSpecAttr, Attribute,
73-
impl::DataLayoutSpecStorage,
74-
DataLayoutSpecInterface::Trait> {
75-
public:
76-
using Base::Base;
77-
78-
/// The keyword used for this attribute in custom syntax.
79-
constexpr const static StringLiteral kAttrKeyword = "dl_spec";
80-
81-
/// Returns the specification containing the given list of keys.
82-
static DataLayoutSpecAttr get(MLIRContext *ctx,
83-
ArrayRef<DataLayoutEntryInterface> entries);
84-
85-
/// Returns the specification containing the given list of keys. If the list
86-
/// contains duplicate keys or is otherwise invalid, reports errors using the
87-
/// given callback and returns null.
88-
static DataLayoutSpecAttr
89-
getChecked(function_ref<InFlightDiagnostic()> emitError, MLIRContext *context,
90-
ArrayRef<DataLayoutEntryInterface> entries);
91-
92-
/// Checks that the given list of entries does not contain duplicate keys.
93-
static LogicalResult verify(function_ref<InFlightDiagnostic()> emitError,
94-
ArrayRef<DataLayoutEntryInterface> entries);
95-
96-
/// Combines this specification with `specs`, enclosing specifications listed
97-
/// from outermost to innermost. This overwrites the older entries with the
98-
/// same key as the newer entries if the entries are compatible. Returns null
99-
/// if the specifications are not compatible.
100-
DataLayoutSpecAttr combineWith(ArrayRef<DataLayoutSpecInterface> specs) const;
101-
102-
/// Returns the list of entries.
103-
DataLayoutEntryListRef getEntries() const;
104-
105-
/// Returns the endiannes identifier.
106-
StringAttr getEndiannessIdentifier(MLIRContext *context) const;
107-
108-
/// Returns the alloca memory space identifier.
109-
StringAttr getAllocaMemorySpaceIdentifier(MLIRContext *context) const;
110-
111-
/// Returns the program memory space identifier.
112-
StringAttr getProgramMemorySpaceIdentifier(MLIRContext *context) const;
113-
114-
/// Returns the global memory space identifier.
115-
StringAttr getGlobalMemorySpaceIdentifier(MLIRContext *context) const;
116-
117-
/// Returns the stack alignment identifier.
118-
StringAttr getStackAlignmentIdentifier(MLIRContext *context) const;
119-
120-
/// Parses an instance of this attribute.
121-
static DataLayoutSpecAttr parse(AsmParser &parser);
122-
123-
/// Prints this attribute.
124-
void print(AsmPrinter &os) const;
125-
126-
static constexpr StringLiteral name = "builtin.data_layout_spec";
127-
};
128-
129-
//===----------------------------------------------------------------------===//
130-
// TargetSystemDescSpecAttr
131-
//===----------------------------------------------------------------------===//
132-
133-
/// A system description attribute is a list of device descriptors, each
134-
/// having a unique device ID
135-
class TargetSystemDescSpecAttr
136-
: public Attribute::AttrBase<TargetSystemDescSpecAttr, Attribute,
137-
impl::TargetSystemDescSpecAttrStorage,
138-
TargetSystemDescSpecInterface::Trait> {
139-
public:
140-
using Base::Base;
141-
142-
/// The keyword used for this attribute in custom syntax.
143-
constexpr const static StringLiteral kAttrKeyword = "tsd_spec";
144-
145-
/// Returns a system descriptor attribute from the given system descriptor
146-
static TargetSystemDescSpecAttr
147-
get(MLIRContext *context, ArrayRef<TargetDeviceDescSpecInterface> entries);
148-
149-
/// Returns the list of entries.
150-
TargetDeviceDescSpecListRef getEntries() const;
151-
152-
/// Return the device descriptor that matches the given device ID
153-
TargetDeviceDescSpecInterface getDeviceDescForDeviceID(uint32_t deviceID);
154-
155-
/// Returns the specification containing the given list of keys. If the list
156-
/// contains duplicate keys or is otherwise invalid, reports errors using the
157-
/// given callback and returns null.
158-
static TargetSystemDescSpecAttr
159-
getChecked(function_ref<InFlightDiagnostic()> emitError, MLIRContext *context,
160-
ArrayRef<TargetDeviceDescSpecInterface> entries);
161-
162-
/// Checks that the given list of entries does not contain duplicate keys.
163-
static LogicalResult verify(function_ref<InFlightDiagnostic()> emitError,
164-
ArrayRef<TargetDeviceDescSpecInterface> entries);
165-
166-
/// Parses an instance of this attribute.
167-
static TargetSystemDescSpecAttr parse(AsmParser &parser);
168-
169-
/// Prints this attribute.
170-
void print(AsmPrinter &os) const;
171-
172-
static constexpr StringLiteral name = "builtin.target_system_description";
173-
};
174-
175-
//===----------------------------------------------------------------------===//
176-
// TargetDeviceDescSpecAttr
177-
//===----------------------------------------------------------------------===//
178-
179-
class TargetDeviceDescSpecAttr
180-
: public Attribute::AttrBase<TargetDeviceDescSpecAttr, Attribute,
181-
impl::TargetDeviceDescSpecAttrStorage,
182-
TargetDeviceDescSpecInterface::Trait> {
183-
public:
184-
using Base::Base;
185-
186-
/// The keyword used for this attribute in custom syntax.
187-
constexpr const static StringLiteral kAttrKeyword = "tdd_spec";
188-
189-
/// Returns a system descriptor attribute from the given system descriptor
190-
static TargetDeviceDescSpecAttr
191-
get(MLIRContext *context, ArrayRef<DataLayoutEntryInterface> entries);
192-
193-
/// Returns the specification containing the given list of keys. If the list
194-
/// contains duplicate keys or is otherwise invalid, reports errors using the
195-
/// given callback and returns null.
196-
static TargetDeviceDescSpecAttr
197-
getChecked(function_ref<InFlightDiagnostic()> emitError, MLIRContext *context,
198-
ArrayRef<DataLayoutEntryInterface> entries);
199-
200-
/// Checks that the given list of entries does not contain duplicate keys.
201-
static LogicalResult verify(function_ref<InFlightDiagnostic()> emitError,
202-
ArrayRef<DataLayoutEntryInterface> entries);
203-
204-
/// Returns the list of entries.
205-
DataLayoutEntryListRef getEntries() const;
206-
207-
/// Parses an instance of this attribute.
208-
static TargetDeviceDescSpecAttr parse(AsmParser &parser);
209-
210-
/// Prints this attribute.
211-
void print(AsmPrinter &os) const;
212-
213-
/// Returns the device ID identifier.
214-
StringAttr getDeviceIDIdentifier(MLIRContext *context);
215-
216-
/// Returns the device type identifier.
217-
StringAttr getDeviceTypeIdentifier(MLIRContext *context);
218-
219-
/// Returns max vector op width identifier.
220-
StringAttr getMaxVectorOpWidthIdentifier(MLIRContext *context);
221-
222-
/// Returns canonicalizer max iterations identifier.
223-
StringAttr getCanonicalizerMaxIterationsIdentifier(MLIRContext *context);
224-
225-
/// Returns canonicalizer max num rewrites identifier.
226-
StringAttr getCanonicalizerMaxNumRewritesIdentifier(MLIRContext *context);
227-
228-
/// Returns L1 cache size identifier
229-
StringAttr getL1CacheSizeInBytesIdentifier(MLIRContext *context);
230-
231-
/// Returns the interface spec for device ID
232-
/// Since we verify that the spec contains device ID the function
233-
/// will return a valid spec.
234-
DataLayoutEntryInterface getSpecForDeviceID(MLIRContext *context);
235-
236-
/// Returns the interface spec for device type
237-
/// Since we verify that the spec contains device type the function
238-
/// will return a valid spec.
239-
DataLayoutEntryInterface getSpecForDeviceType(MLIRContext *context);
240-
241-
/// Returns the interface spec for max vector op width
242-
/// Since max vector op width is an optional property, this function will
243-
/// return a valid spec if the property is defined, otherwise it
244-
/// will return an empty spec.
245-
DataLayoutEntryInterface getSpecForMaxVectorOpWidth(MLIRContext *context);
246-
247-
/// Returns the interface spec for L1 cache size
248-
/// Since L1 cache size is an optional property, this function will
249-
/// return a valid spec if the property is defined, otherwise it
250-
/// will return an empty spec.
251-
DataLayoutEntryInterface getSpecForL1CacheSizeInBytes(MLIRContext *context);
252-
253-
/// Returns the interface spec for canonicalizer max iterations.
254-
/// Since this is an optional property, this function will
255-
/// return a valid spec if the property is defined, otherwise it
256-
/// will return an empty spec.
257-
DataLayoutEntryInterface
258-
getSpecForCanonicalizerMaxIterations(MLIRContext *context);
259-
260-
/// Returns the interface spec for canonicalizer max num rewrites.
261-
/// Since this is an optional property, this function will
262-
/// return a valid spec if the property is defined, otherwise it
263-
/// will return an empty spec.
264-
DataLayoutEntryInterface
265-
getSpecForCanonicalizerMaxNumRewrites(MLIRContext *context);
266-
267-
/// Return the value of device ID
268-
uint32_t getDeviceID(MLIRContext *context);
269-
270-
static constexpr StringLiteral name = "builtin.target_device_description";
271-
};
272-
21+
namespace detail {
22+
class DataLayoutEntryAttrStorage;
23+
} // namespace detail
27324
} // namespace mlir
27425

26+
#define GET_ATTRDEF_CLASSES
27+
#include "mlir/Dialect/DLTI/DLTIAttrs.h.inc"
27528
#include "mlir/Dialect/DLTI/DLTIDialect.h.inc"
27629

27730
#endif // MLIR_DIALECT_DLTI_DLTI_H

0 commit comments

Comments
 (0)