MLIR  19.0.0git
DLTI.h
Go to the documentation of this file.
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"
19 
20 namespace mlir {
21 namespace impl {
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.
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.
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.
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
89 
90  /// Checks that the given list of entries does not contain duplicate keys.
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.
99 
100  /// Returns the list of entries.
102 
103  /// Returns the alloca memory space identifier.
104  StringAttr getAllocaMemorySpaceIdentifier(MLIRContext *context) const;
105 
106  /// Returns the program memory space identifier.
107  StringAttr getProgramMemorySpaceIdentifier(MLIRContext *context) const;
108 
109  /// Returns the global memory space identifier.
110  StringAttr getGlobalMemorySpaceIdentifier(MLIRContext *context) const;
111 
112  /// Returns the stack alignment identifier.
113  StringAttr getStackAlignmentIdentifier(MLIRContext *context) const;
114 
115  /// Parses an instance of this attribute.
116  static DataLayoutSpecAttr parse(AsmParser &parser);
117 
118  /// Prints this attribute.
119  void print(AsmPrinter &os) const;
120 
121  static constexpr StringLiteral name = "builtin.data_layout_spec";
122 };
123 
124 } // namespace mlir
125 
126 #include "mlir/Dialect/DLTI/DLTIDialect.h.inc"
127 
128 #endif // MLIR_DIALECT_DLTI_DLTI_H
This base class exposes generic asm parser hooks, usable across the various derived parsers.
This base class exposes generic asm printer hooks, usable across the various derived printers.
Attributes are known-constant values of operations.
Definition: Attributes.h:25
A data layout entry attribute is a key-value pair where the key is a type or an identifier and the va...
Definition: DLTI.h:36
static DataLayoutEntryAttr parse(AsmParser &parser)
Parses an instance of this attribute.
Definition: DLTI.cpp:68
void print(AsmPrinter &os) const
Prints this attribute.
Definition: DLTI.cpp:95
constexpr static const llvm::StringLiteral kAttrKeyword
The keyword used for this attribute in custom syntax.
Definition: DLTI.h:41
DataLayoutEntryKey getKey() const
Returns the key of this entry.
Definition: DLTI.cpp:60
Attribute getValue() const
Returns the value of this entry.
Definition: DLTI.cpp:64
static DataLayoutEntryAttr get(StringAttr key, Attribute value)
Returns the entry with the given key and value.
Definition: DLTI.cpp:52
static constexpr StringLiteral name
Definition: DLTI.h:59
A data layout specification is a list of entries that specify (partial) data layout information.
Definition: DLTI.h:72
static DataLayoutSpecAttr get(MLIRContext *ctx, ArrayRef< DataLayoutEntryInterface > entries)
Returns the specification containing the given list of keys.
Definition: DLTI.cpp:141
StringAttr getProgramMemorySpaceIdentifier(MLIRContext *context) const
Returns the program memory space identifier.
Definition: DLTI.cpp:290
static constexpr StringLiteral name
Definition: DLTI.h:121
StringAttr getGlobalMemorySpaceIdentifier(MLIRContext *context) const
Returns the global memory space identifier.
Definition: DLTI.cpp:297
void print(AsmPrinter &os) const
Prints this attribute.
Definition: DLTI.cpp:329
StringAttr getStackAlignmentIdentifier(MLIRContext *context) const
Returns the stack alignment identifier.
Definition: DLTI.cpp:302
static LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, ArrayRef< DataLayoutEntryInterface > entries)
Checks that the given list of entries does not contain duplicate keys.
Definition: DLTI.cpp:154
static DataLayoutSpecAttr parse(AsmParser &parser)
Parses an instance of this attribute.
Definition: DLTI.cpp:311
static DataLayoutSpecAttr getChecked(function_ref< InFlightDiagnostic()> emitError, MLIRContext *context, ArrayRef< DataLayoutEntryInterface > entries)
Returns the specification containing the given list of keys.
Definition: DLTI.cpp:147
StringAttr getAllocaMemorySpaceIdentifier(MLIRContext *context) const
Returns the alloca memory space identifier.
Definition: DLTI.cpp:285
constexpr static const StringLiteral kAttrKeyword
The keyword used for this attribute in custom syntax.
Definition: DLTI.h:77
DataLayoutEntryListRef getEntries() const
Returns the list of entries.
Definition: DLTI.cpp:280
DataLayoutSpecAttr combineWith(ArrayRef< DataLayoutSpecInterface > specs) const
Combines this specification with specs, enclosing specifications listed from outermost to innermost.
Definition: DLTI.cpp:254
This class represents a diagnostic that is inflight and set to be reported.
Definition: Diagnostics.h:308
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
Utility class for implementing users of storage classes uniqued by a StorageUniquer.
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26