@@ -883,6 +883,12 @@ namespace LFortran {
883883 occupancy_ptr);
884884
885885 llvm::Value* linear_prob_happened = builder->CreateICmpNE (key_hash, pos);
886+ linear_prob_happened = builder->CreateOr (linear_prob_happened,
887+ builder->CreateICmpEQ (
888+ LLVM::CreateLoad (*builder, llvm_utils->create_ptr_gep (key_mask, key_hash)),
889+ llvm::ConstantInt::get (llvm::Type::getInt8Ty (context), llvm::APInt (8 , 2 )
890+ ))
891+ );
886892 llvm::Value* set_max_2 = builder->CreateSelect (linear_prob_happened,
887893 llvm::ConstantInt::get (llvm::Type::getInt8Ty (context), llvm::APInt (8 , 2 )),
888894 llvm::ConstantInt::get (llvm::Type::getInt8Ty (context), llvm::APInt (8 , 1 )));
@@ -941,7 +947,7 @@ namespace LFortran {
941947 }
942948
943949 llvm::Value* LLVMDict::get_key_hash (llvm::Value* capacity, llvm::Value* key,
944- ASR::ttype_t * key_asr_type, llvm::Module& /* module*/ ) {
950+ ASR::ttype_t * key_asr_type, llvm::Module& module ) {
945951 // Write specialised hash functions for intrinsic types
946952 // This is to avoid unnecessary calls to C-runtime and do
947953 // as much as possible in LLVM directly.
@@ -951,11 +957,12 @@ namespace LFortran {
951957 // We can update it later to do a better hash function
952958 // which produces lesser collisions.
953959
954- return builder->CreateZExtOrTrunc (
960+ llvm::Value* int_hash = builder->CreateZExtOrTrunc (
955961 builder->CreateSRem (key,
956962 builder->CreateZExtOrTrunc (capacity, key->getType ())),
957963 capacity->getType ()
958964 );
965+ return int_hash;
959966 }
960967 case ASR::ttypeType::Character: {
961968 // Polynomial rolling hash function for strings
@@ -1022,6 +1029,18 @@ namespace LFortran {
10221029 hash = builder->CreateTrunc (hash, llvm::Type::getInt32Ty (context));
10231030 return builder->CreateSRem (hash, capacity);
10241031 }
1032+ case ASR::ttypeType::Tuple: {
1033+ llvm::Value* tuple_hash = llvm::ConstantInt::get (llvm::Type::getInt32Ty (context), llvm::APInt (32 , 0 ));
1034+ ASR::Tuple_t* asr_tuple = ASR::down_cast<ASR::Tuple_t>(key_asr_type);
1035+ for ( size_t i = 0 ; i < asr_tuple->n_type ; i++ ) {
1036+ llvm::Value* llvm_tuple_i = llvm_utils->tuple_api ->read_item (key, i,
1037+ LLVM::is_llvm_struct (asr_tuple->m_type [i]));
1038+ tuple_hash = builder->CreateAdd (tuple_hash, get_key_hash (capacity, llvm_tuple_i,
1039+ asr_tuple->m_type [i], module ));
1040+ tuple_hash = builder->CreateSRem (tuple_hash, capacity);
1041+ }
1042+ return tuple_hash;
1043+ }
10251044 default : {
10261045 throw LCompilersException (" Hashing " + ASRUtils::type_to_str_python (key_asr_type) +
10271046 " isn't implemented yet." );
0 commit comments