Skip to content

Commit dcbdc62

Browse files
[ASR Pass] Visit Module in array_op pass
1 parent fc69e4a commit dcbdc62

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/libasr/pass/array_op.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,39 @@ class ArrayOpVisitor : public PassUtils::PassVisitor<ArrayOpVisitor>
183183
}
184184
}
185185

186+
void visit_Module(const ASR::Module_t &x) {
187+
if (strcmp(x.m_name, "_global_symbols") == 0) {
188+
// std::vector<std::pair<std::string, ASR::symbol_t*> > replace_vec;
189+
// FIXME: this is a hack, we need to pass in a non-const `x`,
190+
// which requires to generate a TransformVisitor.
191+
ASR::Module_t &xx = const_cast<ASR::Module_t&>(x);
192+
current_scope = xx.m_symtab;
193+
for (auto &item : x.m_symtab->get_scope()) {
194+
if (is_a<ASR::Function_t>(*item.second)) {
195+
ASR::Function_t *s = ASR::down_cast<ASR::Function_t>(item.second);
196+
if (s->m_return_var) {
197+
/*
198+
* A function which returns an array will be converted
199+
* to a subroutine with the destination array as the last
200+
* argument. This helps in avoiding deep copies and the
201+
* destination memory directly gets filled inside the subroutine.
202+
*/
203+
if( PassUtils::is_array(s->m_return_var) ) {
204+
ASR::symbol_t* s_sub = create_subroutine_from_function(s);
205+
// Update the symtab with this function changes
206+
xx.m_symtab->add_symbol(item.first, s_sub);
207+
}
208+
}
209+
}
210+
}
211+
212+
// Now visit everything else
213+
for (auto &item : x.m_symtab->get_scope()) {
214+
this->visit_symbol(*item.second);
215+
}
216+
}
217+
}
218+
186219
void visit_Program(const ASR::Program_t &x) {
187220
std::vector<std::pair<std::string, ASR::symbol_t*> > replace_vec;
188221
// FIXME: this is a hack, we need to pass in a non-const `x`,

0 commit comments

Comments
 (0)