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

Method BuildFunctionCall

cpp/src/gandiva/llvm_generator.cc:1257–1310  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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