Skip to content
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

Do not load CPtr #2440

Closed
wants to merge 2 commits into from
Closed
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
26 changes: 25 additions & 1 deletion src/libasr/codegen/asr_to_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1245,8 +1245,32 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
llvm::Value* const_list = builder->CreateAlloca(const_list_type, nullptr, "const_list");
list_api->list_init(type_code, const_list, *module, x.n_args, x.n_args);
int64_t ptr_loads_copy = ptr_loads;
ptr_loads = 1;
for( size_t i = 0; i < x.n_args; i++ ) {
if (ASR::is_a<ASR::CPtr_t>(*ASRUtils::expr_type(x.m_args[i]))) {
bool is_argument = false;
ASR::expr_t *var = x.m_args[i];
if (is_a<ASR::Var_t>(*var)) {
ASR::symbol_t *var_sym = ASR::down_cast<ASR::Var_t>(var)
->m_v;
if (is_a<ASR::Variable_t>(*var_sym)) {
ASR::Variable_t *v = down_cast<ASR::Variable_t>(var_sym);
if (v->m_intent == intent_local ||
v->m_intent == intent_return_var ||
!v->m_intent) {
is_argument = false;
} else {
is_argument = true;
}
}
}
Comment on lines +1250 to +1265
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole code here should be refactored into a function that should be put into ASRUtils. We might already have a function for this.

if (is_argument) {
ptr_loads = 0;
} else {
ptr_loads = 1;
}
} else {
ptr_loads = 1;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the issue here is that if x.m_args[i] is an argument, then we want ptr_loads=0, but if it is pi (as in the other example), where it is a local (or global) variable, we want ptr_loads = 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to keep ptr_loads = 1; for all other types as well as for CPtr if it is a local/global variable. Only if it is CPtr and a function argument, then we want to use ptr_loads = 0;.

this->visit_expr(*x.m_args[i]);
llvm::Value* item = tmp;
llvm::Value* pos = llvm::ConstantInt::get(context, llvm::APInt(32, i));
Expand Down
Loading