MLIR  18.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 
60 //===----------------------------------------------------------------------===//
61 // DataLayoutSpecAttr
62 //===----------------------------------------------------------------------===//
63 
64 /// A data layout specification is a list of entries that specify (partial) data
65 /// layout information. It is expected to be attached to operations that serve
66 /// as scopes for data layout requests.
68  : public Attribute::AttrBase<DataLayoutSpecAttr, Attribute,
69  impl::DataLayoutSpecStorage,
70  DataLayoutSpecInterface::Trait> {
71 public:
72  using Base::Base;
73 
74  /// The keyword used for this attribute in custom syntax.
75  constexpr const static StringLiteral kAttrKeyword = "dl_spec";
76 
77  /// Returns the specification containing the given list of keys.
80 
81  /// Returns the specification containing the given list of keys. If the list
82  /// contains duplicate keys or is otherwise invalid, reports errors using the
83  /// given callback and returns null.
84  static DataLayoutSpecAttr
87 
88  /// Checks that the given list of entries does not contain duplicate keys.
91 
92  /// Combines this specification with `specs`, enclosing specifications listed
93  /// from outermost to innermost. This overwrites the older entries with the
94  /// same key as the newer entries if the entries are compatible. Returns null
95  /// if the specifications are not compatible.
97 
98  /// Returns the list of entries.
100 
101  /// Returns the alloca memory space identifier.
102  StringAttr getAllocaMemorySpaceIdentifier(MLIRContext *context) const;
103 
104  /// Returns the stack alignment identifier.
105  StringAttr getStackAlignmentIdentifier(MLIRContext *context) const;
106 
107  /// Parses an instance of this attribute.
108  static DataLayoutSpecAttr parse(AsmParser &parser);
109 
110  /// Prints this attribute.
111  void print(AsmPrinter &os) const;
112 };
113 
114 } // namespace mlir
115 
116 #include "mlir/Dialect/DLTI/DLTIDialect.h.inc"
117 
118 #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
A data layout specification is a list of entries that specify (partial) data layout information.
Definition: DLTI.h:70
static DataLayoutSpecAttr get(MLIRContext *ctx, ArrayRef< DataLayoutEntryInterface > entries)
Returns the specification containing the given list of keys.
Definition: DLTI.cpp:136
void print(AsmPrinter &os) const
Prints this attribute.
Definition: DLTI.cpp:313
StringAttr getStackAlignmentIdentifier(MLIRContext *context) const
Returns the stack alignment identifier.
Definition: DLTI.cpp:286
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:149
static DataLayoutSpecAttr parse(AsmParser &parser)
Parses an instance of this attribute.
Definition: DLTI.cpp:295
static DataLayoutSpecAttr getChecked(function_ref< InFlightDiagnostic()> emitError, MLIRContext *context, ArrayRef< DataLayoutEntryInterface > entries)
Returns the specification containing the given list of keys.
Definition: DLTI.cpp:142
StringAttr getAllocaMemorySpaceIdentifier(MLIRContext *context) const
Returns the alloca memory space identifier.
Definition: DLTI.cpp:280
constexpr static const StringLiteral kAttrKeyword
The keyword used for this attribute in custom syntax.
Definition: DLTI.h:75
DataLayoutEntryListRef getEntries() const
Returns the list of entries.
Definition: DLTI.cpp:275
DataLayoutSpecAttr combineWith(ArrayRef< DataLayoutSpecInterface > specs) const
Combines this specification with specs, enclosing specifications listed from outermost to innermost.
Definition: DLTI.cpp:249
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.
This header declares functions that assist transformations in the MemRef dialect.
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