-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
ENH: support runtime dim for intrinsic sum
#3617
Conversation
} | ||
} | ||
return ret_type; | ||
} |
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.
this will be same, I do not think there can be any other variations possible for this function.
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.
What does this function do?
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.
Ensures return type do not have variables from other scope. As it is passed from create_Sum to instantiate_Sum, it has parameters from different scope.
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.
Can you document this as a comment?
if (func2intrinsicid[x_m_name] == ASRUtils::IntrinsicArrayFunctions::Sum) { | ||
PassUtils::allocate_res_var(al, x, new_args, result_var_, pass_result, {0, 0, 1}); | ||
} |
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.
We will have to map corresponding arguments based on intrinsic function we are replacing.
return_char->m_len = -2; return_char->m_len_expr = nullptr; | ||
|
||
} | ||
std::string new_name = "_lcompilers_merge_" + get_type_code(tsource_type); |
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.
This is unrelated: I wonder if merge
can be just an elemental function.
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.
merge
is an elemental function.
|
||
ASR::stmt_t* allocate_stmt = ASRUtils::STMT(ASR::make_Allocate_t(al, | ||
x->base.base.loc, alloc_args.p, alloc_args.n, nullptr, nullptr, nullptr)); | ||
pass_result.push_back(al, allocate_stmt); |
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.
Is this deallocated properly?
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.
Yes, it gets implicitly deallocated in pass insert_deallocate
deallocate(__libasr__created__var__0_Sum_4_2_1_res) ! Implicit deallocate
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.
Actually this is problematic in general (not here only but other places as well). We need to allocate only when extremely necessary like when there is no other way left. Same for creating auxiliary variables, create only when extremely necessary. Otherwise they lead to a lot of bugs.
How is this runtime We also need to improve tests, as indicated above. Those more robust tests would reveal any possible issues with the implementation. Overall great job, thanks for tackling this difficult feature! Let's iron out these details. |
Implementation of sum is independent of compile time value of lfortran/src/libasr/asr_builder.h Lines 723 to 739 in 755ad60
For intrinsic |
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.
I think that this is good enough to merge. If there are bugs, we'll implement them.
Thanks for implementing this!
9c70fdd
to
dbaae9d
Compare
This is fine in general. |
Fixes #3540