| 380 | } |
| 381 | |
| 382 | Status DecimalIR::BuildCompare(const std::string& function_name, |
| 383 | llvm::ICmpInst::Predicate cmp_instruction) { |
| 384 | // Create fn prototype : |
| 385 | // bool |
| 386 | // function_name(int128_t x_value, int32_t x_precision, int32_t x_scale, |
| 387 | // int128_t y_value, int32_t y_precision, int32_t y_scale) |
| 388 | |
| 389 | auto i32 = types()->i32_type(); |
| 390 | auto i128 = types()->i128_type(); |
| 391 | auto function = BuildFunction(function_name, types()->i1_type(), |
| 392 | { |
| 393 | {"x_value", i128}, |
| 394 | {"x_precision", i32}, |
| 395 | {"x_scale", i32}, |
| 396 | {"y_value", i128}, |
| 397 | {"y_precision", i32}, |
| 398 | {"y_scale", i32}, |
| 399 | }); |
| 400 | |
| 401 | auto arg_iter = function->arg_begin(); |
| 402 | ValueFull x(&arg_iter[0], &arg_iter[1], &arg_iter[2]); |
| 403 | ValueFull y(&arg_iter[3], &arg_iter[4], &arg_iter[5]); |
| 404 | |
| 405 | auto entry = llvm::BasicBlock::Create(*context(), "entry", function); |
| 406 | ir_builder()->SetInsertPoint(entry); |
| 407 | |
| 408 | // Make call to pre-compiled IR function. |
| 409 | auto x_split = ValueSplit::MakeFromInt128(this, x.value()); |
| 410 | auto y_split = ValueSplit::MakeFromInt128(this, y.value()); |
| 411 | |
| 412 | std::vector<llvm::Value*> args = { |
| 413 | x_split.high(), x_split.low(), x.precision(), x.scale(), |
| 414 | y_split.high(), y_split.low(), y.precision(), y.scale(), |
| 415 | }; |
| 416 | auto cmp_value = ir_builder()->CreateCall( |
| 417 | module()->getFunction("compare_decimal128_decimal128_internal"), args); |
| 418 | auto result = |
| 419 | ir_builder()->CreateICmp(cmp_instruction, cmp_value, types()->i32_constant(0)); |
| 420 | ir_builder()->CreateRet(result); |
| 421 | return Status::OK(); |
| 422 | } |
| 423 | |
| 424 | llvm::Value* DecimalIR::CallDecimalFunction(const std::string& function_name, |
| 425 | llvm::Type* return_type, |