1 | //===- DLTI.h - Data Layout and Target Info MLIR Dialect --------*- 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 | // Defines the dialect containing the objects pertaining to target information. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #ifndef MLIR_DIALECT_DLTI_DLTI_H |
14 | #define MLIR_DIALECT_DLTI_DLTI_H |
15 | |
16 | #include "mlir/IR/Attributes.h" |
17 | #include "mlir/IR/Dialect.h" |
18 | #include "mlir/Interfaces/DataLayoutInterfaces.h" |
19 | |
20 | namespace mlir { |
21 | namespace impl { |
22 | class DataLayoutEntryStorage; |
23 | class DataLayoutSpecStorage; |
24 | } // namespace impl |
25 | |
26 | //===----------------------------------------------------------------------===// |
27 | // DataLayoutEntryAttr |
28 | //===----------------------------------------------------------------------===// |
29 | |
30 | /// A data layout entry attribute is a key-value pair where the key is a type or |
31 | /// an identifier and the value is another attribute. These entries form a data |
32 | /// layout specification. |
33 | class DataLayoutEntryAttr |
34 | : public Attribute::AttrBase<DataLayoutEntryAttr, Attribute, |
35 | impl::DataLayoutEntryStorage, |
36 | DataLayoutEntryInterface::Trait> { |
37 | public: |
38 | using Base::Base; |
39 | |
40 | /// The keyword used for this attribute in custom syntax. |
41 | constexpr const static llvm::StringLiteral kAttrKeyword = "dl_entry" ; |
42 | |
43 | /// Returns the entry with the given key and value. |
44 | static DataLayoutEntryAttr get(StringAttr key, Attribute value); |
45 | static DataLayoutEntryAttr get(Type key, Attribute value); |
46 | |
47 | /// Returns the key of this entry. |
48 | DataLayoutEntryKey getKey() const; |
49 | |
50 | /// Returns the value of this entry. |
51 | Attribute getValue() const; |
52 | |
53 | /// Parses an instance of this attribute. |
54 | static DataLayoutEntryAttr parse(AsmParser &parser); |
55 | |
56 | /// Prints this attribute. |
57 | void print(AsmPrinter &os) const; |
58 | |
59 | static constexpr StringLiteral name = "builtin.data_layout_entry" ; |
60 | }; |
61 | |
62 | //===----------------------------------------------------------------------===// |
63 | // DataLayoutSpecAttr |
64 | //===----------------------------------------------------------------------===// |
65 | |
66 | /// A data layout specification is a list of entries that specify (partial) data |
67 | /// layout information. It is expected to be attached to operations that serve |
68 | /// as scopes for data layout requests. |
69 | class DataLayoutSpecAttr |
70 | : public Attribute::AttrBase<DataLayoutSpecAttr, Attribute, |
71 | impl::DataLayoutSpecStorage, |
72 | DataLayoutSpecInterface::Trait> { |
73 | public: |
74 | using Base::Base; |
75 | |
76 | /// The keyword used for this attribute in custom syntax. |
77 | constexpr const static StringLiteral kAttrKeyword = "dl_spec" ; |
78 | |
79 | /// Returns the specification containing the given list of keys. |
80 | static DataLayoutSpecAttr get(MLIRContext *ctx, |
81 | ArrayRef<DataLayoutEntryInterface> entries); |
82 | |
83 | /// Returns the specification containing the given list of keys. If the list |
84 | /// contains duplicate keys or is otherwise invalid, reports errors using the |
85 | /// given callback and returns null. |
86 | static DataLayoutSpecAttr |
87 | getChecked(function_ref<InFlightDiagnostic()> emitError, MLIRContext *context, |
88 | ArrayRef<DataLayoutEntryInterface> entries); |
89 | |
90 | /// Checks that the given list of entries does not contain duplicate keys. |
91 | static LogicalResult verify(function_ref<InFlightDiagnostic()> emitError, |
92 | ArrayRef<DataLayoutEntryInterface> entries); |
93 | |
94 | /// Combines this specification with `specs`, enclosing specifications listed |
95 | /// from outermost to innermost. This overwrites the older entries with the |
96 | /// same key as the newer entries if the entries are compatible. Returns null |
97 | /// if the specifications are not compatible. |
98 | DataLayoutSpecAttr combineWith(ArrayRef<DataLayoutSpecInterface> specs) const; |
99 | |
100 | /// Returns the list of entries. |
101 | DataLayoutEntryListRef getEntries() const; |
102 | |
103 | /// Returns the endiannes identifier. |
104 | StringAttr getEndiannessIdentifier(MLIRContext *context) const; |
105 | |
106 | /// Returns the alloca memory space identifier. |
107 | StringAttr getAllocaMemorySpaceIdentifier(MLIRContext *context) const; |
108 | |
109 | /// Returns the program memory space identifier. |
110 | StringAttr getProgramMemorySpaceIdentifier(MLIRContext *context) const; |
111 | |
112 | /// Returns the global memory space identifier. |
113 | StringAttr getGlobalMemorySpaceIdentifier(MLIRContext *context) const; |
114 | |
115 | /// Returns the stack alignment identifier. |
116 | StringAttr getStackAlignmentIdentifier(MLIRContext *context) const; |
117 | |
118 | /// Parses an instance of this attribute. |
119 | static DataLayoutSpecAttr parse(AsmParser &parser); |
120 | |
121 | /// Prints this attribute. |
122 | void print(AsmPrinter &os) const; |
123 | |
124 | static constexpr StringLiteral name = "builtin.data_layout_spec" ; |
125 | }; |
126 | |
127 | } // namespace mlir |
128 | |
129 | #include "mlir/Dialect/DLTI/DLTIDialect.h.inc" |
130 | |
131 | #endif // MLIR_DIALECT_DLTI_DLTI_H |
132 | |