diff options
author | Mehdi Amini <joker.eph@gmail.com> | 2023-02-26 10:46:01 -0500 |
---|---|---|
committer | Mehdi Amini <joker.eph@gmail.com> | 2023-05-01 15:35:48 -0700 |
commit | d572cd1b067f1177a981a4711bf2e501eaa8117b (patch) | |
tree | 5a278dd65a863579412d6d0236708660d2eb42b9 /mlir/lib/Dialect/SCF | |
parent | 04fc02e583b06b846315904a55af9c273c8b20b9 (diff) | |
download | llvm-d572cd1b067f1177a981a4711bf2e501eaa8117b.tar.gz |
Introduce MLIR Op Properties
This new features enabled to dedicate custom storage inline within operations.
This storage can be used as an alternative to attributes to store data that is
specific to an operation. Attribute can also be stored inside the properties
storage if desired, but any kind of data can be present as well. This offers
a way to store and mutate data without uniquing in the Context like Attribute.
See the OpPropertiesTest.cpp for an example where a struct with a
std::vector<> is attached to an operation and mutated in-place:
struct TestProperties {
int a = -1;
float b = -1.;
std::vector<int64_t> array = {-33};
};
More complex scheme (including reference-counting) are also possible.
The only constraint to enable storing a C++ object as "properties" on an
operation is to implement three functions:
- convert from the candidate object to an Attribute
- convert from the Attribute to the candidate object
- hash the object
Optional the parsing and printing can also be customized with 2 extra
functions.
A new options is introduced to ODS to allow dialects to specify:
let usePropertiesForAttributes = 1;
When set to true, the inherent attributes for all the ops in this dialect
will be using properties instead of being stored alongside discardable
attributes.
The TestDialect showcases this feature.
Another change is that we introduce new APIs on the Operation class
to access separately the inherent attributes from the discardable ones.
We envision deprecating and removing the `getAttr()`, `getAttrsDictionary()`,
and other similar method which don't make the distinction explicit, leading
to an entirely separate namespace for discardable attributes.
Differential Revision: https://reviews.llvm.org/D141742
Diffstat (limited to 'mlir/lib/Dialect/SCF')
-rw-r--r-- | mlir/lib/Dialect/SCF/IR/SCF.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp index 76b3589b15f4..cbd98f39b406 100644 --- a/mlir/lib/Dialect/SCF/IR/SCF.cpp +++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp @@ -1779,7 +1779,7 @@ bool mlir::scf::insideMutuallyExclusiveBranches(Operation *a, Operation *b) { LogicalResult IfOp::inferReturnTypes(MLIRContext *ctx, std::optional<Location> loc, ValueRange operands, DictionaryAttr attrs, - RegionRange regions, + OpaqueProperties properties, RegionRange regions, SmallVectorImpl<Type> &inferredReturnTypes) { if (regions.empty()) return failure(); @@ -1872,7 +1872,8 @@ void IfOp::build(OpBuilder &builder, OperationState &result, Value cond, MLIRContext *ctx = builder.getContext(); auto attrDict = DictionaryAttr::get(ctx, result.attributes); if (succeeded(inferReturnTypes(ctx, std::nullopt, result.operands, attrDict, - result.regions, inferredReturnTypes))) { + /*properties=*/nullptr, result.regions, + inferredReturnTypes))) { result.addTypes(inferredReturnTypes); } } |