You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2018/02/21 01:43:28 UTC

[5/5] impala git commit: IMPALA-5801: Clean up codegen GetType() interface

IMPALA-5801: Clean up codegen GetType() interface

Several functions that return llvm::(Pointer)Type were renamed
to make them shorter or indicate their roles more clearly. Some
additional convenience functions were created to make some common
codegen tasks simpler:

- Get(Ptr)Type functions with string parameter are renamed to
  GetNamed(Ptr)Type
- GetStruct(Ptr)Type template functions are created to make
  GetNamedType(MyStruct::LLVM_CLASS_NAME) calls simpler (some
  classes had LLVM_CLASS_NAME as private, these are changed to
  public)
- integer type convenience functions are renamed to indicate
  bit width instead of matching SQL type (e.g. int_type->i32_type)
- similar convenience functions were created for ptr to primitive
  types, int_ptr_type
- Get(Ptr)Type functions with ColumnType parameter are renamed
  to GetSlot(Ptr)Type
- GetIntConstant function is split to several functions depending
  on the type of the integer e.g. GetI32Constant

The renamed functions can be found in llvm-codegen.h/cc. Changes
in other files are mainly renamed calls with the same functionality.

Testing:
No new tests are necessary, as no functionality was changed.

Change-Id: Ib146ca21af82023b0b460f813eae3435b4b2eb77
Reviewed-on: http://gerrit.cloudera.org:8080/9063
Reviewed-by: Tim Armstrong <ta...@cloudera.com>
Tested-by: Impala Public Jenkins


Project: http://git-wip-us.apache.org/repos/asf/impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/impala/commit/f562be8c
Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/f562be8c
Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/f562be8c

Branch: refs/heads/master
Commit: f562be8c29a080549fa15e689f795b7a57003154
Parents: 3a68e69
Author: Csaba Ringhofer <cs...@cloudera.com>
Authored: Thu Jan 18 21:06:54 2018 +0100
Committer: Impala Public Jenkins <im...@gerrit.cloudera.org>
Committed: Wed Feb 21 01:33:42 2018 +0000

----------------------------------------------------------------------
 be/src/benchmarks/hash-benchmark.cc          |  28 +++---
 be/src/codegen/codegen-anyval.cc             |  82 +++++++--------
 be/src/codegen/llvm-codegen-test.cc          |  25 ++---
 be/src/codegen/llvm-codegen.cc               | 117 +++++++++-------------
 be/src/codegen/llvm-codegen.h                |  79 +++++++++++----
 be/src/exec/exec-node.cc                     |  10 +-
 be/src/exec/filter-context.cc                |  20 ++--
 be/src/exec/hash-table.cc                    |  68 ++++++-------
 be/src/exec/hdfs-avro-scanner.cc             |  23 ++---
 be/src/exec/hdfs-avro-scanner.h              |   4 +-
 be/src/exec/hdfs-parquet-scanner.cc          |   8 +-
 be/src/exec/hdfs-parquet-scanner.h           |   6 +-
 be/src/exec/hdfs-scanner.cc                  |  59 +++++------
 be/src/exec/partitioned-aggregation-node.cc  |  34 +++----
 be/src/exec/partitioned-hash-join-builder.cc |  20 ++--
 be/src/exec/partitioned-hash-join-builder.h  |   6 +-
 be/src/exec/partitioned-hash-join-node.cc    |  18 ++--
 be/src/exec/text-converter.cc                |  20 ++--
 be/src/exprs/compound-predicates.cc          |   6 +-
 be/src/exprs/scalar-expr.cc                  |  10 +-
 be/src/exprs/scalar-fn-call.cc               |   4 +-
 be/src/exprs/slot-ref.cc                     |  22 ++--
 be/src/runtime/descriptors.cc                |  29 +++---
 be/src/runtime/tuple.cc                      |  38 ++++---
 be/src/runtime/types.cc                      |  12 +--
 be/src/util/tuple-row-compare.cc             |   6 +-
 26 files changed, 359 insertions(+), 395 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/benchmarks/hash-benchmark.cc
----------------------------------------------------------------------
diff --git a/be/src/benchmarks/hash-benchmark.cc b/be/src/benchmarks/hash-benchmark.cc
index fffbbdf..3f605c9 100644
--- a/be/src/benchmarks/hash-benchmark.cc
+++ b/be/src/benchmarks/hash-benchmark.cc
@@ -384,11 +384,11 @@ llvm::Function* CodegenCrcHash(LlvmCodeGen* codegen, bool mixed) {
   string name = mixed ? "HashMixed" : "HashInt";
   LlvmCodeGen::FnPrototype prototype(codegen, name, codegen->void_type());
   prototype.AddArgument(
-      LlvmCodeGen::NamedVariable("rows", codegen->GetType(TYPE_INT)));
+      LlvmCodeGen::NamedVariable("rows", codegen->i32_type()));
   prototype.AddArgument(
       LlvmCodeGen::NamedVariable("data", codegen->ptr_type()));
   prototype.AddArgument(
-      LlvmCodeGen::NamedVariable("results", codegen->GetPtrType(TYPE_INT)));
+      LlvmCodeGen::NamedVariable("results", codegen->i32_ptr_type()));
 
   LlvmBuilder builder(codegen->context());
   llvm::Value* args[3];
