@@ -236,7 +236,10 @@ namespace LFortran {
236
236
switch ( asr_type->type ) {
237
237
case ASR::ttypeType::Integer: {
238
238
return builder->CreateICmpEQ (left, right);
239
- };
239
+ }
240
+ case ASR::ttypeType::Logical: {
241
+ return builder->CreateICmpEQ (left, right);
242
+ }
240
243
case ASR::ttypeType::Real: {
241
244
return builder->CreateFCmpOEQ (left, right);
242
245
}
@@ -291,6 +294,11 @@ namespace LFortran {
291
294
return tuple_api->check_tuple_equality (left, right, tuple_type, context,
292
295
builder, module );
293
296
}
297
+ case ASR::ttypeType::List: {
298
+ ASR::List_t* list_type = ASR::down_cast<ASR::List_t>(asr_type);
299
+ return list_api->check_list_equality (left, right, list_type->m_type ,
300
+ context, builder, module );
301
+ }
294
302
default : {
295
303
throw LCompilersException (" LLVMUtils::is_equal_by_value isn't implemented for " +
296
304
ASRUtils::type_to_str_python (asr_type));
@@ -2558,6 +2566,65 @@ namespace LFortran {
2558
2566
LLVM::lfortran_free (context, module , *builder, data);
2559
2567
}
2560
2568
2569
+ llvm::Value* LLVMList::check_list_equality (llvm::Value* l1, llvm::Value* l2,
2570
+ ASR::ttype_t * item_type,
2571
+ llvm::LLVMContext& context,
2572
+ llvm::IRBuilder<>* builder,
2573
+ llvm::Module& module ) {
2574
+ llvm::AllocaInst *is_equal = builder->CreateAlloca (llvm::Type::getInt1Ty (context), nullptr );
2575
+ LLVM::CreateStore (*builder, llvm::ConstantInt::get (context, llvm::APInt (1 , 1 )), is_equal);
2576
+ llvm::Value *a_len = llvm_utils->list_api ->len (l1);
2577
+ llvm::Value *b_len = llvm_utils->list_api ->len (l2);
2578
+ llvm::Value *cond = builder->CreateICmpEQ (a_len, b_len);
2579
+ llvm::Function *fn = builder->GetInsertBlock ()->getParent ();
2580
+ llvm::BasicBlock *thenBB = llvm::BasicBlock::Create (context, " then" , fn);
2581
+ llvm::BasicBlock *elseBB = llvm::BasicBlock::Create (context, " else" );
2582
+ llvm::BasicBlock *mergeBB = llvm::BasicBlock::Create (context, " ifcont" );
2583
+ builder->CreateCondBr (cond, thenBB, elseBB);
2584
+ builder->SetInsertPoint (thenBB);
2585
+ llvm::AllocaInst *idx = builder->CreateAlloca (llvm::Type::getInt32Ty (context), nullptr );
2586
+ LLVM::CreateStore (*builder, llvm::ConstantInt::get (
2587
+ context, llvm::APInt (32 , 0 )), idx);
2588
+ llvm::BasicBlock *loophead = llvm::BasicBlock::Create (context, " loop.head" );
2589
+ llvm::BasicBlock *loopbody = llvm::BasicBlock::Create (context, " loop.body" );
2590
+ llvm::BasicBlock *loopend = llvm::BasicBlock::Create (context, " loop.end" );
2591
+
2592
+ // head
2593
+ llvm_utils->start_new_block (loophead);
2594
+ {
2595
+ llvm::Value* i = LLVM::CreateLoad (*builder, idx);
2596
+ llvm::Value* cnd = builder->CreateICmpSLT (i, a_len);
2597
+ builder->CreateCondBr (cnd, loopbody, loopend);
2598
+ }
2599
+
2600
+ // body
2601
+ llvm_utils->start_new_block (loopbody);
2602
+ {
2603
+ llvm::Value* i = LLVM::CreateLoad (*builder, idx);
2604
+ llvm::Value* left_arg = llvm_utils->list_api ->read_item (l1, i,
2605
+ false , module , LLVM::is_llvm_struct (item_type));
2606
+ llvm::Value* right_arg = llvm_utils->list_api ->read_item (l2, i,
2607
+ false , module , LLVM::is_llvm_struct (item_type));
2608
+ llvm::Value* res = llvm_utils->is_equal_by_value (left_arg, right_arg, module ,
2609
+ item_type);
2610
+ res = builder->CreateAnd (LLVM::CreateLoad (*builder, is_equal), res);
2611
+ LLVM::CreateStore (*builder, res, is_equal);
2612
+ i = builder->CreateAdd (i, llvm::ConstantInt::get (llvm::Type::getInt32Ty (context),
2613
+ llvm::APInt (32 , 1 )));
2614
+ LLVM::CreateStore (*builder, i, idx);
2615
+ }
2616
+
2617
+ builder->CreateBr (loophead);
2618
+
2619
+ // end
2620
+ llvm_utils->start_new_block (loopend);
2621
+
2622
+ builder->CreateBr (mergeBB);
2623
+ llvm_utils->start_new_block (elseBB);
2624
+ LLVM::CreateStore (*builder, llvm::ConstantInt::get (context, llvm::APInt (1 , 0 )), is_equal);
2625
+ llvm_utils->start_new_block (mergeBB);
2626
+ return LLVM::CreateLoad (*builder, is_equal);
2627
+ }
2561
2628
2562
2629
LLVMTuple::LLVMTuple (llvm::LLVMContext& context_,
2563
2630
LLVMUtils* llvm_utils_,
@@ -2619,8 +2686,10 @@ namespace LFortran {
2619
2686
llvm::Module& module ) {
2620
2687
llvm::Value* is_equal = llvm::ConstantInt::get (context, llvm::APInt (1 , 1 ));
2621
2688
for ( size_t i = 0 ; i < tuple_type->n_type ; i++ ) {
2622
- llvm::Value* t1i = llvm_utils->tuple_api ->read_item (t1, i);
2623
- llvm::Value* t2i = llvm_utils->tuple_api ->read_item (t2, i);
2689
+ llvm::Value* t1i = llvm_utils->tuple_api ->read_item (t1, i, LLVM::is_llvm_struct (
2690
+ tuple_type->m_type [i]));
2691
+ llvm::Value* t2i = llvm_utils->tuple_api ->read_item (t2, i, LLVM::is_llvm_struct (
2692
+ tuple_type->m_type [i]));
2624
2693
llvm::Value* is_t1_eq_t2 = llvm_utils->is_equal_by_value (t1i, t2i, module ,
2625
2694
tuple_type->m_type [i]);
2626
2695
is_equal = builder->CreateAnd (is_equal, is_t1_eq_t2);
0 commit comments