MLIR  20.0.0git
Property.h
Go to the documentation of this file.
1 //===- Property.h - Property wrapper class --------------------*- 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 // Property wrapper to simplify using TableGen Record defining a MLIR
10 // Property.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_TABLEGEN_PROPERTY_H_
15 #define MLIR_TABLEGEN_PROPERTY_H_
16 
17 #include "mlir/Support/LLVM.h"
19 #include "llvm/ADT/StringRef.h"
20 
21 namespace llvm {
22 class DefInit;
23 class Record;
24 } // namespace llvm
25 
26 namespace mlir {
27 namespace tblgen {
28 class Dialect;
29 class Type;
30 
31 // Wrapper class providing helper methods for accessing MLIR Property defined
32 // in TableGen. This class should closely reflect what is defined as class
33 // `Property` in TableGen.
34 class Property {
35 public:
36  explicit Property(const llvm::Record *record);
37  explicit Property(const llvm::DefInit *init);
38  Property(StringRef summary, StringRef description, StringRef storageType,
39  StringRef interfaceType, StringRef convertFromStorageCall,
40  StringRef assignToStorageCall, StringRef convertToAttributeCall,
41  StringRef convertFromAttributeCall, StringRef parserCall,
42  StringRef optionalParserCall, StringRef printerCall,
43  StringRef readFromMlirBytecodeCall,
44  StringRef writeToMlirBytecodeCall, StringRef hashPropertyCall,
45  StringRef defaultValue, StringRef storageTypeValueOverride);
46 
47  // Returns the summary (for error messages) of this property's type.
48  StringRef getSummary() const { return summary; }
49 
50  // Returns the description of this property.
51  StringRef getDescription() const { return description; }
52 
53  // Returns the storage type.
54  StringRef getStorageType() const { return storageType; }
55 
56  // Returns the interface type for this property.
57  StringRef getInterfaceType() const { return interfaceType; }
58 
59  // Returns the template getter method call which reads this property's
60  // storage and returns the value as of the desired return type.
61  StringRef getConvertFromStorageCall() const { return convertFromStorageCall; }
62 
63  // Returns the template setter method call which reads this property's
64  // in the provided interface type and assign it to the storage.
65  StringRef getAssignToStorageCall() const { return assignToStorageCall; }
66 
67  // Returns the conversion method call which reads this property's
68  // in the storage type and builds an attribute.
69  StringRef getConvertToAttributeCall() const { return convertToAttributeCall; }
70 
71  // Returns the setter method call which reads this property's
72  // in the provided interface type and assign it to the storage.
73  StringRef getConvertFromAttributeCall() const {
74  return convertFromAttributeCall;
75  }
76 
77  // Returns the method call which parses this property from textual MLIR.
78  StringRef getParserCall() const { return parserCall; }
79 
80  // Returns true if this property has defined an optional parser.
81  bool hasOptionalParser() const { return !optionalParserCall.empty(); }
82 
83  // Returns the method call which optionally parses this property from textual
84  // MLIR.
85  StringRef getOptionalParserCall() const { return optionalParserCall; }
86 
87  // Returns the method call which prints this property to textual MLIR.
88  StringRef getPrinterCall() const { return printerCall; }
89 
90  // Returns the method call which reads this property from
91  // bytecode and assign it to the storage.
92  StringRef getReadFromMlirBytecodeCall() const {
93  return readFromMlirBytecodeCall;
94  }
95 
96  // Returns the method call which write this property's
97  // to the the bytecode.
98  StringRef getWriteToMlirBytecodeCall() const {
99  return writeToMlirBytecodeCall;
100  }
101 
102  // Returns the code to compute the hash for this property.
103  StringRef getHashPropertyCall() const { return hashPropertyCall; }
104 
105  // Returns whether this Property has a default value.
106  bool hasDefaultValue() const { return !defaultValue.empty(); }
107 
108  // Returns the default value for this Property.
109  StringRef getDefaultValue() const { return defaultValue; }
110 
111  // Returns whether this Property has a default storage-type value that is
112  // distinct from its default interface-type value.
114  return !storageTypeValueOverride.empty();
115  }
116 
117  StringRef getStorageTypeValueOverride() const {
118  return storageTypeValueOverride;
119  }
120 
121  // Returns this property's TableGen def-name.
122  StringRef getPropertyDefName() const;
123 
124  // Returns the base-level property that this Property constraint is based on
125  // or the Property itself otherwise. (Note: there are currently no
126  // property constraints, this function is added for future-proofing)
127  Property getBaseProperty() const;
128 
129  // Returns the TableGen definition this Property was constructed from.
130  const llvm::Record &getDef() const { return *def; }
131 
132 private:
133  // The TableGen definition of this constraint.
134  const llvm::Record *def;
135 
136  // Elements describing a Property, in general fetched from the record.
137  StringRef summary;
138  StringRef description;
139  StringRef storageType;
140  StringRef interfaceType;
141  StringRef convertFromStorageCall;
142  StringRef assignToStorageCall;
143  StringRef convertToAttributeCall;
144  StringRef convertFromAttributeCall;
145  StringRef parserCall;
146  StringRef optionalParserCall;
147  StringRef printerCall;
148  StringRef readFromMlirBytecodeCall;
149  StringRef writeToMlirBytecodeCall;
150  StringRef hashPropertyCall;
151  StringRef defaultValue;
152  StringRef storageTypeValueOverride;
153 };
154 
155 // A struct wrapping an op property and its name together
157  llvm::StringRef name;
159 };
160 
161 } // namespace tblgen
162 } // namespace mlir
163 
164 #endif // MLIR_TABLEGEN_PROPERTY_H_
StringRef getPropertyDefName() const
Definition: Property.cpp:87
StringRef getStorageType() const
Definition: Property.h:54
StringRef getConvertFromStorageCall() const
Definition: Property.h:61
StringRef getReadFromMlirBytecodeCall() const
Definition: Property.h:92
StringRef getPrinterCall() const
Definition: Property.h:88
bool hasOptionalParser() const
Definition: Property.h:81
StringRef getDescription() const
Definition: Property.h:51
StringRef getAssignToStorageCall() const
Definition: Property.h:65
Property(const llvm::Record *record)
const llvm::Record & getDef() const
Definition: Property.h:130
StringRef getHashPropertyCall() const
Definition: Property.h:103
StringRef getConvertToAttributeCall() const
Definition: Property.h:69
bool hasDefaultValue() const
Definition: Property.h:106
StringRef getWriteToMlirBytecodeCall() const
Definition: Property.h:98
bool hasStorageTypeValueOverride() const
Definition: Property.h:113
Property getBaseProperty() const
Definition: Property.cpp:94
StringRef getConvertFromAttributeCall() const
Definition: Property.h:73
StringRef getSummary() const
Definition: Property.h:48
StringRef getStorageTypeValueOverride() const
Definition: Property.h:117
StringRef getDefaultValue() const
Definition: Property.h:109
StringRef getParserCall() const
Definition: Property.h:78
StringRef getInterfaceType() const
Definition: Property.h:57
Property(const llvm::DefInit *init)
StringRef getOptionalParserCall() const
Definition: Property.h:85
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition: CallGraph.h:229
@ Type
An inlay hint that for a type annotation.
Include the generated interface declarations.
llvm::StringRef name
Definition: Property.h:157