MCPcopy Create free account
hub / github.com/apache/arrow / BuildFunctionCall

Method BuildFunctionCall

cpp/src/gandiva/llvm_generator.cc:1248–1301  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1246}
1247
1248LValuePtr LLVMGenerator::Visitor::BuildFunctionCall(const NativeFunction* func,
1249 DataTypePtr arrow_return_type,
1250 std::vector<llvm::Value*>* params) {
1251 auto types = generator_->types();
1252 auto arrow_return_type_id = arrow_return_type->id();
1253 auto llvm_return_type = types->IRType(arrow_return_type_id);
1254 DecimalIR decimalIR(generator_->engine_.get());
1255
1256 if (arrow_return_type_id == arrow::Type::DECIMAL) {
1257 // For decimal fns, the output precision/scale are passed along as parameters.
1258 //
1259 // convert from this :
1260 // out = add_decimal(v1, p1, s1, v2, p2, s2)
1261 // to:
1262 // out = add_decimal(v1, p1, s1, v2, p2, s2, out_p, out_s)
1263
1264 // Append the out_precision and out_scale
1265 auto ret_lvalue = generator_->BuildDecimalLValue(nullptr, arrow_return_type);
1266 params->push_back(ret_lvalue->precision());
1267 params->push_back(ret_lvalue->scale());
1268
1269 // Make the function call
1270 auto out = decimalIR.CallDecimalFunction(func->pc_name(), llvm_return_type, *params);
1271 ret_lvalue->set_data(out);
1272 return ret_lvalue;
1273 } else {
1274 bool isDecimalFunction = false;
1275 for (auto& arg : *params) {
1276 if (arg->getType() == types->i128_type()) {
1277 isDecimalFunction = true;
1278 }
1279 }
1280 // add extra arg for return length for variable len return types (allocated on stack).
1281 llvm::AllocaInst* result_len_ptr = nullptr;
1282 if (arrow::is_binary_like(arrow_return_type_id)) {
1283 result_len_ptr = new llvm::AllocaInst(generator_->types()->i32_type(), 0,
1284 "result_len", entry_block_);
1285 params->push_back(result_len_ptr);
1286 has_arena_allocs_ = true;
1287 }
1288
1289 // Make the function call
1290 llvm::IRBuilder<>* builder = ir_builder();
1291 auto value =
1292 isDecimalFunction
1293 ? decimalIR.CallDecimalFunction(func->pc_name(), llvm_return_type, *params)
1294 : generator_->AddFunctionCall(func->pc_name(), llvm_return_type, *params);
1295 auto value_len =
1296 (result_len_ptr == nullptr)
1297 ? nullptr
1298 : builder->CreateLoad(result_len_ptr->getAllocatedType(), result_len_ptr);
1299 return std::make_shared<LValue>(value, value_len);
1300 }
1301}
1302
1303std::vector<llvm::Value*> LLVMGenerator::Visitor::BuildParams(
1304 int holder_idx, const ValueValidityPairVector& args, bool with_validity,

Callers

nothing calls this directly

Calls 12

is_binary_likeFunction · 0.85
typesMethod · 0.80
BuildDecimalLValueMethod · 0.80
push_backMethod · 0.80
CallDecimalFunctionMethod · 0.80
AddFunctionCallMethod · 0.80
ir_builderFunction · 0.70
idMethod · 0.45
getMethod · 0.45
precisionMethod · 0.45
scaleMethod · 0.45
getTypeMethod · 0.45

Tested by

no test coverage detected