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