@@ -125,99 +125,6 @@ class ReplaceFunctionCallWithSubroutineCall:
125125 apply_again (apply_again_)
126126 {}
127127
128- template <typename LOOP_BODY>
129- void create_do_loop (const Location& loc, int result_rank,
130- Vec<ASR::expr_t *>& idx_vars, Vec<ASR::expr_t *>& idx_vars_value,
131- Vec<ASR::expr_t *>& loop_vars, Vec<ASR::stmt_t *>& doloop_body,
132- ASR::expr_t * op_expr, ASR::expr_t * result_var_, LOOP_BODY loop_body) {
133- PassUtils::create_idx_vars (idx_vars_value, result_rank, loc, al, current_scope, " _v" );
134- PassUtils::create_idx_vars (idx_vars, result_rank, loc, al, current_scope, " _t" );
135- loop_vars.from_pointer_n_copy (al, idx_vars.p , idx_vars.size ());
136-
137- ASR::stmt_t * doloop = nullptr ;
138- ASR::ttype_t * int32_type = ASRUtils::TYPE (ASR::make_Integer_t (al, loc, 4 ));
139- ASR::expr_t * const_1 = ASRUtils::EXPR (ASR::make_IntegerConstant_t (al, loc, 1 , int32_type));
140- for ( int i = (int ) loop_vars.size () - 1 ; i >= 0 ; i-- ) {
141- // TODO: Add an If debug node to check if the lower and upper bounds of both the arrays are same.
142- ASR::do_loop_head_t head;
143- head.m_v = loop_vars[i];
144- head.m_start = PassUtils::get_bound (result_var_, i + 1 , " lbound" , al);
145- head.m_end = PassUtils::get_bound (result_var_, i + 1 , " ubound" , al);
146- head.m_increment = nullptr ;
147- head.loc = head.m_v ->base .loc ;
148- doloop_body.reserve (al, 1 );
149- if ( doloop == nullptr ) {
150- loop_body ();
151- } else {
152- if ( ASRUtils::is_array (ASRUtils::expr_type (op_expr)) ) {
153- ASR::expr_t * idx_lb = PassUtils::get_bound (op_expr, i + 1 , " lbound" , al);
154- ASR::stmt_t * set_to_one = ASRUtils::STMT (ASR::make_Assignment_t (
155- al, loc, idx_vars_value[i + 1 ], idx_lb, nullptr ));
156- doloop_body.push_back (al, set_to_one);
157- }
158- doloop_body.push_back (al, doloop);
159- }
160- if ( ASRUtils::is_array (ASRUtils::expr_type (op_expr)) ) {
161- ASR::expr_t * inc_expr = ASRUtils::EXPR (ASR::make_IntegerBinOp_t (
162- al, loc, idx_vars_value[i], ASR::binopType::Add, const_1, int32_type, nullptr ));
163- ASR::stmt_t * assign_stmt = ASRUtils::STMT (ASR::make_Assignment_t (
164- al, loc, idx_vars_value[i], inc_expr, nullptr ));
165- doloop_body.push_back (al, assign_stmt);
166- }
167- doloop = ASRUtils::STMT (ASR::make_DoLoop_t (al, loc, nullptr , head, doloop_body.p , doloop_body.size ()));
168- }
169- if ( ASRUtils::is_array (ASRUtils::expr_type (op_expr)) ) {
170- ASR::expr_t * idx_lb = PassUtils::get_bound (op_expr, 1 , " lbound" , al);
171- ASR::stmt_t * set_to_one = ASRUtils::STMT (ASR::make_Assignment_t (al, loc, idx_vars_value[0 ], idx_lb, nullptr ));
172- pass_result.push_back (al, set_to_one);
173- }
174- pass_result.push_back (al, doloop);
175- }
176-
177- #define allocate_result_var (op_arg, op_dims_arg, op_n_dims_arg ) if ( ASR::is_a<ASR::Allocatable_t>(*ASRUtils::expr_type (result_var_)) || \
178- ASR::is_a<ASR::Pointer_t>(*ASRUtils::expr_type (result_var_)) ) { \
179- bool is_dimension_empty = false ; \
180- for ( int i = 0 ; i < op_n_dims_arg; i++ ) { \
181- if ( op_dims_arg->m_length == nullptr ) { \
182- is_dimension_empty = true ; \
183- break ; \
184- } \
185- } \
186- Vec<ASR::alloc_arg_t > alloc_args; \
187- alloc_args.reserve (al, 1 ); \
188- if ( !is_dimension_empty ) { \
189- ASR::alloc_arg_t alloc_arg; \
190- alloc_arg.loc = loc; \
191- alloc_arg.m_len_expr = nullptr ; \
192- alloc_arg.m_type = nullptr ; \
193- alloc_arg.m_a = result_var_; \
194- alloc_arg.m_dims = op_dims_arg; \
195- alloc_arg.n_dims = op_n_dims_arg; \
196- alloc_args.push_back (al, alloc_arg); \
197- } else { \
198- Vec<ASR::dimension_t > alloc_dims; \
199- alloc_dims.reserve (al, op_n_dims_arg); \
200- for ( int i = 0 ; i < op_n_dims_arg; i++ ) { \
201- ASR::dimension_t alloc_dim; \
202- alloc_dim.loc = loc; \
203- alloc_dim.m_start = PassUtils::get_bound (op_arg, i + 1 , " lbound" , al); \
204- alloc_dim.m_length = ASRUtils::compute_length_from_start_end (al, alloc_dim.m_start , \
205- PassUtils::get_bound (op_arg, i + 1 , " ubound" , al)); \
206- alloc_dims.push_back (al, alloc_dim); \
207- } \
208- ASR::alloc_arg_t alloc_arg; \
209- alloc_arg.loc = loc; \
210- alloc_arg.m_len_expr = nullptr ; \
211- alloc_arg.m_type = nullptr ; \
212- alloc_arg.m_a = result_var_; \
213- alloc_arg.m_dims = alloc_dims.p ; \
214- alloc_arg.n_dims = alloc_dims.size (); \
215- alloc_args.push_back (al, alloc_arg); \
216- } \
217- pass_result.push_back (al, ASRUtils::STMT (ASR::make_Allocate_t (al, \
218- loc, alloc_args.p , alloc_args.size (), nullptr , nullptr , nullptr ))); \
219- }
220-
221128 void replace_FunctionCall (ASR::FunctionCall_t* x) {
222129 // The following checks if the name of a function actually
223130 // points to a subroutine. If true this would mean that the
0 commit comments