25 bool is_real_str =
false;
26 if (case_ti.is_integer() || case_ti.is_time() || case_ti.is_decimal()) {
28 }
else if (case_ti.is_fp()) {
29 case_llvm_type = case_ti.get_type() ==
kFLOAT
32 }
else if (case_ti.is_string()) {
40 }
else if (case_ti.is_boolean()) {
42 }
else if (case_ti.is_geometry()) {
43 throw std::runtime_error(
44 "Geospatial column projections are currently not supported in conditional "
46 }
else if (case_ti.is_array()) {
47 throw std::runtime_error(
48 "Array column projections are currently not supported in conditional "
51 CHECK(case_llvm_type);
53 CHECK_EQ(else_ti.get_type(), case_ti.get_type());
54 llvm::Value* case_val =
codegenCase(case_expr, case_llvm_type, is_real_str, co);
55 std::vector<llvm::Value*> ret_vals{case_val};
67 const bool is_real_str,
76 std::vector<llvm::Value*> then_lvs;
77 std::vector<llvm::BasicBlock*> then_bbs;
78 const auto end_bb = llvm::BasicBlock::Create(
80 for (
const auto& expr_pair : expr_pair_list) {
82 const auto when_lv =
toBool(
codegen(expr_pair.first.get(),
true, co).front());
89 auto then_bb_lvs =
codegen(expr_pair.second.get(),
true, co);
91 if (then_bb_lvs.size() == 3) {
95 then_lvs.push_back(then_bb_lvs.front());
98 CHECK_EQ(
size_t(1), then_bb_lvs.size());
99 then_lvs.push_back(then_bb_lvs.front());
103 const auto when_bb = llvm::BasicBlock::Create(
109 const auto else_expr = case_expr->get_else_expr();
111 auto else_lvs = codegen(else_expr,
true, co);
112 llvm::Value* else_lv{
nullptr};
113 if (else_lvs.size() == 3) {
114 else_lv = cgen_state_->emitCall(
"string_pack", {else_lvs[1], else_lvs[2]});
116 else_lv = else_lvs.front();
119 auto else_bb = cgen_state_->ir_builder_.GetInsertBlock();
120 cgen_state_->ir_builder_.CreateBr(end_bb);
121 cgen_state_->ir_builder_.SetInsertPoint(end_bb);
123 cgen_state_->ir_builder_.CreatePHI(case_llvm_type, expr_pair_list.size() + 1);
124 CHECK_EQ(then_bbs.size(), then_lvs.size());
125 for (
size_t i = 0; i < then_bbs.size(); ++i) {
126 then_phi->addIncoming(then_lvs[i], then_bbs[i]);
128 then_phi->addIncoming(else_lv, else_bb);
const Expr * get_else_expr() const
llvm::IRBuilder ir_builder_
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
size_t get_bit_width(const SQLTypeInfo &ti)
llvm::LLVMContext & context_
llvm::Function * current_func_
const SQLTypeInfo & get_type_info() const
llvm::Value * emitCall(const std::string &fname, const std::vector< llvm::Value * > &args)
std::vector< llvm::Value * > codegen(const Analyzer::Expr *, const bool fetch_columns, const CompilationOptions &)
llvm::StructType * createStringViewStructType()
llvm::Value * codegenCase(const Analyzer::CaseExpr *, llvm::Type *case_llvm_type, const bool is_real_str, const CompilationOptions &)
llvm::Value * toBool(llvm::Value *)
const std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > & get_expr_pair_list() const