@@ -883,6 +883,12 @@ namespace LFortran {
883
883
occupancy_ptr);
884
884
885
885
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
+ );
886
892
llvm::Value* set_max_2 = builder->CreateSelect (linear_prob_happened,
887
893
llvm::ConstantInt::get (llvm::Type::getInt8Ty (context), llvm::APInt (8 , 2 )),
888
894
llvm::ConstantInt::get (llvm::Type::getInt8Ty (context), llvm::APInt (8 , 1 )));
@@ -941,7 +947,7 @@ namespace LFortran {
941
947
}
942
948
943
949
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) {
945
951
// Write specialised hash functions for intrinsic types
946
952
// This is to avoid unnecessary calls to C-runtime and do
947
953
// as much as possible in LLVM directly.
@@ -951,11 +957,12 @@ namespace LFortran {
951
957
// We can update it later to do a better hash function
952
958
// which produces lesser collisions.
953
959
954
- return builder->CreateZExtOrTrunc (
960
+ llvm::Value* int_hash = builder->CreateZExtOrTrunc (
955
961
builder->CreateSRem (key,
956
962
builder->CreateZExtOrTrunc (capacity, key->getType ())),
957
963
capacity->getType ()
958
964
);
965
+ return int_hash;
959
966
}
960
967
case ASR::ttypeType::Character: {
961
968
// Polynomial rolling hash function for strings
@@ -1022,6 +1029,18 @@ namespace LFortran {
1022
1029
hash = builder->CreateTrunc (hash, llvm::Type::getInt32Ty (context));
1023
1030
return builder->CreateSRem (hash, capacity);
1024
1031
}
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
+ }
1025
1044
default : {
1026
1045
throw LCompilersException (" Hashing " + ASRUtils::type_to_str_python (key_asr_type) +
1027
1046
" isn't implemented yet." );
0 commit comments