MCPcopy Create free account
hub / github.com/apache/impala / CodegenCallUda

Method CodegenCallUda

be/src/exec/aggregator.cc:482–519  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

480}
481
482Status AggregatorConfig::CodegenCallUda(LlvmCodeGen* codegen, LlvmBuilder* builder,
483 AggFn* agg_fn, llvm::Value* agg_fn_ctx_val, const vector<CodegenAnyVal>& input_vals,
484 const CodegenAnyVal& dst_val, CodegenAnyVal* updated_dst_val) {
485 llvm::Function* uda_fn;
486 RETURN_IF_ERROR(agg_fn->CodegenUpdateOrMergeFunction(codegen, &uda_fn));
487
488 // Set up arguments for call to UDA, which are the FunctionContext*, followed by
489 // pointers to all input values, followed by a pointer to the destination value.
490 vector<llvm::Value*> uda_fn_args;
491 uda_fn_args.push_back(agg_fn_ctx_val);
492
493 // Create pointers to input args to pass to uda_fn. We must use the unlowered type,
494 // e.g. IntVal, because the UDA interface expects the values to be passed as const
495 // references to the classes.
496 DCHECK_EQ(agg_fn->GetNumChildren(), input_vals.size());
497 for (int i = 0; i < input_vals.size(); ++i) {
498 uda_fn_args.push_back(input_vals[i].GetUnloweredPtr("input_unlowered_ptr"));
499 }
500
501 // Create pointer to dst to pass to uda_fn. We must use the unlowered type for the
502 // same reason as above.
503 llvm::Value* dst_lowered_ptr = dst_val.GetLoweredPtr("dst_lowered_ptr");
504 const ColumnType& dst_type = agg_fn->intermediate_type();
505 llvm::Type* dst_unlowered_ptr_type =
506 CodegenAnyVal::GetUnloweredPtrType(codegen, dst_type);
507 llvm::Value* dst_unlowered_ptr = builder->CreateBitCast(
508 dst_lowered_ptr, dst_unlowered_ptr_type, "dst_unlowered_ptr");
509 uda_fn_args.push_back(dst_unlowered_ptr);
510
511 // Call 'uda_fn'
512 builder->CreateCall(uda_fn, uda_fn_args);
513
514 // Convert intermediate 'dst_arg' back to the native type.
515 llvm::Value* anyval_result = builder->CreateLoad(dst_lowered_ptr, "anyval_result");
516
517 *updated_dst_val = CodegenAnyVal(codegen, builder, dst_type, anyval_result);
518 return Status::OK();
519}
520
521// IR codegen for the UpdateTuple loop. This loop is query specific and based on the
522// aggregate functions. The function signature must match the non- codegen'd UpdateTuple

Callers

nothing calls this directly

Calls 9

OKFunction · 0.85
push_backMethod · 0.80
GetNumChildrenMethod · 0.80
GetUnloweredPtrMethod · 0.80
GetLoweredPtrMethod · 0.80
CreateCallMethod · 0.80
CodegenAnyValClass · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected