Skip to content

Commit 2132ebf

Browse files
author
Jeff Niu
authored
[mlir] Add def to Properties.td to help with enum properties (#89311)
This is useful for defining operation properties that are enums.
1 parent 39bfdb7 commit 2132ebf

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

mlir/include/mlir/IR/Properties.td

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,17 @@ class ArrayProperty<string storageTypeParam = "", int n, string desc = ""> :
153153
let assignToStorage = "::llvm::copy($_value, $_storage)";
154154
}
155155

156+
class EnumProperty<string storageTypeParam, string desc = ""> :
157+
Property<storageTypeParam, desc> {
158+
code writeToMlirBytecode = [{
159+
$_writer.writeVarInt(static_cast<uint64_t>($_storage));
160+
}];
161+
code readFromMlirBytecode = [{
162+
uint64_t val;
163+
if (failed($_reader.readVarInt(val)))
164+
return ::mlir::failure();
165+
$_storage = static_cast<}] # storageTypeParam # [{>(val);
166+
}];
167+
}
168+
156169
#endif // PROPERTIES

0 commit comments

Comments
 (0)