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

Method BuildIfElse

cpp/src/gandiva/llvm_generator.cc:1174–1233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1172}
1173
1174LValuePtr LLVMGenerator::Visitor::BuildIfElse(llvm::Value* condition,
1175 std::function<LValuePtr()> then_func,
1176 std::function<LValuePtr()> else_func,
1177 DataTypePtr result_type) {
1178 llvm::IRBuilder<>* builder = ir_builder();
1179 llvm::LLVMContext* context = generator_->context();
1180 LLVMTypes* types = generator_->types();
1181
1182 // Create blocks for the then, else and merge cases.
1183 llvm::BasicBlock* then_bb = llvm::BasicBlock::Create(*context, "then", function_);
1184 llvm::BasicBlock* else_bb = llvm::BasicBlock::Create(*context, "else", function_);
1185 llvm::BasicBlock* merge_bb = llvm::BasicBlock::Create(*context, "merge", function_);
1186
1187 builder->CreateCondBr(condition, then_bb, else_bb);
1188
1189 // Emit the then block.
1190 builder->SetInsertPoint(then_bb);
1191 LValuePtr then_lvalue = then_func();
1192 builder->CreateBr(merge_bb);
1193
1194 // refresh then_bb for phi (could have changed due to code generation of then_vv).
1195 then_bb = builder->GetInsertBlock();
1196
1197 // Emit the else block.
1198 builder->SetInsertPoint(else_bb);
1199 LValuePtr else_lvalue = else_func();
1200 builder->CreateBr(merge_bb);
1201
1202 // refresh else_bb for phi (could have changed due to code generation of else_vv).
1203 else_bb = builder->GetInsertBlock();
1204
1205 // Emit the merge block.
1206 builder->SetInsertPoint(merge_bb);
1207 auto llvm_type = types->IRType(result_type->id());
1208 llvm::PHINode* result_value = builder->CreatePHI(llvm_type, 2, "res_value");
1209 result_value->addIncoming(then_lvalue->data(), then_bb);
1210 result_value->addIncoming(else_lvalue->data(), else_bb);
1211
1212 LValuePtr ret;
1213 switch (result_type->id()) {
1214 case arrow::Type::STRING:
1215 case arrow::Type::BINARY: {
1216 llvm::PHINode* result_length;
1217 result_length = builder->CreatePHI(types->i32_type(), 2, "res_length");
1218 result_length->addIncoming(then_lvalue->length(), then_bb);
1219 result_length->addIncoming(else_lvalue->length(), else_bb);
1220 ret = std::make_shared<LValue>(result_value, result_length);
1221 break;
1222 }
1223
1224 case arrow::Type::DECIMAL:
1225 ret = generator_->BuildDecimalLValue(result_value, result_type);
1226 break;
1227
1228 default:
1229 ret = std::make_shared<LValue>(result_value);
1230 break;
1231 }

Callers

nothing calls this directly

Calls 7

contextMethod · 0.80
typesMethod · 0.80
BuildDecimalLValueMethod · 0.80
ir_builderFunction · 0.70
idMethod · 0.45
dataMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected