Skip to content

Backend having ASR logic #3620

@ubaidsk

Description

@ubaidsk

if (ASRUtils::is_integer(*x.m_type)) {
int a_kind = down_cast<ASR::Integer_t>(x.m_type)->m_kind;
int init_value_bits = 8*a_kind;
zero = llvm::ConstantInt::get(context,
llvm::APInt(init_value_bits, 0));
cond = builder->CreateICmpEQ(left_val, zero);
} else if (ASRUtils::is_real(*x.m_type)) {
int a_kind = down_cast<ASR::Real_t>(x.m_type)->m_kind;
int init_value_bits = 8*a_kind;
if (init_value_bits == 32) {
zero = llvm::ConstantFP::get(context,
llvm::APFloat((float)0));
} else {
zero = llvm::ConstantFP::get(context,
llvm::APFloat((double)0));
}
cond = builder->CreateFCmpUEQ(left_val, zero);
} else if (ASRUtils::is_character(*x.m_type)) {
zero = llvm::Constant::getNullValue(character_type);
cond = lfortran_str_cmp(left_val, zero, "_lpython_str_compare_eq");
} else if (ASRUtils::is_logical(*x.m_type)) {
zero = llvm::ConstantInt::get(context,
llvm::APInt(1, 0));
cond = builder->CreateICmpEQ(left_val, zero);
} else {

          I think this operation should not be done at the backend level. A backend should exactly follow what the ASR says. In this case, it should always return a logical result. This logical result can/should later be casted to the desired type.

Originally posted by @Shaikh-Ubaid in lcompilers/lpython#1506 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    asrASR Related changesllvm

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions