| 405 | } |
| 406 | |
| 407 | void CodegenAnyVal::SetVal(llvm::Value* val) { |
| 408 | DCHECK(type_.type != TYPE_STRING) << "Use SetPtr and SetLen for StringVals"; |
| 409 | DCHECK(type_.type != TYPE_VARCHAR) << "Use SetPtr and SetLen for StringVals"; |
| 410 | DCHECK(type_.type != TYPE_CHAR) << "Use SetPtr and SetLen for StringVals"; |
| 411 | DCHECK(type_.type != TYPE_FIXED_UDA_INTERMEDIATE) |
| 412 | << "Use SetPtr and SetLen for FixedUdaIntermediate"; |
| 413 | DCHECK(type_.type != TYPE_TIMESTAMP) |
| 414 | << "Use SetDate and SetTimeOfDay for TimestampVals"; |
| 415 | DCHECK(!type_.IsCollectionType()) << "Use SetPtr and SetLen for CollectionVal"; |
| 416 | DCHECK(!type_.IsStructType()) << "Use SetPtr and SetLen for StructVal"; |
| 417 | switch(type_.type) { |
| 418 | case TYPE_BOOLEAN: |
| 419 | case TYPE_TINYINT: |
| 420 | case TYPE_SMALLINT: |
| 421 | case TYPE_INT: |
| 422 | case TYPE_DATE: { |
| 423 | // Lowered type is an integer. Set the high bytes to 'val'. |
| 424 | int num_bits = type_.GetByteSize() * 8; |
| 425 | value_ = SetHighBits(num_bits, val, value_, name_); |
| 426 | break; |
| 427 | } |
| 428 | case TYPE_FLOAT: |
| 429 | // Same as above, but we must cast 'val' to an integer type. |
| 430 | val = builder_->CreateBitCast(val, codegen_->i32_type()); |
| 431 | value_ = SetHighBits(32, val, value_, name_); |
| 432 | break; |
| 433 | case TYPE_BIGINT: |
| 434 | value_ = builder_->CreateInsertValue(value_, val, 1, name_); |
| 435 | break; |
| 436 | case TYPE_DOUBLE: |
| 437 | #ifdef __aarch64__ |
| 438 | val = builder_->CreateBitCast(val, codegen_->i64_type()); |
| 439 | #endif |
| 440 | // Lowered type is of form { i8, * }. Set the second value to 'val'. |
| 441 | value_ = builder_->CreateInsertValue(value_, val, 1, name_); |
| 442 | break; |
| 443 | case TYPE_DECIMAL: { |
| 444 | // Set the i128 value to 'val'. |
| 445 | // (The {i128} corresponds to the union of the different width int types.) |
| 446 | DCHECK_EQ(val->getType()->getIntegerBitWidth(), type_.GetByteSize() * 8); |
| 447 | val = builder_->CreateSExt(val, llvm::Type::getIntNTy(codegen_->context(), 128)); |
| 448 | #ifdef __aarch64__ |
| 449 | // On aarch64, the Lowered type is of form { {i8}, {i128} }. No padding add. |
| 450 | uint32_t idxs[] = {1, 0}; |
| 451 | #else |
| 452 | // On X86-64, the Lowered type is of the form { {i8}, [15 x i8], {i128} } |
| 453 | uint32_t idxs[] = {2, 0}; |
| 454 | #endif |
| 455 | value_ = builder_->CreateInsertValue(value_, val, idxs, name_); |
| 456 | break; |
| 457 | } |
| 458 | default: |
| 459 | DCHECK(false) << "Unsupported type: " << type_; |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | void CodegenAnyVal::SetVal(bool val) { |
| 464 | DCHECK_EQ(type_.type, TYPE_BOOLEAN); |
no test coverage detected