This is an automated email from the ASF dual-hosted git repository.

wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 361285d  ARROW-4209: [Gandiva] Avoid struct return param in IR
361285d is described below

commit 361285d86c345b3943eee8e63d3f9a782e7bf6da
Author: Pindikura Ravindra <[email protected]>
AuthorDate: Wed Jan 9 10:09:48 2019 -0600

    ARROW-4209: [Gandiva] Avoid struct return param in IR
    
    Author: Pindikura Ravindra <[email protected]>
    
    Closes #3356 from pravindra/struct and squashes the following commits:
    
    f437acd0 <Pindikura Ravindra> ARROW-4209:  Avoid struct return param in IR
---
 cpp/src/gandiva/decimal_ir.cc                  | 30 +++++++++++---------------
 cpp/src/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 38b35a6..d10158a 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<llvm::Value*> 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<llvm::Value*> 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 fdc751f..0118100 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"

Reply via email to