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:24 UTC

[1/5] impala git commit: IMPALA-6499: [DOCS] Fixed formatting errors in split_part function

Repository: impala
Updated Branches:
  refs/heads/master ac86e9d93 -> f562be8c2


IMPALA-6499: [DOCS] Fixed formatting errors in split_part function

Change-Id: I7623e32aaf31f21a3be4513f26deb0b789a56b1a
Reviewed-on: http://gerrit.cloudera.org:8080/9275
Reviewed-by: John Russell <jr...@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/04383f17
Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/04383f17
Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/04383f17

Branch: refs/heads/master
Commit: 04383f1769aaf7e2baefa3fe3b18d74643f85e84
Parents: ac86e9d
Author: Alex Rodoni <ar...@cloudera.com>
Authored: Fri Feb 9 17:17:54 2018 -0800
Committer: Impala Public Jenkins <im...@gerrit.cloudera.org>
Committed: Tue Feb 20 22:09:06 2018 +0000

----------------------------------------------------------------------
 docs/topics/impala_string_functions.xml | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/impala/blob/04383f17/docs/topics/impala_string_functions.xml
----------------------------------------------------------------------
diff --git a/docs/topics/impala_string_functions.xml b/docs/topics/impala_string_functions.xml
index 4a15167..a424683 100644
--- a/docs/topics/impala_string_functions.xml
+++ b/docs/topics/impala_string_functions.xml
@@ -1061,11 +1061,10 @@ select replace('hello world','xyz','abc');
 
         <dd>
           <indexterm audience="hidden">split_part() function</indexterm>
-          <b>Purpose:</b> Returns the nth field within a delimited string.
-          The fields are numbered starting from 1.
-          The delimiter can consist of multiple characters, not just a
-          single character. All matching of the delimiter is done exactly, not using any
-          regular expression patterns.
+          <b>Purpose:</b> Returns the nth field within a delimited string. The
+          fields are numbered starting from 1. The delimiter can consist of
+          multiple characters, not just a single character. All matching of the
+          delimiter is done exactly, not using any regular expression patterns.
           <p>
             <b>Return type:</b> <codeph>string</codeph>
           </p>
@@ -1074,7 +1073,8 @@ select replace('hello world','xyz','abc');
           <p conref="../shared/impala_common.xml#common/regexp_escapes"/>
           <p conref="../shared/impala_common.xml#common/example_blurb"/>
           <p>
-            These examples show how to retrieve the nth field from a delimited string:
+            These examples show how to retrieve the nth field from a delimited
+            string:
           </p>
 <codeblock><![CDATA[
 select split_part('x,y,z',',',1);
@@ -1097,8 +1097,8 @@ select split_part('x,y,z',',',3);
 +-----------------------------+
 | z                           |
 +-----------------------------+
+]]>
 </codeblock>
-
           <p>
             These examples show what happens for out-of-range field positions.
             Specifying a value less than 1 produces an error. Specifying a value
@@ -1120,8 +1120,8 @@ from t1
 +-------------------+-------------------------------------+---------------------------+
 |                   | []                                  | 0                         |
 +-------------------+-------------------------------------+---------------------------+
+]]>
 </codeblock>
-
           <p>
             These examples show how the delimiter can be a multi-character value:
           </p>
@@ -1158,8 +1158,8 @@ select split_part('one\|/two\|/three','\|/',3);
           <p>
             <b>Return type:</b> <codeph>string</codeph>
           </p>
-        </dd>
 
+        </dd>
       </dlentry>
 
       <dlentry id="strright">


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

Posted by ta...@apache.org.
http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/exec/partitioned-hash-join-builder.h
----------------------------------------------------------------------
diff --git a/be/src/exec/partitioned-hash-join-builder.h b/be/src/exec/partitioned-hash-join-builder.h
index 4123b1f..e075beb 100644
--- a/be/src/exec/partitioned-hash-join-builder.h
+++ b/be/src/exec/partitioned-hash-join-builder.h
@@ -270,6 +270,9 @@ class PhjBuilder : public DataSink {
     return spillable_buffer_size_ * (num_reserved_buffers - 2) + max_row_buffer_size_ * 2;
   }
 
+  /// Class name in LLVM IR.
+  static const char* LLVM_CLASS_NAME;
+
  private:
   /// Create and initialize a set of hash partitions for partitioning level 'level'.
   /// The previous hash partitions must have been cleared with ClearHashPartitions().
