Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c65ec23

Browse files
Thirumalai-ShaktivelAgent-Hellboy
authored andcommitted
[ASR Pass] Handle ArraySection and SIMDArray BinOp
1 parent 76abb30 commit c65ec23

File tree

1 file changed

+45
-6
lines changed

1 file changed

+45
-6
lines changed

src/libasr/pass/array_op.cpp

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -716,16 +716,25 @@ class ReplaceArrayOp: public ASR::BaseExprReplacer<ReplaceArrayOp> {
716716
op_n_dims = x_dims.size();
717717
}
718718

719-
ASR::ttype_t* x_m_type = ASRUtils::TYPE(ASR::make_Pointer_t(al, loc,
720-
ASRUtils::type_get_past_allocatable(ASRUtils::duplicate_type(al,
721-
ASRUtils::type_get_past_pointer(x->m_type), &empty_dims))));
722-
719+
ASR::ttype_t* x_m_type;
720+
if (op_expr && ASRUtils::is_simd_array(op_expr)) {
721+
x_m_type = ASRUtils::expr_type(op_expr);
722+
} else {
723+
x_m_type = ASRUtils::TYPE(ASR::make_Pointer_t(al, loc,
724+
ASRUtils::type_get_past_allocatable(ASRUtils::duplicate_type(al,
725+
ASRUtils::type_get_past_pointer(x->m_type), &empty_dims))));
726+
}
723727
ASR::expr_t* array_section_pointer = PassUtils::create_var(
724728
result_counter, "_array_section_pointer_", loc,
725729
x_m_type, al, current_scope);
726730
result_counter += 1;
727-
pass_result.push_back(al, ASRUtils::STMT(ASRUtils::make_Associate_t_util(
728-
al, loc, array_section_pointer, *current_expr)));
731+
if (op_expr && ASRUtils::is_simd_array(op_expr)) {
732+
pass_result.push_back(al, ASRUtils::STMT(ASR::make_Assignment_t(
733+
al, loc, array_section_pointer, *current_expr, nullptr)));
734+
} else {
735+
pass_result.push_back(al, ASRUtils::STMT(ASRUtils::make_Associate_t_util(
736+
al, loc, array_section_pointer, *current_expr)));
737+
}
729738
*current_expr = array_section_pointer;
730739

731740
// Might get used in other replace_* methods as well.
@@ -740,6 +749,33 @@ class ReplaceArrayOp: public ASR::BaseExprReplacer<ReplaceArrayOp> {
740749

741750
template <typename T>
742751
void replace_ArrayOpCommon(T* x, std::string res_prefix) {
752+
bool is_left_simd = ASRUtils::is_simd_array(x->m_left);
753+
bool is_right_simd = ASRUtils::is_simd_array(x->m_right);
754+
if ( is_left_simd && is_right_simd ) {
755+
return;
756+
} else if ( ( is_left_simd && !is_right_simd) ||
757+
(!is_left_simd && is_right_simd) ) {
758+
ASR::expr_t** current_expr_copy = current_expr;
759+
ASR::expr_t* op_expr_copy = op_expr;
760+
if (is_left_simd) {
761+
// Replace ArraySection, case: a = a + b(:4)
762+
if (ASR::is_a<ASR::ArraySection_t>(*x->m_right)) {
763+
current_expr = &(x->m_right);
764+
op_expr = x->m_left;
765+
this->replace_expr(x->m_right);
766+
}
767+
} else {
768+
// Replace ArraySection, case: a = b(:4) + a
769+
if (ASR::is_a<ASR::ArraySection_t>(*x->m_left)) {
770+
current_expr = &(x->m_left);
771+
op_expr = x->m_right;
772+
this->replace_expr(x->m_left);
773+
}
774+
}
775+
current_expr = current_expr_copy;
776+
op_expr = op_expr_copy;
777+
return;
778+
}
743779
const Location& loc = x->base.base.loc;
744780
bool current_status = use_custom_loop_params;
745781
use_custom_loop_params = false;
@@ -1587,6 +1623,9 @@ class ArrayOpVisitor : public ASR::CallReplacerOnExpressionsVisitor<ArrayOpVisit
15871623

15881624
void visit_Assignment(const ASR::Assignment_t &x) {
15891625
if (ASRUtils::is_simd_array(x.m_target)) {
1626+
if (!ASR::is_a<ASR::ArrayPhysicalCast_t>(*x.m_value)) {
1627+
this->visit_expr(*x.m_value);
1628+
}
15901629
return;
15911630
}
15921631
if( (ASR::is_a<ASR::Pointer_t>(*ASRUtils::expr_type(x.m_target)) &&

0 commit comments

Comments
 (0)