New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass: Passing Array descriptor by value #77
Conversation
This reverts commit 4b7398a.
As suggested in this #70 (comment), using this pass, we need to change subroutine f(a, b)
integer :: a(:,:)
real :: b(:,:,:)
end subroutine into subroutine f(na1, na2, a, nb1, nb2, nb3, b)
integer, intent(in) :: na1, na2, nb1, nb2, nb3
integer :: a(na1, na2)
real :: b(nb1, nb2, nb3)
end subroutine doubt: Please, could someone possibly share how the following void my_func(int **a, int ***b) {
... // some statements here
} |
class ArrDimsPropagate : public ASR::StatementsFirstBaseWalkVisitor<ArrDimsPropagate> | ||
class ArrDimsPropagate : public ASR::StatementWalkVisitor<ArrDimsPropagate> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On line 21
, do we need to use PassUtils::PassVisitor
or is ASR::StatementWalkVisitor
also fine/works?
ASR::FunctionCall_t xx = const_cast<ASR::FunctionCall_t &>(x); | ||
xx.n_args = new_args.size(); | ||
xx.m_args = new_args.p; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Lines 50
to 52
) Since, the arguments passed to visit_FunctionCall()
(and others) are const
, it was no possible to update them. So, I used a const_cast<>
to allow us to update values but this leads to warnings as follows during build
:
/home/ubaid/OpenSource/lfortran/src/libasr/pass/arr_dims_propagate.cpp:50:29: warning: variable ‘xx’ set but not used [-Wunused-but-set-variable]
50 | ASR::FunctionCall_t xx = const_cast<ASR::FunctionCall_t &>(x);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The solution here is to have a visitor that allows to modify the ASR tree in-place. We just have to do it.
This |
As |
Creating the general ASR pass might be more complicated, so let's do that later. For now, just support the same kind of arrays that @czgdp1807 implemented in LFortran to represent with just a pointer. We will later add an ASR pass to be able to transform more general arrays into that. Conclusion: just get |
Correct me if I am wrong. So we need to do the following things,
If so, then I think it shouldn’t be hard but just lengthy. Can I try to do this? In any case if successful then good otherwise we will know the limitations of this strategy. Please let me know. I will continue this if you agree. |
@czgdp1807 yes exactly. Yes, go ahead and try to do this! This would be very useful optional pass, that we can reuse across all backends. For some, like LLVM, it will give an extra performance in some cases. For some other, like WASM, it would be needed to even get some cases working. |
Great. Added this to my priority list. Will start working on this. |
N.B. #87. Its a WIP. |
Closing in favour of #87 |
This is a
WIP
(Work in progress). The tests might not pass.