MLIR  19.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 storageType, StringRef interfaceType,
39  StringRef convertFromStorageCall, StringRef assignToStorageCall,
40  StringRef convertToAttributeCall, StringRef convertFromAttributeCall,
41  StringRef readFromMlirBytecodeCall,
42  StringRef writeToMlirBytecodeCall, StringRef hashPropertyCall,
43  StringRef defaultValue);
44 
45  // Returns the storage type.
46  StringRef getStorageType() const { return storageType; }
47 
48  // Returns the interface type for this property.
49  StringRef getInterfaceType() const { return interfaceType; }
50 
51  // Returns the template getter method call which reads this property's
52  // storage and returns the value as of the desired return type.
53  StringRef getConvertFromStorageCall() const { return convertFromStorageCall; }
54 
55  // Returns the template setter method call which reads this property's
56  // in the provided interface type and assign it to the storage.
57  StringRef getAssignToStorageCall() const { return assignToStorageCall; }
58 
59  // Returns the conversion method call which reads this property's
60  // in the storage type and builds an attribute.
61  StringRef getConvertToAttributeCall() const { return convertToAttributeCall; }
62 
63  // Returns the setter method call which reads this property's
64  // in the provided interface type and assign it to the storage.
65  StringRef getConvertFromAttributeCall() const {
66  return convertFromAttributeCall;
67  }
68 
69  // Returns the method call which reads this property from
70  // bytecode and assign it to the storage.
71  StringRef getReadFromMlirBytecodeCall() const {
72  return readFromMlirBytecodeCall;
73  }
74 
75  // Returns the method call which write this property's
76  // to the the bytecode.
77  StringRef getWriteToMlirBytecodeCall() const {
78  return writeToMlirBytecodeCall;
79  }
80 
81  // Returns the code to compute the hash for this property.
82  StringRef getHashPropertyCall() const { return hashPropertyCall; }
83 
84  // Returns whether this Property has a default value.
85  bool hasDefaultValue() const { return !defaultValue.empty(); }
86 
87  // Returns the default value for this Property.
88  StringRef getDefaultValue() const { return defaultValue; }
89 
90  // Returns the TableGen definition this Property was constructed from.
91  const llvm::Record &getDef() const { return *def; }
92 
93 private:
94  // The TableGen definition of this constraint.
95  const llvm::Record *def;
96 
97  // Elements describing a Property, in general fetched from the record.
98  StringRef storageType;
99  StringRef interfaceType;
100  StringRef convertFromStorageCall;
101  StringRef assignToStorageCall;
102  StringRef convertToAttributeCall;
103  StringRef convertFromAttributeCall;
104  StringRef readFromMlirBytecodeCall;
105  StringRef writeToMlirBytecodeCall;
106  StringRef hashPropertyCall;
107  StringRef defaultValue;
108 };
109 
110 // A struct wrapping an op property and its name together
112  llvm::StringRef name;
114 };
115 
116 } // namespace tblgen
117 } // namespace mlir
118 
119 #endif // MLIR_TABLEGEN_PROPERTY_H_
StringRef getStorageType() const
Definition: Property.h:46
StringRef getConvertFromStorageCall() const
Definition: Property.h:53
StringRef getReadFromMlirBytecodeCall() const
Definition: Property.h:71
StringRef getAssignToStorageCall() const
Definition: Property.h:57
Property(const llvm::Record *record)
const llvm::Record & getDef() const
Definition: Property.h:91
StringRef getHashPropertyCall() const
Definition: Property.h:82
StringRef getConvertToAttributeCall() const
Definition: Property.h:61
bool hasDefaultValue() const
Definition: Property.h:85
StringRef getWriteToMlirBytecodeCall() const
Definition: Property.h:77
StringRef getConvertFromAttributeCall() const
Definition: Property.h:65
StringRef getDefaultValue() const
Definition: Property.h:88
StringRef getInterfaceType() const
Definition: Property.h:49
Property(const llvm::DefInit *init)
Include the generated interface declarations.
Definition: CallGraph.h:229
@ Type
An inlay hint that for a type annotation.
Include the generated interface declarations.
llvm::StringRef name
Definition: Property.h:112