You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 23, 2021. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 23, 2021. It is now read-only.
What is the Correct Way to Add Data Member in User Defined Dialect Type? #29
I am trying to creating my own dialect with a new dialect type, say ToyArrayType, according to your toy example. My ToyArraytype contains an extra member data, a "string".
I want the "string" go along with me during the lowering to my Toy MLIR. However it seems that the ToyArrayType will be cast to mlir::Type during the lowering, and that makes me lost the "string" data because mlir::Type doesn't have that member.
For example, in Ch5/ToyDialect.cpp, function ReshapeOp::build(...), (around line 355), the statement:
state->types.push_back(ToyArrayType::get(builder->getContext()));
It seems that if the ToyArrayType has some member data, the "string", it will lose it when being pushed into the "state->types", which is a SmallVectormlir::Type.
If I am not on the correct path, could you please let me know the best way to add a data member in user dialect type? (without change/hacking codes for mlir::Type).
On Tue, May 28, 2019 at 4:51 PM yurikamome ***@***.***> wrote:
Hello,
I am trying to creating my own dialect with a new dialect type, say
ToyArrayType, according to your toy example. My ToyArraytype contains an
extra member data, a "string".
I want the "string" go along with me during the lowering to my Toy MLIR.
However it seems that the ToyArrayType will be cast to mlir::Type during
the lowering, and that makes me lost the "string" data because mlir::Type
doesn't have that member.
For example, in Ch5/ToyDialect.cpp, function ReshapeOp::build(...),
(around line 355), the statement:
state->types.push_back(ToyArrayType::get(builder->getContext()));
It seems that if the ToyArrayType has some member data, the "string", it
will lose it when being pushed into the "state->types", which is a
SmallVectormlir::Type.
Thanks for all the answers a lot. But it seems that I still have the issue with dyn_cast<>.
I have a non-empty data member: vector in ToyArray. The ToyArray is assigned to a mlir::Type, and then dyn_cast<> back to a ToyArray, at that time the vector data member becomes empty.
I attached an example code. Could you please correct me if the example is written in the wrong way.
class ToyArrayType has a public data member: vector _hello_world.
At Ch5/ToyDialect.cpp, around line 354,
void ReshapeOp::build(mlir::Builder *builder, mlir::OperationState *state,
mlir::Value *value, ToyArrayType reshapedType) {
//init _hello_world data for reshapedType
reshapedType._hello_world = vector({"Hello","World"});
//push to the operation state
state->types.push_back(reshapedType);
//print size of _hello_world, it prints "2"
llvm::errs()<< reshapedType._hello_world.size() ;
//Now take back the mlir::Type from the state
mlir::Type base_type = state->types[0];
//dynamic cast to ToyArrayType
ToyArrayType toy_type = base_type.dyn_cast<ToyArrayType>();
//print _hello_world.size(). It prints "0", but I expect it to be "2"
llvm::errs()<<toy_type._hello_world.size();
Activity
River707 commentedon May 29, 2019
You may want to checkout:
https://github.com/tensorflow/mlir/blob/master/g3doc/DefiningAttributesAndTypes.md
joker-eph commentedon May 29, 2019
yurikamome commentedon May 29, 2019
Hello all,
Thanks for all the answers a lot. But it seems that I still have the issue with dyn_cast<>.
I have a non-empty data member: vector in ToyArray. The ToyArray is assigned to a mlir::Type, and then dyn_cast<> back to a ToyArray, at that time the vector data member becomes empty.
I attached an example code. Could you please correct me if the example is written in the wrong way.
class ToyArrayType has a public data member: vector _hello_world.
At Ch5/ToyDialect.cpp, around line 354,
void ReshapeOp::build(mlir::Builder *builder, mlir::OperationState *state,
mlir::Value *value, ToyArrayType reshapedType) {
//init _hello_world data for reshapedType
reshapedType._hello_world = vector({"Hello","World"});
}
Thanks,
Rui
River707 commentedon May 29, 2019
It seems like you are putting the field directly on the ToyArrayType class. Types, and many other things in MLIR, are value typed(passed by value). As such, they are essentially just smart pointers to an internal storage class(this is detailed a bit more in the link I posted). To add a field to a Type class you have to add to its storage class:
https://github.com/tensorflow/mlir/blob/master/examples/toy/Ch5/mlir/ToyDialect.cpp#L45
yurikamome commentedon May 29, 2019
Thanks! The way of putting fields into Storage class works! Thanks to all the answers again.
Revert "[Concepts] Placeholder constraints and abbreviated templates"