Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
impala::CodegenAnyVal Class Reference

#include <codegen-anyval.h>

Collaboration diagram for impala::CodegenAnyVal:

Public Member Functions

 CodegenAnyVal (LlvmCodeGen *codegen, LlvmCodeGen::LlvmBuilder *builder, const ColumnType &type, llvm::Value *value=NULL, const char *name="")
 Creates a wrapper around a lowered *Val value. More...
 
llvm::Value * value ()
 Returns the current type-lowered value. More...
 
llvm::Value * GetIsNull (const char *name="is_null")
 Gets the 'is_null' field of the *Val. More...
 
llvm::Value * GetVal (const char *name="val")
 
void SetIsNull (llvm::Value *is_null)
 Sets the 'is_null' field of the *Val. More...
 
void SetVal (llvm::Value *val)
 
void SetVal (bool val)
 Sets the 'val' field of the *Val. The *Val must correspond to the argument type. More...
 
void SetVal (int8_t val)
 
void SetVal (int16_t val)
 
void SetVal (int32_t val)
 
void SetVal (int64_t val)
 
void SetVal (int128_t val)
 
void SetVal (float val)
 
void SetVal (double val)
 
llvm::Value * GetPtr ()
 Getters for StringVals. More...
 
llvm::Value * GetLen ()
 
void SetPtr (llvm::Value *ptr)
 Setters for StringVals. More...
 
void SetLen (llvm::Value *len)
 
llvm::Value * GetDate ()
 Getters for TimestampVals. More...
 
llvm::Value * GetTimeOfDay ()
 
void SetDate (llvm::Value *date)
 Setters for TimestampVals. More...
 
void SetTimeOfDay (llvm::Value *time_of_day)
 
llvm::Value * GetUnloweredPtr ()
 
void SetFromRawValue (llvm::Value *raw_val)
 
void SetFromRawPtr (llvm::Value *raw_ptr)
 
llvm::Value * ToNativeValue ()
 
void ToNativePtr (llvm::Value *native_ptr)
 
llvm::Value * Eq (CodegenAnyVal *other)
 Returns the i1 result of this == other. this and other must be non-null. More...
 
llvm::Value * EqToNativePtr (llvm::Value *native_ptr)
 
 CodegenAnyVal ()
 Ctor for created an uninitialized CodegenAnYVal that can be assigned to later. More...
 

Static Public Member Functions

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. More...
 
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. More...
 
static llvm::Type * GetLoweredType (LlvmCodeGen *cg, const ColumnType &type)
 
static llvm::Type * GetLoweredPtrType (LlvmCodeGen *cg, const ColumnType &type)
 
static llvm::Type * GetUnloweredType (LlvmCodeGen *cg, const ColumnType &type)
 
static llvm::Type * GetUnloweredPtrType (LlvmCodeGen *cg, const ColumnType &type)
 
static llvm::Value * GetNullVal (LlvmCodeGen *codegen, const ColumnType &type)
 
static llvm::Value * GetNullVal (LlvmCodeGen *codegen, llvm::Type *val_type)
 
static CodegenAnyVal GetNonNullVal (LlvmCodeGen *codegen, LlvmCodeGen::LlvmBuilder *builder, const ColumnType &type, const char *name="")
 

Static Public Attributes

static const char * LLVM_BOOLEANVAL_NAME = "struct.impala_udf::BooleanVal"
 
static const char * LLVM_TINYINTVAL_NAME = "struct.impala_udf::TinyIntVal"
 
static const char * LLVM_SMALLINTVAL_NAME = "struct.impala_udf::SmallIntVal"
 
static const char * LLVM_INTVAL_NAME = "struct.impala_udf::IntVal"
 
static const char * LLVM_BIGINTVAL_NAME = "struct.impala_udf::BigIntVal"
 
static const char * LLVM_FLOATVAL_NAME = "struct.impala_udf::FloatVal"
 
static const char * LLVM_DOUBLEVAL_NAME = "struct.impala_udf::DoubleVal"
 
