From f437acd0330e4c13a9afacf2df7ca59475cf0fd3 Mon Sep 17 00:00:00 2001 From: Pindikura Ravindra Date: Wed, 9 Jan 2019 18:43:19 +0530 Subject: [PATCH] ARROW-4209: [Gandiva] Avoid struct return param in IR --- cpp/src/gandiva/decimal_ir.cc | 30 ++++++++----------- .../gandiva/precompiled/decimal_wrapper.cc | 20 +++++-------- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/cpp/src/gandiva/decimal_ir.cc b/cpp/src/gandiva/decimal_ir.cc index 38b35a64b293..d10158a6f048 100644 --- a/cpp/src/gandiva/decimal_ir.cc +++ b/cpp/src/gandiva/decimal_ir.cc @@ -218,27 +218,23 @@ DecimalIR::ValueWithOverflow DecimalIR::AddWithOverflowCheck(const ValueFull& x, // This is pretty complex, so use CPP fns. llvm::Value* DecimalIR::AddLarge(const ValueFull& x, const ValueFull& y, const ValueFull& out) { - std::vector args; - + auto block = ir_builder()->GetInsertBlock(); + auto out_high_ptr = new llvm::AllocaInst(types()->i64_type(), 0, "out_hi", block); + auto out_low_ptr = new llvm::AllocaInst(types()->i64_type(), 0, "out_low", block); auto x_split = ValueSplit::MakeFromInt128(this, x.value()); - args.push_back(x_split.high()); - args.push_back(x_split.low()); - args.push_back(x.precision()); - args.push_back(x.scale()); - auto y_split = ValueSplit::MakeFromInt128(this, y.value()); - args.push_back(y_split.high()); - args.push_back(y_split.low()); - args.push_back(y.precision()); - args.push_back(y.scale()); - args.push_back(out.precision()); - args.push_back(out.scale()); - - auto split = ir_builder()->CreateCall( - module()->getFunction("add_large_decimal128_decimal128"), args); + std::vector args = { + x_split.high(), x_split.low(), x.precision(), x.scale(), + y_split.high(), y_split.low(), y.precision(), y.scale(), + out.precision(), out.scale(), out_high_ptr, out_low_ptr, + }; + ir_builder()->CreateCall(module()->getFunction("add_large_decimal128_decimal128"), + args); - auto sum = ValueSplit::MakeFromStruct(this, split).AsInt128(this); + auto out_high = ir_builder()->CreateLoad(out_high_ptr); + auto out_low = ir_builder()->CreateLoad(out_low_ptr); + auto sum = ValueSplit(out_high, out_low).AsInt128(this); ADD_TRACE_128("AddLarge : sum", sum); return sum; } diff --git a/cpp/src/gandiva/precompiled/decimal_wrapper.cc b/cpp/src/gandiva/precompiled/decimal_wrapper.cc index fdc751f7fe87..011810097122 100644 --- a/cpp/src/gandiva/precompiled/decimal_wrapper.cc +++ b/cpp/src/gandiva/precompiled/decimal_wrapper.cc @@ -20,24 +20,18 @@ extern "C" { -/// TODO : Passing around structs in IR can be fragile due to c-abi compatibility issues. -/// This seems to work for now, but will need to revisit if we hit issues. -struct DecimalSplit { - int64_t high_bits; - uint64_t low_bits; -}; - FORCE_INLINE -DecimalSplit add_large_decimal128_decimal128(int64_t x_high, uint64_t x_low, - int32_t x_precision, int32_t x_scale, - int64_t y_high, uint64_t y_low, - int32_t y_precision, int32_t y_scale, - int32_t out_precision, int32_t out_scale) { +void add_large_decimal128_decimal128(int64_t x_high, uint64_t x_low, int32_t x_precision, + int32_t x_scale, int64_t y_high, uint64_t y_low, + int32_t y_precision, int32_t y_scale, + int32_t out_precision, int32_t out_scale, + int64_t* out_high, uint64_t* out_low) { gandiva::Decimal128Full x(x_high, x_low, x_precision, x_scale); gandiva::Decimal128Full y(y_high, y_low, y_precision, y_scale); arrow::Decimal128 out = gandiva::decimalops::Add(x, y, out_precision, out_scale); - return DecimalSplit{out.high_bits(), out.low_bits()}; + *out_high = out.high_bits(); + *out_low = out.low_bits(); } } // extern "C"