19 #include <llvm/IR/InstIterator.h>
20 #include <llvm/IR/Verifier.h>
21 #include <llvm/Support/raw_os_ostream.h>
22 #include <llvm/Transforms/Utils/BasicBlockUtils.h>
24 #include <boost/algorithm/string.hpp>
32 const auto pi8_type = llvm::PointerType::get(
get_int_type(8, ctx), 0);
33 const auto ppi8_type = llvm::PointerType::get(pi8_type, 0);
34 const auto pi64_type = llvm::PointerType::get(
get_int_type(64, ctx), 0);
35 const auto ppi64_type = llvm::PointerType::get(pi64_type, 0);
38 const auto func_type = llvm::FunctionType::get(
40 {pi8_type, ppi8_type, pi64_type, ppi8_type, ppi64_type, ppi8_type, pi64_type},
43 auto func = llvm::Function::Create(func_type,
44 llvm::Function::ExternalLinkage,
45 "call_table_function",
47 auto arg_it = func->arg_begin();
48 const auto mgr_arg = &*arg_it;
49 mgr_arg->setName(
"mgr_ptr");
50 const auto input_cols_arg = &*(++arg_it);
51 input_cols_arg->setName(
"input_col_buffers");
52 const auto input_row_counts = &*(++arg_it);
53 input_row_counts->setName(
"input_row_counts");
54 const auto input_str_dict_proxies = &*(++arg_it);
55 input_str_dict_proxies->setName(
"input_str_dict_proxies");
56 const auto output_buffers = &*(++arg_it);
57 output_buffers->setName(
"output_buffers");
58 const auto output_str_dict_proxies = &*(++arg_it);
59 output_str_dict_proxies->setName(
"output_str_dict_proxies");
60 const auto output_row_count = &*(++arg_it);
61 output_row_count->setName(
"output_row_count");
66 llvm::LLVMContext& ctx) {
67 if (elem_ti.
is_fp()) {
82 LOG(
FATAL) <<
"get_llvm_type_from_sql_column_type: not implemented for "
87 std::tuple<llvm::Value*, llvm::Value*>
alloc_column(std::string col_name,
90 llvm::Value* data_ptr,
91 llvm::Value* data_size,
92 llvm::Value* data_str_dict_proxy_ptr,
93 llvm::LLVMContext& ctx,
94 llvm::IRBuilder<>& ir_builder) {
110 const bool is_text_encoding_dict_type =
114 llvm::StructType* col_struct_type =
115 is_text_encoding_dict_type
116 ? llvm::StructType::get(
120 llvm::Type::getInt64Ty(ctx),
121 llvm::Type::getInt8PtrTy(ctx)
123 : llvm::StructType::get(ctx,
126 llvm::Type::getInt64Ty(ctx)
128 auto col = ir_builder.CreateAlloca(col_struct_type);
129 col->setName(col_name);
130 auto col_ptr_ptr = ir_builder.CreateStructGEP(col_struct_type, col, 0);
131 auto col_sz_ptr = ir_builder.CreateStructGEP(col_struct_type, col, 1);
132 auto col_str_dict_ptr = is_text_encoding_dict_type
133 ? ir_builder.CreateStructGEP(col_struct_type, col, 2)
135 col_ptr_ptr->setName(col_name +
".ptr");
136 col_sz_ptr->setName(col_name +
".sz");
137 if (is_text_encoding_dict_type) {
138 col_str_dict_ptr->setName(col_name +
".string_dict_proxy");
141 if (data_ptr !=
nullptr) {
142 if (data_ptr->getType() == data_ptr_llvm_type->getPointerElementType()) {
143 ir_builder.CreateStore(data_ptr, col_ptr_ptr);
145 auto tmp = ir_builder.CreateBitCast(data_ptr, data_ptr_llvm_type);
146 ir_builder.CreateStore(tmp, col_ptr_ptr);
149 ir_builder.CreateStore(llvm::Constant::getNullValue(data_ptr_llvm_type), col_ptr_ptr);
151 llvm::Value* size_val =
nullptr;
152 if (data_size !=
nullptr) {
153 auto data_size_type = data_size->getType();
154 if (data_size_type->isPointerTy()) {
155 CHECK(data_size_type->getPointerElementType()->isIntegerTy(64));
157 ir_builder.CreateLoad(data_size->getType()->getPointerElementType(), data_size);
159 CHECK(data_size_type->isIntegerTy(64));
160 size_val = data_size;
162 ir_builder.CreateStore(size_val, col_sz_ptr);
164 auto const_minus1 = llvm::ConstantInt::get(llvm::Type::getInt64Ty(ctx), -1,
true);
165 ir_builder.CreateStore(const_minus1, col_sz_ptr);
167 if (is_text_encoding_dict_type) {
168 if (data_str_dict_proxy_ptr !=
nullptr) {
169 auto data_str_dict_proxy_type = data_str_dict_proxy_ptr->getType();
170 CHECK(data_str_dict_proxy_type->getPointerElementType()->isIntegerTy(8));
171 ir_builder.CreateStore(data_str_dict_proxy_ptr, col_str_dict_ptr);
173 ir_builder.CreateStore(llvm::Constant::getNullValue(llvm::Type::getInt8PtrTy(ctx)),
178 auto col_ptr = ir_builder.CreatePointerCast(
179 col_ptr_ptr, llvm::PointerType::get(llvm::Type::getInt8Ty(ctx), 0));
180 col_ptr->setName(col_name +
"_ptr");
181 return {col, col_ptr};
186 llvm::Value* data_ptrs,
188 llvm::Value* data_size,
189 llvm::Value* data_str_dict_proxy_ptrs,
190 llvm::LLVMContext& ctx,
191 llvm::IRBuilder<>& ir_builder) {
198 llvm::Type* data_ptrs_llvm_type = llvm::Type::getInt8PtrTy(ctx);
199 const bool is_text_encoding_dict_type =
203 llvm::StructType* col_list_struct_type =
204 is_text_encoding_dict_type
205 ? llvm::StructType::get(
209 llvm::Type::getInt64Ty(ctx),
210 llvm::Type::getInt64Ty(ctx),
213 : llvm::StructType::get(ctx,
216 llvm::Type::getInt64Ty(ctx),
217 llvm::Type::getInt64Ty(ctx)
220 auto col_list = ir_builder.CreateAlloca(col_list_struct_type);
221 col_list->setName(col_list_name);
222 auto col_list_ptr_ptr = ir_builder.CreateStructGEP(col_list_struct_type, col_list, 0);
223 auto col_list_length_ptr =
224 ir_builder.CreateStructGEP(col_list_struct_type, col_list, 1);
225 auto col_list_size_ptr = ir_builder.CreateStructGEP(col_list_struct_type, col_list, 2);
226 auto col_str_dict_ptr_ptr =
227 is_text_encoding_dict_type
228 ? ir_builder.CreateStructGEP(col_list_struct_type, col_list, 3)
231 col_list_ptr_ptr->setName(col_list_name +
".ptrs");
232 col_list_length_ptr->setName(col_list_name +
".length");
233 col_list_size_ptr->setName(col_list_name +
".size");
234 if (is_text_encoding_dict_type) {
235 col_str_dict_ptr_ptr->setName(col_list_name +
".string_dict_proxies");
239 auto const_length = llvm::ConstantInt::get(llvm::Type::getInt64Ty(ctx), length,
true);
241 if (data_ptrs !=
nullptr) {
242 if (data_ptrs->getType() == data_ptrs_llvm_type->getPointerElementType()) {
243 ir_builder.CreateStore(data_ptrs, col_list_ptr_ptr);
245 auto tmp = ir_builder.CreateBitCast(data_ptrs, data_ptrs_llvm_type);
246 ir_builder.CreateStore(tmp, col_list_ptr_ptr);
249 ir_builder.CreateStore(llvm::Constant::getNullValue(data_ptrs_llvm_type),
253 ir_builder.CreateStore(const_length, col_list_length_ptr);
255 if (data_size !=
nullptr) {
256 auto data_size_type = data_size->getType();
257 llvm::Value* size_val =
nullptr;
258 if (data_size_type->isPointerTy()) {
259 CHECK(data_size_type->getPointerElementType()->isIntegerTy(64));
261 ir_builder.CreateLoad(data_size->getType()->getPointerElementType(), data_size);
263 CHECK(data_size_type->isIntegerTy(64));
264 size_val = data_size;
266 ir_builder.CreateStore(size_val, col_list_size_ptr);
268 auto const_minus1 = llvm::ConstantInt::get(llvm::Type::getInt64Ty(ctx), -1,
true);
269 ir_builder.CreateStore(const_minus1, col_list_size_ptr);
272 if (is_text_encoding_dict_type) {
273 if (data_str_dict_proxy_ptrs !=
nullptr) {
274 auto data_str_dict_proxies_type = data_str_dict_proxy_ptrs->getType();
275 CHECK(data_str_dict_proxies_type->getPointerElementType()->isIntegerTy(8));
276 ir_builder.CreateStore(data_str_dict_proxy_ptrs, col_str_dict_ptr_ptr);
278 ir_builder.CreateStore(llvm::Constant::getNullValue(data_ptrs_llvm_type),
283 auto col_list_ptr = ir_builder.CreatePointerCast(
284 col_list_ptr_ptr, llvm::PointerType::get(llvm::Type::getInt8Ty(ctx), 0));
285 col_list_ptr->setName(col_list_name +
"_ptrs");
320 throw std::runtime_error(
"Unsupported cast from " + orig_ti.
get_type_name() +
" to " +
326 llvm::Function* func,
330 llvm::IRBuilder<>& ir_builder,
331 llvm::LLVMContext& ctx,
361 llvm::BasicBlock* for_pre =
362 llvm::BasicBlock::Create(ctx,
"for_pre_cast." + index, func);
363 llvm::BasicBlock* for_cond =
364 llvm::BasicBlock::Create(ctx,
"for_cond_cast." + index, func);
365 llvm::BasicBlock* for_body =
366 llvm::BasicBlock::Create(ctx,
"for_body_cast." + index, func);
367 llvm::BasicBlock* for_end =
368 llvm::BasicBlock::Create(ctx,
"for_end_cast." + index, func);
369 ir_builder.CreateBr(for_pre);
372 ir_builder.SetInsertPoint(for_pre);
374 llvm::StructType* col_struct_type =
375 llvm::StructType::get(ctx, {data_type, ir_builder.getInt64Ty()});
376 llvm::Value* struct_cast = ir_builder.CreateBitCast(
377 col_base_ptr, col_struct_type->getPointerTo(),
"col_struct." + index);
378 llvm::Value* gep_ptr = ir_builder.CreateStructGEP(
379 col_struct_type, struct_cast, 0,
"col_ptr_addr." + index);
380 llvm::Value* col_ptr = ir_builder.CreateLoad(data_type, gep_ptr,
"col_ptr." + index);
381 llvm::Value* gep_sz =
382 ir_builder.CreateStructGEP(col_struct_type, struct_cast, 1,
"col_sz_addr." + index);
383 llvm::Value* col_sz =
384 ir_builder.CreateLoad(ir_builder.getInt64Ty(), gep_sz,
"col_sz." + index);
385 ir_builder.CreateBr(for_cond);
388 ir_builder.SetInsertPoint(for_cond);
389 llvm::PHINode* for_ind_var =
390 ir_builder.CreatePHI(ir_builder.getInt64Ty(), 2,
"for_ind_var." + index);
391 for_ind_var->addIncoming(ir_builder.getInt64(0), for_pre);
392 llvm::Value* for_pred =
393 ir_builder.CreateICmpSLT(for_ind_var, col_sz,
"for_pred." + index);
394 ir_builder.CreateCondBr(for_pred, for_body, for_end);
397 ir_builder.SetInsertPoint(for_body);
399 llvm::Value* val_gep = ir_builder.CreateInBoundsGEP(
400 ir_builder.getInt64Ty(), col_ptr, for_ind_var,
"val_gep." + index);
401 llvm::Value* val_load =
402 ir_builder.CreateLoad(ir_builder.getInt64Ty(), val_gep,
"val_load." + index);
403 llvm::Value* cast_result =
cast_value(val_load, orig_ti, dest_ti,
false, codeGenerator);
404 cast_result->setName(
"cast_result." + index);
405 ir_builder.CreateStore(cast_result, val_gep);
406 llvm::Value* for_inc =
407 ir_builder.CreateAdd(for_ind_var, ir_builder.getInt64(1),
"for_inc." + index);
408 ir_builder.CreateBr(for_cond);
411 llvm::Instruction* inc_as_inst = llvm::cast<llvm::Instruction>(for_inc);
412 for_ind_var->addIncoming(for_inc, inc_as_inst->getParent());
413 ir_builder.SetInsertPoint(for_end);
416 std::string
exprsKey(
const std::vector<Analyzer::Expr*>& exprs) {
418 for (
const auto& expr : exprs) {
419 const auto& ti = expr->get_type_info();
420 result += ti.to_string() +
", ";
429 bool emit_only_preflight_fn) {
448 auto cgen_state =
executor_->getCgenStatePtr();
450 CHECK(cgen_state->module_ ==
nullptr);
451 cgen_state->set_module_shallow_copy(
executor_->get_rt_module());
458 CHECK(!emit_only_preflight_fn);
469 auto mod =
executor_->get_rt_udf_module(is_gpu).get();
470 if (mod !=
nullptr) {
471 auto* flag = mod->getModuleFlag(
"pass_column_arguments_by_value");
472 if (
auto* cnt = llvm::mdconst::extract_or_null<llvm::ConstantInt>(flag)) {
473 return cnt->getZExtValue();
483 const std::vector<llvm::Value*>& func_args,
484 llvm::BasicBlock* bb_exit,
485 llvm::Value* output_row_count_ptr,
486 bool emit_only_preflight_fn) {
487 auto cgen_state =
executor_->getCgenStatePtr();
489 llvm::LLVMContext& ctx = cgen_state->context_;
490 llvm::IRBuilder<>* ir_builder = &cgen_state->ir_builder_;
492 std::string func_name =
495 llvm::Value* table_func_return =
496 cgen_state->emitExternalCall(func_name,
get_int_type(32, ctx), func_args);
498 table_func_return->setName(emit_only_preflight_fn ?
"preflight_check_func_ret"
504 llvm::BasicBlock* bb_exit_0 =
507 llvm::Constant* const_zero =
508 llvm::ConstantInt::get(table_func_return->getType(), 0,
true);
509 llvm::Value* is_ok = ir_builder->CreateICmpSGE(table_func_return, const_zero);
510 ir_builder->CreateCondBr(is_ok, bb_exit_0, bb_exit);
512 ir_builder->SetInsertPoint(bb_exit_0);
514 ir_builder->CreateIntCast(table_func_return,
get_int_type(64, ctx),
true);
515 ir_builder->CreateStore(r, output_row_count_ptr);
516 ir_builder->CreateRet(const_zero);
518 ir_builder->SetInsertPoint(bb_exit);
519 ir_builder->CreateRet(table_func_return);
524 bool emit_only_preflight_fn) {
529 const auto mgr_ptr = &*arg_it;
530 const auto input_cols_arg = &*(++arg_it);
531 const auto input_row_counts_arg = &*(++arg_it);
532 const auto input_str_dict_proxies_arg = &*(++arg_it);
533 const auto output_buffers_arg = &*(++arg_it);
534 const auto output_str_dict_proxies_arg = &*(++arg_it);
535 const auto output_row_count_ptr = &*(++arg_it);
536 auto cgen_state =
executor_->getCgenStatePtr();
538 auto& ctx = cgen_state->context_;
540 llvm::BasicBlock* bb_entry =
542 cgen_state->ir_builder_.SetInsertPoint(bb_entry);
544 llvm::BasicBlock* bb_exit = llvm::BasicBlock::Create(ctx,
".exit",
entry_point_func_);
546 llvm::BasicBlock* func_body_bb = llvm::BasicBlock::Create(
547 ctx,
".func_body0", cgen_state->ir_builder_.GetInsertBlock()->getParent());
549 cgen_state->ir_builder_.SetInsertPoint(bb_entry);
550 cgen_state->ir_builder_.CreateBr(func_body_bb);
552 cgen_state->ir_builder_.SetInsertPoint(func_body_bb);
554 exe_unit.
input_exprs.size(), input_cols_arg, cgen_state->ir_builder_, ctx);
557 exe_unit.
input_exprs.size(), input_row_counts_arg, cgen_state->ir_builder_, ctx);
559 auto input_str_dict_proxy_heads = std::vector<llvm::Value*>();
562 input_str_dict_proxies_arg,
563 cgen_state->ir_builder_,
569 std::vector<llvm::Value*> func_args;
570 std::vector<std::pair<llvm::Value*, const SQLTypeInfo>> columns_to_cast;
571 size_t func_arg_index = 0;
573 func_args.push_back(mgr_ptr);
578 for (
size_t i = 0; i < exe_unit.
input_exprs.size(); i++) {
580 const auto& ti = expr->get_type_info();
581 if (col_index == -1) {
585 auto r = cgen_state->ir_builder_.CreateBitCast(
587 llvm::LoadInst* scalar_fp = cgen_state->ir_builder_.CreateLoad(
588 r->getType()->getPointerElementType(),
591 func_args.push_back(scalar_fp);
593 }
else if (ti.is_integer() || ti.is_boolean() || ti.is_timestamp()) {
594 auto r = cgen_state->ir_builder_.CreateBitCast(
596 llvm::LoadInst* scalar_int = cgen_state->ir_builder_.CreateLoad(
597 r->getType()->getPointerElementType(),
600 func_args.push_back(scalar_int);
602 }
else if (ti.is_bytes()) {
604 cgen_state->ir_builder_.CreateBitCast(col_heads[i],
get_int_ptr_type(64, ctx));
605 auto varchar_ptr = cgen_state->ir_builder_.CreateGEP(
606 col_heads[i]->getType()->getScalarType()->getPointerElementType(),
608 cgen_state->llInt(8));
609 auto [varchar_struct, varchar_struct_ptr] =
alloc_column(
610 std::string(
"input_varchar_literal.") +
std::to_string(func_arg_index),
617 cgen_state->ir_builder_);
619 (pass_column_by_value
620 ? cgen_state->ir_builder_.CreateLoad(
621 varchar_struct->getType()->getPointerElementType(), varchar_struct)
622 : varchar_struct_ptr));
624 }
else if (ti.is_column()) {
633 : input_str_dict_proxy_heads[i],
635 cgen_state->ir_builder_);
636 func_args.push_back((pass_column_by_value
637 ? cgen_state->ir_builder_.CreateLoad(
638 col->getType()->getPointerElementType(), col)
643 columns_to_cast.push_back(std::make_pair(col_ptr, ti));
646 }
else if (ti.is_column_list()) {
647 if (col_index == -1) {
654 (emit_only_preflight_fn) ?
nullptr : input_str_dict_proxy_heads[i],
656 cgen_state->ir_builder_);
657 func_args.push_back(col_list);
660 if (col_index + 1 == ti.get_dimension()) {
664 throw std::runtime_error(
665 "Only integer and floating point columns or scalars are supported as inputs to "
671 auto output_str_dict_proxy_heads =
674 output_str_dict_proxies_arg,
675 cgen_state->ir_builder_,
677 : std::vector<llvm::Value*>();
679 std::vector<llvm::Value*> output_col_args;
680 for (
size_t i = 0; i < exe_unit.
target_exprs.size(); i++) {
681 auto* gep = cgen_state->ir_builder_.CreateGEP(
682 output_buffers_arg->getType()->getScalarType()->getPointerElementType(),
684 cgen_state->llInt(i));
686 cgen_state->ir_builder_.CreateLoad(gep->getType()->getPointerElementType(), gep);
688 const auto& ti = expr->get_type_info();
689 CHECK(!ti.is_column());
690 CHECK(!ti.is_column_list());
700 output_row_count_ptr,
704 cgen_state->ir_builder_);
706 cgen_state->emitExternalCall(
707 "TableFunctionManager_register_output_column",
708 llvm::Type::getVoidTy(ctx),
709 {mgr_ptr, llvm::ConstantInt::get(
get_int_type(32, ctx), i,
true), col_ptr});
711 output_col_args.push_back((pass_column_by_value ? col : col_ptr));
719 cgen_state->emitExternalCall(
720 "TableFunctionManager_set_output_row_size",
721 llvm::Type::getVoidTy(ctx),
723 cgen_state->ir_builder_.CreateLoad(
724 output_row_count_ptr->getType()->getPointerElementType(),
725 output_row_count_ptr)});
728 if (!emit_only_preflight_fn) {
729 for (
auto& col : output_col_args) {
730 func_args.push_back((pass_column_by_value
731 ? cgen_state->ir_builder_.CreateLoad(
732 col->getType()->getPointerElementType(), col)
742 exe_unit, func_args, bb_exit, output_row_count_ptr, emit_only_preflight_fn);
753 const std::vector<std::pair<llvm::Value*, const SQLTypeInfo>>& columns_to_cast,
754 llvm::Value* mgr_ptr) {
755 auto* cgen_state =
executor_->getCgenStatePtr();
756 llvm::LLVMContext& ctx = cgen_state->context_;
757 llvm::IRBuilder<>* ir_builder = &cgen_state->ir_builder_;
759 llvm::Function* old_func = cgen_state->current_func_;
760 cgen_state->current_func_ =
763 for (
unsigned i = 0; i < columns_to_cast.size(); ++i) {
764 auto [col_ptr, ti] = columns_to_cast[i];
766 if (ti.is_column() && ti.get_subtype() ==
kTIMESTAMP && ti.get_precision() != 9) {
769 ti.get_subtype(), ti.get_precision(), ti.get_dimension(), ti.get_notnull());
792 std::vector<llvm::ReturnInst*> rets_to_replace;
794 for (llvm::Instruction& I : BB) {
795 if (!llvm::isa<llvm::ReturnInst>(&I)) {
798 llvm::ReturnInst* RI = llvm::cast<llvm::ReturnInst>(&I);
799 llvm::Value* retValue = RI->getReturnValue();
800 if (!retValue || !llvm::isa<llvm::ConstantInt>(retValue)) {
803 llvm::ConstantInt* retConst = llvm::cast<llvm::ConstantInt>(retValue);
804 if (retConst->getValue() == 7) {
806 rets_to_replace.push_back(RI);
811 auto prev_insert_point = ir_builder->saveIP();
812 for (llvm::ReturnInst* RI : rets_to_replace) {
813 ir_builder->SetInsertPoint(RI);
814 llvm::Value* err_msg = ir_builder->CreateGlobalStringPtr(
815 "Underflow or overflow during casting of input types!",
"cast_err_str");
816 llvm::Value* error_call;
818 error_call = cgen_state->emitExternalCall(
"TableFunctionManager_error_message",
819 ir_builder->getInt32Ty(),
822 error_call = cgen_state->emitExternalCall(
823 "table_function_error", ir_builder->getInt32Ty(), {err_msg});
825 llvm::ReplaceInstWithInst(RI, llvm::ReturnInst::Create(ctx, error_call));
827 ir_builder->restoreIP(prev_insert_point);
829 cgen_state->current_func_ = old_func;
835 std::vector<llvm::Type*> arg_types;
839 [&arg_types](
const auto& arg) { arg_types.push_back(arg.getType()); });
842 auto cgen_state =
executor_->getCgenStatePtr();
844 auto& ctx = cgen_state->context_;
846 std::vector<llvm::Type*> wrapper_arg_types(arg_types.size() + 1);
847 wrapper_arg_types[0] = llvm::PointerType::get(
get_int_type(32, ctx), 0);
848 wrapper_arg_types[1] = arg_types[0];
850 for (
size_t i = 1; i < arg_types.size(); ++i) {
851 wrapper_arg_types[i + 1] = arg_types[i];
855 llvm::FunctionType::get(llvm::Type::getVoidTy(ctx), wrapper_arg_types,
false);
857 llvm::Function::ExternalLinkage,
859 cgen_state->module_);
861 auto wrapper_bb_entry = llvm::BasicBlock::Create(ctx,
".entry",
kernel_func_, 0);
862 llvm::IRBuilder<> b(ctx);
863 b.SetInsertPoint(wrapper_bb_entry);
864 std::vector<llvm::Value*> loaded_args = {
kernel_func_->arg_begin() + 1};
865 for (
size_t i = 2; i < wrapper_arg_types.size(); ++i) {
874 bool emit_only_preflight_fn) {
880 auto cgen_state =
executor_->getCgenStatePtr();
882 if (
executor_->has_rt_udf_module(is_gpu)) {
884 *(cgen_state->module_),
886 llvm::Linker::Flags::OverrideFromSrc);
889 LOG(
IR) << (emit_only_preflight_fn ?
"Pre Flight Function Entry Point IR\n"
890 :
"Table Function Entry Point IR\n")
892 std::shared_ptr<CompilationContext> code;
914 auto cpu_code = std::make_shared<CpuCompilationContext>(std::move(ee));
918 LOG(
IR) <<
"End of IR";
llvm::Type * get_fp_ptr_type(const int width, llvm::LLVMContext &context)
llvm::Function * kernel_func_
HOST DEVICE SQLTypes get_subtype() const
std::string exprsKey(const std::vector< Analyzer::Expr * > &exprs)
HOST DEVICE int get_size() const
bool is_timestamp() const
void generateEntryPoint(const TableFunctionExecutionUnit &exe_unit, bool emit_only_preflight_fn)
bool passColumnsByValue(const TableFunctionExecutionUnit &exe_unit)
std::vector< Analyzer::Expr * > input_exprs
const table_functions::TableFunction table_func
std::tuple< llvm::Value *, llvm::Value * > alloc_column(std::string col_name, const size_t index, const SQLTypeInfo &data_target_info, llvm::Value *data_ptr, llvm::Value *data_size, llvm::Value *data_str_dict_proxy_ptr, llvm::LLVMContext &ctx, llvm::IRBuilder<> &ir_builder)
bool mayRequireCastingInputTypes() const
llvm::Function * generate_entry_point(const CgenState *cgen_state)
std::shared_ptr< CompilationContext > finalize(bool emit_only_preflight_fn)
std::vector< std::string > CodeCacheKey
void generateCastsForInputTypes(const TableFunctionExecutionUnit &exe_unit, const std::vector< std::pair< llvm::Value *, const SQLTypeInfo >> &columns_to_cast, llvm::Value *mgr_ptr)
static ExecutionEngineWrapper generateNativeCPUCode(llvm::Function *func, const std::unordered_set< llvm::Function * > &live_funcs, const CompilationOptions &co)
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
llvm::Value * alloc_column_list(std::string col_list_name, const SQLTypeInfo &data_target_info, llvm::Value *data_ptrs, int length, llvm::Value *data_size, llvm::Value *data_str_dict_proxy_ptrs, llvm::LLVMContext &ctx, llvm::IRBuilder<> &ir_builder)
bool hasOutputSizeKnownPreLaunch() const
void verify_function_ir(const llvm::Function *func)
size_t get_bit_width(const SQLTypeInfo &ti)
llvm::LLVMContext & context_
const CompilationOptions & co_
std::string getPreFlightFnName() const
static void link_udf_module(const std::unique_ptr< llvm::Module > &udf_module, llvm::Module &module, CgenState *cgen_state, llvm::Linker::Flags flags=llvm::Linker::Flags::None)
void generateTableFunctionCall(const TableFunctionExecutionUnit &exe_unit, const std::vector< llvm::Value * > &func_args, llvm::BasicBlock *bb_exit, llvm::Value *output_row_count_ptr, bool emit_only_preflight_fn)
std::string toString(const Executor::ExtModuleKinds &kind)
std::string getName(const bool drop_suffix=false, const bool lower=false) const
int get_precision() const
ExecutorDeviceType device_type
HOST DEVICE EncodingType get_compression() const
std::string serialize_llvm_object(const T *llvm_obj)
static std::shared_ptr< GpuCompilationContext > generateNativeGPUCode(Executor *executor, llvm::Function *func, llvm::Function *wrapper_func, const std::unordered_set< llvm::Function * > &live_funcs, const bool is_gpu_smem_used, const CompilationOptions &co, const GPUTarget &gpu_target)
static CodeCacheAccessor< CompilationContext > tf_code_accessor
bool hasPreFlightOutputSizer() const
llvm::Function * entry_point_func_
std::vector< llvm::Value * > generate_column_heads_load(const int num_columns, llvm::Value *byte_stream_arg, llvm::IRBuilder<> &ir_builder, llvm::LLVMContext &ctx)
std::string get_type_name() const
void cast_column(llvm::Value *col_base_ptr, llvm::Function *func, SQLTypeInfo &orig_ti, SQLTypeInfo &dest_ti, std::string index, llvm::IRBuilder<> &ir_builder, llvm::LLVMContext &ctx, CodeGenerator &codeGenerator)
llvm::Value * codegenCastBetweenTimestamps(llvm::Value *ts_lv, const SQLTypeInfo &operand_dimen, const SQLTypeInfo &target_dimen, const bool nullable)
llvm::Type * get_llvm_type_from_sql_column_type(const SQLTypeInfo elem_ti, llvm::LLVMContext &ctx)
#define DEBUG_TIMER(name)
static bool columnTypeRequiresCasting(const SQLTypeInfo &ti)
std::shared_ptr< CompilationContext > compile(const TableFunctionExecutionUnit &exe_unit, bool emit_only_preflight_fn)
std::vector< Analyzer::Expr * > target_exprs
HOST DEVICE bool get_notnull() const
llvm::Type * get_int_ptr_type(const int width, llvm::LLVMContext &context)
llvm::Value * cast_value(llvm::Value *value, SQLTypeInfo &orig_ti, SQLTypeInfo &dest_ti, bool nullable, CodeGenerator &codeGenerator)