static const char * LLVM_STRINGVAL_NAME = "struct.impala_udf::StringVal"
 
static const char * LLVM_TIMESTAMPVAL_NAME = "struct.impala_udf::TimestampVal"
 
static const char * LLVM_DECIMALVAL_NAME = "struct.impala_udf::DecimalVal"
 

Private Member Functions

llvm::Value * GetHighBits (int num_bits, llvm::Value *v, const char *name="")
 
llvm::Value * SetHighBits (int num_bits, llvm::Value *src, llvm::Value *dst, const char *name="")
 

Private Attributes

ColumnType type_
 
llvm::Value * value_
 
const char * name_
 
LlvmCodeGencodegen_
 
LlvmCodeGen::LlvmBuilderbuilder_
 

Detailed Description

Class for handling AnyVal subclasses during codegen. Codegen functions should use this wrapper instead of creating or manipulating Val values directly in most cases. This is because the struct types must be lowered to integer types in many cases in order to conform to the standard calling convention (e.g., { i8, i32 } => i64). This class wraps the lowered types for each Val struct. This class conceptually represents a single Val that is mutated, but operates by generating IR instructions involving value_ (each of which generates a new Value, since IR uses SSA), and then setting value_ to the most recent Value generated. The generated instructions perform the integer manipulation equivalent to setting the fields of the original struct type. Lowered types: TYPE_BOOLEAN/BooleanVal: i16 TYPE_TINYINT/TinyIntVal: i16 TYPE_SMALLINT/SmallIntVal: i32 TYPE_INT/INTVal: i64 TYPE_BIGINT/BigIntVal: { i8, i64 } TYPE_FLOAT/FloatVal: i64 TYPE_DOUBLE/DoubleVal: { i8, double } TYPE_STRING/StringVal: { i64, i8 } TYPE_TIMESTAMP/TimestampVal: { i64, i64 } TODO:

  • unit tests

Definition at line 52 of file codegen-anyval.h.

Constructor & Destructor Documentation

impala::CodegenAnyVal::CodegenAnyVal ( LlvmCodeGen codegen,
LlvmCodeGen::LlvmBuilder builder,
const ColumnType type,
llvm::Value *  value = NULL,
const char *  name = "" 
)

Creates a wrapper around a lowered *Val value.

Instructions for manipulating the value are generated using 'builder'. The insert point of 'builder' is not modified by this class, and it is safe to call 'builder'.SetInsertPoint() after passing 'builder' to this class. 'type' identified the type of wrapped value (e.g., TYPE_INT corresponds to IntVal, which is lowered to i64). If 'value' is NULL, a new value of the lowered type is alloca'd. Otherwise 'value' must be of the correct lowered type. If 'name' is specified, it will be used when generated instructions that set value_.

impala::CodegenAnyVal::CodegenAnyVal ( )
inline

Ctor for created an uninitialized CodegenAnYVal that can be assigned to later.

Definition at line 211 of file codegen-anyval.h.

Referenced by GetNonNullVal().

Member Function Documentation

Value * CodegenAnyVal::CreateCall ( LlvmCodeGen cg,
LlvmCodeGen::LlvmBuilder builder,
llvm::Function *  fn,
llvm::ArrayRef< llvm::Value * >  args,
const char *  name = "",
llvm::Value *  result_ptr = NULL 
)
static

'name' optionally specifies the name of the returned value.

Creates a call to 'fn', which should return a (lowered) Val, and returns the result. This abstracts over the x64 calling convention, in particular for functions returning a DecimalVal, which pass the return value as an output argument. If 'result_ptr' is non-NULL, it should be a pointer to the lowered return type of 'fn' (e.g. if 'fn' returns a BooleanVal, 'result_ptr' should have type i16). The result of calling 'fn' will be stored in 'result_ptr' and this function will return NULL. If 'result_ptr' is NULL, this function will return the result (note that the result will not be a pointer in this case).

Definition at line 116 of file codegen-anyval.cc.

References impala::LlvmCodeGen::CreateEntryBlockAlloca(), and impala::LlvmCodeGen::GetType().

Referenced by impala::CaseExpr::GetCodegendComputeFn(), impala::ScalarFnCall::GetCodegendComputeFn(), and impala::Expr::GetCodegendComputeFnWrapper().

Value * CodegenAnyVal::EqToNativePtr ( llvm::Value *  native_ptr)

Compares this Val to the value of 'native_ptr'. 'native_ptr' should be a pointer to a native type, StringValue, or TimestampValue. This *Val should match 'native_ptr's type (e.g. if this is an IntVal, 'native_ptr' should have type i32). Returns the i1 result of the equality comparison.

Definition at line 582 of file codegen-anyval.cc.

References builder_, codegen_, impala::ColumnType::DebugString(), impala::LlvmCodeGen::false_value(), impala::LlvmCodeGen::GetFunction(), GetUnloweredPtr(), GetVal(), impala::ColumnType::IsStringType(), impala::ColumnType::type, type_, impala::TYPE_BIGINT, impala::TYPE_BOOLEAN, impala::TYPE_DECIMAL, impala::TYPE_DOUBLE, impala::TYPE_FLOAT, impala::TYPE_INT, impala::TYPE_NULL, impala::TYPE_SMALLINT, impala::TYPE_STRING, impala::TYPE_TIMESTAMP, impala::TYPE_TINYINT, and impala::TYPE_VARCHAR.

Referenced by impala::HashTableCtx::CodegenEquals(), and impala::OldHashTable::CodegenEquals().

Value * CodegenAnyVal::GetDate ( )

Getters for TimestampVals.

Definition at line 424 of file codegen-anyval.cc.

References builder_, GetHighBits(), impala::ColumnType::type, type_, impala::TYPE_TIMESTAMP, and value_.

Referenced by ToNativeValue().

Value * CodegenAnyVal::GetHighBits ( int  num_bits,
llvm::Value *  v,
const char *  name = "" 
)
private

Helper function for getting the top (most significant) half of 'v'. 'v' should have width = 'num_bits' * 2 and be an integer type.

Definition at line 616 of file codegen-anyval.cc.

References builder_, codegen_, and impala::LlvmCodeGen::context().

Referenced by GetDate(), GetLen(), and GetVal().

Value * CodegenAnyVal::GetLen ( )

Definition at line 397 of file codegen-anyval.cc.

References builder_, GetHighBits(), impala::ColumnType::IsStringType(), type_, and value_.

Referenced by ToNativeValue().

Type * CodegenAnyVal::GetLoweredPtrType ( LlvmCodeGen cg,
const ColumnType type 
)
static

Returns the lowered AnyVal pointer type associated with 'type'. E.g.: TYPE_BOOLEAN => i16*

Definition at line 65 of file codegen-anyval.cc.

Referenced by impala::ScalarFnCall::GetCodegendComputeFn().

CodegenAnyVal CodegenAnyVal::GetNonNullVal ( LlvmCodeGen codegen,
LlvmCodeGen::LlvmBuilder builder,
const ColumnType type,
const char *  name = "" 
)
static

Return the constant type-lowered value corresponding to a non-null Val. E.g.: TYPE_DOUBLE (lowered DoubleVal: { i8, double }) => { 0, 0 } This returns a CodegenAnyVal, rather than the unwrapped Value, because the actual value still needs to be set.

Definition at line 674 of file codegen-anyval.cc.

References CodegenAnyVal(), and GetLoweredType().

Referenced by impala::AggregationNode::CodegenUpdateSlot(), impala::PartitionedAggregationNode::CodegenUpdateSlot(), impala::SlotRef::GetCodegendComputeFn(), and impala::Literal::GetCodegendComputeFn().

Value * CodegenAnyVal::GetNullVal ( LlvmCodeGen codegen,
const ColumnType type 
)
static

Return the constant type-lowered value corresponding to a null *Val. E.g.: passing TYPE_DOUBLE (corresponding to the lowered DoubleVal { i8, double }) returns the constant struct { 1, 0.0 }

Definition at line 639 of file codegen-anyval.cc.

References GetLoweredType().

Referenced by impala::CaseExpr::GetCodegendComputeFn().

static llvm::Value* impala::CodegenAnyVal::GetNullVal ( LlvmCodeGen codegen,
llvm::Type *  val_type 
)
static

Return the constant type-lowered value corresponding to a null *Val. 'val_type' must be a lowered type (i.e. one of the types returned by GetType)

Value * CodegenAnyVal::GetPtr ( )

Getters for StringVals.

Definition at line 391 of file codegen-anyval.cc.

References builder_, impala::ColumnType::IsStringType(), name_, type_, and value_.

Referenced by ToNativeValue().

Value * CodegenAnyVal::GetTimeOfDay ( )

Definition at line 418 of file codegen-anyval.cc.

References builder_, impala::ColumnType::type, type_, impala::TYPE_TIMESTAMP, and value_.

Referenced by ToNativeValue().

Value * CodegenAnyVal::GetUnloweredPtr ( )

Allocas and stores this value in an unlowered pointer, and returns the pointer. This *Val should be non-null.

Definition at line 445 of file codegen-anyval.cc.

References builder_, codegen_, impala::LlvmCodeGen::CreateEntryBlockAlloca(), GetUnloweredPtrType(), type_, and value_.

Referenced by Eq(), and EqToNativePtr().

Type * CodegenAnyVal::GetUnloweredPtrType ( LlvmCodeGen cg,
const ColumnType type 
)
static

Returns the unlowered AnyVal pointer type associated with 'type'. E.g.: TYPE_BOOLEAN => %"struct.impala_udf::BooleanVal"*

Definition at line 112 of file codegen-anyval.cc.

Referenced by impala::PartitionedAggregationNode::CodegenUpdateSlot(), impala::ScalarFnCall::GetUdf(), and GetUnloweredPtr().

void CodegenAnyVal::SetDate ( llvm::Value *  date)

Setters for TimestampVals.

Definition at line 437 of file codegen-anyval.cc.

References builder_, name_, SetHighBits(), impala::ColumnType::type, type_, impala::TYPE_TIMESTAMP, and value_.

Referenced by impala::SlotRef::GetCodegendComputeFn(), and SetFromRawValue().

void CodegenAnyVal::SetFromRawPtr ( llvm::Value *  raw_ptr)

Set this Val's value based on void 'raw_ptr'. 'raw_ptr' should be a pointer to a native type, StringValue, or TimestampValue (i.e. the value returned by an interpreted compute fn).

Definition at line 451 of file codegen-anyval.cc.

References builder_, codegen_, impala::LlvmCodeGen::GetPtrType(), SetFromRawValue(), and type_.

Value * CodegenAnyVal::SetHighBits ( int  num_bits,
llvm::Value *  src,
llvm::Value *  dst,
const char *  name = "" 
)
private

Helper function for setting the top (most significant) half of a 'dst' to 'src'. 'src' must have width <= 'num_bits' and 'dst' must have width = 'num_bits' * 2. Both 'dst' and 'src' should be integer types.

Definition at line 628 of file codegen-anyval.cc.

References builder_, codegen_, and impala::LlvmCodeGen::context().

Referenced by SetDate(), and SetLen().

void CodegenAnyVal::SetLen ( llvm::Value *  len)
void CodegenAnyVal::SetPtr ( llvm::Value *  ptr)
void CodegenAnyVal::SetTimeOfDay ( llvm::Value *  time_of_day)
void impala::CodegenAnyVal::SetVal ( llvm::Value *  val)

Sets the 'val' field of the *Val. Do not call if this represents a StringVal or TimestampVal.

Referenced by impala::CompoundPredicate::CodegenComputeFn(), impala::SlotRef::GetCodegendComputeFn(), impala::Literal::GetCodegendComputeFn(), SetFromRawValue(), and SetVal().

void CodegenAnyVal::SetVal ( bool  val)

Sets the 'val' field of the *Val. The *Val must correspond to the argument type.

Definition at line 345 of file codegen-anyval.cc.

References builder_, SetVal(), impala::ColumnType::type, type_, and impala::TYPE_BOOLEAN.

void CodegenAnyVal::SetVal ( int8_t  val)
void CodegenAnyVal::SetVal ( int16_t  val)
void CodegenAnyVal::SetVal ( int32_t  val)
void CodegenAnyVal::SetVal ( int64_t  val)
void CodegenAnyVal::SetVal ( float  val)

Definition at line 381 of file codegen-anyval.cc.

References builder_, SetVal(), impala::ColumnType::type, type_, and impala::TYPE_FLOAT.

void CodegenAnyVal::SetVal ( double  val)

Definition at line 386 of file codegen-anyval.cc.

References builder_, SetVal(), impala::ColumnType::type, type_, and impala::TYPE_DOUBLE.

void CodegenAnyVal::ToNativePtr ( llvm::Value *  native_ptr)

Sets 'native_ptr' to this *Val's value. 'native_ptr' should be a pointer to a native type, StringValue, TimestampValue, etc. This should only be used if this *Val is not null.

Definition at line 547 of file codegen-anyval.cc.

References builder_, and ToNativeValue().

Referenced by impala::HashTableCtx::CodegenEvalRow(), and impala::OldHashTable::CodegenEvalTupleRow().

llvm::Value* impala::CodegenAnyVal::value ( )
inline

Member Data Documentation

const char * CodegenAnyVal::LLVM_BIGINTVAL_NAME = "struct.impala_udf::BigIntVal"
static

Definition at line 58 of file codegen-anyval.h.

const char * CodegenAnyVal::LLVM_BOOLEANVAL_NAME = "struct.impala_udf::BooleanVal"
static

Definition at line 54 of file codegen-anyval.h.

const char * CodegenAnyVal::LLVM_DECIMALVAL_NAME = "struct.impala_udf::DecimalVal"
static

Definition at line 63 of file codegen-anyval.h.

Referenced by impala::LlvmCodeGen::AddFunctionToJit().

const char * CodegenAnyVal::LLVM_DOUBLEVAL_NAME = "struct.impala_udf::DoubleVal"
static

Definition at line 60 of file codegen-anyval.h.

const char * CodegenAnyVal::LLVM_FLOATVAL_NAME = "struct.impala_udf::FloatVal"
static

Definition at line 59 of file codegen-anyval.h.

const char * CodegenAnyVal::LLVM_INTVAL_NAME = "struct.impala_udf::IntVal"
static

Definition at line 57 of file codegen-anyval.h.

const char * CodegenAnyVal::LLVM_SMALLINTVAL_NAME = "struct.impala_udf::SmallIntVal"
static

Definition at line 56 of file codegen-anyval.h.

const char * CodegenAnyVal::LLVM_STRINGVAL_NAME = "struct.impala_udf::StringVal"
static

Definition at line 61 of file codegen-anyval.h.

const char * CodegenAnyVal::LLVM_TIMESTAMPVAL_NAME = "struct.impala_udf::TimestampVal"
static

Definition at line 62 of file codegen-anyval.h.

const char * CodegenAnyVal::LLVM_TINYINTVAL_NAME = "struct.impala_udf::TinyIntVal"
static

Definition at line 55 of file codegen-anyval.h.

const char* impala::CodegenAnyVal::name_
private

Definition at line 217 of file codegen-anyval.h.

Referenced by GetPtr(), SetDate(), SetIsNull(), SetLen(), SetPtr(), and SetTimeOfDay().

llvm::Value* impala::CodegenAnyVal::value_
private

The documentation for this class was generated from the following files: