Sample IR output: define i16 @IfExpr(%"class.impala::ScalarExprEvaluator"* %eval, %"class.impala::TupleRow"* %row) #47 { is_condition_null: %condition = call i16 @"impala::Operators::Gt_BigIntVal_BigIntValWrapper"( %"class.impala::ScalarExprEvaluator"* %eval, %"class.impala::TupleRow"* %row) %is_null = trunc i16 %condition to i1 br i1 %is_null, label %return_else, label %eval_condition eval_condi
| 49 | /// ret i16 %else_val |
| 50 | /// } |
| 51 | Status IfExpr::GetCodegendComputeFnImpl(LlvmCodeGen* codegen, llvm::Function** fn) { |
| 52 | constexpr int IF_NUM_CHILDREN = 3; |
| 53 | DCHECK_EQ(IF_NUM_CHILDREN, GetNumChildren()); |
| 54 | |
| 55 | llvm::Function* child_fns[IF_NUM_CHILDREN]; |
| 56 | for (int i = 0; i < IF_NUM_CHILDREN; ++i) { |
| 57 | RETURN_IF_ERROR(GetChild(i)->GetCodegendComputeFn(codegen, false, &child_fns[i])); |
| 58 | } |
| 59 | |
| 60 | llvm::LLVMContext& context = codegen->context(); |
| 61 | LlvmBuilder builder(context); |
| 62 | |
| 63 | llvm::Value* args[2]; |
| 64 | llvm::Function* function = CreateIrFunctionPrototype("IfExpr", codegen, &args); |
| 65 | |
| 66 | llvm::BasicBlock* is_condition_null_block = llvm::BasicBlock::Create( |
| 67 | context, "is_condition_null", function); |
| 68 | llvm::BasicBlock* eval_condition_block = llvm::BasicBlock::Create( |
| 69 | context, "eval_condition", function); |
| 70 | llvm::BasicBlock* return_then_block = llvm::BasicBlock::Create( |
| 71 | context, "return_then", function); |
| 72 | llvm::BasicBlock* return_else_block = llvm::BasicBlock::Create( |
| 73 | context, "return_else", function); |
| 74 | |
| 75 | // Check if the condition is a null value. |
| 76 | builder.SetInsertPoint(is_condition_null_block); |
| 77 | CodegenAnyVal condition = CodegenAnyVal::CreateCallWrapped( |
| 78 | codegen, &builder, children()[0]->type(), child_fns[0], args, "condition"); |
| 79 | builder.CreateCondBr( |
| 80 | condition.GetIsNull(), return_else_block, eval_condition_block); |
| 81 | |
| 82 | // Condition is non-null, branch according to its value. |
| 83 | builder.SetInsertPoint(eval_condition_block); |
| 84 | builder.CreateCondBr(condition.GetVal(), return_then_block, return_else_block); |
| 85 | |
| 86 | // Eval and return then value. |
| 87 | builder.SetInsertPoint(return_then_block); |
| 88 | llvm::Value* then_val = |
| 89 | CodegenAnyVal::CreateCall(codegen, &builder, child_fns[1], args, "then_val"); |
| 90 | builder.CreateRet(then_val); |
| 91 | |
| 92 | // Eval and return else value. |
| 93 | builder.SetInsertPoint(return_else_block); |
| 94 | llvm::Value* else_val = |
| 95 | CodegenAnyVal::CreateCall(codegen, &builder, child_fns[2], args, "else_val"); |
| 96 | builder.CreateRet(else_val); |
| 97 | |
| 98 | *fn = codegen->FinalizeFunction(function); |
| 99 | if (UNLIKELY(*fn == nullptr)) return Status(TErrorCode::IR_VERIFY_FAILED, "IfExpr"); |
| 100 | return Status::OK(); |
| 101 | } |
| 102 | |
| 103 | /// Sample IR output for three columns: |
| 104 | /// define i64 @CoalesceExpr(%"class.impala::ScalarExprEvaluator"* %eval, |
nothing calls this directly
no test coverage detected