| 1351 | } /* anonymous namespace */ |
| 1352 | |
| 1353 | void SlotDescriptor::CodegenWriteCollectionToSlot( |
| 1354 | const CodegenAnyValReadWriteInfo& read_write_info, |
| 1355 | llvm::Value* slot_ptr, llvm::Value* pool_val, const SlotDescriptor* slot_desc, |
| 1356 | const NonWritableBasicBlock& insert_before) { |
| 1357 | LlvmCodeGen* codegen = read_write_info.codegen(); |
| 1358 | LlvmBuilder* builder = read_write_info.builder(); |
| 1359 | const ColumnType& type = read_write_info.type(); |
| 1360 | DCHECK(type.IsCollectionType()); |
| 1361 | |
| 1362 | // Convert to 'CollectionValue'. |
| 1363 | llvm::Type* raw_type = codegen->GetSlotType(type); |
| 1364 | llvm::Value* coll_value = llvm::Constant::getNullValue(raw_type); |
| 1365 | coll_value = CodegenCollValueSetLen(codegen, builder, coll_value, |
| 1366 | read_write_info.GetPtrAndLen().len); |
| 1367 | if (pool_val != nullptr) { |
| 1368 | llvm::Value* num_tuples = read_write_info.GetPtrAndLen().len; |
| 1369 | DCHECK(slot_desc != nullptr) << "SlotDescriptor needed to calculate the size of " |
| 1370 | << "the collection for copying."; |
| 1371 | // For a 'CollectionValue', 'len' is not the byte size of the whole data but the |
| 1372 | // number of items, so we have to multiply it with the byte size of the item tuple |
| 1373 | // to get the data size. |
| 1374 | int item_tuple_byte_size = slot_desc->children_tuple_descriptor()->byte_size(); |
| 1375 | llvm::Value* byte_len = builder->CreateMul(num_tuples, |
| 1376 | codegen->GetI32Constant(item_tuple_byte_size), "coll_tuple_byte_len"); |
| 1377 | |
| 1378 | // Allocate a 'new_ptr' from 'pool_val' and copy the data from 'read_write_info->ptr'. |
| 1379 | llvm::Value* new_ptr = codegen->CodegenMemPoolAllocate( |
| 1380 | builder, pool_val, byte_len, "new_coll_val_ptr"); |
| 1381 | codegen->CodegenMemcpy(builder, new_ptr, read_write_info.GetPtrAndLen().ptr, |
| 1382 | byte_len); |
| 1383 | coll_value = CodegenCollValueSetPtr(codegen, builder, coll_value, new_ptr); |
| 1384 | |
| 1385 | slot_desc->CodegenWriteCollectionItemsToSlot(codegen, builder, new_ptr, |
| 1386 | read_write_info.GetPtrAndLen().len, pool_val, insert_before); |
| 1387 | } else { |
| 1388 | coll_value = CodegenCollValueSetPtr(codegen, builder, coll_value, |
| 1389 | read_write_info.GetPtrAndLen().ptr); |
| 1390 | } |
| 1391 | builder->CreateStore(coll_value, slot_ptr); |
| 1392 | } |
| 1393 | |
| 1394 | void SlotDescriptor::CodegenWriteStringToSlot( |
| 1395 | const CodegenAnyValReadWriteInfo& read_write_info, |
nothing calls this directly
no test coverage detected