@@ -503,9 +506,6 @@ class PhjBuilder : public DataSink {
   /// Jitted Partition::InsertBatch() function pointers. NULL if codegen is disabled.
   InsertBatchFn insert_batch_fn_;
   InsertBatchFn insert_batch_fn_level0_;
-
-  /// Class name in LLVM IR.
-  static const char* LLVM_CLASS_NAME;
 };
 }
 

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/exec/partitioned-hash-join-node.cc
----------------------------------------------------------------------
diff --git a/be/src/exec/partitioned-hash-join-node.cc b/be/src/exec/partitioned-hash-join-node.cc
index dd3efd1..5aa9e98 100644
--- a/be/src/exec/partitioned-hash-join-node.cc
+++ b/be/src/exec/partitioned-hash-join-node.cc
@@ -1293,18 +1293,13 @@ string PartitionedHashJoinNode::NodeDebugString() const {
 // }
 Status PartitionedHashJoinNode::CodegenCreateOutputRow(
     LlvmCodeGen* codegen, llvm::Function** fn) {
-  llvm::Type* tuple_row_type = codegen->GetType(TupleRow::LLVM_CLASS_NAME);
-  DCHECK(tuple_row_type != NULL);
-  llvm::PointerType* tuple_row_ptr_type = llvm::PointerType::get(tuple_row_type, 0);
+  llvm::PointerType* tuple_row_ptr_type = codegen->GetStructPtrType<TupleRow>();
 
-  llvm::Type* this_type = codegen->GetType(BlockingJoinNode::LLVM_CLASS_NAME);
-  DCHECK(this_type != NULL);
-  llvm::PointerType* this_ptr_type = llvm::PointerType::get(this_type, 0);
+  llvm::PointerType* this_ptr_type = codegen->GetStructPtrType<BlockingJoinNode>();
 
   // TupleRows are really just an array of pointers.  Easier to work with them
   // this way.
-  llvm::PointerType* tuple_row_working_type =
-      llvm::PointerType::get(codegen->ptr_type(), 0);
+  llvm::PointerType* tuple_row_working_type = codegen->ptr_ptr_type();
 
   // Construct function signature to match CreateOutputRow()
   LlvmCodeGen::FnPrototype prototype(codegen, "CreateOutputRow", codegen->void_type());
@@ -1329,7 +1324,7 @@ Status PartitionedHashJoinNode::CodegenCreateOutputRow(
 
   // Copy probe row
   codegen->CodegenMemcpy(&builder, out_row_arg, probe_row_arg, probe_tuple_row_size_);
-  llvm::Value* build_row_idx[] = {codegen->GetIntConstant(TYPE_INT, num_probe_tuples)};
+  llvm::Value* build_row_idx[] = {codegen->GetI32Constant(num_probe_tuples)};
   llvm::Value* build_row_dst =
       builder.CreateInBoundsGEP(out_row_arg, build_row_idx, "build_dst_ptr");
 
@@ -1352,7 +1347,7 @@ Status PartitionedHashJoinNode::CodegenCreateOutputRow(
     builder.SetInsertPoint(build_null_block);
     for (int i = 0; i < num_build_tuples; ++i) {
       llvm::Value* array_idx[] = {
-          codegen->GetIntConstant(TYPE_INT, i + num_probe_tuples)};
+          codegen->GetI32Constant(i + num_probe_tuples)};
       llvm::Value* dst =
           builder.CreateInBoundsGEP(out_row_arg, array_idx, "dst_tuple_ptr");
       builder.CreateStore(codegen->null_ptr_value(), dst);
@@ -1430,8 +1425,7 @@ Status PartitionedHashJoinNode::CodegenProcessProbeBatch(
   llvm::Value* prefetch_mode_arg = codegen->GetArgument(process_probe_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));
 
   // Codegen HashTable::Equals
   llvm::Function* probe_equals_fn;

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/exec/text-converter.cc
----------------------------------------------------------------------
diff --git a/be/src/exec/text-converter.cc b/be/src/exec/text-converter.cc
index ddd0d6e..9e919a3 100644
--- a/be/src/exec/text-converter.cc
+++ b/be/src/exec/text-converter.cc
@@ -133,10 +133,10 @@ Status TextConverter::CodegenWriteSlot(LlvmCodeGen* codegen,
   llvm::PointerType* tuple_ptr_type = tuple_type->getPointerTo();
 
   LlvmCodeGen::FnPrototype prototype(
-      codegen, "WriteSlot", codegen->GetType(TYPE_BOOLEAN));
+      codegen, "WriteSlot", codegen->bool_type());
   prototype.AddArgument(LlvmCodeGen::NamedVariable("tuple_arg", tuple_ptr_type));
   prototype.AddArgument(LlvmCodeGen::NamedVariable("data", codegen->ptr_type()));
-  prototype.AddArgument(LlvmCodeGen::NamedVariable("len", codegen->GetType(TYPE_INT)));
+  prototype.AddArgument(LlvmCodeGen::NamedVariable("len", codegen->i32_type()));
 
   LlvmBuilder builder(codegen->context());
   llvm::Value* args[3];
@@ -161,7 +161,7 @@ Status TextConverter::CodegenWriteSlot(LlvmCodeGen* codegen,
           llvm::ArrayRef<llvm::Value*>(
               {args[1], args[2], codegen->CastPtrToLlvmPtr(codegen->ptr_type(),
                                      const_cast<char*>(null_col_val)),
-                  codegen->GetIntConstant(TYPE_INT, len)}));
+                  codegen->GetI32Constant(len)}));
     }
   } else {
     // Constant FALSE as branch condition. We rely on later optimization passes
@@ -175,7 +175,7 @@ Status TextConverter::CodegenWriteSlot(LlvmCodeGen* codegen,
     builder.SetInsertPoint(check_zero_block);
     // If len == 0 and it is not a string col, set slot to NULL
     llvm::Value* null_len =
-        builder.CreateICmpEQ(args[2], codegen->GetIntConstant(TYPE_INT, 0));
+        builder.CreateICmpEQ(args[2], codegen->GetI32Constant(0));
     builder.CreateCondBr(null_len, set_null_block, parse_slot_block);
   }
 
@@ -193,7 +193,7 @@ Status TextConverter::CodegenWriteSlot(LlvmCodeGen* codegen,
     DCHECK(slot_desc->type().type != TYPE_CHAR);
     if (slot_desc->type().type == TYPE_VARCHAR) {
       // determine if we need to truncate the string
-      llvm::Value* maxlen = codegen->GetIntConstant(TYPE_INT, slot_desc->type().len);
+      llvm::Value* maxlen = codegen->GetI32Constant(slot_desc->type().len);
       llvm::Value* len_lt_maxlen =
           builder.CreateICmpSLT(args[2], maxlen, "len_lt_maxlen");
       llvm::Value* minlen =
@@ -260,7 +260,7 @@ Status TextConverter::CodegenWriteSlot(LlvmCodeGen* codegen,
     llvm::BasicBlock *parse_success_block, *parse_failed_block;
     codegen->CreateIfElseBlocks(*fn, "parse_success", "parse_fail",
         &parse_success_block, &parse_failed_block);
-    LlvmCodeGen::NamedVariable parse_result("parse_result", codegen->GetType(TYPE_INT));
+    LlvmCodeGen::NamedVariable parse_result("parse_result", codegen->i32_type());
     llvm::Value* parse_result_ptr = codegen->CreateEntryBlockAlloca(*fn, parse_result);
 
     llvm::CallInst* parse_return;
@@ -269,8 +269,8 @@ Status TextConverter::CodegenWriteSlot(LlvmCodeGen* codegen,
     if (slot_desc->type().type == TYPE_DECIMAL) {
       // Special case for decimal since it has additional precision/scale parameters
       parse_return = builder.CreateCall(parse_fn, {args[1], args[2],
-          codegen->GetIntConstant(TYPE_INT, slot_desc->type().precision),
-          codegen->GetIntConstant(TYPE_INT, slot_desc->type().scale), parse_result_ptr});
+          codegen->GetI32Constant(slot_desc->type().precision),
+          codegen->GetI32Constant(slot_desc->type().scale), parse_result_ptr});
     } else if (slot_desc->type().type == TYPE_TIMESTAMP) {
       // If the return value is large (more than 16 bytes in our toolchain) the first
       // parameter would be a pointer to value parsed and the return value of callee
@@ -282,7 +282,7 @@ Status TextConverter::CodegenWriteSlot(LlvmCodeGen* codegen,
     }
     llvm::Value* parse_result_val = builder.CreateLoad(parse_result_ptr, "parse_result");
     llvm::Value* failed_value =
-        codegen->GetIntConstant(TYPE_INT, StringParser::PARSE_FAILURE);
+        codegen->GetI32Constant(StringParser::PARSE_FAILURE);
 
     // Check for parse error.
     llvm::Value* parse_failed =
@@ -290,7 +290,7 @@ Status TextConverter::CodegenWriteSlot(LlvmCodeGen* codegen,
     if (strict_mode) {
       // In strict_mode, also check if parse_result is PARSE_OVERFLOW.
       llvm::Value* overflow_value =
-          codegen->GetIntConstant(TYPE_INT, StringParser::PARSE_OVERFLOW);
+          codegen->GetI32Constant(StringParser::PARSE_OVERFLOW);
       llvm::Value* parse_overflow =
           builder.CreateICmpEQ(parse_result_val, overflow_value, "overflowed");
       parse_failed = builder.CreateOr(parse_failed, parse_overflow, "failed_or");

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/exprs/compound-predicates.cc
----------------------------------------------------------------------
diff --git a/be/src/exprs/compound-predicates.cc b/be/src/exprs/compound-predicates.cc
index 4d89cfa..55bc5c6 100644
--- a/be/src/exprs/compound-predicates.cc
+++ b/be/src/exprs/compound-predicates.cc
@@ -213,7 +213,7 @@ Status CompoundPredicate::CodegenComputeFn(
 
   // not-NULL block
   builder.SetInsertPoint(not_null_block);
-  llvm::PHINode* not_null_phi = builder.CreatePHI(codegen->GetType(TYPE_BOOLEAN), 3);
+  llvm::PHINode* not_null_phi = builder.CreatePHI(codegen->bool_type(), 3);
   if (and_fn) {
     not_null_phi->addIncoming(codegen->false_value(), lhs_null_rhs_not_null_block);
     not_null_phi->addIncoming(codegen->false_value(), lhs_not_null_rhs_null_block);
@@ -227,11 +227,11 @@ Status CompoundPredicate::CodegenComputeFn(
 
   // Ret/merge block
   builder.SetInsertPoint(ret_block);
-  llvm::PHINode* is_null_phi = builder.CreatePHI(codegen->boolean_type(), 2, "is_null");
+  llvm::PHINode* is_null_phi = builder.CreatePHI(codegen->bool_type(), 2, "is_null");
   is_null_phi->addIncoming(codegen->true_value(), null_block);
   is_null_phi->addIncoming(codegen->false_value(), not_null_block);
 
-  llvm::PHINode* val_phi = builder.CreatePHI(codegen->boolean_type(), 2, "val");
+  llvm::PHINode* val_phi = builder.CreatePHI(codegen->bool_type(), 2, "val");
   val_phi->addIncoming(codegen->false_value(), null_block);
   val_phi->addIncoming(not_null_phi, not_null_block);
 

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/exprs/scalar-expr.cc
----------------------------------------------------------------------
diff --git a/be/src/exprs/scalar-expr.cc b/be/src/exprs/scalar-expr.cc
index 035dad5..42c2867 100644
--- a/be/src/exprs/scalar-expr.cc
+++ b/be/src/exprs/scalar-expr.cc
@@ -367,9 +367,9 @@ llvm::Function* ScalarExpr::CreateIrFunctionPrototype(
   LlvmCodeGen::FnPrototype prototype(codegen, name, return_type);
   prototype.AddArgument(
       LlvmCodeGen::NamedVariable(
-          "eval", codegen->GetPtrType(ScalarExprEvaluator::LLVM_CLASS_NAME)));
-  prototype.AddArgument(
-      LlvmCodeGen::NamedVariable("row", codegen->GetPtrType(TupleRow::LLVM_CLASS_NAME)));
+          "eval", codegen->GetStructPtrType<ScalarExprEvaluator>()));
+  prototype.AddArgument(LlvmCodeGen::NamedVariable(
+      "row", codegen->GetStructPtrType<TupleRow>()));
   llvm::Function* function = prototype.GeneratePrototype(NULL, args[0]);
   DCHECK(function != NULL);
   return function;
@@ -389,8 +389,8 @@ Status ScalarExpr::GetCodegendComputeFnWrapper(
   llvm::BasicBlock* entry_block =
       llvm::BasicBlock::Create(codegen->context(), "entry", ir_compute_fn_);
   LlvmBuilder builder(entry_block);
-  llvm::Value* this_ptr =
-      codegen->CastPtrToLlvmPtr(codegen->GetPtrType(ScalarExpr::LLVM_CLASS_NAME), this);
+  llvm::Value* this_ptr = codegen->CastPtrToLlvmPtr(
+      codegen->GetStructPtrType<ScalarExpr>(), this);
   llvm::Value* compute_fn_args[] = {this_ptr, args[0], args[1]};
   llvm::Value* ret = CodegenAnyVal::CreateCall(
       codegen, &builder, static_getval_fn, compute_fn_args, "ret");

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/exprs/scalar-fn-call.cc
----------------------------------------------------------------------
diff --git a/be/src/exprs/scalar-fn-call.cc b/be/src/exprs/scalar-fn-call.cc
index ffe8d27..acf6208 100644
--- a/be/src/exprs/scalar-fn-call.cc
+++ b/be/src/exprs/scalar-fn-call.cc
@@ -367,7 +367,7 @@ Status ScalarFnCall::GetCodegendComputeFn(LlvmCodeGen* codegen, llvm::Function**
       // Set 'child_fn' to the interpreted function
       child_fn = GetStaticGetValWrapper(children_[i]->type(), codegen);
       // First argument to interpreted function is children_[i]
-      llvm::Type* expr_ptr_type = codegen->GetPtrType(ScalarExpr::LLVM_CLASS_NAME);
+      llvm::Type* expr_ptr_type = codegen->GetStructPtrType<ScalarExpr>();
       child_fn_args.push_back(codegen->CastPtrToLlvmPtr(expr_ptr_type, children_[i]));
     }
     child_fn_args.push_back(eval);
@@ -400,7 +400,7 @@ Status ScalarFnCall::GetCodegendComputeFn(LlvmCodeGen* codegen, llvm::Function**
     DCHECK_EQ(udf_args.size(), vararg_start_idx_ + 1);
     DCHECK_GE(GetNumChildren(), 1);
     // Add the number of varargs
-    udf_args.push_back(codegen->GetIntConstant(TYPE_INT, NumVarArgs()));
+    udf_args.push_back(codegen->GetI32Constant(NumVarArgs()));
     // Add all the accumulated vararg inputs as one input argument.
     llvm::PointerType* vararg_type =
         CodegenAnyVal::GetUnloweredPtrType(codegen, VarArgsType());

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/exprs/slot-ref.cc
----------------------------------------------------------------------
diff --git a/be/src/exprs/slot-ref.cc b/be/src/exprs/slot-ref.cc
index d529013..00616b3 100644
--- a/be/src/exprs/slot-ref.cc
+++ b/be/src/exprs/slot-ref.cc
@@ -188,10 +188,10 @@ Status SlotRef::GetCodegendComputeFn(LlvmCodeGen* codegen, llvm::Function** fn)
   *fn = CreateIrFunctionPrototype("GetSlotRef", codegen, &args);
   llvm::Value* row_ptr = args[1];
 
-  llvm::Value* tuple_offset = llvm::ConstantInt::get(codegen->int_type(), tuple_idx_);
-  llvm::Value* slot_offset = llvm::ConstantInt::get(codegen->int_type(), slot_offset_);
-  llvm::Value* zero = llvm::ConstantInt::get(codegen->GetType(TYPE_TINYINT), 0);
-  llvm::Value* one = llvm::ConstantInt::get(codegen->GetType(TYPE_TINYINT), 1);
+  llvm::Value* tuple_offset = codegen->GetI32Constant(tuple_idx_);
+  llvm::Value* slot_offset = codegen->GetI32Constant(slot_offset_);
+  llvm::Value* zero = codegen->GetI8Constant(0);
+  llvm::Value* one = codegen->GetI8Constant(1);
 
   llvm::BasicBlock* entry_block = llvm::BasicBlock::Create(context, "entry", *fn);
   bool slot_is_nullable = null_indicator_offset_.bit_mask != 0;
@@ -206,7 +206,7 @@ Status SlotRef::GetCodegendComputeFn(LlvmCodeGen* codegen, llvm::Function** fn)
   LlvmBuilder builder(entry_block);
   // Get the tuple offset addr from the row
   llvm::Value* cast_row_ptr = builder.CreateBitCast(
-      row_ptr, llvm::PointerType::get(codegen->ptr_type(), 0), "cast_row_ptr");
+      row_ptr, codegen->ptr_ptr_type(), "cast_row_ptr");
   llvm::Value* tuple_addr =
       builder.CreateInBoundsGEP(cast_row_ptr, tuple_offset, "tuple_addr");
   // Load the tuple*
@@ -240,8 +240,8 @@ Status SlotRef::GetCodegendComputeFn(LlvmCodeGen* codegen, llvm::Function** fn)
   // Branch for slot != NULL
   builder.SetInsertPoint(get_slot_block);
   llvm::Value* slot_ptr = builder.CreateInBoundsGEP(tuple_ptr, slot_offset, "slot_addr");
-  llvm::Value* val_ptr =
-      builder.CreateBitCast(slot_ptr, codegen->GetPtrType(type_), "val_ptr");
+  llvm::Value* val_ptr = builder.CreateBitCast(slot_ptr,
+      codegen->GetSlotPtrType(type_), "val_ptr");
   // Depending on the type, load the values we need
   llvm::Value* val = NULL;
   llvm::Value* ptr = NULL;
@@ -256,18 +256,18 @@ Status SlotRef::GetCodegendComputeFn(LlvmCodeGen* codegen, llvm::Function** fn)
   } else if (type_.type == TYPE_FIXED_UDA_INTERMEDIATE) {
     // ptr and len are the slot and its fixed length.
     ptr = builder.CreateBitCast(val_ptr, codegen->ptr_type());
-    len = codegen->GetIntConstant(TYPE_INT, type_.len);
+    len = codegen->GetI32Constant(type_.len);
   } else if (type_.type == TYPE_TIMESTAMP) {
     llvm::Value* time_of_day_ptr =
         builder.CreateStructGEP(NULL, val_ptr, 0, "time_of_day_ptr");
     // Cast boost::posix_time::time_duration to i64
     llvm::Value* time_of_day_cast =
-        builder.CreateBitCast(time_of_day_ptr, codegen->GetPtrType(TYPE_BIGINT));
+        builder.CreateBitCast(time_of_day_ptr, codegen->i64_ptr_type());
     time_of_day = builder.CreateLoad(time_of_day_cast, "time_of_day");
     llvm::Value* date_ptr = builder.CreateStructGEP(NULL, val_ptr, 1, "date_ptr");
     // Cast boost::gregorian::date to i32
     llvm::Value* date_cast =
-        builder.CreateBitCast(date_ptr, codegen->GetPtrType(TYPE_INT));
+        builder.CreateBitCast(date_ptr, codegen->i32_ptr_type());
     date = builder.CreateLoad(date_cast, "date");
   } else {
     // val_ptr is a native type
@@ -278,7 +278,7 @@ Status SlotRef::GetCodegendComputeFn(LlvmCodeGen* codegen, llvm::Function** fn)
   // Return block
   builder.SetInsertPoint(ret_block);
   llvm::PHINode* is_null_phi =
-      builder.CreatePHI(codegen->tinyint_type(), 2, "is_null_phi");
+      builder.CreatePHI(codegen->i8_type(), 2, "is_null_phi");
   if (tuple_is_nullable_) is_null_phi->addIncoming(one, entry_block);
   if (check_slot_null_indicator_block != NULL) {
     is_null_phi->addIncoming(one, check_slot_null_indicator_block);

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/runtime/descriptors.cc
----------------------------------------------------------------------
diff --git a/be/src/runtime/descriptors.cc b/be/src/runtime/descriptors.cc
index bd67689..bc983de 100644
--- a/be/src/runtime/descriptors.cc
+++ b/be/src/runtime/descriptors.cc
@@ -76,13 +76,13 @@ string NullIndicatorOffset::DebugString() const {
 
 llvm::Constant* NullIndicatorOffset::ToIR(LlvmCodeGen* codegen) const {
   llvm::StructType* null_indicator_offset_type =
-      static_cast<llvm::StructType*>(codegen->GetType(LLVM_CLASS_NAME));
+      codegen->GetStructType<NullIndicatorOffset>();
   // Populate padding at end of struct with zeroes.
   llvm::ConstantAggregateZero* zeroes =
       llvm::ConstantAggregateZero::get(null_indicator_offset_type);
   return llvm::ConstantStruct::get(null_indicator_offset_type,
-      {llvm::ConstantInt::get(codegen->int_type(), byte_offset),
-          llvm::ConstantInt::get(codegen->tinyint_type(), bit_mask),
+      {codegen->GetI32Constant(byte_offset),
+          codegen->GetI8Constant(bit_mask),
           zeroes->getStructElement(2)});
 }
 
@@ -634,10 +634,9 @@ llvm::Value* SlotDescriptor::CodegenIsNull(LlvmCodeGen* codegen, LlvmBuilder* bu
     const NullIndicatorOffset& null_indicator_offset, llvm::Value* tuple) {
   llvm::Value* null_byte =
       CodegenGetNullByte(codegen, builder, null_indicator_offset, tuple, nullptr);
-  llvm::Constant* mask =
-      llvm::ConstantInt::get(codegen->tinyint_type(), null_indicator_offset.bit_mask);
+  llvm::Constant* mask = codegen->GetI8Constant(null_indicator_offset.bit_mask);
   llvm::Value* null_mask = builder->CreateAnd(null_byte, mask, "null_mask");
-  llvm::Constant* zero = llvm::ConstantInt::get(codegen->tinyint_type(), 0);
+  llvm::Constant* zero = codegen->GetI8Constant(0);
   return builder->CreateICmpNE(null_mask, zero, "is_null");
 }
 
@@ -653,14 +652,12 @@ llvm::Value* SlotDescriptor::CodegenIsNull(LlvmCodeGen* codegen, LlvmBuilder* bu
 void SlotDescriptor::CodegenSetNullIndicator(
     LlvmCodeGen* codegen, LlvmBuilder* builder, llvm::Value* tuple, llvm::Value* is_null)
     const {
-  DCHECK_EQ(is_null->getType(), codegen->boolean_type());
+  DCHECK_EQ(is_null->getType(), codegen->bool_type());
   llvm::Value* null_byte_ptr;
   llvm::Value* null_byte =
       CodegenGetNullByte(codegen, builder, null_indicator_offset_, tuple, &null_byte_ptr);
-  llvm::Constant* mask =
-      llvm::ConstantInt::get(codegen->tinyint_type(), null_indicator_offset_.bit_mask);
-  llvm::Constant* not_mask =
-      llvm::ConstantInt::get(codegen->tinyint_type(), ~null_indicator_offset_.bit_mask);
+  llvm::Constant* mask = codegen->GetI8Constant(null_indicator_offset_.bit_mask);
+  llvm::Constant* not_mask = codegen->GetI8Constant(~null_indicator_offset_.bit_mask);
 
   llvm::ConstantInt* constant_is_null = llvm::dyn_cast<llvm::ConstantInt>(is_null);
   llvm::Value* result = nullptr;
@@ -677,7 +674,7 @@ void SlotDescriptor::CodegenSetNullIndicator(
     llvm::Value* byte_with_cleared_bit =
         builder->CreateAnd(null_byte, not_mask, "null_bit_cleared");
     llvm::Value* sign_extended_null =
-        builder->CreateSExt(is_null, codegen->tinyint_type());
+        builder->CreateSExt(is_null, codegen->i8_type());
     llvm::Value* bit_only = builder->CreateAnd(sign_extended_null, mask, "null_bit");
     result = builder->CreateOr(byte_with_cleared_bit, bit_only, "null_bit_set");
   }
@@ -690,7 +687,7 @@ llvm::Value* SlotDescriptor::CodegenGetNullByte(
     const NullIndicatorOffset& null_indicator_offset, llvm::Value* tuple,
     llvm::Value** null_byte_ptr) {
   llvm::Constant* byte_offset =
-      llvm::ConstantInt::get(codegen->int_type(), null_indicator_offset.byte_offset);
+      codegen->GetI32Constant(null_indicator_offset.byte_offset);
   llvm::Value* tuple_bytes = builder->CreateBitCast(tuple, codegen->ptr_type());
   llvm::Value* byte_ptr =
       builder->CreateInBoundsGEP(tuple_bytes, byte_offset, "null_byte_ptr");
@@ -716,18 +713,18 @@ llvm::StructType* TupleDescriptor::GetLlvmStruct(LlvmCodeGen* codegen) const {
     if (slot->type().type == TYPE_CHAR) return nullptr;
     DCHECK_EQ(curr_struct_offset, slot->tuple_offset());
     slot->llvm_field_idx_ = struct_fields.size();
-    struct_fields.push_back(codegen->GetType(slot->type()));
+    struct_fields.push_back(codegen->GetSlotType(slot->type()));
     curr_struct_offset = slot->tuple_offset() + slot->slot_size();
   }
   // For each null byte, add a byte to the struct
   for (int i = 0; i < num_null_bytes_; ++i) {
-    struct_fields.push_back(codegen->GetType(TYPE_TINYINT));
+    struct_fields.push_back(codegen->i8_type());
     ++curr_struct_offset;
   }
 
   DCHECK_LE(curr_struct_offset, byte_size_);
   if (curr_struct_offset < byte_size_) {
-    struct_fields.push_back(llvm::ArrayType::get(codegen->GetType(TYPE_TINYINT),
+    struct_fields.push_back(llvm::ArrayType::get(codegen->i8_type(),
         byte_size_ - curr_struct_offset));
   }
 

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/runtime/tuple.cc
----------------------------------------------------------------------
diff --git a/be/src/runtime/tuple.cc b/be/src/runtime/tuple.cc
index 787c3a4..627c7a4 100644
--- a/be/src/runtime/tuple.cc
+++ b/be/src/runtime/tuple.cc
@@ -330,15 +330,14 @@ Status Tuple::CodegenMaterializeExprs(LlvmCodeGen* codegen, bool collect_string_
   // void MaterializeExprs(Tuple* tuple, TupleRow* row, TupleDescriptor* desc,
   //     ScalarExprEvaluator** slot_materialize_exprs, MemPool* pool,
   //     StringValue** non_null_string_values, int* total_string_lengths)
-  llvm::PointerType* opaque_tuple_type = codegen->GetPtrType(Tuple::LLVM_CLASS_NAME);
-  llvm::PointerType* row_type = codegen->GetPtrType(TupleRow::LLVM_CLASS_NAME);
-  llvm::PointerType* desc_type = codegen->GetPtrType(TupleDescriptor::LLVM_CLASS_NAME);
+  llvm::PointerType* opaque_tuple_type = codegen->GetStructPtrType<Tuple>();
+  llvm::PointerType* row_type = codegen->GetStructPtrType<TupleRow>();
+  llvm::PointerType* desc_type = codegen->GetStructPtrType<TupleDescriptor>();
   llvm::PointerType* expr_evals_type =
-      codegen->GetPtrType(codegen->GetPtrType(ScalarExprEvaluator::LLVM_CLASS_NAME));
-  llvm::PointerType* pool_type = codegen->GetPtrType(MemPool::LLVM_CLASS_NAME);
-  llvm::PointerType* string_values_type =
-      codegen->GetPtrType(codegen->GetPtrType(StringValue::LLVM_CLASS_NAME));
-  llvm::PointerType* int_ptr_type = codegen->GetPtrType(TYPE_INT);
+      codegen->GetStructPtrPtrType<ScalarExprEvaluator>();
+  llvm::PointerType* pool_type = codegen->GetStructPtrType<MemPool>();
+  llvm::PointerType* string_values_type = codegen->GetStructPtrPtrType<StringValue>();
+  llvm::PointerType* int_ptr_type = codegen->i32_ptr_type();
   LlvmCodeGen::FnPrototype prototype(codegen, "MaterializeExprs", codegen->void_type());
   prototype.AddArgument("opaque_tuple", opaque_tuple_type);
   prototype.AddArgument("row", row_type);
@@ -401,20 +400,18 @@ Status Tuple::CodegenMaterializeExprs(LlvmCodeGen* codegen, bool collect_string_
 
 Status Tuple::CodegenCopyStrings(
     LlvmCodeGen* codegen, const TupleDescriptor& desc, llvm::Function** copy_strings_fn) {
-  llvm::PointerType* opaque_tuple_type = codegen->GetPtrType(Tuple::LLVM_CLASS_NAME);
-  llvm::PointerType* runtime_state_type =
-      codegen->GetPtrType(RuntimeState::LLVM_CLASS_NAME);
-  llvm::StructType* slot_offsets_type =
-      static_cast<llvm::StructType*>(codegen->GetType(SlotOffsets::LLVM_CLASS_NAME));
-  llvm::PointerType* pool_type = codegen->GetPtrType(MemPool::LLVM_CLASS_NAME);
-  llvm::PointerType* status_type = codegen->GetPtrType(Status::LLVM_CLASS_NAME);
+  llvm::PointerType* opaque_tuple_type = codegen->GetStructPtrType<Tuple>();
+  llvm::PointerType* runtime_state_type = codegen->GetStructPtrType<RuntimeState>();
+  llvm::StructType* slot_offsets_type = codegen->GetStructType<SlotOffsets>();
+  llvm::PointerType* pool_type = codegen->GetStructPtrType<MemPool>();
+  llvm::PointerType* status_type = codegen->GetStructPtrType<Status>();
   LlvmCodeGen::FnPrototype prototype(
-      codegen, "CopyStringsWrapper", codegen->boolean_type());
+      codegen, "CopyStringsWrapper", codegen->bool_type());
   prototype.AddArgument("opaque_tuple", opaque_tuple_type);
   prototype.AddArgument("err_ctx", codegen->ptr_type());
   prototype.AddArgument("state", runtime_state_type);
   prototype.AddArgument("slot_offsets", codegen->GetPtrType(slot_offsets_type));
-  prototype.AddArgument("num_string_slots", codegen->int_type());
+  prototype.AddArgument("num_string_slots", codegen->i32_type());
   prototype.AddArgument("pool", pool_type);
   prototype.AddArgument("status", status_type);
 
@@ -440,8 +437,7 @@ Status Tuple::CodegenCopyStrings(
   }
   llvm::Constant* constant_slot_offsets = codegen->ConstantsToGVArrayPtr(
       slot_offsets_type, slot_offset_ir_constants, "slot_offsets");
-  llvm::Constant* num_string_slots =
-      llvm::ConstantInt::get(codegen->int_type(), desc.string_slots().size());
+  llvm::Constant* num_string_slots = codegen->GetI32Constant(desc.string_slots().size());
   // Get SlotOffsets* pointer to the first element of the constant array.
   llvm::Value* constant_slot_offsets_first_element_ptr =
       builder.CreateConstGEP2_64(constant_slot_offsets, 0, 0);
@@ -460,9 +456,9 @@ Status Tuple::CodegenCopyStrings(
 
 llvm::Constant* SlotOffsets::ToIR(LlvmCodeGen* codegen) const {
   return llvm::ConstantStruct::get(
-      static_cast<llvm::StructType*>(codegen->GetType(LLVM_CLASS_NAME)),
+      codegen->GetStructType<SlotOffsets>(),
       {null_indicator_offset.ToIR(codegen),
-          llvm::ConstantInt::get(codegen->int_type(), tuple_offset)});
+          codegen->GetI32Constant(tuple_offset)});
 }
 
 template void Tuple::MaterializeExprs<false, false>(TupleRow*, const TupleDescriptor&,

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/runtime/types.cc
----------------------------------------------------------------------
diff --git a/be/src/runtime/types.cc b/be/src/runtime/types.cc
index d2b215f..c18c66e 100644
--- a/be/src/runtime/types.cc
+++ b/be/src/runtime/types.cc
@@ -345,18 +345,16 @@ ostream& operator<<(ostream& os, const ColumnType& type) {
 
 llvm::ConstantStruct* ColumnType::ToIR(LlvmCodeGen* codegen) const {
   // ColumnType = { i32, i32, i32, i32, <vector>, <vector> }
-  llvm::StructType* column_type_type =
-      llvm::cast<llvm::StructType>(codegen->GetType(LLVM_CLASS_NAME));
+  llvm::StructType* column_type_type = codegen->GetStructType<ColumnType>();
 
   DCHECK_EQ(sizeof(type), sizeof(int32_t));
-  llvm::Constant* type_field = llvm::ConstantInt::get(codegen->int_type(), type);
+  llvm::Constant* type_field = codegen->GetI32Constant(type);
   DCHECK_EQ(sizeof(len), sizeof(int32_t));
-  llvm::Constant* len_field = llvm::ConstantInt::get(codegen->int_type(), len);
+  llvm::Constant* len_field = codegen->GetI32Constant(len);
   DCHECK_EQ(sizeof(precision), sizeof(int32_t));
-  llvm::Constant* precision_field =
-      llvm::ConstantInt::get(codegen->int_type(), precision);
+  llvm::Constant* precision_field = codegen->GetI32Constant(precision);
   DCHECK_EQ(sizeof(scale), sizeof(int32_t));
-  llvm::Constant* scale_field = llvm::ConstantInt::get(codegen->int_type(), scale);
+  llvm::Constant* scale_field = codegen->GetI32Constant(scale);
 
   // Create empty 'children' and 'field_names' vectors
   DCHECK(children.empty()) << "Nested types NYI";

http://git-wip-us.apache.org/repos/asf/impala/blob/f562be8c/be/src/util/tuple-row-compare.cc
----------------------------------------------------------------------
diff --git a/be/src/util/tuple-row-compare.cc b/be/src/util/tuple-row-compare.cc
index ad92e84..5620dae 100644
--- a/be/src/util/tuple-row-compare.cc
+++ b/be/src/util/tuple-row-compare.cc
@@ -221,9 +221,9 @@ Status TupleRowComparator::CodegenCompare(LlvmCodeGen* codegen, llvm::Function**
   //     ScalarExprEvaluator** ordering_expr_evals_rhs,
   //     TupleRow* lhs, TupleRow* rhs)
   llvm::PointerType* expr_evals_type =
-      codegen->GetPtrPtrType(ScalarExprEvaluator::LLVM_CLASS_NAME);
-  llvm::PointerType* tuple_row_type = codegen->GetPtrType(TupleRow::LLVM_CLASS_NAME);
-  LlvmCodeGen::FnPrototype prototype(codegen, "Compare", codegen->int_type());
+      codegen->GetStructPtrPtrType<ScalarExprEvaluator>();
+  llvm::PointerType* tuple_row_type = codegen->GetStructPtrType<TupleRow>();
+  LlvmCodeGen::FnPrototype prototype(codegen, "Compare", codegen->i32_type());
   prototype.AddArgument("ordering_expr_evals_lhs", expr_evals_type);
   prototype.AddArgument("ordering_expr_evals_rhs", expr_evals_type);
   prototype.AddArgument("lhs", tuple_row_type);


[2/5] impala git commit: IMPALA-6424: Avoid loading metadata twice when refreshing unloaded tables

Posted by ta...@apache.org.
IMPALA-6424: Avoid loading metadata twice when refreshing unloaded tables

This commit fixes an issue where table metadata are loaded twice if a
REFRESH statement is executed on an unloaded table. With this fix, we
initially check the state of the table (loaded, unloaded) and we only
refresh metadata if the table is in a loaded state. If table is
unloaded, we load the metadata from scratch.

Testing:
Run exhaustive tests

Change-Id: Ie41a734493dcea0e36d6b051966f1d0302907dee
Reviewed-on: http://gerrit.cloudera.org:8080/9224
Reviewed-by: Dimitris Tsirogiannis <dt...@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/97f950c5
Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/97f950c5
Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/97f950c5

Branch: refs/heads/master
Commit: 97f950c54ac587970c9bc90dbf7808875e3d712d
Parents: 04383f1
Author: Dimitris Tsirogiannis <dt...@cloudera.com>
Authored: Mon Feb 5 10:20:13 2018 -0800
Committer: Impala Public Jenkins <im...@gerrit.cloudera.org>
Committed: Tue Feb 20 22:09:56 2018 +0000

----------------------------------------------------------------------
 .../impala/service/CatalogOpExecutor.java       | 28 ++++++++++++++++----
 1 file changed, 23 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/impala/blob/97f950c5/fe/src/main/java/org/apache/impala/service/CatalogOpExecutor.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/service/CatalogOpExecutor.java b/fe/src/main/java/org/apache/impala/service/CatalogOpExecutor.java
index f1422db..69137ef 100644
--- a/fe/src/main/java/org/apache/impala/service/CatalogOpExecutor.java
+++ b/fe/src/main/java/org/apache/impala/service/CatalogOpExecutor.java
@@ -3095,12 +3095,30 @@ public class CatalogOpExecutor {
       TCatalogObject updatedThriftTable = null;
       if (req.isIs_refresh()) {
         TableName tblName = TableName.fromThrift(req.getTable_name());
-        Table tbl = getExistingTable(tblName.getDb(), tblName.getTbl());
+        // Quick check to see if the table exists in the catalog without triggering
+        // a table load.
+        Table tbl = catalog_.getTable(tblName.getDb(), tblName.getTbl());
         if (tbl != null) {
-          if (req.isSetPartition_spec()) {
-            updatedThriftTable = catalog_.reloadPartition(tbl, req.getPartition_spec());
-          } else {
-            updatedThriftTable = catalog_.reloadTable(tbl);
+          // If the table is not loaded, no need to perform refresh after the initial
+          // metadata load.
+          boolean needsRefresh = tbl.isLoaded();
+          tbl = getExistingTable(tblName.getDb(), tblName.getTbl());
+          if (tbl != null) {
+            if (needsRefresh) {
+              if (req.isSetPartition_spec()) {
+                updatedThriftTable = catalog_.reloadPartition(tbl, req.getPartition_spec());
+              } else {
+                updatedThriftTable = catalog_.reloadTable(tbl);
+              }
+            } else {
+              // Table was loaded from scratch, so it's already "refreshed".
+              tbl.getLock().lock();
+              try {
+                updatedThriftTable = tbl.toTCatalogObject();
+              } finally {
+                tbl.getLock().unlock();
+              }
+            }
           }
         }
       } else {


[3/5] impala git commit: [security] test and fixes for TLS socket EINTR issues

Posted by ta...@apache.org.
[security] test and fixes for TLS socket EINTR issues

SSL_{read,write}() can return SSL_ERROR_WANT_{READ,WRITE}
correspondingly when signal interrupts recv()/send() calls even if
SSL_MODE_AUTO_RETRY is set in the TLS context.  To handle that
properly in Socket::Blocking{Recv,Write}() methods, return
NetworkError() with appropriate POSIX error code from
TlsSocket::{Recv,Write}().

As a by-product, this changelist fixes flakiness in TestUniqueClientIds
scenario of the ClientStressTest test and other flaky tests which failed
with errors like below:

  Bad status: IO error: Could not connect to the cluster: \
    Client connection negotiation failed: client connection to \
    IP:port: Read zero bytes on a blocking Recv() call: \
    Transferred 0 of 4 bytes

Prior to this fix, the test failure ratio observed with dist-test
for TSAN builds was about 6% in multiple 1K runs.  After the fix,
no failures observed.

Change-Id: Ibec9049186f79f1c43295e4735538ed7ba4e516e
Reviewed-on: http://gerrit.cloudera.org:8080/8462
Tested-by: Kudu Jenkins
Reviewed-by: Dan Burkert <da...@apache.org>
Reviewed-by: Alexey Serbin <as...@cloudera.com>
Reviewed-on: http://gerrit.cloudera.org:8080/9360
Reviewed-by: Sailesh Mukil <sa...@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/3a68e69e
Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/3a68e69e
Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/3a68e69e

Branch: refs/heads/master
Commit: 3a68e69ec7117e697bd8964fe32ae63c7b95b319
Parents: 97f950c
Author: Todd Lipcon <to...@apache.org>
Authored: Fri Nov 3 12:39:25 2017 -0700
Committer: Impala Public Jenkins <im...@gerrit.cloudera.org>
Committed: Tue Feb 20 22:32:02 2018 +0000

----------------------------------------------------------------------
 be/src/kudu/security/CMakeLists.txt   |   1 +
 be/src/kudu/security/tls_handshake.cc |   1 -
 be/src/kudu/security/tls_socket.cc    |   9 ++
 be/src/kudu/util/net/socket.cc        |  27 +++-
 security/tls_socket-test.cc           | 196 +++++++++++++++++++++++++++++
 5 files changed, 227 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/impala/blob/3a68e69e/be/src/kudu/security/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/be/src/kudu/security/CMakeLists.txt b/be/src/kudu/security/CMakeLists.txt
index 8736e66..d3539de 100644
--- a/be/src/kudu/security/CMakeLists.txt
+++ b/be/src/kudu/security/CMakeLists.txt
@@ -122,5 +122,6 @@ if (NOT NO_TESTS)
   ADD_KUDU_TEST(crypto-test)
   ADD_KUDU_TEST(test/mini_kdc-test)
   ADD_KUDU_TEST(tls_handshake-test)
+  ADD_KUDU_TEST(tls_socket-test)
   ADD_KUDU_TEST(token-test)
 endif()

http://git-wip-us.apache.org/repos/asf/impala/blob/3a68e69e/be/src/kudu/security/tls_handshake.cc
----------------------------------------------------------------------
diff --git a/be/src/kudu/security/tls_handshake.cc b/be/src/kudu/security/tls_handshake.cc
index fdf3bb1..e1314bc 100644
--- a/be/src/kudu/security/tls_handshake.cc
+++ b/be/src/kudu/security/tls_handshake.cc
@@ -117,7 +117,6 @@ Status TlsHandshake::Continue(const string& recv, string* send) {
     DCHECK_GE(send->size(), 0);
     return Status::OK();
   }
-  DCHECK_GT(send->size(), 0);
   return Status::Incomplete("TLS Handshake incomplete");
 }
 

http://git-wip-us.apache.org/repos/asf/impala/blob/3a68e69e/be/src/kudu/security/tls_socket.cc
----------------------------------------------------------------------
diff --git a/be/src/kudu/security/tls_socket.cc b/be/src/kudu/security/tls_socket.cc
index 7aeca31..f725a49 100644
--- a/be/src/kudu/security/tls_socket.cc
+++ b/be/src/kudu/security/tls_socket.cc
@@ -52,9 +52,14 @@ Status TlsSocket::Write(const uint8_t *buf, int32_t amt, int32_t *nwritten) {
 
   errno = 0;
   int32_t bytes_written = SSL_write(ssl_.get(), buf, amt);
+  int save_errno = errno;
   if (bytes_written <= 0) {
     auto error_code = SSL_get_error(ssl_.get(), bytes_written);
     if (error_code == SSL_ERROR_WANT_WRITE) {
+      if (save_errno != 0) {
+        return Status::NetworkError("SSL_write error",
+                                    ErrnoToString(save_errno), save_errno);
+      }
       // Socket not ready to write yet.
       *nwritten = 0;
       return Status::OK();
@@ -102,6 +107,10 @@ Status TlsSocket::Recv(uint8_t *buf, int32_t amt, int32_t *nread) {
     }
     auto error_code = SSL_get_error(ssl_.get(), bytes_read);
     if (error_code == SSL_ERROR_WANT_READ) {
+      if (save_errno != 0) {
+        return Status::NetworkError("SSL_read error",
+                                    ErrnoToString(save_errno), save_errno);
+      }
       // Nothing available to read yet.
       *nread = 0;
       return Status::OK();

http://git-wip-us.apache.org/repos/asf/impala/blob/3a68e69e/be/src/kudu/util/net/socket.cc
----------------------------------------------------------------------
diff --git a/be/src/kudu/util/net/socket.cc b/be/src/kudu/util/net/socket.cc
index 60f3d4b..1603da7 100644
--- a/be/src/kudu/util/net/socket.cc
+++ b/be/src/kudu/util/net/socket.cc
@@ -27,6 +27,7 @@
 
 #include <limits>
 #include <string>
+#include <type_traits>
 
 #include <glog/logging.h>
 
@@ -55,6 +56,14 @@ DEFINE_bool_hidden(socket_inject_short_recvs, false,
 TAG_FLAG(socket_inject_short_recvs, hidden);
 TAG_FLAG(socket_inject_short_recvs, unsafe);
 
+// TODO(todd) consolidate with other copies of this!
+// Retry on EINTR for functions like read() that return -1 on error.
+#define RETRY_ON_EINTR(err, expr) do { \
+  static_assert(std::is_signed<decltype(err)>::value == true, \
+                #err " must be a signed integer"); \
+  (err) = (expr); \
+} while ((err) == -1 && errno == EINTR)
+
 namespace kudu {
 
 Socket::Socket()
@@ -339,20 +348,25 @@ Status Socket::Accept(Socket *new_conn, Sockaddr *remote, int flags) {
   if (flags & FLAG_NONBLOCKING) {
     accept_flags |= SOCK_NONBLOCK;
   }
-  new_conn->Reset(::accept4(fd_, (struct sockaddr*)&addr,
-                  &olen, accept_flags));
-  if (new_conn->GetFd() < 0) {
+  int fd = -1;
+  RETRY_ON_EINTR(fd, accept4(fd_, (struct sockaddr*)&addr,
+                             &olen, accept_flags));
+  if (fd < 0) {
     int err = errno;
     return Status::NetworkError(std::string("accept4(2) error: ") +
                                 ErrnoToString(err), Slice(), err);
   }
+  new_conn->Reset(fd);
+
 #else
-  new_conn->Reset(::accept(fd_, (struct sockaddr*)&addr, &olen));
-  if (new_conn->GetFd() < 0) {
+  int fd = -1;
+  RETRY_ON_EINTR(fd, accept(fd_, (struct sockaddr*)&addr, &olen));
+  if (fd < 0) {
     int err = errno;
     return Status::NetworkError(std::string("accept(2) error: ") +
                                 ErrnoToString(err), Slice(), err);
   }
+  new_conn->Reset(fd);
   RETURN_NOT_OK(new_conn->SetNonBlocking(flags & FLAG_NONBLOCKING));
   RETURN_NOT_OK(new_conn->SetCloseOnExec());
 #endif // defined(__linux__)
@@ -509,7 +523,8 @@ Status Socket::Recv(uint8_t *buf, int32_t amt, int32_t *nread) {
   }
 
   DCHECK_GE(fd_, 0);
-  int res = ::recv(fd_, buf, amt, 0);
+  int res;
+  RETRY_ON_EINTR(res, recv(fd_, buf, amt, 0));
   if (res <= 0) {
     if (res == 0) {
       return Status::NetworkError("Recv() got EOF from remote", Slice(), ESHUTDOWN);

http://git-wip-us.apache.org/repos/asf/impala/blob/3a68e69e/security/tls_socket-test.cc
----------------------------------------------------------------------
diff --git a/security/tls_socket-test.cc b/security/tls_socket-test.cc
new file mode 100644
index 0000000..a978e68
--- /dev/null
+++ b/security/tls_socket-test.cc
@@ -0,0 +1,196 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "kudu/security/tls_handshake.h"
+
+#include <pthread.h>
+
+#include <atomic>
+#include <csignal>
+#include <cstdint>
+#include <cstdlib>
+#include <cstring>
+#include <iostream>
+#include <memory>
+#include <string>
+#include <thread>
+
+#include <glog/logging.h>
+#include <gtest/gtest.h>
+
+#include "kudu/gutil/macros.h"
+#include "kudu/security/tls_context.h"
+#include "kudu/util/countdown_latch.h"
+#include "kudu/util/monotime.h"
+#include "kudu/util/net/sockaddr.h"
+#include "kudu/util/net/socket.h"
+#include "kudu/util/scoped_cleanup.h"
+#include "kudu/util/status.h"
+#include "kudu/util/test_macros.h"
+#include "kudu/util/test_util.h"
+
+using std::string;
+using std::thread;
+using std::unique_ptr;
+
+
+namespace kudu {
+namespace security {
+
+
+class TlsSocketTest : public KuduTest {
+ public:
+  void SetUp() override {
+    KuduTest::SetUp();
+
+    ASSERT_OK(client_tls_.Init());
+    ASSERT_OK(server_tls_.Init());
+    ASSERT_OK(server_tls_.GenerateSelfSignedCertAndKey());
+  }
+
+ protected:
+  TlsContext client_tls_;
+  TlsContext server_tls_;
+};
+
+Status DoNegotiationSide(Socket* sock, TlsHandshake* tls, const char* side) {
+  tls->set_verification_mode(TlsVerificationMode::VERIFY_NONE);
+
+  bool done = false;
+  string received;
+  while (!done) {
+    string to_send;
+    Status s = tls->Continue(received, &to_send);
+    if (s.ok()) {
+      done = true;
+    } else if (!s.IsIncomplete()) {
+      RETURN_NOT_OK_PREPEND(s, "unexpected tls error");
+    }
+    if (!to_send.empty()) {
+      size_t nwritten;
+      auto deadline = MonoTime::Now() + MonoDelta::FromSeconds(10);
+      RETURN_NOT_OK_PREPEND(sock->BlockingWrite(
+          reinterpret_cast<const uint8_t*>(to_send.data()),
+          to_send.size(), &nwritten, deadline),
+                            "error sending");
+    }
+
+    if (!done) {
+      uint8_t buf[1024];
+      int32_t n = 0;
+      RETURN_NOT_OK_PREPEND(sock->Recv(buf, arraysize(buf), &n),
+                            "error receiving");
+      received = string(reinterpret_cast<char*>(&buf[0]), n);
+    }
+  }
+  LOG(INFO) << side << ": negotiation complete";
+  return Status::OK();
+}
+
+void handler(int /* signal */) {}
+
+// Test for failures to handle EINTR during TLS connection
+// negotiation and data send/receive.
+TEST_F(TlsSocketTest, TestTlsSocketInterrupted) {
+  const MonoDelta kTimeout = MonoDelta::FromSeconds(10);
+  Sockaddr listen_addr;
+  ASSERT_OK(listen_addr.ParseString("127.0.0.1", 0));
+  Socket listener;
+  ASSERT_OK(listener.Init(0));
+  ASSERT_OK(listener.BindAndListen(listen_addr, /*listen_queue_size=*/10));
+  ASSERT_OK(listener.GetSocketAddress(&listen_addr));
+
+  // Set up a no-op signal handler for SIGUSR2.
+  struct sigaction sa, sa_old;
+  memset(&sa, 0, sizeof(sa));
+  sa.sa_handler = &handler;
+  sigaction(SIGUSR2, &sa, &sa_old);
+  SCOPED_CLEANUP({ sigaction(SIGUSR2, &sa_old, nullptr); });
+
+  // Size is big enough to not fit into output socket buffer of default size
+  // (controlled by setsockopt() with SO_SNDBUF).
+  constexpr size_t kSize = 32 * 1024 * 1024;
+
+  pthread_t server_tid;
+  CountDownLatch server_tid_sync(1);
+  std::atomic<bool> stop { false };
+  thread server([&] {
+      server_tid = pthread_self();
+      server_tid_sync.CountDown();
+      unique_ptr<Socket> sock(new Socket());
+      Sockaddr remote;
+      CHECK_OK(listener.Accept(sock.get(), &remote, /*flags=*/0));
+
+      TlsHandshake server;
+      CHECK_OK(server_tls_.InitiateHandshake(TlsHandshakeType::SERVER, &server));
+      CHECK_OK(DoNegotiationSide(sock.get(), &server, "server"));
+      CHECK_OK(server.Finish(&sock));
+
+      CHECK_OK(sock->SetRecvTimeout(kTimeout));
+      unique_ptr<uint8_t[]> buf(new uint8_t[kSize]);
+      // An "echo" loop for kSize byte buffers.
+      while (!stop) {
+        size_t n;
+        Status s = sock->BlockingRecv(buf.get(), kSize, &n, MonoTime::Now() + kTimeout);
+        if (s.ok()) {
+          size_t written;
+          s = sock->BlockingWrite(buf.get(), n, &written, MonoTime::Now() + kTimeout);
+        }
+        if (!s.ok()) {
+          CHECK(stop) << "unexpected error: " << s.ToString();
+        }
+      }
+    });
+  SCOPED_CLEANUP({ server.join(); });
+
+  // Start a thread to send signals to the server thread.
+  thread killer([&]() {
+    server_tid_sync.Wait();
+    while (!stop) {
+      PCHECK(pthread_kill(server_tid, SIGUSR2) == 0);
+      SleepFor(MonoDelta::FromMicroseconds(rand() % 10));
+    }
+  });
+  SCOPED_CLEANUP({ killer.join(); });
+
+  unique_ptr<Socket> client_sock(new Socket());
+  ASSERT_OK(client_sock->Init(0));
+  ASSERT_OK(client_sock->Connect(listen_addr));
+
+  TlsHandshake client;
+  ASSERT_OK(client_tls_.InitiateHandshake(TlsHandshakeType::CLIENT, &client));
+  ASSERT_OK(DoNegotiationSide(client_sock.get(), &client, "client"));
+  ASSERT_OK(client.Finish(&client_sock));
+
+  unique_ptr<uint8_t[]> buf(new uint8_t[kSize]);
+  for (int i = 0; i < 10; i++) {
+    SleepFor(MonoDelta::FromMilliseconds(1));
+    size_t nwritten;
+    ASSERT_OK(client_sock->BlockingWrite(buf.get(), kSize, &nwritten,
+        MonoTime::Now() + kTimeout));
+    size_t n;
+    ASSERT_OK(client_sock->BlockingRecv(buf.get(), kSize, &n,
+        MonoTime::Now() + kTimeout));
+  }
+  stop = true;
+  ASSERT_OK(client_sock->Close());
+
+  LOG(INFO) << "client done";
+}
+
+} // namespace security
+} // namespace kudu


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

Posted by ta...@apache.org.
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]);