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

Method GetCodegendComputeFnImpl

be/src/exprs/kudu-partition-expr.cc:240–321  ·  view source on GitHub ↗

Sample IR: To reproduce, run bin/impala-py.test tests/query_test/test_kudu.py:: TestKuduPartitioning::test_partitions_evenly_distributed define i64 @KuduPartitionExpr(%"class.impala::ScalarExprEvaluator"* %eval, %"class.impala::TupleRow"* %row) #47 { entry: %0 = alloca %"struct.impala::ColumnType" %status_ptr = alloca %"class.impala::Status" %1 = alloca i32 %kudu_partitioner_ptr_ptr = alloca %"

Source from the content-addressed store, hash-verified

238/// ret i64 %ret_val
239/// }
240Status KuduPartitionExpr::GetCodegendComputeFnImpl(
241 LlvmCodeGen* codegen, llvm::Function** fn) {
242 llvm::Function* const kudu_partition_row_fn =
243 codegen->GetFunction(IRFunction::GET_KUDU_PARTITION_ROW, false);
244
245 // Function prototype.
246 llvm::LLVMContext& context = codegen->context();
247 LlvmBuilder builder(context);
248
249 // Parameters of the generated function (ScalarExprEvaluator*, TupleRow*).
250 llvm::Value* args[2];
251 llvm::Function* const function =
252 CreateIrFunctionPrototype("KuduPartitionExpr", codegen, &args);
253
254 // Codegen the initialisation of function context etc.
255 llvm::BasicBlock* const entry_block =
256 llvm::BasicBlock::Create(context, "entry", function);
257 builder.SetInsertPoint(entry_block);
258
259 llvm::Value* kudu_row_ptr = nullptr;
260 llvm::Value* kudu_partitioner_ptr = nullptr;
261 CodegenGetKuduPartialRowAndPartitioner(codegen, &builder, args[0], fn_ctx_idx_,
262 &kudu_row_ptr, &kudu_partitioner_ptr);
263
264 llvm::BasicBlock* current_eval_child_block = llvm::BasicBlock::Create(
265 context, "eval_child", function);
266 builder.CreateBr(current_eval_child_block);
267
268 const int num_children = GetNumChildren();
269 for (int i = 0; i < num_children; ++i) {
270 ScalarExpr* const child_expr = GetChild(i);
271 llvm::Function* child_fn = nullptr;
272 RETURN_IF_ERROR(child_expr->GetCodegendComputeFn(codegen, false, &child_fn));
273
274 builder.SetInsertPoint(current_eval_child_block);
275 const ColumnType& child_type = child_expr->type();
276 CodegenAnyVal child_wrapped = CodegenAnyVal::CreateCallWrapped(
277 codegen, &builder, child_type, child_fn, {args[0], args[1]}, "child");
278
279 CodegenAnyValReadWriteInfo rwi = child_wrapped.ToReadWriteInfo();
280 rwi.entry_block().BranchTo(&builder);
281
282 // Child is null.
283 builder.SetInsertPoint(rwi.null_block());
284 CodegenAnyVal error_ret_val =
285 CodegenAnyVal::GetNonNullVal(codegen, &builder, type(), "error_ret_val");
286 error_ret_val.SetVal(-1);
287 builder.CreateRet(error_ret_val.GetLoweredValue());
288
289 // Child is not null.
290 builder.SetInsertPoint(rwi.non_null_block());
291 const int col = tkudu_partition_expr_.referenced_columns[i];
292 const ColumnDescriptor& col_desc = table_desc_->col_descs()[col];
293 const ColumnType& type = col_desc.type();
294 DCHECK_EQ(child_expr->type().type, type.type);
295
296 llvm::Value* const child_native_val =
297 SlotDescriptor::CodegenStoreNonNullAnyValToNewAlloca(rwi);

Callers

nothing calls this directly

Calls 15

CreateClass · 0.85
OKFunction · 0.85
contextMethod · 0.80
GetCodegendComputeFnMethod · 0.80
ToReadWriteInfoMethod · 0.80
BranchToMethod · 0.80
entry_blockMethod · 0.80
null_blockMethod · 0.80
SetValMethod · 0.80
GetLoweredValueMethod · 0.80

Tested by

no test coverage detected