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

Rename IntrinsicFunction to IntrinsicScalarFunction #2273

Merged
merged 1 commit into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/libasr/ASR.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ expr
| NamedExpr(expr target, expr value, ttype type)
| FunctionCall(symbol name, symbol? original_name, call_arg* args,
ttype type, expr? value, expr? dt)
| IntrinsicFunction(int intrinsic_id, expr* args, int overload_id,
| IntrinsicScalarFunction(int intrinsic_id, expr* args, int overload_id,
ttype? type, expr? value)
| IntrinsicArrayFunction(int arr_intrinsic_id, expr* args, int overload_id,
ttype? type, expr? value)
Expand Down
2 changes: 1 addition & 1 deletion src/libasr/asr_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ ASR::asr_t* make_Cast_t_value(Allocator &al, const Location &a_loc,
args.reserve(al, 1);
args.push_back(al, a_arg);
LCompilers::ASRUtils::create_intrinsic_function create_function =
LCompilers::ASRUtils::IntrinsicFunctionRegistry::get_create_function("SymbolicInteger");
LCompilers::ASRUtils::IntrinsicScalarFunctionRegistry::get_create_function("SymbolicInteger");
value = ASR::down_cast<ASR::expr_t>(create_function(al, a_loc, args,
[](const std::string&, const Location&) {
}));
Expand Down
4 changes: 2 additions & 2 deletions src/libasr/asr_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4167,7 +4167,7 @@ static inline ASR::expr_t* cast_to_descriptor(Allocator& al, ASR::expr_t* arg) {
return arg;
}

static inline ASR::asr_t* make_IntrinsicFunction_t_util(
static inline ASR::asr_t* make_IntrinsicScalarFunction_t_util(
Allocator &al, const Location &a_loc, int64_t a_intrinsic_id,
ASR::expr_t** a_args, size_t n_args, int64_t a_overload_id,
ASR::ttype_t* a_type, ASR::expr_t* a_value) {
Expand All @@ -4186,7 +4186,7 @@ static inline ASR::asr_t* make_IntrinsicFunction_t_util(
}
}

return ASR::make_IntrinsicFunction_t(al, a_loc, a_intrinsic_id,
return ASR::make_IntrinsicScalarFunction_t(al, a_loc, a_intrinsic_id,
a_args, n_args, a_overload_id, a_type, a_value);
}

Expand Down
8 changes: 4 additions & 4 deletions src/libasr/asr_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,16 +974,16 @@ class VerifyVisitor : public BaseWalkVisitor<VerifyVisitor>
}
}

void visit_IntrinsicFunction(const ASR::IntrinsicFunction_t& x) {
void visit_IntrinsicScalarFunction(const ASR::IntrinsicScalarFunction_t& x) {
if( !check_external ) {
BaseWalkVisitor<VerifyVisitor>::visit_IntrinsicFunction(x);
BaseWalkVisitor<VerifyVisitor>::visit_IntrinsicScalarFunction(x);
return ;
}
ASRUtils::verify_function verify_ = ASRUtils::IntrinsicFunctionRegistry
ASRUtils::verify_function verify_ = ASRUtils::IntrinsicScalarFunctionRegistry
::get_verify_function(x.m_intrinsic_id);
LCOMPILERS_ASSERT(verify_ != nullptr);
verify_(x, diagnostics);
BaseWalkVisitor<VerifyVisitor>::visit_IntrinsicFunction(x);
BaseWalkVisitor<VerifyVisitor>::visit_IntrinsicScalarFunction(x);
}

void visit_IntrinsicArrayFunction(const ASR::IntrinsicArrayFunction_t& x) {
Expand Down
10 changes: 5 additions & 5 deletions src/libasr/codegen/asr_to_c_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2739,12 +2739,12 @@ PyMODINIT_FUNC PyInit_lpython_module_)" + fn_name + R"((void) {
src = indent + sym_name + "(" + construct_call_args(x.n_args, x.m_args) + ");\n";
}

#define SET_INTRINSIC_NAME(X, func_name) \
case (static_cast<int64_t>(ASRUtils::IntrinsicFunctions::X)) : { \
out += func_name; break; \
#define SET_INTRINSIC_NAME(X, func_name) \
case (static_cast<int64_t>(ASRUtils::IntrinsicScalarFunctions::X)) : { \
out += func_name; break; \
}

void visit_IntrinsicFunction(const ASR::IntrinsicFunction_t &x) {
void visit_IntrinsicScalarFunction(const ASR::IntrinsicScalarFunction_t &x) {
std::string out;
std::string indent(4, ' ');
switch (x.m_intrinsic_id) {
Expand All @@ -2762,7 +2762,7 @@ PyMODINIT_FUNC PyInit_lpython_module_)" + fn_name + R"((void) {
SET_INTRINSIC_NAME(Exp2, "exp2");
SET_INTRINSIC_NAME(Expm1, "expm1");
default : {
throw LCompilersException("IntrinsicFunction: `"
throw LCompilersException("IntrinsicScalarFunction: `"
+ ASRUtils::get_intrinsic_name(x.m_intrinsic_id)
+ "` is not implemented");
}
Expand Down
9 changes: 2 additions & 7 deletions src/libasr/codegen/asr_to_julia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1893,12 +1893,7 @@ class ASRToJuliaVisitor : public ASR::BaseVisitor<ASRToJuliaVisitor>
src = out;
}

#define SET_INTRINSIC_NAME(X, func_name) \
case (static_cast<int64_t>(ASRUtils::IntrinsicFunctions::X)) : { \
out += func_name; break; \
}

void visit_IntrinsicFunction(const ASR::IntrinsicFunction_t &x) {
void visit_IntrinsicScalarFunction(const ASR::IntrinsicScalarFunction_t &x) {
std::string out;
LCOMPILERS_ASSERT(x.n_args == 1);
visit_expr(*x.m_args[0]);
Expand All @@ -1917,7 +1912,7 @@ class ASRToJuliaVisitor : public ASR::BaseVisitor<ASRToJuliaVisitor>
SET_INTRINSIC_NAME(Exp2, "exp2");
SET_INTRINSIC_NAME(Expm1, "expm1");
default : {
throw LCompilersException("IntrinsicFunction: `"
throw LCompilersException("IntrinsicScalarFunction: `"
+ ASRUtils::get_intrinsic_name(x.m_intrinsic_id)
+ "` is not implemented");
}
Expand Down
28 changes: 14 additions & 14 deletions src/libasr/codegen/asr_to_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1779,9 +1779,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
llvm_utils->set_api->remove_item(pset, el, *module, asr_el_type);
}

void visit_IntrinsicFunction(const ASR::IntrinsicFunction_t& x) {
switch (static_cast<ASRUtils::IntrinsicFunctions>(x.m_intrinsic_id)) {
case ASRUtils::IntrinsicFunctions::ListIndex: {
void visit_IntrinsicScalarFunction(const ASR::IntrinsicScalarFunction_t& x) {
switch (static_cast<ASRUtils::IntrinsicScalarFunctions>(x.m_intrinsic_id)) {
case ASRUtils::IntrinsicScalarFunctions::ListIndex: {
ASR::expr_t* m_arg = x.m_args[0];
ASR::expr_t* m_ele = x.m_args[1];
ASR::expr_t* m_start = nullptr;
Expand All @@ -1807,11 +1807,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
generate_ListIndex(m_arg, m_ele, m_start, m_end);
break ;
}
case ASRUtils::IntrinsicFunctions::ListReverse: {
case ASRUtils::IntrinsicScalarFunctions::ListReverse: {
generate_ListReverse(x.m_args[0]);
break;
}
case ASRUtils::IntrinsicFunctions::ListPop: {
case ASRUtils::IntrinsicScalarFunctions::ListPop: {
switch(x.m_overload_id) {
case 0:
generate_ListPop_0(x.m_args[0]);
Expand All @@ -1822,27 +1822,27 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
}
break;
}
case ASRUtils::IntrinsicFunctions::Reserve: {
case ASRUtils::IntrinsicScalarFunctions::Reserve: {
generate_Reserve(x.m_args[0], x.m_args[1]);
break;
}
case ASRUtils::IntrinsicFunctions::DictKeys: {
case ASRUtils::IntrinsicScalarFunctions::DictKeys: {
generate_DictElems(x.m_args[0], 0);
break;
}
case ASRUtils::IntrinsicFunctions::DictValues: {
case ASRUtils::IntrinsicScalarFunctions::DictValues: {
generate_DictElems(x.m_args[0], 1);
break;
}
case ASRUtils::IntrinsicFunctions::SetAdd: {
case ASRUtils::IntrinsicScalarFunctions::SetAdd: {
generate_SetAdd(x.m_args[0], x.m_args[1]);
break;
}
case ASRUtils::IntrinsicFunctions::SetRemove: {
case ASRUtils::IntrinsicScalarFunctions::SetRemove: {
generate_SetRemove(x.m_args[0], x.m_args[1]);
break;
}
case ASRUtils::IntrinsicFunctions::Exp: {
case ASRUtils::IntrinsicScalarFunctions::Exp: {
switch (x.m_overload_id) {
case 0: {
ASR::expr_t* m_arg = x.m_args[0];
Expand All @@ -1856,7 +1856,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
}
break ;
}
case ASRUtils::IntrinsicFunctions::Exp2: {
case ASRUtils::IntrinsicScalarFunctions::Exp2: {
switch (x.m_overload_id) {
case 0: {
ASR::expr_t* m_arg = x.m_args[0];
Expand All @@ -1870,7 +1870,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
}
break ;
}
case ASRUtils::IntrinsicFunctions::Expm1: {
case ASRUtils::IntrinsicScalarFunctions::Expm1: {
switch (x.m_overload_id) {
case 0: {
ASR::expr_t* m_arg = x.m_args[0];
Expand All @@ -1885,7 +1885,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
break ;
}
default: {
throw CodeGenError( ASRUtils::IntrinsicFunctionRegistry::
throw CodeGenError( ASRUtils::IntrinsicScalarFunctionRegistry::
get_intrinsic_function_name(x.m_intrinsic_id) +
" is not implemented by LLVM backend.", x.base.base.loc);
}
Expand Down
4 changes: 2 additions & 2 deletions src/libasr/pass/array_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,8 +1014,8 @@ class ReplaceArrayOp: public ASR::BaseExprReplacer<ReplaceArrayOp> {
result_var = nullptr;
}

void replace_IntrinsicFunction(ASR::IntrinsicFunction_t* x) {
if(!ASRUtils::IntrinsicFunctionRegistry::is_elemental(x->m_intrinsic_id)) {
void replace_IntrinsicScalarFunction(ASR::IntrinsicScalarFunction_t* x) {
if(!ASRUtils::IntrinsicScalarFunctionRegistry::is_elemental(x->m_intrinsic_id)) {
return ;
}
replace_intrinsic_function(x);
Expand Down
18 changes: 9 additions & 9 deletions src/libasr/pass/intrinsic_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ in the backend.

*/

class ReplaceIntrinsicFunction: public ASR::BaseExprReplacer<ReplaceIntrinsicFunction> {
class ReplaceIntrinsicFunctions: public ASR::BaseExprReplacer<ReplaceIntrinsicFunctions> {

private:

Expand All @@ -35,14 +35,14 @@ class ReplaceIntrinsicFunction: public ASR::BaseExprReplacer<ReplaceIntrinsicFun

public:

ReplaceIntrinsicFunction(Allocator& al_, SymbolTable* global_scope_,
ReplaceIntrinsicFunctions(Allocator& al_, SymbolTable* global_scope_,
std::map<ASR::symbol_t*, ASRUtils::IntrinsicArrayFunctions>& func2intrinsicid_) :
al(al_), global_scope(global_scope_), func2intrinsicid(func2intrinsicid_) {}


void replace_IntrinsicFunction(ASR::IntrinsicFunction_t* x) {
void replace_IntrinsicScalarFunction(ASR::IntrinsicScalarFunction_t* x) {
Vec<ASR::call_arg_t> new_args;
// Replace any IntrinsicFunctions in the argument first:
// Replace any IntrinsicScalarFunctions in the argument first:
{
new_args.reserve(al, x->n_args);
for( size_t i = 0; i < x->n_args; i++ ) {
Expand All @@ -63,7 +63,7 @@ class ReplaceIntrinsicFunction: public ASR::BaseExprReplacer<ReplaceIntrinsicFun
// We could maintain a mapping of type -> id and look it up.

ASRUtils::impl_function instantiate_function =
ASRUtils::IntrinsicFunctionRegistry::get_instantiate_function(x->m_intrinsic_id);
ASRUtils::IntrinsicScalarFunctionRegistry::get_instantiate_function(x->m_intrinsic_id);
if( instantiate_function == nullptr ) {
return ;
}
Expand Down Expand Up @@ -137,15 +137,15 @@ The following visitor calls the above replacer i.e., ReplaceFunctionCalls
on expressions present in ASR so that FunctionCall get replaced everywhere
and we don't end up with false positives.
*/
class ReplaceIntrinsicFunctionVisitor : public ASR::CallReplacerOnExpressionsVisitor<ReplaceIntrinsicFunctionVisitor>
class ReplaceIntrinsicFunctionsVisitor : public ASR::CallReplacerOnExpressionsVisitor<ReplaceIntrinsicFunctionsVisitor>
{
private:

ReplaceIntrinsicFunction replacer;
ReplaceIntrinsicFunctions replacer;

public:

ReplaceIntrinsicFunctionVisitor(Allocator& al_, SymbolTable* global_scope_,
ReplaceIntrinsicFunctionsVisitor(Allocator& al_, SymbolTable* global_scope_,
std::map<ASR::symbol_t*, ASRUtils::IntrinsicArrayFunctions>& func2intrinsicid_) :
replacer(al_, global_scope_, func2intrinsicid_) {}

Expand Down Expand Up @@ -377,7 +377,7 @@ class ReplaceFunctionCallReturningArrayVisitor : public ASR::CallReplacerOnExpre
void pass_replace_intrinsic_function(Allocator &al, ASR::TranslationUnit_t &unit,
const LCompilers::PassOptions& /*pass_options*/) {
std::map<ASR::symbol_t*, ASRUtils::IntrinsicArrayFunctions> func2intrinsicid;
ReplaceIntrinsicFunctionVisitor v(al, unit.m_global_scope, func2intrinsicid);
ReplaceIntrinsicFunctionsVisitor v(al, unit.m_global_scope, func2intrinsicid);
v.visit_TranslationUnit(unit);
ReplaceFunctionCallReturningArrayVisitor u(al, func2intrinsicid);
u.visit_TranslationUnit(unit);
Expand Down
Loading