@@ -406,41 +406,41 @@ llvm::Function* CodegenCrcHash(LlvmCodeGen* codegen, bool mixed) {
 
   llvm::Value* row_size = NULL;
   if (mixed) {
-    row_size = codegen->GetIntConstant(TYPE_INT,
-      sizeof(int8_t) + sizeof(int32_t) + sizeof(int64_t) + sizeof(StringValue));
+    row_size = codegen->GetI32Constant(
+        sizeof(int8_t) + sizeof(int32_t) + sizeof(int64_t) + sizeof(StringValue));
   } else {
-    row_size = codegen->GetIntConstant(TYPE_INT, fixed_byte_size);
+    row_size = codegen->GetI32Constant(fixed_byte_size);
   }
-  llvm::Value* dummy_len = codegen->GetIntConstant(TYPE_INT, 0);
+  llvm::Value* dummy_len = codegen->GetI32Constant(0);
 
   // Check loop counter
   llvm::Value* counter_check =
-      builder.CreateICmpSGT(args[0], codegen->GetIntConstant(TYPE_INT, 0));
+      builder.CreateICmpSGT(args[0], codegen->GetI32Constant(0));
   builder.CreateCondBr(counter_check, loop_body, loop_exit);
 
   // Loop body
   builder.SetInsertPoint(loop_body);
-  llvm::PHINode* counter = builder.CreatePHI(codegen->GetType(TYPE_INT), 2, "counter");
-  counter->addIncoming(codegen->GetIntConstant(TYPE_INT, 0), loop_start);
+  llvm::PHINode* counter = builder.CreatePHI(codegen->i32_type(), 2, "counter");
+  counter->addIncoming(codegen->GetI32Constant(0), loop_start);
 
   llvm::Value* next_counter =
-      builder.CreateAdd(counter, codegen->GetIntConstant(TYPE_INT, 1));
+      builder.CreateAdd(counter, codegen->GetI32Constant(1));
   counter->addIncoming(next_counter, loop_body);
 
   // Hash the current data
   llvm::Value* offset = builder.CreateMul(counter, row_size);
   llvm::Value* data = builder.CreateGEP(args[1], offset);
 
-  llvm::Value* seed = codegen->GetIntConstant(TYPE_INT, HashUtil::FNV_SEED);
+  llvm::Value* seed = codegen->GetI32Constant(HashUtil::FNV_SEED);
   seed =
       builder.CreateCall(fixed_fn, llvm::ArrayRef<llvm::Value*>({data, dummy_len, seed}));
 
   // Get the string data
   if (mixed) {
     llvm::Value* string_data =
-        builder.CreateGEP(data, codegen->GetIntConstant(TYPE_INT, fixed_byte_size));
-    llvm::Value* string_val =
-        builder.CreateBitCast(string_data, codegen->GetPtrType(TYPE_STRING));
+        builder.CreateGEP(data, codegen->GetI32Constant(fixed_byte_size));
+    llvm::Value* string_val = builder.CreateBitCast(string_data,
+            codegen->GetSlotPtrType(TYPE_STRING));
     llvm::Value* str_ptr = builder.CreateStructGEP(NULL, string_val, 0);
     llvm::Value* str_len = builder.CreateStructGEP(NULL, string_val, 1);
     str_ptr = builder.CreateLoad(str_ptr);

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/codegen/codegen-anyval.cc
----------------------------------------------------------------------
diff --git a/be/src/codegen/codegen-anyval.cc b/be/src/codegen/codegen-anyval.cc
index f7edec2..6575cfd 100644
--- a/be/src/codegen/codegen-anyval.cc
+++ b/be/src/codegen/codegen-anyval.cc
@@ -38,31 +38,31 @@ const char* CodegenAnyVal::LLVM_DECIMALVAL_NAME   = "struct.impala_udf::DecimalV
 llvm::Type* CodegenAnyVal::GetLoweredType(LlvmCodeGen* cg, const ColumnType& type) {
   switch(type.type) {
     case TYPE_BOOLEAN: // i16
-      return cg->smallint_type();
+      return cg->i16_type();
     case TYPE_TINYINT: // i16
-      return cg->smallint_type();
+      return cg->i16_type();
     case TYPE_SMALLINT: // i32
-      return cg->int_type();
+      return cg->i32_type();
     case TYPE_INT: // i64
-      return cg->bigint_type();
+      return cg->i64_type();
     case TYPE_BIGINT: // { i8, i64 }
-      return llvm::StructType::get(cg->tinyint_type(), cg->bigint_type(), NULL);
+      return llvm::StructType::get(cg->i8_type(), cg->i64_type(), NULL);
     case TYPE_FLOAT: // i64
-      return cg->bigint_type();
+      return cg->i64_type();
     case TYPE_DOUBLE: // { i8, double }
-      return llvm::StructType::get(cg->tinyint_type(), cg->double_type(), NULL);
+      return llvm::StructType::get(cg->i8_type(), cg->double_type(), NULL);
     case TYPE_STRING: // { i64, i8* }
     case TYPE_VARCHAR: // { i64, i8* }
     case TYPE_FIXED_UDA_INTERMEDIATE: // { i64, i8* }
-      return llvm::StructType::get(cg->bigint_type(), cg->ptr_type(), NULL);
+      return llvm::StructType::get(cg->i64_type(), cg->ptr_type(), NULL);
     case TYPE_CHAR:
       DCHECK(false) << "NYI:" << type.DebugString();
       return NULL;
     case TYPE_TIMESTAMP: // { i64, i64 }
-      return llvm::StructType::get(cg->bigint_type(), cg->bigint_type(), NULL);
+      return llvm::StructType::get(cg->i64_type(), cg->i64_type(), NULL);
     case TYPE_DECIMAL: // %"struct.impala_udf::DecimalVal" (isn't lowered)
                        // = { {i8}, [15 x i8], {i128} }
-      return cg->GetType(LLVM_DECIMALVAL_NAME);
+      return cg->GetNamedType(LLVM_DECIMALVAL_NAME);
     default:
       DCHECK(false) << "Unsupported type: " << type;
       return NULL;
@@ -78,39 +78,39 @@ llvm::Type* CodegenAnyVal::GetUnloweredType(LlvmCodeGen* cg, const ColumnType& t
   llvm::Type* result;
   switch(type.type) {
     case TYPE_BOOLEAN:
-      result = cg->GetType(LLVM_BOOLEANVAL_NAME);
+      result = cg->GetNamedType(LLVM_BOOLEANVAL_NAME);
       break;
     case TYPE_TINYINT:
-      result = cg->GetType(LLVM_TINYINTVAL_NAME);
+      result = cg->GetNamedType(LLVM_TINYINTVAL_NAME);
       break;
     case TYPE_SMALLINT:
-      result = cg->GetType(LLVM_SMALLINTVAL_NAME);
+      result = cg->GetNamedType(LLVM_SMALLINTVAL_NAME);
       break;
     case TYPE_INT:
-      result = cg->GetType(LLVM_INTVAL_NAME);
+      result = cg->GetNamedType(LLVM_INTVAL_NAME);
       break;
     case TYPE_BIGINT:
-      result = cg->GetType(LLVM_BIGINTVAL_NAME);
+      result = cg->GetNamedType(LLVM_BIGINTVAL_NAME);
       break;
     case TYPE_FLOAT:
-      result = cg->GetType(LLVM_FLOATVAL_NAME);
+      result = cg->GetNamedType(LLVM_FLOATVAL_NAME);
       break;
     case TYPE_DOUBLE:
-      result = cg->GetType(LLVM_DOUBLEVAL_NAME);
+      result = cg->GetNamedType(LLVM_DOUBLEVAL_NAME);
       break;
     case TYPE_STRING:
     case TYPE_VARCHAR:
     case TYPE_FIXED_UDA_INTERMEDIATE:
-      result = cg->GetType(LLVM_STRINGVAL_NAME);
+      result = cg->GetNamedType(LLVM_STRINGVAL_NAME);
       break;
     case TYPE_CHAR:
       DCHECK(false) << "NYI:" << type.DebugString();
       return NULL;
     case TYPE_TIMESTAMP:
-      result = cg->GetType(LLVM_TIMESTAMPVAL_NAME);
+      result = cg->GetNamedType(LLVM_TIMESTAMPVAL_NAME);
       break;
     case TYPE_DECIMAL:
-      result = cg->GetType(LLVM_DECIMALVAL_NAME);
+      result = cg->GetNamedType(LLVM_DECIMALVAL_NAME);
       break;
     default:
       DCHECK(false) << "Unsupported type: " << type;
@@ -134,7 +134,7 @@ llvm::Value* CodegenAnyVal::CreateCall(LlvmCodeGen* cg, LlvmBuilder* builder,
     llvm::Function::arg_iterator ret_arg = fn->arg_begin();
     DCHECK(ret_arg->getType()->isPointerTy());
     llvm::Type* ret_type = ret_arg->getType()->getPointerElementType();
-    DCHECK_EQ(ret_type, cg->GetType(LLVM_DECIMALVAL_NAME));
+    DCHECK_EQ(ret_type, cg->GetNamedType(LLVM_DECIMALVAL_NAME));
 
     // We need to pass a DecimalVal pointer to 'fn' that will be populated with the result
     // value. Use 'result_ptr' if specified, otherwise alloca one.
@@ -189,15 +189,15 @@ llvm::Value* CodegenAnyVal::GetIsNull(const char* name) const {
     case TYPE_DOUBLE: {
       // Lowered type is of form { i8, * }. Get the i8 value.
       llvm::Value* is_null_i8 = builder_->CreateExtractValue(value_, 0);
-      DCHECK(is_null_i8->getType() == codegen_->tinyint_type());
-      return builder_->CreateTrunc(is_null_i8, codegen_->boolean_type(), name);
+      DCHECK(is_null_i8->getType() == codegen_->i8_type());
+      return builder_->CreateTrunc(is_null_i8, codegen_->bool_type(), name);
     }
     case TYPE_DECIMAL: {
       // Lowered type is of the form { {i8}, ... }
       uint32_t idxs[] = {0, 0};
       llvm::Value* is_null_i8 = builder_->CreateExtractValue(value_, idxs);
-      DCHECK(is_null_i8->getType() == codegen_->tinyint_type());
-      return builder_->CreateTrunc(is_null_i8, codegen_->boolean_type(), name);
+      DCHECK(is_null_i8->getType() == codegen_->i8_type());
+      return builder_->CreateTrunc(is_null_i8, codegen_->bool_type(), name);
     }
     case TYPE_STRING:
     case TYPE_VARCHAR:
@@ -205,8 +205,8 @@ llvm::Value* CodegenAnyVal::GetIsNull(const char* name) const {
     case TYPE_TIMESTAMP: {
       // Lowered type is of form { i64, *}. Get the first byte of the i64 value.
       llvm::Value* v = builder_->CreateExtractValue(value_, 0);
-      DCHECK(v->getType() == codegen_->bigint_type());
-      return builder_->CreateTrunc(v, codegen_->boolean_type(), name);
+      DCHECK(v->getType() == codegen_->i64_type());
+      return builder_->CreateTrunc(v, codegen_->bool_type(), name);
     }
     case TYPE_CHAR:
       DCHECK(false) << "NYI:" << type_.DebugString();
@@ -217,7 +217,7 @@ llvm::Value* CodegenAnyVal::GetIsNull(const char* name) const {
     case TYPE_INT:
     case TYPE_FLOAT:
       // Lowered type is an integer. Get the first byte.
-      return builder_->CreateTrunc(value_, codegen_->boolean_type(), name);
+      return builder_->CreateTrunc(value_, codegen_->bool_type(), name);
     default:
       DCHECK(false);
       return NULL;
@@ -230,7 +230,7 @@ void CodegenAnyVal::SetIsNull(llvm::Value* is_null) {
     case TYPE_DOUBLE: {
       // Lowered type is of form { i8, * }. Set the i8 value to 'is_null'.
       llvm::Value* is_null_ext =
-          builder_->CreateZExt(is_null, codegen_->tinyint_type(), "is_null_ext");
+          builder_->CreateZExt(is_null, codegen_->i8_type(), "is_null_ext");
       value_ = builder_->CreateInsertValue(value_, is_null_ext, 0, name_);
       break;
     }
@@ -238,7 +238,7 @@ void CodegenAnyVal::SetIsNull(llvm::Value* is_null) {
       // Lowered type is of form { {i8}, [15 x i8], {i128} }. Set the i8 value to
       // 'is_null'.
       llvm::Value* is_null_ext =
-          builder_->CreateZExt(is_null, codegen_->tinyint_type(), "is_null_ext");
+          builder_->CreateZExt(is_null, codegen_->i8_type(), "is_null_ext");
       // Index into the {i8} struct as well as the outer struct.
       uint32_t idxs[] = {0, 0};
       value_ = builder_->CreateInsertValue(value_, is_null_ext, idxs, name_);
@@ -318,7 +318,8 @@ llvm::Value* CodegenAnyVal::GetVal(const char* name) {
       // different width int types.)
       uint32_t idxs[] = {2, 0};
       llvm::Value* val = builder_->CreateExtractValue(value_, idxs, name);
-      return builder_->CreateTrunc(val, codegen_->GetType(type_), name);
+      return builder_->CreateTrunc(val,
+          codegen_->GetSlotType(type_), name);
     }
     default:
       DCHECK(false) << "Unsupported type: " << type_;
@@ -346,7 +347,7 @@ void CodegenAnyVal::SetVal(llvm::Value* val) {
     }
     case TYPE_FLOAT:
       // Same as above, but we must cast 'val' to an integer type.
-      val = builder_->CreateBitCast(val, codegen_->int_type());
+      val = builder_->CreateBitCast(val, codegen_->i32_type());
       value_ = SetHighBits(32, val, value_, name_);
       break;
     case TYPE_BIGINT:
@@ -485,10 +486,11 @@ llvm::Value* CodegenAnyVal::GetUnloweredPtr(const string& name) const {
 void CodegenAnyVal::LoadFromNativePtr(llvm::Value* raw_val_ptr) {
   DCHECK(raw_val_ptr->getType()->isPointerTy());
   llvm::Type* raw_val_type = raw_val_ptr->getType()->getPointerElementType();
-  DCHECK_EQ(raw_val_type, codegen_->GetType(type_))
+  DCHECK_EQ(raw_val_type, codegen_->GetSlotType(type_))
       << endl
       << LlvmCodeGen::Print(raw_val_ptr) << endl
-      << type_ << " => " << LlvmCodeGen::Print(codegen_->GetType(type_));
+      << type_ << " => " << LlvmCodeGen::Print(
+          codegen_->GetSlotType(type_));
   switch (type_.type) {
     case TYPE_STRING:
     case TYPE_VARCHAR: {
@@ -501,7 +503,7 @@ void CodegenAnyVal::LoadFromNativePtr(llvm::Value* raw_val_ptr) {
     case TYPE_FIXED_UDA_INTERMEDIATE: {
       // Convert fixed-size slot to StringVal.
       SetPtr(builder_->CreateBitCast(raw_val_ptr, codegen_->ptr_type()));
-      SetLen(codegen_->GetIntConstant(TYPE_INT, type_.len));
+      SetLen(codegen_->GetI32Constant(type_.len));
       break;
     }
     case TYPE_CHAR:
@@ -544,7 +546,7 @@ void CodegenAnyVal::LoadFromNativePtr(llvm::Value* raw_val_ptr) {
 }
 
 void CodegenAnyVal::StoreToNativePtr(llvm::Value* raw_val_ptr, llvm::Value* pool_val) {
-  llvm::Type* raw_type = codegen_->GetType(type_);
+  llvm::Type* raw_type = codegen_->GetSlotType(type_);
   switch (type_.type) {
     case TYPE_STRING:
     case TYPE_VARCHAR: {
@@ -602,8 +604,8 @@ void CodegenAnyVal::StoreToNativePtr(llvm::Value* raw_val_ptr, llvm::Value* pool
 }
 
 llvm::Value* CodegenAnyVal::ToNativePtr(llvm::Value* pool_val) {
-  llvm::Value* native_ptr =
-      codegen_->CreateEntryBlockAlloca(*builder_, codegen_->GetType(type_));
+  llvm::Value* native_ptr = codegen_->CreateEntryBlockAlloca(*builder_,
+      codegen_->GetSlotType(type_));
   StoreToNativePtr(native_ptr, pool_val);
   return native_ptr;
 }
@@ -747,7 +749,7 @@ llvm::Value* CodegenAnyVal::Compare(CodegenAnyVal* other, const char* name) {
   llvm::Value* void_v2 = builder_->CreateBitCast(v2, codegen_->ptr_type());
   // Create a global constant of the values' ColumnType. It needs to be a constant
   // for constant propagation and dead code elimination in 'compare_fn'.
-  llvm::Type* col_type = codegen_->GetType(ColumnType::LLVM_CLASS_NAME);
+  llvm::Type* col_type = codegen_->GetStructType<ColumnType>();
   llvm::Constant* type_ptr =
       codegen_->ConstantToGVPtr(col_type, type_.ToIR(codegen_), "type");
   llvm::Function* compare_fn =
@@ -797,7 +799,7 @@ llvm::Value* CodegenAnyVal::GetNullVal(LlvmCodeGen* codegen, llvm::Type* val_typ
   if (val_type->isStructTy()) {
     llvm::StructType* struct_type = llvm::cast<llvm::StructType>(val_type);
     if (struct_type->getNumElements() == 3) {
-      DCHECK_EQ(val_type, codegen->GetType(LLVM_DECIMALVAL_NAME));
+      DCHECK_EQ(val_type, codegen->GetNamedType(LLVM_DECIMALVAL_NAME));
       // Return the struct { {1}, 0, 0 } (the 'is_null' byte, i.e. the first value's first
       // byte, is set to 1, the other bytes don't matter)
       llvm::StructType* anyval_struct_type =

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/codegen/llvm-codegen-test.cc
----------------------------------------------------------------------
diff --git a/be/src/codegen/llvm-codegen-test.cc b/be/src/codegen/llvm-codegen-test.cc
index 9069898..dbb190a 100644
--- a/be/src/codegen/llvm-codegen-test.cc
+++ b/be/src/codegen/llvm-codegen-test.cc
@@ -160,9 +160,9 @@ llvm::Function* CodegenInnerLoop(
   codegen->CodegenDebugTrace(&builder, "Jitted\n");
 
   // Store &jitted_counter as a constant.
-  llvm::Value* const_delta = llvm::ConstantInt::get(context, llvm::APInt(64, delta));
+  llvm::Value* const_delta = codegen->GetI64Constant(delta);
   llvm::Value* counter_ptr =
-      codegen->CastPtrToLlvmPtr(codegen->GetPtrType(TYPE_BIGINT), jitted_counter);
+      codegen->CastPtrToLlvmPtr(codegen->i64_ptr_type(), jitted_counter);
   llvm::Value* loaded_counter = builder.CreateLoad(counter_ptr);
   llvm::Value* incremented_value = builder.CreateAdd(loaded_counter, const_delta);
   builder.CreateStore(incremented_value, counter_ptr);
@@ -284,10 +284,11 @@ TEST_F(LlvmCodeGenTest, ReplaceFnCall) {
 //   ret i32 %len
 // }
 llvm::Function* CodegenStringTest(LlvmCodeGen* codegen) {
-  llvm::PointerType* string_val_ptr_type = codegen->GetPtrType(TYPE_STRING);
+  llvm::PointerType* string_val_ptr_type =
+      codegen->GetSlotPtrType(TYPE_STRING);
   EXPECT_TRUE(string_val_ptr_type != NULL);
 
-  LlvmCodeGen::FnPrototype prototype(codegen, "StringTest", codegen->GetType(TYPE_INT));
+  LlvmCodeGen::FnPrototype prototype(codegen, "StringTest", codegen->i32_type());
   prototype.AddArgument(LlvmCodeGen::NamedVariable("str", string_val_ptr_type));
   LlvmBuilder builder(codegen->context());
 
@@ -297,15 +298,15 @@ llvm::Function* CodegenStringTest(LlvmCodeGen* codegen) {
   // strval->ptr[0] = 'A'
   llvm::Value* str_ptr = builder.CreateStructGEP(NULL, str, 0, "str_ptr");
   llvm::Value* ptr = builder.CreateLoad(str_ptr, "ptr");
-  llvm::Value* first_char_offset[] = {codegen->GetIntConstant(TYPE_INT, 0)};
+  llvm::Value* first_char_offset[] = {codegen->GetI32Constant(0)};
   llvm::Value* first_char_ptr =
       builder.CreateGEP(ptr, first_char_offset, "first_char_ptr");
-  builder.CreateStore(codegen->GetIntConstant(TYPE_TINYINT, 'A'), first_char_ptr);
+  builder.CreateStore(codegen->GetI8Constant('A'), first_char_ptr);
 
   // Update and return old len
   llvm::Value* len_ptr = builder.CreateStructGEP(NULL, str, 1, "len_ptr");
   llvm::Value* len = builder.CreateLoad(len_ptr, "len");
-  builder.CreateStore(codegen->GetIntConstant(TYPE_INT, 1), len_ptr);
+  builder.CreateStore(codegen->GetI32Constant(1), len_ptr);
   builder.CreateRet(len);
 
   return codegen->FinalizeFunction(interop_fn);
@@ -363,7 +364,7 @@ TEST_F(LlvmCodeGenTest, MemcpyTest) {
   LlvmCodeGen::FnPrototype prototype(codegen.get(), "MemcpyTest", codegen->void_type());
   prototype.AddArgument(LlvmCodeGen::NamedVariable("dest", codegen->ptr_type()));
   prototype.AddArgument(LlvmCodeGen::NamedVariable("src", codegen->ptr_type()));
-  prototype.AddArgument(LlvmCodeGen::NamedVariable("n", codegen->GetType(TYPE_INT)));
+  prototype.AddArgument(LlvmCodeGen::NamedVariable("n", codegen->i32_type()));
 
   LlvmBuilder builder(codegen->context());
 
@@ -412,8 +413,8 @@ TEST_F(LlvmCodeGenTest, HashTest) {
         codegen->CastPtrToLlvmPtr(codegen->ptr_type(), const_cast<char*>(data1));
     llvm::Value* llvm_data2 =
         codegen->CastPtrToLlvmPtr(codegen->ptr_type(), const_cast<char*>(data2));
-    llvm::Value* llvm_len1 = codegen->GetIntConstant(TYPE_INT, strlen(data1));
-    llvm::Value* llvm_len2 = codegen->GetIntConstant(TYPE_INT, strlen(data2));
+    llvm::Value* llvm_len1 = codegen->GetI32Constant(strlen(data1));
+    llvm::Value* llvm_len2 = codegen->GetI32Constant(strlen(data2));
 
     uint32_t expected_hash = 0;
     expected_hash = HashUtil::Hash(data1, strlen(data1), expected_hash);
@@ -423,7 +424,7 @@ TEST_F(LlvmCodeGenTest, HashTest) {
     // Create a codegen'd function that hashes all the types and returns the results.
     // The tuple/values to hash are baked into the codegen for simplicity.
     LlvmCodeGen::FnPrototype prototype(
-        codegen.get(), "HashTest", codegen->GetType(TYPE_INT));
+        codegen.get(), "HashTest", codegen->i32_type());
     LlvmBuilder builder(codegen->context());
 
     // Test both byte-size specific hash functions and the generic loop hash function
@@ -436,7 +437,7 @@ TEST_F(LlvmCodeGenTest, HashTest) {
     ASSERT_TRUE(data2_hash_fn != NULL);
     ASSERT_TRUE(generic_hash_fn != NULL);
 
-    llvm::Value* seed = codegen->GetIntConstant(TYPE_INT, 0);
+    llvm::Value* seed = codegen->GetI32Constant(0);
     seed = builder.CreateCall(
         data1_hash_fn, llvm::ArrayRef<llvm::Value*>({llvm_data1, llvm_len1, seed}));
     seed = builder.CreateCall(

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/codegen/llvm-codegen.cc
----------------------------------------------------------------------
diff --git a/be/src/codegen/llvm-codegen.cc b/be/src/codegen/llvm-codegen.cc
index e1a606c..892b395 100644
--- a/be/src/codegen/llvm-codegen.cc
+++ b/be/src/codegen/llvm-codegen.cc
@@ -355,10 +355,10 @@ Status LlvmCodeGen::CreateImpalaCodegen(RuntimeState* state,
   SCOPED_TIMER(codegen->prepare_module_timer_);
 
   // Get type for StringValue
-  codegen->string_value_type_ = codegen->GetType(StringValue::LLVM_CLASS_NAME);
+  codegen->string_value_type_ = codegen->GetStructType<StringValue>();
 
   // Get type for TimestampValue
-  codegen->timestamp_value_type_ = codegen->GetType(TimestampValue::LLVM_CLASS_NAME);
+  codegen->timestamp_value_type_ = codegen->GetStructType<TimestampValue>();
 
   // Verify size is correct
   const llvm::DataLayout& data_layout = codegen->execution_engine()->getDataLayout();
@@ -411,7 +411,7 @@ Status LlvmCodeGen::Init(unique_ptr<llvm::Module> module) {
   module_->setDataLayout(execution_engine_->getDataLayout());
 
   void_type_ = llvm::Type::getVoidTy(context());
-  ptr_type_ = llvm::PointerType::get(GetType(TYPE_TINYINT), 0);
+  ptr_type_ = llvm::PointerType::get(i8_type(), 0);
   true_value_ = llvm::ConstantInt::get(context(), llvm::APInt(1, true, true));
   false_value_ = llvm::ConstantInt::get(context(), llvm::APInt(1, false, true));
 
@@ -479,30 +479,30 @@ string LlvmCodeGen::GetIR(bool full_module) const {
   return str;
 }
 
-llvm::Type* LlvmCodeGen::GetType(const ColumnType& type) {
+llvm::Type* LlvmCodeGen::GetSlotType(const ColumnType& type) {
   switch (type.type) {
     case TYPE_NULL:
       return llvm::Type::getInt1Ty(context());
     case TYPE_BOOLEAN:
-      return llvm::Type::getInt1Ty(context());
+      return bool_type();
     case TYPE_TINYINT:
-      return llvm::Type::getInt8Ty(context());
+      return i8_type();
     case TYPE_SMALLINT:
-      return llvm::Type::getInt16Ty(context());
+      return i16_type();
     case TYPE_INT:
-      return llvm::Type::getInt32Ty(context());
+      return i32_type();
     case TYPE_BIGINT:
-      return llvm::Type::getInt64Ty(context());
+      return i64_type();
     case TYPE_FLOAT:
-      return llvm::Type::getFloatTy(context());
+      return float_type();
     case TYPE_DOUBLE:
-      return llvm::Type::getDoubleTy(context());
+      return double_type();
     case TYPE_STRING:
     case TYPE_VARCHAR:
       return string_value_type_;
     case TYPE_FIXED_UDA_INTERMEDIATE:
       // Represent this as an array of bytes.
-      return llvm::ArrayType::get(GetType(TYPE_TINYINT), type.len);
+      return llvm::ArrayType::get(i8_type(), type.len);
     case TYPE_CHAR:
       // IMPALA-3207: Codegen for CHAR is not yet implemented, this should not
       // be called for TYPE_CHAR.
@@ -518,18 +518,18 @@ llvm::Type* LlvmCodeGen::GetType(const ColumnType& type) {
   }
 }
 
-llvm::PointerType* LlvmCodeGen::GetPtrType(const ColumnType& type) {
-  return llvm::PointerType::get(GetType(type), 0);
+llvm::PointerType* LlvmCodeGen::GetSlotPtrType(const ColumnType& type) {
+  return llvm::PointerType::get(GetSlotType(type), 0);
 }
 
-llvm::Type* LlvmCodeGen::GetType(const string& name) {
+llvm::Type* LlvmCodeGen::GetNamedType(const string& name) {
   llvm::Type* type = module_->getTypeByName(name);
   DCHECK(type != NULL) << name;
   return type;
 }
 
-llvm::PointerType* LlvmCodeGen::GetPtrType(const string& name) {
-  llvm::Type* type = GetType(name);
+llvm::PointerType* LlvmCodeGen::GetNamedPtrType(const string& name) {
+  llvm::Type* type = GetNamedType(name);
   DCHECK(type != NULL) << name;
   return llvm::PointerType::get(type, 0);
 }
@@ -542,34 +542,17 @@ llvm::PointerType* LlvmCodeGen::GetPtrPtrType(llvm::Type* type) {
   return llvm::PointerType::get(llvm::PointerType::get(type, 0), 0);
 }
 
-llvm::PointerType* LlvmCodeGen::GetPtrPtrType(const string& name) {
-  return llvm::PointerType::get(GetPtrType(name), 0);
+llvm::PointerType* LlvmCodeGen::GetNamedPtrPtrType(const string& name) {
+  return llvm::PointerType::get(GetNamedPtrType(name), 0);
 }
 
 // Llvm doesn't let you create a PointerValue from a c-side ptr.  Instead
 // cast it to an int and then to 'type'.
 llvm::Value* LlvmCodeGen::CastPtrToLlvmPtr(llvm::Type* type, const void* ptr) {
-  llvm::Constant* const_int =
-      llvm::ConstantInt::get(llvm::Type::getInt64Ty(context()), (int64_t)ptr);
+  llvm::Constant* const_int = GetI64Constant((int64_t)ptr);
   return llvm::ConstantExpr::getIntToPtr(const_int, type);
 }
 
-llvm::Constant* LlvmCodeGen::GetIntConstant(PrimitiveType type, uint64_t val) {
-  switch (type) {
-    case TYPE_TINYINT:
-      return llvm::ConstantInt::get(context(), llvm::APInt(8, val));
-    case TYPE_SMALLINT:
-      return llvm::ConstantInt::get(context(), llvm::APInt(16, val));
-    case TYPE_INT:
-      return llvm::ConstantInt::get(context(), llvm::APInt(32, val));
-    case TYPE_BIGINT:
-      return llvm::ConstantInt::get(context(), llvm::APInt(64, val));
-    default:
-      DCHECK(false);
-      return NULL;
-  }
-}
-
 llvm::Constant* LlvmCodeGen::GetIntConstant(
     int num_bytes, uint64_t low_bits, uint64_t high_bits) {
   DCHECK_GE(num_bytes, 1);
@@ -593,7 +576,7 @@ llvm::AllocaInst* LlvmCodeGen::CreateEntryBlockAlloca(
     llvm::Function* f, const NamedVariable& var) {
   llvm::IRBuilder<> tmp(&f->getEntryBlock(), f->getEntryBlock().begin());
   llvm::AllocaInst* alloca = tmp.CreateAlloca(var.type, NULL, var.name.c_str());
-  if (var.type == GetType(CodegenAnyVal::LLVM_DECIMALVAL_NAME)) {
+  if (var.type == GetNamedType(CodegenAnyVal::LLVM_DECIMALVAL_NAME)) {
     // Generated functions may manipulate DecimalVal arguments via SIMD instructions such
     // as 'movaps' that require 16-byte memory alignment. LLVM uses 8-byte alignment by
     // default, so explicitly set the alignment for DecimalVals.
@@ -613,7 +596,7 @@ llvm::AllocaInst* LlvmCodeGen::CreateEntryBlockAlloca(const LlvmBuilder& builder
   llvm::Function* fn = builder.GetInsertBlock()->getParent();
   llvm::IRBuilder<> tmp(&fn->getEntryBlock(), fn->getEntryBlock().begin());
   llvm::AllocaInst* alloca =
-      tmp.CreateAlloca(type, GetIntConstant(TYPE_INT, num_entries), name);
+      tmp.CreateAlloca(type, GetI32Constant(num_entries), name);
   alloca->setAlignment(alignment);
   return alloca;
 }
@@ -837,7 +820,7 @@ Status LlvmCodeGen::LoadFunction(const TFunction& fn, const std::string& symbol,
     }
 
     // The "FunctionContext*" argument.
-    prototype.AddArgument("ctx", GetPtrType("class.impala_udf::FunctionContext"));
+    prototype.AddArgument("ctx", GetNamedPtrType("class.impala_udf::FunctionContext"));
 
     // The "fixed" arguments for the UDF function, followed by the variable arguments,
     // if any.
@@ -847,7 +830,7 @@ Status LlvmCodeGen::LoadFunction(const TFunction& fn, const std::string& symbol,
     }
 
     if (has_varargs) {
-      prototype.AddArgument("num_var_arg", GetType(TYPE_INT));
+      prototype.AddArgument("num_var_arg", i32_type());
       // Get the vararg type from the first vararg.
       prototype.AddArgument(
           "var_arg", CodegenAnyVal::GetUnloweredPtrType(this, arg_types[num_fixed_args]));
@@ -935,8 +918,7 @@ int LlvmCodeGen::ReplaceCallSitesWithValue(
 
 int LlvmCodeGen::ReplaceCallSitesWithBoolConst(llvm::Function* caller, bool constant,
     const string& target_name) {
-  llvm::Value* replacement =
-      llvm::ConstantInt::get(llvm::Type::getInt1Ty(context()), constant);
+  llvm::Value* replacement = GetBoolConstant(constant);
   return ReplaceCallSitesWithValue(caller, replacement, target_name);
 }
 
@@ -975,7 +957,7 @@ int LlvmCodeGen::InlineConstFnAttrs(const FunctionContext::TypeDesc& ret_type,
     int i_val = static_cast<int>(i_arg->getSExtValue());
     DCHECK(state_ != nullptr);
     // All supported constants are currently integers.
-    call_instr->replaceAllUsesWith(llvm::ConstantInt::get(GetType(TYPE_INT),
+    call_instr->replaceAllUsesWith(GetI32Constant(
         FunctionContextImpl::GetConstFnAttr(state_, ret_type, arg_types, t_val, i_val)));
     call_instr->eraseFromParent();
     ++replaced;
@@ -1247,7 +1229,7 @@ void LlvmCodeGen::DestroyModule() {
 void LlvmCodeGen::AddFunctionToJit(llvm::Function* fn, void** fn_ptr) {
   DCHECK(finalized_functions_.find(fn) != finalized_functions_.end())
       << "Attempted to add a non-finalized function to Jit: " << fn->getName().str();
-  llvm::Type* decimal_val_type = GetType(CodegenAnyVal::LLVM_DECIMALVAL_NAME);
+  llvm::Type* decimal_val_type = GetNamedType(CodegenAnyVal::LLVM_DECIMALVAL_NAME);
   if (fn->getReturnType() == decimal_val_type) {
     // Per the x86 calling convention ABI, DecimalVals should be returned via an extra
     // first DecimalVal* argument. We generate non-compliant functions that return the
@@ -1400,7 +1382,7 @@ void LlvmCodeGen::CodegenMinMax(LlvmBuilder* builder, const ColumnType& type,
 Status LlvmCodeGen::LoadIntrinsics() {
   // Load memcpy
   {
-    llvm::Type* types[] = {ptr_type(), ptr_type(), GetType(TYPE_INT)};
+    llvm::Type* types[] = {ptr_type(), ptr_type(), i32_type()};
     llvm::Function* fn =
         llvm::Intrinsic::getDeclaration(module_, llvm::Intrinsic::memcpy, types);
     if (fn == NULL) {
@@ -1440,7 +1422,7 @@ void LlvmCodeGen::CodegenMemcpy(
     LlvmBuilder* builder, llvm::Value* dst, llvm::Value* src, int size) {
   DCHECK_GE(size, 0);
   if (size == 0) return;
-  llvm::Value* size_val = GetIntConstant(TYPE_BIGINT, size);
+  llvm::Value* size_val = GetI64Constant(size);
   CodegenMemcpy(builder, dst, src, size_val);
 }
 
@@ -1456,15 +1438,14 @@ void LlvmCodeGen::CodegenMemset(
   DCHECK(dst->getType()->isPointerTy()) << Print(dst);
   DCHECK_GE(size, 0);
   if (size == 0) return;
-  llvm::Value* value_const = GetIntConstant(TYPE_TINYINT, value);
+  llvm::Value* value_const = GetI8Constant(value);
   builder->CreateMemSet(dst, value_const, size, /* no alignment */ 0);
 }
 
 void LlvmCodeGen::CodegenClearNullBits(
     LlvmBuilder* builder, llvm::Value* tuple_ptr, const TupleDescriptor& tuple_desc) {
   llvm::Value* int8_ptr = builder->CreateBitCast(tuple_ptr, ptr_type(), "int8_ptr");
-  llvm::Value* null_bytes_offset =
-      llvm::ConstantInt::get(int_type(), tuple_desc.null_bytes_offset());
+  llvm::Value* null_bytes_offset = GetI32Constant(tuple_desc.null_bytes_offset());
   llvm::Value* null_bytes_ptr =
       builder->CreateInBoundsGEP(int8_ptr, null_bytes_offset, "null_bytes_ptr");
   CodegenMemset(builder, null_bytes_ptr, 0, tuple_desc.num_null_bytes());
@@ -1475,13 +1456,13 @@ llvm::Value* LlvmCodeGen::CodegenMemPoolAllocate(LlvmBuilder* builder,
   DCHECK(pool_val != nullptr);
   DCHECK(size_val->getType()->isIntegerTy());
   DCHECK_LE(size_val->getType()->getIntegerBitWidth(), 64);
-  DCHECK_EQ(pool_val->getType(), GetPtrType(MemPool::LLVM_CLASS_NAME));
+  DCHECK_EQ(pool_val->getType(), GetStructPtrType<MemPool>());
   // Extend 'size_val' to i64 if necessary
   if (size_val->getType()->getIntegerBitWidth() < 64) {
-    size_val = builder->CreateSExt(size_val, bigint_type());
+    size_val = builder->CreateSExt(size_val, i64_type());
   }
   llvm::Function* allocate_fn = GetFunction(IRFunction::MEMPOOL_ALLOCATE, false);
-  llvm::Value* alignment = GetIntConstant(TYPE_INT, MemPool::DEFAULT_ALIGNMENT);
+  llvm::Value* alignment = GetI32Constant(MemPool::DEFAULT_ALIGNMENT);
   llvm::Value* fn_args[] = {pool_val, size_val, alignment};
   return builder->CreateCall(allocate_fn, fn_args, name);
 }
@@ -1544,10 +1525,10 @@ llvm::Function* LlvmCodeGen::GetHashFunction(int num_bytes) {
     // Generate a function to hash these bytes
     stringstream ss;
     ss << "CrcHash" << num_bytes;
-    FnPrototype prototype(this, ss.str(), GetType(TYPE_INT));
+    FnPrototype prototype(this, ss.str(), i32_type());
     prototype.AddArgument(LlvmCodeGen::NamedVariable("data", ptr_type()));
-    prototype.AddArgument(LlvmCodeGen::NamedVariable("len", GetType(TYPE_INT)));
-    prototype.AddArgument(LlvmCodeGen::NamedVariable("seed", GetType(TYPE_INT)));
+    prototype.AddArgument(LlvmCodeGen::NamedVariable("len", i32_type()));
+    prototype.AddArgument(LlvmCodeGen::NamedVariable("seed", i32_type()));
 
     llvm::Value* args[3];
     LlvmBuilder builder(context());
@@ -1562,38 +1543,38 @@ llvm::Function* LlvmCodeGen::GetHashFunction(int num_bytes) {
 
     // Generate the crc instructions starting with the highest number of bytes
     if (num_bytes >= 8) {
-      llvm::Value* result_64 = builder.CreateZExt(result, GetType(TYPE_BIGINT));
-      llvm::Value* ptr = builder.CreateBitCast(data, GetPtrType(TYPE_BIGINT));
+      llvm::Value* result_64 = builder.CreateZExt(result, i64_type());
+      llvm::Value* ptr = builder.CreateBitCast(data, i64_ptr_type());
       int i = 0;
       while (num_bytes >= 8) {
-        llvm::Value* index[] = {GetIntConstant(TYPE_INT, i++)};
+        llvm::Value* index[] = {GetI32Constant(i++)};
         llvm::Value* d = builder.CreateLoad(builder.CreateInBoundsGEP(ptr, index));
         result_64 =
             builder.CreateCall(crc64_fn, llvm::ArrayRef<llvm::Value*>({result_64, d}));
         num_bytes -= 8;
       }
-      result = builder.CreateTrunc(result_64, GetType(TYPE_INT));
-      llvm::Value* index[] = {GetIntConstant(TYPE_INT, i * 8)};
+      result = builder.CreateTrunc(result_64, i32_type());
+      llvm::Value* index[] = {GetI32Constant(i * 8)};
       // Update data to past the 8-byte chunks
       data = builder.CreateInBoundsGEP(data, index);
     }
 
     if (num_bytes >= 4) {
       DCHECK_LT(num_bytes, 8);
-      llvm::Value* ptr = builder.CreateBitCast(data, GetPtrType(TYPE_INT));
+      llvm::Value* ptr = builder.CreateBitCast(data, i32_ptr_type());
       llvm::Value* d = builder.CreateLoad(ptr);
       result = builder.CreateCall(crc32_fn, llvm::ArrayRef<llvm::Value*>({result, d}));
-      llvm::Value* index[] = {GetIntConstant(TYPE_INT, 4)};
+      llvm::Value* index[] = {GetI32Constant(4)};
       data = builder.CreateInBoundsGEP(data, index);
       num_bytes -= 4;
     }
 
     if (num_bytes >= 2) {
       DCHECK_LT(num_bytes, 4);
-      llvm::Value* ptr = builder.CreateBitCast(data, GetPtrType(TYPE_SMALLINT));
+      llvm::Value* ptr = builder.CreateBitCast(data, i16_ptr_type());
       llvm::Value* d = builder.CreateLoad(ptr);
       result = builder.CreateCall(crc16_fn, llvm::ArrayRef<llvm::Value*>({result, d}));
-      llvm::Value* index[] = {GetIntConstant(TYPE_INT, 2)};
+      llvm::Value* index[] = {GetI16Constant(2)};
       data = builder.CreateInBoundsGEP(data, index);
       num_bytes -= 2;
     }
@@ -1606,7 +1587,7 @@ llvm::Function* LlvmCodeGen::GetHashFunction(int num_bytes) {
     }
     DCHECK_EQ(num_bytes, 0);
 
-    llvm::Value* shift_16 = GetIntConstant(TYPE_INT, 16);
+    llvm::Value* shift_16 = GetI32Constant(16);
     llvm::Value* upper_bits = builder.CreateShl(result, shift_16);
     llvm::Value* lower_bits = builder.CreateLShr(result, shift_16);
     result = builder.CreateOr(upper_bits, lower_bits);
@@ -1631,7 +1612,7 @@ static llvm::Function* GetLenOptimizedHashFn(
     // length with num_bytes.
     fn = codegen->CloneFunction(fn);
     llvm::Value* len_arg = codegen->GetArgument(fn, 1);
-    len_arg->replaceAllUsesWith(codegen->GetIntConstant(TYPE_INT, len));
+    len_arg->replaceAllUsesWith(codegen->GetI32Constant(len));
   }
   return codegen->FinalizeFunction(fn);
 }
@@ -1664,7 +1645,7 @@ llvm::Constant* LlvmCodeGen::ConstantToGVPtr(
   llvm::GlobalVariable* gv = new llvm::GlobalVariable(
       *module_, type, true, llvm::GlobalValue::PrivateLinkage, ir_constant, name);
   return llvm::ConstantExpr::getGetElementPtr(
-      NULL, gv, llvm::ArrayRef<llvm::Constant*>({GetIntConstant(TYPE_INT, 0)}));
+      NULL, gv, llvm::ArrayRef<llvm::Constant*>({GetI32Constant(0)}));
 }
 
 llvm::Constant* LlvmCodeGen::ConstantsToGVArrayPtr(llvm::Type* element_type,

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/codegen/llvm-codegen.h
----------------------------------------------------------------------
diff --git a/be/src/codegen/llvm-codegen.h b/be/src/codegen/llvm-codegen.h
index 33fcdba..268ab6d 100644
--- a/be/src/codegen/llvm-codegen.h
+++ b/be/src/codegen/llvm-codegen.h
@@ -246,24 +246,40 @@ class LlvmCodeGen {
   llvm::PointerType* GetPtrPtrType(llvm::Type* type);
 
   /// Return a pointer to pointer type for 'name' type.
-  llvm::PointerType* GetPtrPtrType(const std::string& name);
+  llvm::PointerType* GetNamedPtrPtrType(const std::string& name);
 
   /// Returns llvm type for Impala's internal representation of this column type,
   /// i.e. the way Impala represents this type in a Tuple.
-  llvm::Type* GetType(const ColumnType& type);
+  llvm::Type* GetSlotType(const ColumnType& type);
 
   /// Return a pointer type to 'type' (e.g. int16_t*)
-  llvm::PointerType* GetPtrType(const ColumnType& type);
+  llvm::PointerType* GetSlotPtrType(const ColumnType& type);
 
   /// Returns the type with 'name'.  This is used to pull types from clang
   /// compiled IR.  The types we generate at runtime are unnamed.
   /// The name is generated by the clang compiler in this form:
   /// <class/struct>.<namespace>::<class name>.  For example:
   /// "class.impala::AggregationNode"
-  llvm::Type* GetType(const std::string& name);
+  llvm::Type* GetNamedType(const std::string& name);
 
-  /// Returns the pointer type of the type returned by GetType(name)
-  llvm::PointerType* GetPtrType(const std::string& name);
+  /// Returns the pointer type of the type returned by GetNamedType(name)
+  llvm::PointerType* GetNamedPtrType(const std::string& name);
+
+  /// Template versions of GetNamed*Type functions that expect the llvm name of
+  /// type T to be T::LLVM_CLASS_NAME. T must be a struct/class, so GetStructType
+  /// can return llvm::StructType* to avoid casting on the caller side.
+  template<class T>
+  llvm::StructType* GetStructType() {
+    return llvm::cast<llvm::StructType>(GetNamedType(T::LLVM_CLASS_NAME));
+  }
+
+  template<class T>
+  llvm::PointerType* GetStructPtrType() { return GetNamedPtrType(T::LLVM_CLASS_NAME); }
+
+  template<class T>
+  llvm::PointerType* GetStructPtrPtrType() {
+    return GetNamedPtrPtrType(T::LLVM_CLASS_NAME);
+  }
 
   /// Alloca's an instance of the appropriate pointer type and sets it to point at 'v'
   llvm::Value* GetPtrTo(LlvmBuilder* builder, llvm::Value* v, const char* name = "");
@@ -475,9 +491,6 @@ class LlvmCodeGen {
   /// c-code and code-generated IR.  The resulting value will be of 'type'.
   llvm::Value* CastPtrToLlvmPtr(llvm::Type* type, const void* ptr);
 
-  /// Returns the constant 'val' of 'type'.
-  llvm::Constant* GetIntConstant(PrimitiveType type, uint64_t val);
-
   /// Returns a constant int of 'byte_size' bytes based on 'low_bits' and 'high_bits'
   /// which stand for the lower and upper 64-bits of the constant respectively. For
   /// values less than or equal to 64-bits, 'high_bits' is not used. This function
@@ -488,21 +501,43 @@ class LlvmCodeGen {
   llvm::Value* GetStringConstant(LlvmBuilder* builder, char* data, int len);
 
   /// Returns true/false constants (bool type)
-  llvm::Value* true_value() { return true_value_; }
-  llvm::Value* false_value() { return false_value_; }
-  llvm::Value* null_ptr_value() { return llvm::ConstantPointerNull::get(ptr_type()); }
+  llvm::Constant* true_value() { return true_value_; }
+  llvm::Constant* false_value() { return false_value_; }
+  llvm::Constant* null_ptr_value() { return llvm::ConstantPointerNull::get(ptr_type()); }
 
   /// Simple wrappers to reduce code verbosity
-  llvm::Type* boolean_type() { return GetType(TYPE_BOOLEAN); }
-  llvm::Type* tinyint_type() { return GetType(TYPE_TINYINT); }
-  llvm::Type* smallint_type() { return GetType(TYPE_SMALLINT); }
-  llvm::Type* int_type() { return GetType(TYPE_INT); }
-  llvm::Type* bigint_type() { return GetType(TYPE_BIGINT); }
-  llvm::Type* float_type() { return GetType(TYPE_FLOAT); }
-  llvm::Type* double_type() { return GetType(TYPE_DOUBLE); }
+  llvm::Type* bool_type() { return llvm::Type::getInt1Ty(context()); }
+  llvm::Type* i8_type() { return llvm::Type::getInt8Ty(context()); }
+  llvm::Type* i16_type() { return llvm::Type::getInt16Ty(context()); }
+  llvm::Type* i32_type() { return llvm::Type::getInt32Ty(context()); }
+  llvm::Type* i64_type() { return llvm::Type::getInt64Ty(context()); }
+  llvm::Type* i128_type() { return llvm::Type::getIntNTy(context(), 128); }
+  llvm::Type* float_type() { return llvm::Type::getFloatTy(context()); }
+  llvm::Type* double_type() { return llvm::Type::getDoubleTy(context()); }
   llvm::PointerType* ptr_type() { return ptr_type_; }
   llvm::Type* void_type() { return void_type_; }
-  llvm::Type* i128_type() { return llvm::Type::getIntNTy(context(), 128); }
+
+  llvm::PointerType* i8_ptr_type() { return GetPtrType(i8_type()); }
+  llvm::PointerType* i16_ptr_type() { return GetPtrType(i16_type()); }
+  llvm::PointerType* i32_ptr_type() { return GetPtrType(i32_type()); }
+  llvm::PointerType* i64_ptr_type() { return GetPtrType(i64_type()); }
+  llvm::PointerType* float_ptr_type() { return GetPtrType(float_type()); }
+  llvm::PointerType* double_ptr_type() { return GetPtrType(double_type()); }
+  llvm::PointerType* ptr_ptr_type() { return GetPtrType(ptr_type_); }
+
+  llvm::Constant* GetBoolConstant(bool val) { return val ? true_value_ : false_value_; }
+  llvm::Constant* GetI8Constant(uint64_t val) {
+    return llvm::ConstantInt::get(context(), llvm::APInt(8, val));
+  }
+  llvm::Constant* GetI16Constant(uint64_t val) {
+    return llvm::ConstantInt::get(context(), llvm::APInt(16, val));
+  }
+  llvm::Constant* GetI32Constant(uint64_t val) {
+    return llvm::ConstantInt::get(context(), llvm::APInt(32, val));
+  }
+  llvm::Constant* GetI64Constant(uint64_t val) {
+    return llvm::ConstantInt::get(context(), llvm::APInt(64, val));
+  }
 
   /// Load the module temporarily and populate 'symbols' with the symbols in the module.
   static Status GetSymbols(const string& file, const string& module_id,
@@ -811,8 +846,8 @@ class LlvmCodeGen {
   llvm::Type* timestamp_value_type_;        // TimestampValue
 
   /// llvm constants to help with code gen verbosity
-  llvm::Value* true_value_;
-  llvm::Value* false_value_;
+  llvm::Constant* true_value_;
+  llvm::Constant* false_value_;
 
   /// The symbol emitted associated with 'execution_engine_'. Methods on
   /// 'symbol_emitter_' are called by 'execution_engine_' when code is emitted or freed.

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/exec/exec-node.cc
----------------------------------------------------------------------
diff --git a/be/src/exec/exec-node.cc b/be/src/exec/exec-node.cc
index 08856f1..294e755 100644
--- a/be/src/exec/exec-node.cc
+++ b/be/src/exec/exec-node.cc
@@ -564,14 +564,14 @@ Status ExecNode::CodegenEvalConjuncts(LlvmCodeGen* codegen,
 
   // Construct function signature to match
   // bool EvalConjuncts(ScalarExprEvaluator**, int, TupleRow*)
-  llvm::PointerType* tuple_row_ptr_type = codegen->GetPtrType(TupleRow::LLVM_CLASS_NAME);
-  llvm::Type* eval_type = codegen->GetType(ScalarExprEvaluator::LLVM_CLASS_NAME);
+  llvm::PointerType* tuple_row_ptr_type = codegen->GetStructPtrType<TupleRow>();
+  llvm::Type* eval_type = codegen->GetStructType<ScalarExprEvaluator>();
 
-  LlvmCodeGen::FnPrototype prototype(codegen, name, codegen->GetType(TYPE_BOOLEAN));
+  LlvmCodeGen::FnPrototype prototype(codegen, name, codegen->bool_type());
   prototype.AddArgument(
       LlvmCodeGen::NamedVariable("evals", codegen->GetPtrPtrType(eval_type)));
   prototype.AddArgument(
-      LlvmCodeGen::NamedVariable("num_evals", codegen->GetType(TYPE_INT)));
+      LlvmCodeGen::NamedVariable("num_evals", codegen->i32_type()));
   prototype.AddArgument(LlvmCodeGen::NamedVariable("row", tuple_row_ptr_type));
 
   LlvmBuilder builder(codegen->context());
@@ -588,7 +588,7 @@ Status ExecNode::CodegenEvalConjuncts(LlvmCodeGen* codegen,
       llvm::BasicBlock* true_block =
           llvm::BasicBlock::Create(context, "continue", *fn, false_block);
       llvm::Value* eval_arg_ptr = builder.CreateInBoundsGEP(
-          NULL, evals_arg, codegen->GetIntConstant(TYPE_INT, i), "eval_ptr");
+          NULL, evals_arg, codegen->GetI32Constant(i), "eval_ptr");
       llvm::Value* eval_arg = builder.CreateLoad(eval_arg_ptr, "eval");
 
       // Call conjunct_fns[i]

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/exec/filter-context.cc
----------------------------------------------------------------------
diff --git a/be/src/exec/filter-context.cc b/be/src/exec/filter-context.cc
index 70618df..5c39ff9 100644
--- a/be/src/exec/filter-context.cc
+++ b/be/src/exec/filter-context.cc
@@ -145,10 +145,10 @@ Status FilterContext::CodegenEval(
   LlvmBuilder builder(context);
 
   *fn = nullptr;
-  llvm::PointerType* this_type = codegen->GetPtrType(FilterContext::LLVM_CLASS_NAME);
-  llvm::PointerType* tuple_row_ptr_type = codegen->GetPtrType(TupleRow::LLVM_CLASS_NAME);
+  llvm::PointerType* this_type = codegen->GetStructPtrType<FilterContext>();
+  llvm::PointerType* tuple_row_ptr_type = codegen->GetStructPtrType<TupleRow>();
   LlvmCodeGen::FnPrototype prototype(codegen, "FilterContextEval",
-      codegen->boolean_type());
+      codegen->bool_type());
   prototype.AddArgument(LlvmCodeGen::NamedVariable("this", this_type));
   prototype.AddArgument(LlvmCodeGen::NamedVariable("row", tuple_row_ptr_type));
 
@@ -206,7 +206,7 @@ Status FilterContext::CodegenEval(
 
   // Create a global constant of the filter expression's ColumnType. It needs to be a
   // constant for constant propagation and dead code elimination in 'runtime_filter_fn'.
-  llvm::Type* col_type = codegen->GetType(ColumnType::LLVM_CLASS_NAME);
+  llvm::Type* col_type = codegen->GetStructType<ColumnType>();
   llvm::Constant* expr_type_arg = codegen->ConstantToGVPtr(
       col_type, filter_expr->type().ToIR(codegen), "expr_type_arg");
 
@@ -281,8 +281,8 @@ Status FilterContext::CodegenInsert(LlvmCodeGen* codegen, ScalarExpr* filter_exp
   LlvmBuilder builder(context);
 
   *fn = nullptr;
-  llvm::PointerType* this_type = codegen->GetPtrType(FilterContext::LLVM_CLASS_NAME);
-  llvm::PointerType* tuple_row_ptr_type = codegen->GetPtrType(TupleRow::LLVM_CLASS_NAME);
+  llvm::PointerType* this_type = codegen->GetStructPtrType<FilterContext>();
+  llvm::PointerType* tuple_row_ptr_type = codegen->GetStructPtrType<TupleRow>();
   LlvmCodeGen::FnPrototype prototype(
       codegen, "FilterContextInsert", codegen->void_type());
   prototype.AddArgument(LlvmCodeGen::NamedVariable("this", this_type));
@@ -306,8 +306,8 @@ Status FilterContext::CodegenInsert(LlvmCodeGen* codegen, ScalarExpr* filter_exp
     llvm::Value* local_min_max_filter_ptr =
         builder.CreateStructGEP(nullptr, this_arg, 4, "local_min_max_filter_ptr");
     llvm::PointerType* min_max_filter_type =
-        codegen->GetPtrType(MinMaxFilter::GetLlvmClassName(filter_expr->type().type))
-            ->getPointerTo();
+        codegen->GetNamedPtrType(MinMaxFilter::GetLlvmClassName(
+        filter_expr->type().type))->getPointerTo();
     local_min_max_filter_ptr = builder.CreatePointerCast(
         local_min_max_filter_ptr, min_max_filter_type, "cast_min_max_filter_ptr");
     local_filter_arg =
@@ -372,13 +372,13 @@ Status FilterContext::CodegenInsert(LlvmCodeGen* codegen, ScalarExpr* filter_exp
   if (ctx->filter->is_bloom_filter()) {
     // Create a global constant of the filter expression's ColumnType. It needs to be a
     // constant for constant propagation and dead code elimination in 'get_hash_value_fn'.
-    llvm::Type* col_type = codegen->GetType(ColumnType::LLVM_CLASS_NAME);
+    llvm::Type* col_type = codegen->GetStructType<ColumnType>();
     llvm::Constant* expr_type_arg = codegen->ConstantToGVPtr(
         col_type, filter_expr->type().ToIR(codegen), "expr_type_arg");
 
     // Call RawValue::GetHashValue() on the result of the filter's expression.
     llvm::Value* seed_arg =
-        codegen->GetIntConstant(TYPE_INT, RuntimeFilterBank::DefaultHashSeed());
+        codegen->GetI32Constant(RuntimeFilterBank::DefaultHashSeed());
     llvm::Value* get_hash_value_args[] = {val_ptr_phi, expr_type_arg, seed_arg};
     llvm::Function* get_hash_value_fn =
         codegen->GetFunction(IRFunction::RAW_VALUE_GET_HASH_VALUE, false);

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/exec/hash-table.cc
----------------------------------------------------------------------
diff --git a/be/src/exec/hash-table.cc b/be/src/exec/hash-table.cc
index da9f195..38e0d26 100644
--- a/be/src/exec/hash-table.cc
+++ b/be/src/exec/hash-table.cc
@@ -585,7 +585,7 @@ static void CodegenAssignNullValue(LlvmCodeGen* codegen, LlvmBuilder* builder,
   if (type.type == TYPE_STRING || type.type == TYPE_VARCHAR) {
     llvm::Value* dst_ptr = builder->CreateStructGEP(NULL, dst, 0, "string_ptr");
     llvm::Value* dst_len = builder->CreateStructGEP(NULL, dst, 1, "string_len");
-    llvm::Value* null_len = codegen->GetIntConstant(TYPE_INT, fnv_seed);
+    llvm::Value* null_len = codegen->GetI32Constant(fnv_seed);
     llvm::Value* null_ptr = builder->CreateIntToPtr(null_len, codegen->ptr_type());
     builder->CreateStore(null_ptr, dst_ptr);
     builder->CreateStore(null_len, dst_len);
@@ -597,7 +597,7 @@ static void CodegenAssignNullValue(LlvmCodeGen* codegen, LlvmBuilder* builder,
       case TYPE_BOOLEAN:
         // In results, booleans are stored as 1 byte
         dst = builder->CreateBitCast(dst, codegen->ptr_type());
-        null_value = codegen->GetIntConstant(TYPE_TINYINT, fnv_seed);
+        null_value = codegen->GetI8Constant(fnv_seed);
         break;
       case TYPE_TIMESTAMP: {
         // Cast 'dst' to 'i128*'
@@ -718,14 +718,10 @@ Status HashTableCtx::CodegenEvalRow(
   }
 
   // Get types to generate function prototype
-  llvm::Type* this_type = codegen->GetType(HashTableCtx::LLVM_CLASS_NAME);
-  DCHECK(this_type != NULL);
-  llvm::PointerType* this_ptr_type = codegen->GetPtrType(this_type);
-  llvm::Type* tuple_row_type = codegen->GetType(TupleRow::LLVM_CLASS_NAME);
-  DCHECK(tuple_row_type != NULL);
-  llvm::PointerType* tuple_row_ptr_type = codegen->GetPtrType(tuple_row_type);
+  llvm::PointerType* this_ptr_type = codegen->GetStructPtrType<HashTableCtx>();
+  llvm::PointerType* tuple_row_ptr_type = codegen->GetStructPtrType<TupleRow>();
   LlvmCodeGen::FnPrototype prototype(codegen, build ? "EvalBuildRow" : "EvalProbeRow",
-      codegen->GetType(TYPE_BOOLEAN));
+      codegen->bool_type());
   prototype.AddArgument(LlvmCodeGen::NamedVariable("this_ptr", this_ptr_type));
   prototype.AddArgument(LlvmCodeGen::NamedVariable("row", tuple_row_ptr_type));
   prototype.AddArgument(LlvmCodeGen::NamedVariable("expr_values", codegen->ptr_type()));
@@ -755,9 +751,9 @@ Status HashTableCtx::CodegenEvalRow(
     // Convert result buffer to llvm ptr type
     int offset = expr_values_cache_.expr_values_offsets(i);
     llvm::Value* loc = builder.CreateInBoundsGEP(
-        NULL, expr_values, codegen->GetIntConstant(TYPE_INT, offset), "loc_addr");
-    llvm::Value* llvm_loc =
-        builder.CreatePointerCast(loc, codegen->GetPtrType(exprs[i]->type()), "loc");
+        NULL, expr_values, codegen->GetI32Constant(offset), "loc_addr");
+    llvm::Value* llvm_loc = builder.CreatePointerCast(loc,
+        codegen->GetSlotPtrType(exprs[i]->type()), "loc");
 
     llvm::BasicBlock* null_block = llvm::BasicBlock::Create(context, "null", *fn);
     llvm::BasicBlock* not_null_block = llvm::BasicBlock::Create(context, "not_null", *fn);
@@ -784,9 +780,9 @@ Status HashTableCtx::CodegenEvalRow(
     llvm::Value* is_null = result.GetIsNull();
 
     // Set null-byte result
-    llvm::Value* null_byte = builder.CreateZExt(is_null, codegen->GetType(TYPE_TINYINT));
+    llvm::Value* null_byte = builder.CreateZExt(is_null, codegen->i8_type());
     llvm::Value* llvm_null_byte_loc = builder.CreateInBoundsGEP(
-        NULL, expr_values_null, codegen->GetIntConstant(TYPE_INT, i), "null_byte_loc");
+        NULL, expr_values_null, codegen->GetI32Constant(i), "null_byte_loc");
     builder.CreateStore(null_byte, llvm_null_byte_loc);
     builder.CreateCondBr(is_null, null_block, not_null_block);
 
@@ -810,7 +806,7 @@ Status HashTableCtx::CodegenEvalRow(
     if (stores_nulls_) {
       // Update has_null
       llvm::PHINode* is_null_phi =
-          builder.CreatePHI(codegen->boolean_type(), 2, "is_null_phi");
+          builder.CreatePHI(codegen->bool_type(), 2, "is_null_phi");
       is_null_phi->addIncoming(codegen->true_value(), null_block);
       is_null_phi->addIncoming(codegen->false_value(), not_null_block);
       has_null = builder.CreateOr(has_null, is_null_phi, "has_null");
@@ -875,12 +871,10 @@ Status HashTableCtx::CodegenHashRow(
   }
 
   // Get types to generate function prototype
-  llvm::Type* this_type = codegen->GetType(HashTableCtx::LLVM_CLASS_NAME);
-  DCHECK(this_type != NULL);
-  llvm::PointerType* this_ptr_type = codegen->GetPtrType(this_type);
+  llvm::PointerType* this_ptr_type = codegen->GetStructPtrType<HashTableCtx>();
 
   LlvmCodeGen::FnPrototype prototype(
-      codegen, (use_murmur ? "MurmurHashRow" : "HashRow"), codegen->GetType(TYPE_INT));
+      codegen, (use_murmur ? "MurmurHashRow" : "HashRow"), codegen->i32_type());
   prototype.AddArgument(LlvmCodeGen::NamedVariable("this_ptr", this_ptr_type));
   prototype.AddArgument(LlvmCodeGen::NamedVariable("expr_values", codegen->ptr_type()));
   prototype.AddArgument(
@@ -907,7 +901,7 @@ Status HashTableCtx::CodegenHashRow(
       llvm::Function* hash_fn = use_murmur ?
           codegen->GetMurmurHashFunction(expr_values_bytes_per_row) :
           codegen->GetHashFunction(expr_values_bytes_per_row);
-      llvm::Value* len = codegen->GetIntConstant(TYPE_INT, expr_values_bytes_per_row);
+      llvm::Value* len = codegen->GetI32Constant(expr_values_bytes_per_row);
       hash_result = builder.CreateCall(
           hash_fn, llvm::ArrayRef<llvm::Value*>({expr_values, len, hash_result}), "hash");
     }
@@ -916,7 +910,7 @@ Status HashTableCtx::CodegenHashRow(
       llvm::Function* hash_fn = use_murmur ?
           codegen->GetMurmurHashFunction(var_result_offset) :
           codegen->GetHashFunction(var_result_offset);
-      llvm::Value* len = codegen->GetIntConstant(TYPE_INT, var_result_offset);
+      llvm::Value* len = codegen->GetI32Constant(var_result_offset);
       hash_result = builder.CreateCall(
           hash_fn, llvm::ArrayRef<llvm::Value*>({expr_values, len, hash_result}), "hash");
     }
@@ -935,7 +929,7 @@ Status HashTableCtx::CodegenHashRow(
 
       int offset = expr_values_cache_.expr_values_offsets(i);
       llvm::Value* llvm_loc = builder.CreateInBoundsGEP(
-          NULL, expr_values, codegen->GetIntConstant(TYPE_INT, offset), "loc_addr");
+          NULL, expr_values, codegen->GetI32Constant(offset), "loc_addr");
 
       // If the hash table stores nulls, we need to check if the stringval
       // evaluated to NULL
@@ -945,10 +939,10 @@ Status HashTableCtx::CodegenHashRow(
         continue_block = llvm::BasicBlock::Create(context, "continue", *fn);
 
         llvm::Value* llvm_null_byte_loc = builder.CreateInBoundsGEP(NULL,
-            expr_values_null, codegen->GetIntConstant(TYPE_INT, i), "null_byte_loc");
+            expr_values_null, codegen->GetI32Constant(i), "null_byte_loc");
         llvm::Value* null_byte = builder.CreateLoad(llvm_null_byte_loc, "null_byte");
         llvm::Value* is_null = builder.CreateICmpNE(
-            null_byte, codegen->GetIntConstant(TYPE_TINYINT, 0), "is_null");
+            null_byte, codegen->GetI8Constant(0), "is_null");
         builder.CreateCondBr(is_null, null_block, not_null_block);
 
         // For null, we just want to call the hash function on the portion of
@@ -957,7 +951,7 @@ Status HashTableCtx::CodegenHashRow(
         llvm::Function* null_hash_fn = use_murmur ?
             codegen->GetMurmurHashFunction(sizeof(StringValue)) :
             codegen->GetHashFunction(sizeof(StringValue));
-        llvm::Value* len = codegen->GetIntConstant(TYPE_INT, sizeof(StringValue));
+        llvm::Value* len = codegen->GetI32Constant(sizeof(StringValue));
         str_null_result = builder.CreateCall(null_hash_fn,
             llvm::ArrayRef<llvm::Value*>({llvm_loc, len, hash_result}), "str_null");
         builder.CreateBr(continue_block);
@@ -967,7 +961,7 @@ Status HashTableCtx::CodegenHashRow(
 
       // Convert expr_values_buffer_ loc to llvm value
       llvm::Value* str_val = builder.CreatePointerCast(
-          llvm_loc, codegen->GetPtrType(TYPE_STRING), "str_val");
+          llvm_loc, codegen->GetSlotPtrType(TYPE_STRING), "str_val");
 
       llvm::Value* ptr = builder.CreateStructGEP(NULL, str_val, 0);
       llvm::Value* len = builder.CreateStructGEP(NULL, str_val, 1);
@@ -986,7 +980,7 @@ Status HashTableCtx::CodegenHashRow(
         // Use phi node to reconcile that we could have come from the string-null
         // path and string not null paths.
         llvm::PHINode* phi_node =
-            builder.CreatePHI(codegen->GetType(TYPE_INT), 2, "hash_phi");
+            builder.CreatePHI(codegen->i32_type(), 2, "hash_phi");
         phi_node->addIncoming(string_hash_result, not_null_block);
         phi_node->addIncoming(str_null_result, null_block);
         hash_result = phi_node;
@@ -1086,14 +1080,10 @@ Status HashTableCtx::CodegenEquals(
   }
 
   // Get types to generate function prototype
-  llvm::Type* this_type = codegen->GetType(HashTableCtx::LLVM_CLASS_NAME);
-  DCHECK(this_type != NULL);
-  llvm::PointerType* this_ptr_type = codegen->GetPtrType(this_type);
-  llvm::Type* tuple_row_type = codegen->GetType(TupleRow::LLVM_CLASS_NAME);
-  DCHECK(tuple_row_type != NULL);
-  llvm::PointerType* tuple_row_ptr_type = codegen->GetPtrType(tuple_row_type);
-
-  LlvmCodeGen::FnPrototype prototype(codegen, "Equals", codegen->GetType(TYPE_BOOLEAN));
+  llvm::PointerType* this_ptr_type = codegen->GetStructPtrType<HashTableCtx>();
+  llvm::PointerType* tuple_row_ptr_type = codegen->GetStructPtrType<TupleRow>();
+
+  LlvmCodeGen::FnPrototype prototype(codegen, "Equals", codegen->bool_type());
   prototype.AddArgument(LlvmCodeGen::NamedVariable("this_ptr", this_ptr_type));
   prototype.AddArgument(LlvmCodeGen::NamedVariable("row", tuple_row_ptr_type));
   prototype.AddArgument(LlvmCodeGen::NamedVariable("expr_values", codegen->ptr_type()));
@@ -1148,18 +1138,18 @@ Status HashTableCtx::CodegenEquals(
     // predicate is <=>
     if (force_null_equality || finds_nulls_[i]) {
       llvm::Value* llvm_null_byte_loc = builder.CreateInBoundsGEP(
-          NULL, expr_values_null, codegen->GetIntConstant(TYPE_INT, i), "null_byte_loc");
+          NULL, expr_values_null, codegen->GetI32Constant(i), "null_byte_loc");
       llvm::Value* null_byte = builder.CreateLoad(llvm_null_byte_loc);
       row_is_null =
-          builder.CreateICmpNE(null_byte, codegen->GetIntConstant(TYPE_TINYINT, 0));
+          builder.CreateICmpNE(null_byte, codegen->GetI8Constant(0));
     }
 
     // Get llvm value for row_val from 'expr_values'
     int offset = expr_values_cache_.expr_values_offsets(i);
     llvm::Value* loc = builder.CreateInBoundsGEP(
-        NULL, expr_values, codegen->GetIntConstant(TYPE_INT, offset), "loc");
+        NULL, expr_values, codegen->GetI32Constant(offset), "loc");
     llvm::Value* row_val = builder.CreatePointerCast(
-        loc, codegen->GetPtrType(build_exprs_[i]->type()), "row_val");
+        loc, codegen->GetSlotPtrType(build_exprs_[i]->type()), "row_val");
 
     // Branch for GetValue() returning NULL
     builder.CreateCondBr(is_null, null_block, not_null_block);

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/exec/hdfs-avro-scanner.cc
----------------------------------------------------------------------
diff --git a/be/src/exec/hdfs-avro-scanner.cc b/be/src/exec/hdfs-avro-scanner.cc
index 3ec1f09..fe1bed4 100644
--- a/be/src/exec/hdfs-avro-scanner.cc
+++ b/be/src/exec/hdfs-avro-scanner.cc
@@ -759,23 +759,18 @@ Status HdfsAvroScanner::CodegenMaterializeTuple(const HdfsScanNodeBase* node,
   llvm::LLVMContext& context = codegen->context();
   LlvmBuilder builder(context);
 
-  llvm::Type* this_type = codegen->GetType(HdfsAvroScanner::LLVM_CLASS_NAME);
-  DCHECK(this_type != nullptr);
-  llvm::PointerType* this_ptr_type = llvm::PointerType::get(this_type, 0);
+  llvm::PointerType* this_ptr_type = codegen->GetStructPtrType<HdfsAvroScanner>();
 
   TupleDescriptor* tuple_desc = const_cast<TupleDescriptor*>(node->tuple_desc());
   llvm::StructType* tuple_type = tuple_desc->GetLlvmStruct(codegen);
   if (tuple_type == nullptr) return Status("Could not generate tuple struct.");
   llvm::Type* tuple_ptr_type = llvm::PointerType::get(tuple_type, 0);
 
-  llvm::Type* tuple_opaque_type = codegen->GetType(Tuple::LLVM_CLASS_NAME);
-  llvm::PointerType* tuple_opaque_ptr_type = llvm::PointerType::get(tuple_opaque_type, 0);
+  llvm::PointerType* tuple_opaque_ptr_type = codegen->GetStructPtrType<Tuple>();
 
-  llvm::Type* data_ptr_type = llvm::PointerType::get(codegen->ptr_type(), 0); // char**
-  llvm::Type* mempool_type =
-      llvm::PointerType::get(codegen->GetType(MemPool::LLVM_CLASS_NAME), 0);
-  llvm::Type* schema_element_type =
-      codegen->GetPtrType(AvroSchemaElement::LLVM_CLASS_NAME);
+  llvm::Type* data_ptr_type = codegen->ptr_ptr_type(); // char**
+  llvm::Type* mempool_type = codegen->GetStructPtrType<MemPool>();
+  llvm::Type* schema_element_type = codegen->GetStructPtrType<AvroSchemaElement>();
 
   // Schema can be null if metadata is stale. See test in
   // queries/QueryTest/avro-schema-changes.test.
@@ -792,7 +787,7 @@ Status HdfsAvroScanner::CodegenMaterializeTuple(const HdfsScanNodeBase* node,
   std::vector<llvm::Function*> helper_functions;
 
   // prototype re-used several times by amending with SetName()
-  LlvmCodeGen::FnPrototype prototype(codegen, "", codegen->boolean_type());
+  LlvmCodeGen::FnPrototype prototype(codegen, "", codegen->bool_type());
   prototype.AddArgument(LlvmCodeGen::NamedVariable("this", this_ptr_type));
   prototype.AddArgument(LlvmCodeGen::NamedVariable("record_schema", schema_element_type));
   prototype.AddArgument(LlvmCodeGen::NamedVariable("pool", mempool_type));
@@ -933,9 +928,9 @@ Status HdfsAvroScanner::CodegenReadRecord(const SchemaPath& path,
       llvm::Function* read_union_fn =
           codegen->GetFunction(IRFunction::READ_UNION_TYPE, false);
       llvm::Value* null_union_pos_val =
-          codegen->GetIntConstant(TYPE_INT, field->null_union_position);
+          codegen->GetI32Constant(field->null_union_position);
       if (is_null_ptr == nullptr) {
-        is_null_ptr = codegen->CreateEntryBlockAlloca(*builder, codegen->boolean_type(),
+        is_null_ptr = codegen->CreateEntryBlockAlloca(*builder, codegen->bool_type(),
             "is_null_ptr");
       }
       llvm::Value* is_null_ptr_cast =
@@ -1097,7 +1092,7 @@ Status HdfsAvroScanner::CodegenDecodeAvroData(const HdfsScanNodeBase* node,
 
   int tuple_byte_size = node->tuple_desc()->byte_size();
   replaced = codegen->ReplaceCallSitesWithValue(fn,
-      codegen->GetIntConstant(TYPE_INT, tuple_byte_size), "tuple_byte_size");
+      codegen->GetI32Constant(tuple_byte_size), "tuple_byte_size");
   DCHECK_EQ(replaced, 1);
 
   fn->setName("DecodeAvroData");

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/exec/hdfs-avro-scanner.h
----------------------------------------------------------------------
diff --git a/be/src/exec/hdfs-avro-scanner.h b/be/src/exec/hdfs-avro-scanner.h
index e2260a6..f7b1c31 100644
--- a/be/src/exec/hdfs-avro-scanner.h
+++ b/be/src/exec/hdfs-avro-scanner.h
@@ -100,6 +100,8 @@ class HdfsAvroScanner : public BaseSequenceScanner {
       llvm::Function** decode_avro_data_fn)
       WARN_UNUSED_RESULT;
 
+  static const char* LLVM_CLASS_NAME;
+
  protected:
   /// Implementation of BaseSeqeunceScanner super class methods
   virtual FileHeader* AllocateFileHeader();
@@ -309,8 +311,6 @@ class HdfsAvroScanner : public BaseSequenceScanner {
 
   /// Unit test constructor
   HdfsAvroScanner();
-
-  static const char* LLVM_CLASS_NAME;
 };
 } // namespace impala
 

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/exec/hdfs-parquet-scanner.cc
----------------------------------------------------------------------
diff --git a/be/src/exec/hdfs-parquet-scanner.cc b/be/src/exec/hdfs-parquet-scanner.cc
index 7a10f3c..e279369 100644
--- a/be/src/exec/hdfs-parquet-scanner.cc
+++ b/be/src/exec/hdfs-parquet-scanner.cc
@@ -1183,10 +1183,10 @@ Status HdfsParquetScanner::CodegenEvalRuntimeFilters(
   LlvmBuilder builder(context);
 
   *fn = nullptr;
-  llvm::Type* this_type = codegen->GetPtrType(HdfsParquetScanner::LLVM_CLASS_NAME);
-  llvm::PointerType* tuple_row_ptr_type = codegen->GetPtrType(TupleRow::LLVM_CLASS_NAME);
+  llvm::Type* this_type = codegen->GetStructPtrType<HdfsParquetScanner>();
+  llvm::PointerType* tuple_row_ptr_type = codegen->GetStructPtrType<TupleRow>();
   LlvmCodeGen::FnPrototype prototype(codegen, "EvalRuntimeFilters",
-      codegen->GetType(TYPE_BOOLEAN));
+      codegen->bool_type());
   prototype.AddArgument(LlvmCodeGen::NamedVariable("this", this_type));
   prototype.AddArgument(LlvmCodeGen::NamedVariable("row", tuple_row_ptr_type));
 
@@ -1221,7 +1221,7 @@ Status HdfsParquetScanner::CodegenEvalRuntimeFilters(
           "FilterContext4Eval");
       DCHECK_EQ(replaced, 1);
 
-      llvm::Value* idx = codegen->GetIntConstant(TYPE_INT, i);
+      llvm::Value* idx = codegen->GetI32Constant(i);
       llvm::Value* passed_filter = builder.CreateCall(
           eval_runtime_filter_fn, llvm::ArrayRef<llvm::Value*>({this_arg, idx, row_arg}));
 

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/exec/hdfs-parquet-scanner.h
----------------------------------------------------------------------
diff --git a/be/src/exec/hdfs-parquet-scanner.h b/be/src/exec/hdfs-parquet-scanner.h
index b1409d7..f0043b5 100644
--- a/be/src/exec/hdfs-parquet-scanner.h
+++ b/be/src/exec/hdfs-parquet-scanner.h
@@ -351,6 +351,9 @@ class HdfsParquetScanner : public HdfsScanner {
   /// Indicates an invalid position value.
   static const int16_t INVALID_POS = -1;
 
+  /// Class name in LLVM IR.
+  static const char* LLVM_CLASS_NAME;
+
  private:
   friend class ParquetColumnReader;
   friend class CollectionColumnReader;
@@ -367,9 +370,6 @@ class HdfsParquetScanner : public HdfsScanner {
       "You can increase FOOTER_SIZE if you want, "
       "just don't forget to increase READ_SIZE_MIN_VALUE as well.");
 
-  /// Class name in LLVM IR.
-  static const char* LLVM_CLASS_NAME;
-
   /// Index of the current row group being processed. Initialized to -1 which indicates
   /// that we have not started processing the first row group yet (GetNext() has not yet
   /// been called).

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/exec/hdfs-scanner.cc
----------------------------------------------------------------------
diff --git a/be/src/exec/hdfs-scanner.cc b/be/src/exec/hdfs-scanner.cc
index d62ccc7..1809fe5 100644
--- a/be/src/exec/hdfs-scanner.cc
+++ b/be/src/exec/hdfs-scanner.cc
@@ -340,26 +340,13 @@ Status HdfsScanner::CodegenWriteCompleteTuple(const HdfsScanNodeBase* node,
   node->ComputeSlotMaterializationOrder(&materialize_order);
 
   // Get types to construct matching function signature to WriteCompleteTuple
-  llvm::PointerType* uint8_ptr_type =
-      llvm::PointerType::get(codegen->GetType(TYPE_TINYINT), 0);
-
-  llvm::StructType* field_loc_type = reinterpret_cast<llvm::StructType*>(
-      codegen->GetType(FieldLocation::LLVM_CLASS_NAME));
-  llvm::Type* tuple_row_type = codegen->GetType(TupleRow::LLVM_CLASS_NAME);
-  llvm::Type* tuple_opaque_type = codegen->GetType(Tuple::LLVM_CLASS_NAME);
-  llvm::Type* mem_pool_type = codegen->GetType(MemPool::LLVM_CLASS_NAME);
-  llvm::Type* hdfs_scanner_type = codegen->GetType(HdfsScanner::LLVM_CLASS_NAME);
-
-  DCHECK(tuple_opaque_type != NULL);
-  DCHECK(tuple_row_type != NULL);
-  DCHECK(field_loc_type != NULL);
-  DCHECK(hdfs_scanner_type != NULL);
-
-  llvm::PointerType* field_loc_ptr_type = llvm::PointerType::get(field_loc_type, 0);
-  llvm::PointerType* tuple_opaque_ptr_type = llvm::PointerType::get(tuple_opaque_type, 0);
-  llvm::PointerType* tuple_row_ptr_type = llvm::PointerType::get(tuple_row_type, 0);
-  llvm::PointerType* mem_pool_ptr_type = llvm::PointerType::get(mem_pool_type, 0);
-  llvm::PointerType* hdfs_scanner_ptr_type = llvm::PointerType::get(hdfs_scanner_type, 0);
+  llvm::PointerType* uint8_ptr_type = codegen->i8_ptr_type();
+
+  llvm::PointerType* field_loc_ptr_type = codegen->GetStructPtrType<FieldLocation>();
+  llvm::PointerType* tuple_opaque_ptr_type = codegen->GetStructPtrType<Tuple>();
+  llvm::PointerType* tuple_row_ptr_type = codegen->GetStructPtrType<TupleRow>();
+  llvm::PointerType* mem_pool_ptr_type = codegen->GetStructPtrType<MemPool>();
+  llvm::PointerType* hdfs_scanner_ptr_type = codegen->GetStructPtrType<HdfsScanner>();
 
   // Generate the typed llvm struct for the output tuple
   llvm::StructType* tuple_type = tuple_desc->GetLlvmStruct(codegen);
@@ -369,7 +356,7 @@ Status HdfsScanner::CodegenWriteCompleteTuple(const HdfsScanNodeBase* node,
   // Initialize the function prototype.  This needs to match
   // HdfsScanner::WriteCompleteTuple's signature identically.
   LlvmCodeGen::FnPrototype prototype(
-      codegen, "WriteCompleteTuple", codegen->GetType(TYPE_BOOLEAN));
+      codegen, "WriteCompleteTuple", codegen->bool_type());
   prototype.AddArgument(LlvmCodeGen::NamedVariable("this", hdfs_scanner_ptr_type));
   prototype.AddArgument(LlvmCodeGen::NamedVariable("pool", mem_pool_ptr_type));
   prototype.AddArgument(LlvmCodeGen::NamedVariable("fields", field_loc_ptr_type));
@@ -408,7 +395,7 @@ Status HdfsScanner::CodegenWriteCompleteTuple(const HdfsScanNodeBase* node,
   // Put tuple in tuple_row
   llvm::Value* tuple_row_typed =
       builder.CreateBitCast(tuple_row_arg, llvm::PointerType::get(tuple_ptr_type, 0));
-  llvm::Value* tuple_row_idxs[] = {codegen->GetIntConstant(TYPE_INT, node->tuple_idx())};
+  llvm::Value* tuple_row_idxs[] = {codegen->GetI32Constant(node->tuple_idx())};
   llvm::Value* tuple_in_row_addr =
       builder.CreateInBoundsGEP(tuple_row_typed, tuple_row_idxs);
   builder.CreateStore(tuple_arg, tuple_in_row_addr);
@@ -437,15 +424,15 @@ Status HdfsScanner::CodegenWriteCompleteTuple(const HdfsScanNodeBase* node,
 
       // Extract ptr/len from fields
       llvm::Value* data_idxs[] = {
-          codegen->GetIntConstant(TYPE_INT, slot_idx),
-          codegen->GetIntConstant(TYPE_INT, 0),
+          codegen->GetI32Constant(slot_idx),
+          codegen->GetI32Constant(0),
       };
       llvm::Value* len_idxs[] = {
-          codegen->GetIntConstant(TYPE_INT, slot_idx),
-          codegen->GetIntConstant(TYPE_INT, 1),
+          codegen->GetI32Constant(slot_idx),
+          codegen->GetI32Constant(1),
       };
       llvm::Value* error_idxs[] = {
-          codegen->GetIntConstant(TYPE_INT, slot_idx),
+          codegen->GetI32Constant(slot_idx),
       };
       llvm::Value* data_ptr =
           builder.CreateInBoundsGEP(fields_arg, data_idxs, "data_ptr");
@@ -462,10 +449,10 @@ Status HdfsScanner::CodegenWriteCompleteTuple(const HdfsScanNodeBase* node,
       // send a 'need_escape' bool to CodegenWriteSlot(), since we are making the length
       // positive here.
       llvm::Value* len_lt_zero =
-          builder.CreateICmpSLT(len, codegen->GetIntConstant(TYPE_INT, 0), "len_lt_zero");
+          builder.CreateICmpSLT(len, codegen->GetI32Constant(0), "len_lt_zero");
       llvm::Value* ones_compliment_len = builder.CreateNot(len, "ones_compliment_len");
       llvm::Value* positive_len = builder.CreateAdd(
-          ones_compliment_len, codegen->GetIntConstant(TYPE_INT, 1), "positive_len");
+          ones_compliment_len, codegen->GetI32Constant(1), "positive_len");
       len = builder.CreateSelect(len_lt_zero, positive_len, len,
           "select_positive_len");
 
@@ -475,7 +462,7 @@ Status HdfsScanner::CodegenWriteCompleteTuple(const HdfsScanNodeBase* node,
           slot_fn, llvm::ArrayRef<llvm::Value*>({tuple_arg, data, len}));
       llvm::Value* slot_error = builder.CreateNot(slot_parsed, "slot_parse_error");
       error_in_row = builder.CreateOr(error_in_row, slot_error, "error_in_row");
-      slot_error = builder.CreateZExt(slot_error, codegen->GetType(TYPE_TINYINT));
+      slot_error = builder.CreateZExt(slot_error, codegen->i8_type());
       builder.CreateStore(slot_error, error_ptr);
     }
 
@@ -484,7 +471,7 @@ Status HdfsScanner::CodegenWriteCompleteTuple(const HdfsScanNodeBase* node,
       // This slots are the last to get materialized.  If we are in this branch, the
       // tuple passed all conjuncts and should be added to the row batch.
       llvm::Value* error_ret =
-          builder.CreateZExt(error_in_row, codegen->GetType(TYPE_TINYINT));
+          builder.CreateZExt(error_in_row, codegen->i8_type());
       builder.CreateStore(error_ret, error_in_row_arg);
       builder.CreateRet(codegen->true_value());
     } else {
@@ -510,7 +497,7 @@ Status HdfsScanner::CodegenWriteCompleteTuple(const HdfsScanNodeBase* node,
           codegen->GetFunction(IRFunction::HDFS_SCANNER_GET_CONJUNCT_EVALUATOR, false);
       llvm::Value* eval = builder.CreateCall(
           get_eval_fn, llvm::ArrayRef<llvm::Value*>(
-                           {this_arg, codegen->GetIntConstant(TYPE_INT, conjunct_idx)}));
+                           {this_arg, codegen->GetI32Constant(conjunct_idx)}));
 
       llvm::Value* conjunct_args[] = {eval, tuple_row_arg};
       CodegenAnyVal result = CodegenAnyVal::CreateCallWrapped(
@@ -559,7 +546,7 @@ Status HdfsScanner::CodegenWriteAlignedTuples(const HdfsScanNodeBase* node,
 
   int tuple_byte_size = node->tuple_desc()->byte_size();
   replaced = codegen->ReplaceCallSitesWithValue(write_tuples_fn,
-      codegen->GetIntConstant(TYPE_INT, tuple_byte_size), "tuple_byte_size");
+      codegen->GetI32Constant(tuple_byte_size), "tuple_byte_size");
   DCHECK_EQ(replaced, 1);
 
   *write_aligned_tuples_fn = codegen->FinalizeFunction(write_tuples_fn);
@@ -581,16 +568,16 @@ Status HdfsScanner::CodegenInitTuple(
 
   const TupleDescriptor* tuple_desc = node->tuple_desc();
   replaced = codegen->ReplaceCallSitesWithValue(*init_tuple_fn,
-      codegen->GetIntConstant(TYPE_INT, tuple_desc->byte_size()), "tuple_byte_size");
+      codegen->GetI32Constant(tuple_desc->byte_size()), "tuple_byte_size");
   DCHECK_EQ(replaced, 1);
 
   replaced = codegen->ReplaceCallSitesWithValue(*init_tuple_fn,
-      codegen->GetIntConstant(TYPE_INT, tuple_desc->null_bytes_offset()),
+      codegen->GetI32Constant(tuple_desc->null_bytes_offset()),
       "null_bytes_offset");
   DCHECK_EQ(replaced, 1);
 
   replaced = codegen->ReplaceCallSitesWithValue(*init_tuple_fn,
-      codegen->GetIntConstant(TYPE_INT, tuple_desc->num_null_bytes()), "num_null_bytes");
+      codegen->GetI32Constant(tuple_desc->num_null_bytes()), "num_null_bytes");
   DCHECK_EQ(replaced, 1);
 
   *init_tuple_fn = codegen->FinalizeFunction(*init_tuple_fn);

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/exec/partitioned-aggregation-node.cc
----------------------------------------------------------------------
diff --git a/be/src/exec/partitioned-aggregation-node.cc b/be/src/exec/partitioned-aggregation-node.cc
index c90613b..c6c6189 100644
--- a/be/src/exec/partitioned-aggregation-node.cc
+++ b/be/src/exec/partitioned-aggregation-node.cc
@@ -1477,15 +1477,14 @@ void PartitionedAggregationNode::ClosePartitions() {
 //
 Status PartitionedAggregationNode::CodegenUpdateSlot(LlvmCodeGen* codegen, int agg_fn_idx,
     SlotDescriptor* slot_desc, llvm::Function** fn) {
-  llvm::PointerType* agg_fn_eval_type =
-      codegen->GetPtrType(AggFnEvaluator::LLVM_CLASS_NAME);
+  llvm::PointerType* agg_fn_eval_type = codegen->GetStructPtrType<AggFnEvaluator>();
   llvm::StructType* tuple_struct = intermediate_tuple_desc_->GetLlvmStruct(codegen);
   if (tuple_struct == NULL) {
     return Status("PartitionedAggregationNode::CodegenUpdateSlot(): failed to generate "
                   "intermediate tuple desc");
   }
   llvm::PointerType* tuple_ptr_type = codegen->GetPtrType(tuple_struct);
-  llvm::PointerType* tuple_row_ptr_type = codegen->GetPtrType(TupleRow::LLVM_CLASS_NAME);
+  llvm::PointerType* tuple_row_ptr_type = codegen->GetStructPtrType<TupleRow>();
 
   LlvmCodeGen::FnPrototype prototype(codegen, "UpdateSlot", codegen->void_type());
   prototype.AddArgument(
@@ -1548,7 +1547,7 @@ Status PartitionedAggregationNode::CodegenUpdateSlot(LlvmCodeGen* codegen, int a
     llvm::Value* result = agg_fn->is_merge() ?
         builder.CreateAdd(dst_value, src.GetVal(), "count_sum") :
         builder.CreateAdd(
-            dst_value, codegen->GetIntConstant(TYPE_BIGINT, 1), "count_inc");
+            dst_value, codegen->GetI64Constant(1), "count_inc");
     builder.CreateStore(result, dst_slot_ptr);
     DCHECK(!slot_desc->is_nullable());
   } else if ((agg_op == AggFn::MIN || agg_op == AggFn::MAX) && dst_is_numeric_or_bool) {
@@ -1737,15 +1736,11 @@ Status PartitionedAggregationNode::CodegenUpdateTuple(
   }
 
   // Get the types to match the UpdateTuple signature
-  llvm::Type* agg_node_type =
-      codegen->GetType(PartitionedAggregationNode::LLVM_CLASS_NAME);
-  llvm::Type* tuple_type = codegen->GetType(Tuple::LLVM_CLASS_NAME);
-  llvm::Type* tuple_row_type = codegen->GetType(TupleRow::LLVM_CLASS_NAME);
-
-  llvm::PointerType* agg_node_ptr_type = codegen->GetPtrType(agg_node_type);
-  llvm::PointerType* evals_type = codegen->GetPtrPtrType(AggFnEvaluator::LLVM_CLASS_NAME);
-  llvm::PointerType* tuple_ptr_type = codegen->GetPtrType(tuple_type);
-  llvm::PointerType* tuple_row_ptr_type = codegen->GetPtrType(tuple_row_type);
+  llvm::PointerType* agg_node_ptr_type =
+      codegen->GetStructPtrType<PartitionedAggregationNode>();
+  llvm::PointerType* evals_type = codegen->GetStructPtrPtrType<AggFnEvaluator>();
+  llvm::PointerType* tuple_ptr_type = codegen->GetStructPtrType<Tuple>();
+  llvm::PointerType* tuple_row_ptr_type = codegen->GetStructPtrType<TupleRow>();
 
   llvm::StructType* tuple_struct = intermediate_tuple_desc_->GetLlvmStruct(codegen);
   llvm::PointerType* tuple_ptr = codegen->GetPtrType(tuple_struct);
@@ -1754,7 +1749,7 @@ Status PartitionedAggregationNode::CodegenUpdateTuple(
   prototype.AddArgument(LlvmCodeGen::NamedVariable("agg_fn_evals", evals_type));
   prototype.AddArgument(LlvmCodeGen::NamedVariable("tuple", tuple_ptr_type));
   prototype.AddArgument(LlvmCodeGen::NamedVariable("row", tuple_row_ptr_type));
-  prototype.AddArgument(LlvmCodeGen::NamedVariable("is_merge", codegen->boolean_type()));
+  prototype.AddArgument(LlvmCodeGen::NamedVariable("is_merge", codegen->bool_type()));
 
   LlvmBuilder builder(codegen->context());
   llvm::Value* args[5];
@@ -1777,7 +1772,7 @@ Status PartitionedAggregationNode::CodegenUpdateTuple(
       // TODO: we should be able to hoist this up to the loop over the batch and just
       // increment the slot by the number of rows in the batch.
       int field_idx = slot_desc->llvm_field_idx();
-      llvm::Value* const_one = codegen->GetIntConstant(TYPE_BIGINT, 1);
+      llvm::Value* const_one = codegen->GetI64Constant(1);
       llvm::Value* slot_ptr =
           builder.CreateStructGEP(NULL, tuple_arg, field_idx, "src_slot");
       llvm::Value* slot_loaded = builder.CreateLoad(slot_ptr, "count_star_val");
@@ -1834,8 +1829,7 @@ Status PartitionedAggregationNode::CodegenProcessBatch(LlvmCodeGen* codegen,
 
     // Replace prefetch_mode with constant so branches can be optimised out.
     llvm::Value* prefetch_mode_arg = codegen->GetArgument(process_batch_fn, 3);
-    prefetch_mode_arg->replaceAllUsesWith(llvm::ConstantInt::get(
-        llvm::Type::getInt32Ty(codegen->context()), prefetch_mode));
+    prefetch_mode_arg->replaceAllUsesWith(codegen->GetI32Constant(prefetch_mode));
 
     // The codegen'd ProcessBatch function is only used in Open() with level_ = 0,
     // so don't use murmur hash
@@ -1898,13 +1892,11 @@ Status PartitionedAggregationNode::CodegenProcessBatchStreaming(
 
   // Make needs_serialize arg constant so dead code can be optimised out.
   llvm::Value* needs_serialize_arg = codegen->GetArgument(process_batch_streaming_fn, 2);
-  needs_serialize_arg->replaceAllUsesWith(llvm::ConstantInt::get(
-      llvm::Type::getInt1Ty(codegen->context()), needs_serialize_));
+  needs_serialize_arg->replaceAllUsesWith(codegen->GetBoolConstant(needs_serialize_));
 
   // Replace prefetch_mode with constant so branches can be optimised out.
   llvm::Value* prefetch_mode_arg = codegen->GetArgument(process_batch_streaming_fn, 3);
-  prefetch_mode_arg->replaceAllUsesWith(
-      llvm::ConstantInt::get(llvm::Type::getInt32Ty(codegen->context()), prefetch_mode));
+  prefetch_mode_arg->replaceAllUsesWith(codegen->GetI32Constant(prefetch_mode));
 
   llvm::Function* update_tuple_fn;
   RETURN_IF_ERROR(CodegenUpdateTuple(codegen, &update_tuple_fn));

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/exec/partitioned-hash-join-builder.cc
----------------------------------------------------------------------
diff --git a/be/src/exec/partitioned-hash-join-builder.cc b/be/src/exec/partitioned-hash-join-builder.cc
index 53e58c1..194bb92 100644
--- a/be/src/exec/partitioned-hash-join-builder.cc
+++ b/be/src/exec/partitioned-hash-join-builder.cc
@@ -820,8 +820,7 @@ Status PhjBuilder::CodegenProcessBuildBatch(LlvmCodeGen* codegen, llvm::Function
 
   llvm::Value* is_null_aware_arg = codegen->GetArgument(process_build_batch_fn, 5);
   is_null_aware_arg->replaceAllUsesWith(
-      llvm::ConstantInt::get(llvm::Type::getInt1Ty(codegen->context()),
-          join_op_ == TJoinOp::NULL_AWARE_LEFT_ANTI_JOIN));
+      codegen->GetBoolConstant(join_op_ == TJoinOp::NULL_AWARE_LEFT_ANTI_JOIN));
 
   llvm::Function* process_build_batch_fn_level0 =
       codegen->CloneFunction(process_build_batch_fn);
@@ -830,8 +829,8 @@ Status PhjBuilder::CodegenProcessBuildBatch(LlvmCodeGen* codegen, llvm::Function
   // Note that the first argument of this function is the return value.
   llvm::Value* build_filter_l0_arg =
       codegen->GetArgument(process_build_batch_fn_level0, 4);
-  build_filter_l0_arg->replaceAllUsesWith(llvm::ConstantInt::get(
-      llvm::Type::getInt1Ty(codegen->context()), filter_ctxs_.size() > 0));
+  build_filter_l0_arg->replaceAllUsesWith(
+      codegen->GetBoolConstant(filter_ctxs_.size() > 0));
 
   // process_build_batch_fn_level0 uses CRC hash if available,
   replaced =
@@ -847,8 +846,7 @@ Status PhjBuilder::CodegenProcessBuildBatch(LlvmCodeGen* codegen, llvm::Function
   // filters during the level0 build. Note that the first argument of this function is the
   // return value.
   llvm::Value* build_filter_arg = codegen->GetArgument(process_build_batch_fn, 4);
-  build_filter_arg->replaceAllUsesWith(
-      llvm::ConstantInt::get(llvm::Type::getInt1Ty(codegen->context()), false));
+  build_filter_arg->replaceAllUsesWith(codegen->false_value());
 
   // Finalize ProcessBuildBatch functions
   process_build_batch_fn = codegen->FinalizeFunction(process_build_batch_fn);
@@ -885,8 +883,7 @@ Status PhjBuilder::CodegenInsertBatch(LlvmCodeGen* codegen, llvm::Function* hash
   llvm::Value* prefetch_mode_arg = codegen->GetArgument(insert_batch_fn, 1);
   DCHECK_GE(prefetch_mode, TPrefetchMode::NONE);
   DCHECK_LE(prefetch_mode, TPrefetchMode::HT_BUCKET);
-  prefetch_mode_arg->replaceAllUsesWith(
-      llvm::ConstantInt::get(llvm::Type::getInt32Ty(codegen->context()), prefetch_mode));
+  prefetch_mode_arg->replaceAllUsesWith(codegen->GetI32Constant(prefetch_mode));
 
   // Use codegen'd EvalBuildRow() function
   int replaced = codegen->ReplaceCallSites(insert_batch_fn, eval_row_fn, "EvalBuildRow");
@@ -955,8 +952,8 @@ Status PhjBuilder::CodegenInsertRuntimeFilters(
   LlvmBuilder builder(context);
 
   *fn = nullptr;
-  llvm::Type* this_type = codegen->GetPtrType(PhjBuilder::LLVM_CLASS_NAME);
-  llvm::PointerType* tuple_row_ptr_type = codegen->GetPtrType(TupleRow::LLVM_CLASS_NAME);
+  llvm::Type* this_type = codegen->GetStructPtrType<PhjBuilder>();
+  llvm::PointerType* tuple_row_ptr_type = codegen->GetStructPtrType<TupleRow>();
   LlvmCodeGen::FnPrototype prototype(
       codegen, "InsertRuntimeFilters", codegen->void_type());
   prototype.AddArgument(LlvmCodeGen::NamedVariable("this", this_type));
@@ -971,8 +968,7 @@ Status PhjBuilder::CodegenInsertRuntimeFilters(
     llvm::Function* insert_fn;
     RETURN_IF_ERROR(FilterContext::CodegenInsert(
         codegen, filter_exprs_[i], &filter_ctxs_[i], &insert_fn));
-    llvm::PointerType* filter_context_type =
-        codegen->GetPtrType(FilterContext::LLVM_CLASS_NAME);
+    llvm::PointerType* filter_context_type = codegen->GetStructPtrType<FilterContext>();
     llvm::Value* filter_context_ptr =
         codegen->CastPtrToLlvmPtr(filter_context_type, &filter_ctxs_[i]);