Skip to content

changes from lfortran #13

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions src/libasr/pass/intrinsic_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ class ReplaceIntrinsicFunctions: public ASR::BaseExprReplacer<ReplaceIntrinsicFu
}
ASR::expr_t* current_expr_ = instantiate_function(al, x->base.base.loc,
global_scope, arg_types, x->m_type, new_args, x->m_overload_id);
if( ASR::is_a<ASR::ArrayPhysicalCast_t>(*(*current_expr)) ) {
ASR::ArrayPhysicalCast_t* array_physical_cast_t = ASR::down_cast<ASR::ArrayPhysicalCast_t>(*current_expr);
array_physical_cast_t->m_arg = current_expr_;
} else {
*current_expr = current_expr_;
}
*current_expr = current_expr_;
// if( ASR::is_a<ASR::ArrayPhysicalCast_t>(*(*current_expr)) ) {
// ASR::ArrayPhysicalCast_t* array_physical_cast_t = ASR::down_cast<ASR::ArrayPhysicalCast_t>(*current_expr);
// array_physical_cast_t->m_arg = current_expr_;
// } else {
// *current_expr = current_expr_;
// }
}

void replace_IntrinsicArrayFunction(ASR::IntrinsicArrayFunction_t* x) {
Expand Down Expand Up @@ -120,12 +121,13 @@ class ReplaceIntrinsicFunctions: public ASR::BaseExprReplacer<ReplaceIntrinsicFu
ASR::expr_t* current_expr_ = instantiate_function(al, x->base.base.loc,
global_scope, arg_types, x->m_type, new_args, x->m_overload_id);
ASR::expr_t* func_call = current_expr_;
if( ASR::is_a<ASR::ArrayPhysicalCast_t>(*(*current_expr)) ) {
ASR::ArrayPhysicalCast_t* array_physical_cast_t = ASR::down_cast<ASR::ArrayPhysicalCast_t>(*current_expr);
array_physical_cast_t->m_arg = current_expr_;
} else {
*current_expr = current_expr_;
}
*current_expr = current_expr_;
// if( ASR::is_a<ASR::ArrayPhysicalCast_t>(*(*current_expr)) ) {
// ASR::ArrayPhysicalCast_t* array_physical_cast_t = ASR::down_cast<ASR::ArrayPhysicalCast_t>(*current_expr);
// array_physical_cast_t->m_arg = current_expr_;
// } else {
// *current_expr = current_expr_;
// }
if (ASR::is_a<ASR::FunctionCall_t>(*func_call)) {
ASR::symbol_t *call_sym = ASRUtils::symbol_get_past_external(
ASR::down_cast<ASR::FunctionCall_t>(func_call)->m_name);
Expand Down Expand Up @@ -287,7 +289,7 @@ class ReplaceFunctionCallReturningArray: public ASR::BaseExprReplacer<ReplaceFun
ASR::expr_t* result_var_ = nullptr;
int dim_index = ASRUtils::IntrinsicArrayFunctionRegistry::
get_dim_index(func2intrinsicid[x_m_name]);
if( dim_index != -1 ) {
if( dim_index == 1 ) {
ASR::expr_t* dim = x->m_args[dim_index].m_value;
if( !ASRUtils::is_value_constant(ASRUtils::expr_value(dim)) ) {
// Possibly can be replaced by calling "get_result_var_for_runtime_dim"
Expand All @@ -302,6 +304,12 @@ class ReplaceFunctionCallReturningArray: public ASR::BaseExprReplacer<ReplaceFun
throw LCompilersException("Constant dimension cannot be extracted.");
}
}
} else if ( dim_index == 2 ) {
result_var_ = PassUtils::create_var(result_counter,
std::string(ASRUtils::symbol_name(x->m_name)) + "_res",
x->base.base.loc, x->m_type, al, current_scope);
} else {
LCOMPILERS_ASSERT(false);
}
result_counter += 1;
ASR::call_arg_t new_arg;
Expand Down Expand Up @@ -366,14 +374,14 @@ class ReplaceFunctionCallReturningArrayVisitor : public ASR::CallReplacerOnExpre
pass_result.n = 0;
}

void visit_Assignment(const ASR::Assignment_t& x) {
ASR::CallReplacerOnExpressionsVisitor<
ReplaceFunctionCallReturningArrayVisitor>::visit_Assignment(x);
ASR::Assignment_t& xx = const_cast<ASR::Assignment_t&>(x);
if( ASR::is_a<ASR::ArrayPhysicalCast_t>(*x.m_value) ) {
xx.m_value = ASR::down_cast<ASR::ArrayPhysicalCast_t>(x.m_value)->m_arg;
}
}
// void visit_Assignment(const ASR::Assignment_t& x) {
// ASR::CallReplacerOnExpressionsVisitor<
// ReplaceFunctionCallReturningArrayVisitor>::visit_Assignment(x);
// ASR::Assignment_t& xx = const_cast<ASR::Assignment_t&>(x);
// if( ASR::is_a<ASR::ArrayPhysicalCast_t>(*x.m_value) ) {
// xx.m_value = ASR::down_cast<ASR::ArrayPhysicalCast_t>(x.m_value)->m_arg;
// }
// }

};

Expand Down