19 using namespace impala;
20 using namespace impala_udf;
58 return cg->
GetType(LLVM_DECIMALVAL_NAME);
60 DCHECK(
false) <<
"Unsupported type: " << type;
66 return GetLoweredType(cg, type)->getPointerTo();
73 result = cg->
GetType(LLVM_BOOLEANVAL_NAME);
76 result = cg->
GetType(LLVM_TINYINTVAL_NAME);
79 result = cg->
GetType(LLVM_SMALLINTVAL_NAME);
82 result = cg->
GetType(LLVM_INTVAL_NAME);
85 result = cg->
GetType(LLVM_BIGINTVAL_NAME);
88 result = cg->
GetType(LLVM_FLOATVAL_NAME);
91 result = cg->
GetType(LLVM_DOUBLEVAL_NAME);
96 result = cg->
GetType(LLVM_STRINGVAL_NAME);
99 result = cg->
GetType(LLVM_TIMESTAMPVAL_NAME);
102 result = cg->
GetType(LLVM_DECIMALVAL_NAME);
105 DCHECK(
false) <<
"Unsupported type: " << type;
113 return GetUnloweredType(cg, type)->getPointerTo();
118 ArrayRef<Value*> args,
const char*
name, Value* result_ptr) {
119 if (fn->getReturnType()->isVoidTy()) {
122 Function::arg_iterator ret_arg = fn->arg_begin();
123 DCHECK(ret_arg->getType()->isPointerTy());
124 Type* ret_type = ret_arg->getType()->getPointerElementType();
125 DCHECK_EQ(ret_type, cg->
GetType(LLVM_DECIMALVAL_NAME));
129 Value* ret_ptr = (result_ptr == NULL) ?
131 vector<Value*> new_args = args.vec();
132 new_args.insert(new_args.begin(), ret_ptr);
133 builder->CreateCall(fn, new_args);
136 if (result_ptr != NULL)
return NULL;
137 return builder->CreateLoad(ret_ptr, name);
141 Value* ret = builder->CreateCall(fn, args, name);
142 if (result_ptr == NULL)
return ret;
143 builder->CreateStore(ret, result_ptr);
150 Function* fn, ArrayRef<Value*> args,
const char*
name, Value* result_ptr) {
151 Value* v = CreateCall(cg, builder, fn, args, name, result_ptr);
168 DCHECK_EQ(
value_->getType(), value_type);
182 uint32_t idxs[] = {0, 0};
225 uint32_t idxs[] = {0, 0};
236 v =
builder_->CreateAnd(v, -0x100LL,
"masked");
237 Value* is_null_ext =
builder_->CreateZExt(is_null, v->getType(),
"is_null_ext");
238 v =
builder_->CreateOr(v, is_null_ext);
249 Value* is_null_ext =
builder_->CreateZExt(is_null,
value_->getType(),
"is_null_ext");
260 <<
"Use GetPtr and GetLen for StringVal";
262 <<
"Use GetPtr and GetLen for Varchar";
264 <<
"Use GetPtr and GetLen for Char";
266 <<
"Use GetDate and GetTimeOfDay for TimestampVals";
294 uint32_t idxs[] = {2, 0};
300 DCHECK(
false) <<
"Unsupported type: " <<
type_;
310 <<
"Use SetDate and SetTimeOfDay for TimestampVals";
336 uint32_t idxs[] = {2, 0};
341 DCHECK(
false) <<
"Unsupported type: " <<
type_;
375 ir_val =
builder_->CreateShl(ir_val, 64,
"tmp");
454 Value* val =
builder_->CreateLoad(val_ptr);
478 uint32_t time_of_day_idxs[] = {0, 0, 0, 0};
480 builder_->CreateExtractValue(raw_val, time_of_day_idxs,
"time_of_day");
481 DCHECK(time_of_day->getType()->isIntegerTy(64));
484 uint32_t date_idxs[] = {1, 0, 0};
485 Value* date =
builder_->CreateExtractValue(raw_val, date_idxs,
"date");
486 DCHECK(date->getType()->isIntegerTy(32));
509 Value* raw_val = Constant::getNullValue(raw_type);
523 uint32_t time_of_day_idxs[] = {0, 0, 0, 0};
525 uint32_t date_idxs[] = {1, 0, 0};
585 val =
builder_->CreateLoad(native_ptr);
617 DCHECK_EQ(v->getType()->getIntegerBitWidth(), num_bits * 2);
618 Value* shifted =
builder_->CreateAShr(v, num_bits);
630 DCHECK_LE(src->getType()->getIntegerBitWidth(), num_bits);
631 DCHECK_EQ(dst->getType()->getIntegerBitWidth(), num_bits * 2);
632 Value* extended_src =
634 Value* shifted_src =
builder_->CreateShl(extended_src, num_bits);
635 Value* masked_dst =
builder_->CreateAnd(dst, (1LL << num_bits) - 1);
636 return builder_->CreateOr(masked_dst, shifted_src, name);
645 if (val_type->isStructTy()) {
646 StructType* struct_type = cast<StructType>(val_type);
647 if (struct_type->getNumElements() == 3) {
651 StructType* anyval_struct_type = cast<StructType>(struct_type->getElementType(0));
652 Type* is_null_type = anyval_struct_type->getElementType(0);
654 ConstantStruct::get(anyval_struct_type, ConstantInt::get(is_null_type, 1));
655 Type* type2 = struct_type->getElementType(1);
656 Type* type3 = struct_type->getElementType(2);
657 return ConstantStruct::get(struct_type, null_anyval, Constant::getNullValue(type2),
658 Constant::getNullValue(type3), NULL);
662 DCHECK_EQ(struct_type->getNumElements(), 2);
663 Type* type1 = struct_type->getElementType(0);
665 Type* type2 = struct_type->getElementType(1);
666 return ConstantStruct::get(
667 struct_type, ConstantInt::get(type1, 1), Constant::getNullValue(type2), NULL);
670 DCHECK(val_type->isIntegerTy());
671 return ConstantInt::get(val_type, 1);
678 Value* value = Constant::getNullValue(val_type);
void SetFromRawValue(llvm::Value *raw_val)
static llvm::Type * GetLoweredPtrType(LlvmCodeGen *cg, const ColumnType &type)
static CodegenAnyVal CreateCallWrapped(LlvmCodeGen *cg, LlvmCodeGen::LlvmBuilder *builder, const ColumnType &type, llvm::Function *fn, llvm::ArrayRef< llvm::Value * > args, const char *name="", llvm::Value *result_ptr=NULL)
Same as above but wraps the result in a CodegenAnyVal.
llvm::PointerType * GetPtrType(llvm::Type *type)
Return a pointer type to 'type'.
llvm::Value * Eq(CodegenAnyVal *other)
Returns the i1 result of this == other. this and other must be non-null.
void SetLen(llvm::Value *len)
static const char * LLVM_TIMESTAMPVAL_NAME
llvm::Type * bigint_type()
void SetIsNull(llvm::Value *is_null)
Sets the 'is_null' field of the *Val.
static llvm::Type * GetUnloweredType(LlvmCodeGen *cg, const ColumnType &type)
CodegenAnyVal()
Ctor for created an uninitialized CodegenAnYVal that can be assigned to later.
static const char * LLVM_STRINGVAL_NAME
static llvm::Value * CreateCall(LlvmCodeGen *cg, LlvmCodeGen::LlvmBuilder *builder, llvm::Function *fn, llvm::ArrayRef< llvm::Value * > args, const char *name="", llvm::Value *result_ptr=NULL)
'name' optionally specifies the name of the returned value.
static const char * LLVM_FLOATVAL_NAME
llvm::Value * GetHighBits(int num_bits, llvm::Value *v, const char *name="")
void SetVal(llvm::Value *val)
llvm::Value * ToNativeValue()
llvm::Type * boolean_type()
Simple wrappers to reduce code verbosity.
static llvm::Type * GetUnloweredPtrType(LlvmCodeGen *cg, const ColumnType &type)
void SetDate(llvm::Value *date)
Setters for TimestampVals.
static const char * LLVM_BIGINTVAL_NAME
static CodegenAnyVal GetNonNullVal(LlvmCodeGen *codegen, LlvmCodeGen::LlvmBuilder *builder, const ColumnType &type, const char *name="")
static const char * LLVM_BOOLEANVAL_NAME
llvm::Value * GetPtr()
Getters for StringVals.
static std::string Print(T *value_or_type)
Returns the string representation of a llvm::Value* or llvm::Type*.
LLVM code generator. This is the top level object to generate jitted code.
bool IsStringType() const
std::string DebugString() const
llvm::Type * double_type()
llvm::Value * GetUnloweredPtr()
static const char * LLVM_DOUBLEVAL_NAME
llvm::Value * SetHighBits(int num_bits, llvm::Value *src, llvm::Value *dst, const char *name="")
void SetPtr(llvm::Value *ptr)
Setters for StringVals.
void SetTimeOfDay(llvm::Value *time_of_day)
static llvm::Type * GetLoweredType(LlvmCodeGen *cg, const ColumnType &type)
int GetByteSize() const
Returns the byte size of this type. Returns 0 for variable length types.
llvm::Function * GetFunction(IRFunction::Type)
static const char * LLVM_TINYINTVAL_NAME
llvm::Type * tinyint_type()
llvm::Value * EqToNativePtr(llvm::Value *native_ptr)
LlvmCodeGen::LlvmBuilder * builder_
llvm::Type * float_type()
llvm::Value * GetDate()
Getters for TimestampVals.
llvm::Value * false_value()
uint64_t LowBits(int128_t x)
llvm::Value * GetVal(const char *name="val")
llvm::Type * GetType(const ColumnType &type)
Returns llvm type for the column type.
llvm::Value * GetIsNull(const char *name="is_null")
Gets the 'is_null' field of the *Val.
static const char * LLVM_DECIMALVAL_NAME
static const char * LLVM_INTVAL_NAME
static llvm::Value * GetNullVal(LlvmCodeGen *codegen, const ColumnType &type)
llvm::Type * smallint_type()
uint64_t HighBits(int128_t x)
Get the high and low bits of an int128_t.
void SetFromRawPtr(llvm::Value *raw_ptr)
llvm::LLVMContext & context()
llvm::AllocaInst * CreateEntryBlockAlloca(llvm::Function *f, const NamedVariable &var)
llvm::Value * GetTimeOfDay()
void ToNativePtr(llvm::Value *native_ptr)
llvm::PointerType * ptr_type()
static const char * LLVM_SMALLINTVAL_NAME
__int128_t int128_t
We use the c++ int128_t type. This is stored using 16 bytes and very performant.