| 423 | } |
| 424 | |
| 425 | llvm::Value* DecimalIR::CallDecimalFunction(const std::string& function_name, |
| 426 | llvm::Type* return_type, |
| 427 | const std::vector<llvm::Value*>& params) { |
| 428 | auto create_call = [&](const std::vector<llvm::Value*>& args) { |
| 429 | auto* call = ir_builder()->CreateCall(module()->getFunction(function_name), args); |
| 430 | internal::CopyZExtAttrs(*call->getCalledFunction(), *call); |
| 431 | return call; |
| 432 | }; |
| 433 | |
| 434 | if (kDecimalIRBuilderFunctions.count(function_name) != 0) { |
| 435 | // this is fn built with the irbuilder. |
| 436 | return create_call(params); |
| 437 | } |
| 438 | |
| 439 | // ppre-compiler fn : disassemble i128 to two i64s and re-assemble. |
| 440 | auto i128 = types()->i128_type(); |
| 441 | auto i64 = types()->i64_type(); |
| 442 | std::vector<llvm::Value*> dis_assembled_args; |
| 443 | for (auto& arg : params) { |
| 444 | if (arg->getType() == i128) { |
| 445 | // split i128 arg into two int64s. |
| 446 | auto split = ValueSplit::MakeFromInt128(this, arg); |
| 447 | dis_assembled_args.push_back(split.high()); |
| 448 | dis_assembled_args.push_back(split.low()); |
| 449 | } else { |
| 450 | dis_assembled_args.push_back(arg); |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | llvm::Value* result = nullptr; |
| 455 | if (return_type == i128) { |
| 456 | // for i128 ret, replace with two int64* args, and join them. |
| 457 | auto block = ir_builder()->GetInsertBlock(); |
| 458 | auto out_high_ptr = new llvm::AllocaInst(i64, 0, "out_hi", block); |
| 459 | auto out_low_ptr = new llvm::AllocaInst(i64, 0, "out_low", block); |
| 460 | dis_assembled_args.push_back(out_high_ptr); |
| 461 | dis_assembled_args.push_back(out_low_ptr); |
| 462 | |
| 463 | // Make call to pre-compiled IR function. |
| 464 | create_call(dis_assembled_args); |
| 465 | |
| 466 | auto out_high = ir_builder()->CreateLoad(i64, out_high_ptr); |
| 467 | auto out_low = ir_builder()->CreateLoad(i64, out_low_ptr); |
| 468 | result = ValueSplit(out_high, out_low).AsInt128(this); |
| 469 | } else { |
| 470 | DCHECK_NE(return_type, types()->void_type()); |
| 471 | |
| 472 | // Make call to pre-compiled IR function. |
| 473 | result = create_call(dis_assembled_args); |
| 474 | } |
| 475 | return result; |
| 476 | } |
| 477 | |
| 478 | Status DecimalIR::AddFunctions(Engine* engine) { |
| 479 | auto decimal_ir = std::make_shared<DecimalIR>(engine); |
no test coverage detected