Hi, I have a question about member function in MLIR.
Suppose I have a snip of code like python
class MyClass:
def foo(self, a: Int):
return a
x = MyClass()
b = x.foo(1)
After I parse the code into an AST
, how to I implement the member function in MLIR
?
I know that common function can be lowered to llvm.func
with function name and parameters, but how can I call a member function of an object of MyClass
in MLIR
?
I checked the builtin
and llvm
dialect, and DataLayout
documents, and I can think of an idea as below:
- define a
struct
type inMLIR
to representMyClass
. - convert
struct MyClass
toMemrefType
inMLIR
. - for every member function in
MyClass
, convert it into allvm.func
with name prefixed with class name, for example,foo
would beMyClass.foo
. And for first parameterself
, replace it withMemrefType
value which is amlir::Value
that represent an actual object. - for every call of
foo
, it would use the object as first parameter.
So is this idea correct ? Or are there any other idea to solve this problem ?