@@ -244,6 +244,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
244244 ptr_loads (2 ),
245245 is_assignment_target (false )
246246 {
247+ llvm_utils->tuple_api = tuple_api.get ();
248+ llvm_utils->list_api = list_api.get ();
247249 }
248250
249251 llvm::Value* CreateLoad (llvm::Value *x) {
@@ -1147,7 +1149,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
11471149 this ->visit_expr (*x.m_args [i]);
11481150 llvm::Value* item = tmp;
11491151 llvm::Value* pos = llvm::ConstantInt::get (context, llvm::APInt (32 , i));
1150- list_api->write_item (const_list, pos, item);
1152+ list_api->write_item (const_list, pos, item, list_type-> m_type , * module );
11511153 }
11521154 ptr_loads = ptr_loads_copy;
11531155 tmp = const_list;
@@ -1203,31 +1205,34 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
12031205 }
12041206
12051207 void visit_ListAppend (const ASR::ListAppend_t& x) {
1208+ ASR::List_t* asr_list = ASR::down_cast<ASR::List_t>(ASRUtils::expr_type (x.m_a ));
12061209 uint64_t ptr_loads_copy = ptr_loads;
12071210 ptr_loads = 0 ;
12081211 this ->visit_expr (*x.m_a );
1209- ptr_loads = ptr_loads_copy;
12101212 llvm::Value* plist = tmp;
12111213
1214+ ptr_loads = !LLVM::is_llvm_struct (asr_list->m_type );
12121215 this ->visit_expr_wrapper (x.m_ele , true );
12131216 llvm::Value *item = tmp;
1217+ ptr_loads = ptr_loads_copy;
12141218
1215- ASR::List_t* asr_list = ASR::down_cast<ASR::List_t>(ASRUtils::expr_type (x.m_a ));
1216- std::string type_code = ASRUtils::get_type_code (asr_list->m_type );
1217- list_api->append (plist, item, *module , type_code);
1219+ list_api->append (plist, item, asr_list->m_type , *module );
12181220 }
12191221
12201222 void visit_ListItem (const ASR::ListItem_t& x) {
1223+ ASR::ttype_t * el_type = ASRUtils::get_contained_type (
1224+ ASRUtils::expr_type (x.m_a ));
12211225 uint64_t ptr_loads_copy = ptr_loads;
12221226 ptr_loads = 0 ;
12231227 this ->visit_expr (*x.m_a );
1224- ptr_loads = ptr_loads_copy;
12251228 llvm::Value* plist = tmp;
12261229
1230+ ptr_loads = 1 ;
12271231 this ->visit_expr_wrapper (x.m_pos , true );
1232+ ptr_loads = ptr_loads_copy;
12281233 llvm::Value *pos = tmp;
12291234
1230- tmp = list_api->read_item (plist, pos);
1235+ tmp = list_api->read_item (plist, pos, LLVM::is_llvm_struct (el_type) );
12311236 }
12321237
12331238 void visit_ListLen (const ASR::ListLen_t& x) {
@@ -1244,36 +1249,47 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
12441249 }
12451250
12461251 void visit_ListInsert (const ASR::ListInsert_t& x) {
1252+ ASR::List_t* asr_list = ASR::down_cast<ASR::List_t>(
1253+ ASRUtils::expr_type (x.m_a ));
12471254 uint64_t ptr_loads_copy = ptr_loads;
12481255 ptr_loads = 0 ;
12491256 this ->visit_expr (*x.m_a );
1250- ptr_loads = ptr_loads_copy;
12511257 llvm::Value* plist = tmp;
12521258
1259+ ptr_loads = 1 ;
12531260 this ->visit_expr_wrapper (x.m_pos , true );
12541261 llvm::Value *pos = tmp;
12551262
1263+ ptr_loads = !LLVM::is_llvm_struct (asr_list->m_type );
12561264 this ->visit_expr_wrapper (x.m_ele , true );
12571265 llvm::Value *item = tmp;
1266+ ptr_loads = ptr_loads_copy;
12581267
1259- ASR::List_t* asr_list = ASR::down_cast<ASR::List_t>(
1260- ASRUtils::expr_type (x.m_a ));
1261- std::string type_code = ASRUtils::get_type_code (asr_list->m_type );
1262-
1263- list_api->insert_item (plist, pos, item, *module , type_code);
1268+ list_api->insert_item (plist, pos, item, asr_list->m_type , *module );
12641269 }
12651270
12661271 void visit_ListRemove (const ASR::ListRemove_t& x) {
12671272 ASR::ttype_t * asr_el_type = ASRUtils::get_contained_type (ASRUtils::expr_type (x.m_a ));
12681273 uint64_t ptr_loads_copy = ptr_loads;
12691274 ptr_loads = 0 ;
12701275 this ->visit_expr (*x.m_a );
1271- ptr_loads = ptr_loads_copy;
12721276 llvm::Value* plist = tmp;
12731277
1278+ ptr_loads = !LLVM::is_llvm_struct (asr_el_type);
12741279 this ->visit_expr_wrapper (x.m_ele , true );
1280+ ptr_loads = ptr_loads_copy;
12751281 llvm::Value *item = tmp;
1276- list_api->remove (plist, item, asr_el_type->type , *module );
1282+ list_api->remove (plist, item, asr_el_type, *module );
1283+ }
1284+
1285+ void visit_ListClear (const ASR::ListClear_t& x) {
1286+ uint64_t ptr_loads_copy = ptr_loads;
1287+ ptr_loads = 0 ;
1288+ this ->visit_expr (*x.m_a );
1289+ llvm::Value* plist = tmp;
1290+ ptr_loads = ptr_loads_copy;
1291+
1292+ list_api->list_clear (plist);
12771293 }
12781294
12791295 void visit_TupleLen (const ASR::TupleLen_t& x) {
@@ -1291,7 +1307,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
12911307 this ->visit_expr_wrapper (x.m_pos , true );
12921308 llvm::Value *pos = tmp;
12931309
1294- tmp = tuple_api->read_item (ptuple, pos);
1310+ tmp = tuple_api->read_item (ptuple, pos, LLVM::is_llvm_struct (x. m_type ) );
12951311 }
12961312
12971313 void visit_ArrayItem (const ASR::ArrayItem_t& x) {
@@ -1838,7 +1854,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
18381854 a_kind);
18391855 std::string el_type_code = ASRUtils::get_type_code (asr_list->m_type );
18401856 int32_t type_size = -1 ;
1841- if ( ASR::is_a<ASR::Character_t>(*asr_list->m_type ) ) {
1857+ if ( LLVM::is_llvm_struct (asr_list->m_type ) ||
1858+ ASR::is_a<ASR::Character_t>(*asr_list->m_type ) ||
1859+ ASR::is_a<ASR::Complex_t>(*asr_list->m_type ) ) {
18421860 llvm::DataLayout data_layout (module .get ());
18431861 type_size = data_layout.getTypeAllocSize (el_llvm_type);
18441862 } else {
@@ -2218,8 +2236,17 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
22182236 is_malloc_array_type,
22192237 is_list, m_dims, n_dims,
22202238 a_kind);
2239+ int32_t type_size = -1 ;
2240+ if ( LLVM::is_llvm_struct (asr_list->m_type ) ||
2241+ ASR::is_a<ASR::Character_t>(*asr_list->m_type ) ||
2242+ ASR::is_a<ASR::Complex_t>(*asr_list->m_type ) ) {
2243+ llvm::DataLayout data_layout (module .get ());
2244+ type_size = data_layout.getTypeAllocSize (el_llvm_type);
2245+ } else {
2246+ type_size = a_kind;
2247+ }
22212248 std::string el_type_code = ASRUtils::get_type_code (asr_list->m_type );
2222- type = list_api->get_list_type (el_llvm_type, el_type_code, a_kind )->getPointerTo ();
2249+ type = list_api->get_list_type (el_llvm_type, el_type_code, type_size )->getPointerTo ();
22232250 break ;
22242251 }
22252252 default :
@@ -2943,7 +2970,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
29432970 ASR::List_t* value_asr_list = ASR::down_cast<ASR::List_t>(
29442971 ASRUtils::expr_type (x.m_value ));
29452972 std::string value_type_code = ASRUtils::get_type_code (value_asr_list->m_type );
2946- list_api->list_deepcopy (value_list, target_list, value_type_code, *module );
2973+ list_api->list_deepcopy (value_list, target_list,
2974+ value_asr_list, *module );
29472975 return ;
29482976 } else if ( is_target_tuple && is_value_tuple ) {
29492977 uint64_t ptr_loads_copy = ptr_loads;
@@ -2981,7 +3009,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
29813009 ASR::Tuple_t* value_tuple_type = ASR::down_cast<ASR::Tuple_t>(asr_value_type);
29823010 std::string type_code = ASRUtils::get_type_code (value_tuple_type->m_type ,
29833011 value_tuple_type->n_type );
2984- tuple_api->tuple_deepcopy (value_tuple, target_tuple, type_code);
3012+ tuple_api->tuple_deepcopy (value_tuple, target_tuple,
3013+ value_tuple_type, *module );
29853014 }
29863015 }
29873016 return ;
0 commit comments