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 2017/11/15 21:58:03 UTC

[5/5] incubator-impala git commit: IMPALA-6084: Avoid using of global namespace for llvm

IMPALA-6084: Avoid using of global namespace for llvm

There are a large number of places in the backend where
we import everything from the llvm namespace into the
global namespace. (e.g. using namespace llvm;)

Here are the reasons why we don't prefer this:
* It could make symbol conflicts if a newly added code
has same symbole name.
* It makes code readability uncomfortable. We may not
recognize a symbol came from.

We adopt a sequence of namespace specifiers in each use case.

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


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

Branch: refs/heads/master
Commit: e98d2f1c0af270930cd8a50d31b8924ad263937d
Parents: a8c123b
Author: Jinchul <ji...@gmail.com>
Authored: Wed Nov 8 06:13:33 2017 +0900
Committer: Impala Public Jenkins <im...@gerrit.cloudera.org>
Committed: Wed Nov 15 21:50:50 2017 +0000

----------------------------------------------------------------------
 be/src/benchmarks/hash-benchmark.cc          |  56 +--
 be/src/codegen/codegen-anyval.cc             | 282 +++++------
 be/src/codegen/codegen-callgraph.cc          |  30 +-
 be/src/codegen/codegen-symbol-emitter.cc     |  42 +-
 be/src/codegen/codegen-util.cc               |  17 +-
 be/src/codegen/instruction-counter-test.cc   |  82 ++--
 be/src/codegen/instruction-counter.cc        |  15 +-
 be/src/codegen/llvm-codegen-test.cc          | 100 ++--
 be/src/codegen/llvm-codegen.cc               | 560 +++++++++++-----------
 be/src/codegen/llvm-codegen.h                |   2 +-
 be/src/exec/blocking-join-node.cc            |   1 -
 be/src/exec/exec-node.cc                     |  34 +-
 be/src/exec/filter-context.cc                | 140 +++---
 be/src/exec/hash-table.cc                    | 247 +++++-----
 be/src/exec/hdfs-avro-scanner.cc             | 162 ++++---
 be/src/exec/hdfs-parquet-scanner.cc          |  49 +-
 be/src/exec/hdfs-scan-node-base.cc           |   3 +-
 be/src/exec/hdfs-scanner.cc                  | 144 +++---
 be/src/exec/hdfs-sequence-scanner.cc         |   5 +-
 be/src/exec/hdfs-text-scanner.cc             |   5 +-
 be/src/exec/partitioned-aggregation-node.cc  | 165 +++----
 be/src/exec/partitioned-hash-join-builder.cc |  78 ++-
 be/src/exec/partitioned-hash-join-node.cc    |  79 ++-
 be/src/exec/select-node.cc                   |   7 +-
 be/src/exec/text-converter.cc                |  78 +--
 be/src/exec/topn-node.cc                     |   7 +-
 be/src/exec/union-node.cc                    |   3 +-
 be/src/exprs/agg-fn-evaluator.cc             |   1 -
 be/src/exprs/agg-fn.cc                       |   4 +-
 be/src/exprs/case-expr.cc                    |  42 +-
 be/src/exprs/compound-predicates.cc          |  54 ++-
 be/src/exprs/expr-codegen-test.cc            |   4 +-
 be/src/exprs/expr-test.cc                    |   1 -
 be/src/exprs/literal.cc                      |   6 +-
 be/src/exprs/null-literal.cc                 |   8 +-
 be/src/exprs/scalar-expr.cc                  |  29 +-
 be/src/exprs/scalar-fn-call.cc               |  53 +-
 be/src/exprs/slot-ref.cc                     |  93 ++--
 be/src/runtime/descriptors.cc                |  22 +-
 be/src/runtime/runtime-state.cc              |   3 +-
 be/src/runtime/types.cc                      |  27 +-
 be/src/util/tuple-row-compare.cc             |  67 ++-
 42 files changed, 1420 insertions(+), 1387 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/e98d2f1c/be/src/benchmarks/hash-benchmark.cc
----------------------------------------------------------------------
diff --git a/be/src/benchmarks/hash-benchmark.cc b/be/src/benchmarks/hash-benchmark.cc
index d0ecc82..fffbbdf 100644
--- a/be/src/benchmarks/hash-benchmark.cc
+++ b/be/src/benchmarks/hash-benchmark.cc
@@ -33,7 +33,6 @@
 using boost::hash_combine;
 using boost::hash_range;
 using namespace impala;
-using namespace llvm;
 
 
 // Benchmark tests for hashing tuples.  There are two sets of inputs
@@ -381,7 +380,7 @@ int NumCollisions(TestData* data, int num_buckets) {
 // exit:                                             ; preds = %loop, %entry
 //   ret void
 // }
-Function* CodegenCrcHash(LlvmCodeGen* codegen, bool mixed) {
+llvm::Function* CodegenCrcHash(LlvmCodeGen* codegen, bool mixed) {
   string name = mixed ? "HashMixed" : "HashInt";
   LlvmCodeGen::FnPrototype prototype(codegen, name, codegen->void_type());
   prototype.AddArgument(
@@ -392,62 +391,65 @@ Function* CodegenCrcHash(LlvmCodeGen* codegen, bool mixed) {
       LlvmCodeGen::NamedVariable("results", codegen->GetPtrType(TYPE_INT)));
 
   LlvmBuilder builder(codegen->context());
-  Value* args[3];
-  Function* fn = prototype.GeneratePrototype(&builder, &args[0]);
+  llvm::Value* args[3];
+  llvm::Function* fn = prototype.GeneratePrototype(&builder, &args[0]);
 
-  BasicBlock* loop_start = builder.GetInsertBlock();
-  BasicBlock* loop_body = BasicBlock::Create(codegen->context(), "loop", fn);
-  BasicBlock* loop_exit = BasicBlock::Create(codegen->context(), "exit", fn);
+  llvm::BasicBlock* loop_start = builder.GetInsertBlock();
+  llvm::BasicBlock* loop_body = llvm::BasicBlock::Create(codegen->context(), "loop", fn);
+  llvm::BasicBlock* loop_exit = llvm::BasicBlock::Create(codegen->context(), "exit", fn);
 
   int fixed_byte_size = mixed ?
     sizeof(int8_t) + sizeof(int32_t) + sizeof(int64_t) : sizeof(int32_t) * 4;
 
-  Function* fixed_fn = codegen->GetHashFunction(fixed_byte_size);
-  Function* string_hash_fn = codegen->GetHashFunction();
+  llvm::Function* fixed_fn = codegen->GetHashFunction(fixed_byte_size);
+  llvm::Function* string_hash_fn = codegen->GetHashFunction();
 
-  Value* row_size = NULL;
+  llvm::Value* row_size = NULL;
   if (mixed) {
     row_size = codegen->GetIntConstant(TYPE_INT,
       sizeof(int8_t) + sizeof(int32_t) + sizeof(int64_t) + sizeof(StringValue));
   } else {
     row_size = codegen->GetIntConstant(TYPE_INT, fixed_byte_size);
   }
-  Value* dummy_len = codegen->GetIntConstant(TYPE_INT, 0);
+  llvm::Value* dummy_len = codegen->GetIntConstant(TYPE_INT, 0);
 
   // Check loop counter
-  Value* counter_check =
+  llvm::Value* counter_check =
       builder.CreateICmpSGT(args[0], codegen->GetIntConstant(TYPE_INT, 0));
   builder.CreateCondBr(counter_check, loop_body, loop_exit);
 
   // Loop body
   builder.SetInsertPoint(loop_body);
-  PHINode* counter = builder.CreatePHI(codegen->GetType(TYPE_INT), 2, "counter");
+  llvm::PHINode* counter = builder.CreatePHI(codegen->GetType(TYPE_INT), 2, "counter");
   counter->addIncoming(codegen->GetIntConstant(TYPE_INT, 0), loop_start);
 
-  Value* next_counter = builder.CreateAdd(counter, codegen->GetIntConstant(TYPE_INT, 1));
+  llvm::Value* next_counter =
+      builder.CreateAdd(counter, codegen->GetIntConstant(TYPE_INT, 1));
   counter->addIncoming(next_counter, loop_body);
 
   // Hash the current data
-  Value* offset = builder.CreateMul(counter, row_size);
-  Value* data = builder.CreateGEP(args[1], offset);
+  llvm::Value* offset = builder.CreateMul(counter, row_size);
+  llvm::Value* data = builder.CreateGEP(args[1], offset);
 
-  Value* seed = codegen->GetIntConstant(TYPE_INT, HashUtil::FNV_SEED);
-  seed = builder.CreateCall(fixed_fn, ArrayRef<Value*>({data, dummy_len, seed}));
+  llvm::Value* seed = codegen->GetIntConstant(TYPE_INT, HashUtil::FNV_SEED);
+  seed =
+      builder.CreateCall(fixed_fn, llvm::ArrayRef<llvm::Value*>({data, dummy_len, seed}));
 
   // Get the string data
   if (mixed) {
-    Value* string_data = builder.CreateGEP(
-        data, codegen->GetIntConstant(TYPE_INT, fixed_byte_size));
-    Value* string_val =
+    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));
-    Value* str_ptr = builder.CreateStructGEP(NULL, string_val, 0);
-    Value* str_len = builder.CreateStructGEP(NULL, string_val, 1);
+    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);
     str_len = builder.CreateLoad(str_len);
-    seed = builder.CreateCall(string_hash_fn, ArrayRef<Value*>({str_ptr, str_len, seed}));
+    seed = builder.CreateCall(
+        string_hash_fn, llvm::ArrayRef<llvm::Value*>({str_ptr, str_len, seed}));
   }
 
-  Value* result = builder.CreateGEP(args[2], counter);
+  llvm::Value* result = builder.CreateGEP(args[2], counter);
   builder.CreateStore(seed, result);
 
   counter_check = builder.CreateICmpSLT(next_counter, args[0]);
@@ -497,11 +499,11 @@ int main(int argc, char **argv) {
   }
   codegen->EnableOptimizations(true);
 
-  Function* hash_ints = CodegenCrcHash(codegen.get(), false);
+  llvm::Function* hash_ints = CodegenCrcHash(codegen.get(), false);
   void* jitted_hash_ints;
   codegen->AddFunctionToJit(hash_ints, &jitted_hash_ints);
 
-  Function* hash_mixed = CodegenCrcHash(codegen.get(), true);
+  llvm::Function* hash_mixed = CodegenCrcHash(codegen.get(), true);
   void* jitted_hash_mixed;
   codegen->AddFunctionToJit(hash_mixed, &jitted_hash_mixed);
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/e98d2f1c/be/src/codegen/codegen-anyval.cc
----------------------------------------------------------------------
diff --git a/be/src/codegen/codegen-anyval.cc b/be/src/codegen/codegen-anyval.cc
index b116cfe..45e8ee3 100644
--- a/be/src/codegen/codegen-anyval.cc
+++ b/be/src/codegen/codegen-anyval.cc
@@ -23,7 +23,6 @@
 
 using namespace impala;
 using namespace impala_udf;
-using namespace llvm;
 
 const char* CodegenAnyVal::LLVM_BOOLEANVAL_NAME   = "struct.impala_udf::BooleanVal";
 const char* CodegenAnyVal::LLVM_TINYINTVAL_NAME   = "struct.impala_udf::TinyIntVal";
@@ -36,7 +35,7 @@ const char* CodegenAnyVal::LLVM_STRINGVAL_NAME    = "struct.impala_udf::StringVa
 const char* CodegenAnyVal::LLVM_TIMESTAMPVAL_NAME = "struct.impala_udf::TimestampVal";
 const char* CodegenAnyVal::LLVM_DECIMALVAL_NAME   = "struct.impala_udf::DecimalVal";
 
-Type* CodegenAnyVal::GetLoweredType(LlvmCodeGen* cg, const ColumnType& type) {
+llvm::Type* CodegenAnyVal::GetLoweredType(LlvmCodeGen* cg, const ColumnType& type) {
   switch(type.type) {
     case TYPE_BOOLEAN: // i16
       return cg->smallint_type();
@@ -47,20 +46,20 @@ Type* CodegenAnyVal::GetLoweredType(LlvmCodeGen* cg, const ColumnType& type) {
     case TYPE_INT: // i64
       return cg->bigint_type();
     case TYPE_BIGINT: // { i8, i64 }
-      return StructType::get(cg->tinyint_type(), cg->bigint_type(), NULL);
+      return llvm::StructType::get(cg->tinyint_type(), cg->bigint_type(), NULL);
     case TYPE_FLOAT: // i64
       return cg->bigint_type();
     case TYPE_DOUBLE: // { i8, double }
-      return StructType::get(cg->tinyint_type(), cg->double_type(), NULL);
+      return llvm::StructType::get(cg->tinyint_type(), cg->double_type(), NULL);
     case TYPE_STRING: // { i64, i8* }
     case TYPE_VARCHAR: // { i64, i8* }
     case TYPE_FIXED_UDA_INTERMEDIATE: // { i64, i8* }
-      return StructType::get(cg->bigint_type(), cg->ptr_type(), NULL);
+      return llvm::StructType::get(cg->bigint_type(), cg->ptr_type(), NULL);
     case TYPE_CHAR:
       DCHECK(false) << "NYI:" << type.DebugString();
       return NULL;
     case TYPE_TIMESTAMP: // { i64, i64 }
-      return StructType::get(cg->bigint_type(), cg->bigint_type(), NULL);
+      return llvm::StructType::get(cg->bigint_type(), cg->bigint_type(), NULL);
     case TYPE_DECIMAL: // %"struct.impala_udf::DecimalVal" (isn't lowered)
                        // = { {i8}, [15 x i8], {i128} }
       return cg->GetType(LLVM_DECIMALVAL_NAME);
@@ -70,12 +69,13 @@ Type* CodegenAnyVal::GetLoweredType(LlvmCodeGen* cg, const ColumnType& type) {
   }
 }
 
-PointerType* CodegenAnyVal::GetLoweredPtrType(LlvmCodeGen* cg, const ColumnType& type) {
+llvm::PointerType* CodegenAnyVal::GetLoweredPtrType(
+    LlvmCodeGen* cg, const ColumnType& type) {
   return GetLoweredType(cg, type)->getPointerTo();
 }
 
-Type* CodegenAnyVal::GetUnloweredType(LlvmCodeGen* cg, const ColumnType& type) {
-  Type* result;
+llvm::Type* CodegenAnyVal::GetUnloweredType(LlvmCodeGen* cg, const ColumnType& type) {
+  llvm::Type* result;
   switch(type.type) {
     case TYPE_BOOLEAN:
       result = cg->GetType(LLVM_BOOLEANVAL_NAME);
@@ -120,25 +120,28 @@ Type* CodegenAnyVal::GetUnloweredType(LlvmCodeGen* cg, const ColumnType& type) {
   return result;
 }
 
-PointerType* CodegenAnyVal::GetUnloweredPtrType(LlvmCodeGen* cg, const ColumnType& type) {
+llvm::PointerType* CodegenAnyVal::GetUnloweredPtrType(
+    LlvmCodeGen* cg, const ColumnType& type) {
   return GetUnloweredType(cg, type)->getPointerTo();
 }
 
-Value* CodegenAnyVal::CreateCall(LlvmCodeGen* cg, LlvmBuilder* builder, Function* fn,
-    ArrayRef<Value*> args, const char* name, Value* result_ptr) {
+llvm::Value* CodegenAnyVal::CreateCall(LlvmCodeGen* cg, LlvmBuilder* builder,
+    llvm::Function* fn, llvm::ArrayRef<llvm::Value*> args, const char* name,
+    llvm::Value* result_ptr) {
   if (fn->getReturnType()->isVoidTy()) {
     // Void return type indicates that this function returns a DecimalVal via the first
     // argument (which should be a DecimalVal*).
-    Function::arg_iterator ret_arg = fn->arg_begin();
+    llvm::Function::arg_iterator ret_arg = fn->arg_begin();
     DCHECK(ret_arg->getType()->isPointerTy());
-    Type* ret_type = ret_arg->getType()->getPointerElementType();
+    llvm::Type* ret_type = ret_arg->getType()->getPointerElementType();
     DCHECK_EQ(ret_type, cg->GetType(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.
-    Value* ret_ptr = (result_ptr == NULL) ?
-                     cg->CreateEntryBlockAlloca(*builder, ret_type, name) : result_ptr;
-    vector<Value*> new_args = args.vec();
+    llvm::Value* ret_ptr = (result_ptr == NULL) ?
+        cg->CreateEntryBlockAlloca(*builder, ret_type, name) :
+        result_ptr;
+    vector<llvm::Value*> new_args = args.vec();
     new_args.insert(new_args.begin(), ret_ptr);
     // Bitcasting the args is often necessary when calling an IR UDF because the types
     // in the IR module may have been renamed while linking. Bitcasting them avoids a
@@ -149,12 +152,12 @@ Value* CodegenAnyVal::CreateCall(LlvmCodeGen* cg, LlvmBuilder* builder, Function
     if (result_ptr != NULL) return NULL;
     return builder->CreateLoad(ret_ptr, name);
   } else {
-    // Function returns *Val normally (note that it could still be returning a DecimalVal,
-    // since we generate non-compliant functions).
+    // Function returns *Val normally (note that it could still be returning a
+    // DecimalVal, since we generate non-compliant functions).
     // Bitcasting the args is often necessary when calling an IR UDF because the types
     // in the IR module may have been renamed while linking. Bitcasting them avoids a
     // type assertion.
-    Value* ret = CodeGenUtil::CreateCallWithBitCasts(builder, fn, args, name);
+    llvm::Value* ret = CodeGenUtil::CreateCallWithBitCasts(builder, fn, args, name);
     if (result_ptr == NULL) return ret;
     builder->CreateStore(ret, result_ptr);
     return NULL;
@@ -162,36 +165,37 @@ Value* CodegenAnyVal::CreateCall(LlvmCodeGen* cg, LlvmBuilder* builder, Function
 }
 
 CodegenAnyVal CodegenAnyVal::CreateCallWrapped(LlvmCodeGen* cg, LlvmBuilder* builder,
-    const ColumnType& type, Function* fn, ArrayRef<Value*> args, const char* name) {
-  Value* v = CreateCall(cg, builder, fn, args, name);
+    const ColumnType& type, llvm::Function* fn, llvm::ArrayRef<llvm::Value*> args,
+    const char* name) {
+  llvm::Value* v = CreateCall(cg, builder, fn, args, name);
   return CodegenAnyVal(cg, builder, type, v, name);
 }
 
 CodegenAnyVal::CodegenAnyVal(LlvmCodeGen* codegen, LlvmBuilder* builder,
-    const ColumnType& type, Value* value, const char* name)
+    const ColumnType& type, llvm::Value* value, const char* name)
   : type_(type), value_(value), name_(name), codegen_(codegen), builder_(builder) {
-  Type* value_type = GetLoweredType(codegen, type);
+  llvm::Type* value_type = GetLoweredType(codegen, type);
   if (value_ == NULL) {
     // No Value* was specified, so allocate one on the stack and load it.
-    Value* ptr = codegen_->CreateEntryBlockAlloca(*builder, value_type);
+    llvm::Value* ptr = codegen_->CreateEntryBlockAlloca(*builder, value_type);
     value_ = builder_->CreateLoad(ptr, name_);
   }
   DCHECK_EQ(value_->getType(), value_type);
 }
 
-Value* CodegenAnyVal::GetIsNull(const char* name) const {
+llvm::Value* CodegenAnyVal::GetIsNull(const char* name) const {
   switch (type_.type) {
     case TYPE_BIGINT:
     case TYPE_DOUBLE: {
       // Lowered type is of form { i8, * }. Get the i8 value.
-      Value* is_null_i8 = builder_->CreateExtractValue(value_, 0);
+      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);
     }
     case TYPE_DECIMAL: {
       // Lowered type is of the form { {i8}, ... }
       uint32_t idxs[] = {0, 0};
-      Value* is_null_i8 = builder_->CreateExtractValue(value_, idxs);
+      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);
     }
@@ -200,7 +204,7 @@ Value* CodegenAnyVal::GetIsNull(const char* name) const {
     case TYPE_FIXED_UDA_INTERMEDIATE:
     case TYPE_TIMESTAMP: {
       // Lowered type is of form { i64, *}. Get the first byte of the i64 value.
-      Value* v = builder_->CreateExtractValue(value_, 0);
+      llvm::Value* v = builder_->CreateExtractValue(value_, 0);
       DCHECK(v->getType() == codegen_->bigint_type());
       return builder_->CreateTrunc(v, codegen_->boolean_type(), name);
     }
@@ -220,12 +224,12 @@ Value* CodegenAnyVal::GetIsNull(const char* name) const {
   }
 }
 
-void CodegenAnyVal::SetIsNull(Value* is_null) {
+void CodegenAnyVal::SetIsNull(llvm::Value* is_null) {
   switch(type_.type) {
     case TYPE_BIGINT:
     case TYPE_DOUBLE: {
       // Lowered type is of form { i8, * }. Set the i8 value to 'is_null'.
-      Value* is_null_ext =
+      llvm::Value* is_null_ext =
           builder_->CreateZExt(is_null, codegen_->tinyint_type(), "is_null_ext");
       value_ = builder_->CreateInsertValue(value_, is_null_ext, 0, name_);
       break;
@@ -233,7 +237,7 @@ void CodegenAnyVal::SetIsNull(Value* is_null) {
     case TYPE_DECIMAL: {
       // Lowered type is of form { {i8}, [15 x i8], {i128} }. Set the i8 value to
       // 'is_null'.
-      Value* is_null_ext =
+      llvm::Value* is_null_ext =
           builder_->CreateZExt(is_null, codegen_->tinyint_type(), "is_null_ext");
       // Index into the {i8} struct as well as the outer struct.
       uint32_t idxs[] = {0, 0};
@@ -246,9 +250,10 @@ void CodegenAnyVal::SetIsNull(Value* is_null) {
     case TYPE_TIMESTAMP: {
       // Lowered type is of the form { i64, * }. Set the first byte of the i64 value to
       // 'is_null'
-      Value* v = builder_->CreateExtractValue(value_, 0);
+      llvm::Value* v = builder_->CreateExtractValue(value_, 0);
       v = builder_->CreateAnd(v, -0x100LL, "masked");
-      Value* is_null_ext = builder_->CreateZExt(is_null, v->getType(), "is_null_ext");
+      llvm::Value* is_null_ext =
+          builder_->CreateZExt(is_null, v->getType(), "is_null_ext");
       v = builder_->CreateOr(v, is_null_ext);
       value_ = builder_->CreateInsertValue(value_, v, 0, name_);
       break;
@@ -263,7 +268,8 @@ void CodegenAnyVal::SetIsNull(Value* is_null) {
     case TYPE_FLOAT: {
       // Lowered type is an integer. Set the first byte to 'is_null'.
       value_ = builder_->CreateAnd(value_, -0x100LL, "masked");
-      Value* is_null_ext = builder_->CreateZExt(is_null, value_->getType(), "is_null_ext");
+      llvm::Value* is_null_ext =
+          builder_->CreateZExt(is_null, value_->getType(), "is_null_ext");
       value_ = builder_->CreateOr(value_, is_null_ext, name_);
       break;
     }
@@ -272,7 +278,7 @@ void CodegenAnyVal::SetIsNull(Value* is_null) {
   }
 }
 
-Value* CodegenAnyVal::GetVal(const char* name) {
+llvm::Value* CodegenAnyVal::GetVal(const char* name) {
   DCHECK(type_.type != TYPE_STRING)
       << "Use GetPtr and GetLen for StringVal";
   DCHECK(type_.type != TYPE_VARCHAR)
@@ -290,7 +296,7 @@ Value* CodegenAnyVal::GetVal(const char* name) {
     case TYPE_INT: {
       // Lowered type is an integer. Get the high bytes.
       int num_bits = type_.GetByteSize() * 8;
-      Value* val = GetHighBits(num_bits, value_, name);
+      llvm::Value* val = GetHighBits(num_bits, value_, name);
       if (type_.type == TYPE_BOOLEAN) {
         // Return booleans as i1 (vs. i8)
         val = builder_->CreateTrunc(val, builder_->getInt1Ty(), name);
@@ -299,7 +305,7 @@ Value* CodegenAnyVal::GetVal(const char* name) {
     }
     case TYPE_FLOAT: {
       // Same as above, but we must cast the value to a float.
-      Value* val = GetHighBits(32, value_);
+      llvm::Value* val = GetHighBits(32, value_);
       return builder_->CreateBitCast(val, codegen_->float_type());
     }
     case TYPE_BIGINT:
@@ -311,7 +317,7 @@ Value* CodegenAnyVal::GetVal(const char* name) {
       // truncate it to the correct size. (The {i128} corresponds to the union of the
       // different width int types.)
       uint32_t idxs[] = {2, 0};
-      Value* val = builder_->CreateExtractValue(value_, idxs, name);
+      llvm::Value* val = builder_->CreateExtractValue(value_, idxs, name);
       return builder_->CreateTrunc(val, codegen_->GetType(type_), name);
     }
     default:
@@ -320,7 +326,7 @@ Value* CodegenAnyVal::GetVal(const char* name) {
   }
 }
 
-void CodegenAnyVal::SetVal(Value* val) {
+void CodegenAnyVal::SetVal(llvm::Value* val) {
   DCHECK(type_.type != TYPE_STRING) << "Use SetPtr and SetLen for StringVals";
   DCHECK(type_.type != TYPE_VARCHAR) << "Use SetPtr and SetLen for StringVals";
   DCHECK(type_.type != TYPE_CHAR) << "Use SetPtr and SetLen for StringVals";
@@ -352,7 +358,7 @@ void CodegenAnyVal::SetVal(Value* val) {
       // Lowered type is of the form { {i8}, [15 x i8], {i128} }. Set the i128 value to
       // 'val'. (The {i128} corresponds to the union of the different width int types.)
       DCHECK_EQ(val->getType()->getIntegerBitWidth(), type_.GetByteSize() * 8);
-      val = builder_->CreateSExt(val, Type::getIntNTy(codegen_->context(), 128));
+      val = builder_->CreateSExt(val, llvm::Type::getIntNTy(codegen_->context(), 128));
       uint32_t idxs[] = {2, 0};
       value_ = builder_->CreateInsertValue(value_, val, idxs, name_);
       break;
@@ -390,82 +396,83 @@ void CodegenAnyVal::SetVal(int64_t val) {
 void CodegenAnyVal::SetVal(int128_t val) {
   DCHECK_EQ(type_.type, TYPE_DECIMAL);
   vector<uint64_t> vals({LowBits(val), HighBits(val)});
-  Value* ir_val = ConstantInt::get(codegen_->context(), APInt(128, vals));
+  llvm::Value* ir_val =
+      llvm::ConstantInt::get(codegen_->context(), llvm::APInt(128, vals));
   SetVal(ir_val);
 }
 
 void CodegenAnyVal::SetVal(float val) {
   DCHECK_EQ(type_.type, TYPE_FLOAT);
-  SetVal(ConstantFP::get(builder_->getFloatTy(), val));
+  SetVal(llvm::ConstantFP::get(builder_->getFloatTy(), val));
 }
 
 void CodegenAnyVal::SetVal(double val) {
   DCHECK_EQ(type_.type, TYPE_DOUBLE);
-  SetVal(ConstantFP::get(builder_->getDoubleTy(), val));
+  SetVal(llvm::ConstantFP::get(builder_->getDoubleTy(), val));
 }
 
-Value* CodegenAnyVal::GetPtr() {
+llvm::Value* CodegenAnyVal::GetPtr() {
   // Set the second pointer value to 'ptr'.
   DCHECK(type_.IsStringType());
   return builder_->CreateExtractValue(value_, 1, name_);
 }
 
-Value* CodegenAnyVal::GetLen() {
+llvm::Value* CodegenAnyVal::GetLen() {
   // Get the high bytes of the first value.
   DCHECK(type_.IsStringType());
-  Value* v = builder_->CreateExtractValue(value_, 0);
+  llvm::Value* v = builder_->CreateExtractValue(value_, 0);
   return GetHighBits(32, v);
 }
 
-void CodegenAnyVal::SetPtr(Value* ptr) {
+void CodegenAnyVal::SetPtr(llvm::Value* ptr) {
   // Set the second pointer value to 'ptr'.
   DCHECK(type_.IsStringType() || type_.type == TYPE_FIXED_UDA_INTERMEDIATE);
   value_ = builder_->CreateInsertValue(value_, ptr, 1, name_);
 }
 
-void CodegenAnyVal::SetLen(Value* len) {
+void CodegenAnyVal::SetLen(llvm::Value* len) {
   // Set the high bytes of the first value to 'len'.
   DCHECK(type_.IsStringType() || type_.type == TYPE_FIXED_UDA_INTERMEDIATE);
-  Value* v = builder_->CreateExtractValue(value_, 0);
+  llvm::Value* v = builder_->CreateExtractValue(value_, 0);
   v = SetHighBits(32, len, v);
   value_ = builder_->CreateInsertValue(value_, v, 0, name_);
 }
 
-Value* CodegenAnyVal::GetTimeOfDay() {
+llvm::Value* CodegenAnyVal::GetTimeOfDay() {
   // Get the second i64 value.
   DCHECK_EQ(type_.type, TYPE_TIMESTAMP);
   return builder_->CreateExtractValue(value_, 1);
 }
 
-Value* CodegenAnyVal::GetDate() {
+llvm::Value* CodegenAnyVal::GetDate() {
   // Get the high bytes of the first value.
   DCHECK_EQ(type_.type, TYPE_TIMESTAMP);
-  Value* v = builder_->CreateExtractValue(value_, 0);
+  llvm::Value* v = builder_->CreateExtractValue(value_, 0);
   return GetHighBits(32, v);
 }
 
-void CodegenAnyVal::SetTimeOfDay(Value* time_of_day) {
+void CodegenAnyVal::SetTimeOfDay(llvm::Value* time_of_day) {
   // Set the second i64 value to 'time_of_day'.
   DCHECK_EQ(type_.type, TYPE_TIMESTAMP);
   value_ = builder_->CreateInsertValue(value_, time_of_day, 1, name_);
 }
 
-void CodegenAnyVal::SetDate(Value* date) {
+void CodegenAnyVal::SetDate(llvm::Value* date) {
   // Set the high bytes of the first value to 'date'.
   DCHECK_EQ(type_.type, TYPE_TIMESTAMP);
-  Value* v = builder_->CreateExtractValue(value_, 0);
+  llvm::Value* v = builder_->CreateExtractValue(value_, 0);
   v = SetHighBits(32, date, v);
   value_ = builder_->CreateInsertValue(value_, v, 0, name_);
 }
 
-Value* CodegenAnyVal::GetLoweredPtr(const string& name) const {
-  Value* lowered_ptr =
+llvm::Value* CodegenAnyVal::GetLoweredPtr(const string& name) const {
+  llvm::Value* lowered_ptr =
       codegen_->CreateEntryBlockAlloca(*builder_, value_->getType(), name.c_str());
   builder_->CreateStore(GetLoweredValue(), lowered_ptr);
   return lowered_ptr;
 }
 
-Value* CodegenAnyVal::GetUnloweredPtr(const string& name) const {
+llvm::Value* CodegenAnyVal::GetUnloweredPtr(const string& name) const {
   // Get an unlowered pointer by creating a lowered pointer then bitcasting it.
   // TODO: if the original value was unlowered, this generates roundabout code that
   // lowers the value and casts it back. Generally LLVM's optimiser can reason
@@ -475,9 +482,9 @@ Value* CodegenAnyVal::GetUnloweredPtr(const string& name) const {
       GetLoweredPtr(), GetUnloweredPtrType(codegen_, type_), name);
 }
 
-void CodegenAnyVal::LoadFromNativePtr(Value* raw_val_ptr) {
+void CodegenAnyVal::LoadFromNativePtr(llvm::Value* raw_val_ptr) {
   DCHECK(raw_val_ptr->getType()->isPointerTy());
-  Type* raw_val_type = raw_val_ptr->getType()->getPointerElementType();
+  llvm::Type* raw_val_type = raw_val_ptr->getType()->getPointerElementType();
   DCHECK_EQ(raw_val_type, codegen_->GetType(type_))
       << endl
       << LlvmCodeGen::Print(raw_val_ptr) << endl
@@ -486,7 +493,7 @@ void CodegenAnyVal::LoadFromNativePtr(Value* raw_val_ptr) {
     case TYPE_STRING:
     case TYPE_VARCHAR: {
       // Convert StringValue to StringVal
-      Value* string_value = builder_->CreateLoad(raw_val_ptr, "string_value");
+      llvm::Value* string_value = builder_->CreateLoad(raw_val_ptr, "string_value");
       SetPtr(builder_->CreateExtractValue(string_value, 0, "ptr"));
       SetLen(builder_->CreateExtractValue(string_value, 1, "len"));
       break;
@@ -506,16 +513,16 @@ void CodegenAnyVal::LoadFromNativePtr(Value* raw_val_ptr) {
       //   { boost::posix_time::time_duration, boost::gregorian::date }
       // = { {{{i64}}}, {{i32}} }
 
-      Value* ts_value = builder_->CreateLoad(raw_val_ptr, "ts_value");
+      llvm::Value* ts_value = builder_->CreateLoad(raw_val_ptr, "ts_value");
       // Extract time_of_day i64 from boost::posix_time::time_duration.
       uint32_t time_of_day_idxs[] = {0, 0, 0, 0};
-      Value* time_of_day =
+      llvm::Value* time_of_day =
           builder_->CreateExtractValue(ts_value, time_of_day_idxs, "time_of_day");
       DCHECK(time_of_day->getType()->isIntegerTy(64));
       SetTimeOfDay(time_of_day);
       // Extract i32 from boost::gregorian::date
       uint32_t date_idxs[] = {1, 0, 0};
-      Value* date = builder_->CreateExtractValue(ts_value, date_idxs, "date");
+      llvm::Value* date = builder_->CreateExtractValue(ts_value, date_idxs, "date");
       DCHECK(date->getType()->isIntegerTy(32));
       SetDate(date);
       break;
@@ -536,21 +543,21 @@ void CodegenAnyVal::LoadFromNativePtr(Value* raw_val_ptr) {
   }
 }
 
-void CodegenAnyVal::StoreToNativePtr(Value* raw_val_ptr, Value* pool_val) {
-  Type* raw_type = codegen_->GetType(type_);
+void CodegenAnyVal::StoreToNativePtr(llvm::Value* raw_val_ptr, llvm::Value* pool_val) {
+  llvm::Type* raw_type = codegen_->GetType(type_);
   switch (type_.type) {
     case TYPE_STRING:
     case TYPE_VARCHAR: {
       // Convert StringVal to StringValue
-      Value* string_value = Constant::getNullValue(raw_type);
-      Value* len = GetLen();
+      llvm::Value* string_value = llvm::Constant::getNullValue(raw_type);
+      llvm::Value* len = GetLen();
       string_value = builder_->CreateInsertValue(string_value, len, 1);
       if (pool_val == nullptr) {
         // Set string_value.ptr from this->ptr
         string_value = builder_->CreateInsertValue(string_value, GetPtr(), 0);
       } else {
         // Allocate string_value.ptr from 'pool_val' and copy this->ptr
-        Value* new_ptr =
+        llvm::Value* new_ptr =
             codegen_->CodegenMemPoolAllocate(builder_, pool_val, len, "new_ptr");
         codegen_->CodegenMemcpy(builder_, new_ptr, GetPtr(), len);
         string_value = builder_->CreateInsertValue(string_value, new_ptr, 0);
@@ -567,7 +574,7 @@ void CodegenAnyVal::StoreToNativePtr(Value* raw_val_ptr, Value* pool_val) {
       // TimestampValue has type
       //   { boost::posix_time::time_duration, boost::gregorian::date }
       // = { {{{i64}}}, {{i32}} }
-      Value* timestamp_value = Constant::getNullValue(raw_type);
+      llvm::Value* timestamp_value = llvm::Constant::getNullValue(raw_type);
       uint32_t time_of_day_idxs[] = {0, 0, 0, 0};
       timestamp_value =
           builder_->CreateInsertValue(timestamp_value, GetTimeOfDay(), time_of_day_idxs);
@@ -594,8 +601,8 @@ void CodegenAnyVal::StoreToNativePtr(Value* raw_val_ptr, Value* pool_val) {
   }
 }
 
-Value* CodegenAnyVal::ToNativePtr(Value* pool_val) {
-  Value* native_ptr =
+llvm::Value* CodegenAnyVal::ToNativePtr(llvm::Value* pool_val) {
+  llvm::Value* native_ptr =
       codegen_->CreateEntryBlockAlloca(*builder_, codegen_->GetType(type_));
   StoreToNativePtr(native_ptr, pool_val);
   return native_ptr;
@@ -621,26 +628,28 @@ Value* CodegenAnyVal::ToNativePtr(Value* pool_val) {
 //
 // end_write:                                        ; preds = %null, %non_null
 //   ; [insert point ends here]
-void CodegenAnyVal::WriteToSlot(const SlotDescriptor& slot_desc, Value* tuple_val,
-    Value* pool_val, BasicBlock* insert_before) {
+void CodegenAnyVal::WriteToSlot(const SlotDescriptor& slot_desc, llvm::Value* tuple_val,
+    llvm::Value* pool_val, llvm::BasicBlock* insert_before) {
   DCHECK(tuple_val->getType()->isPointerTy());
   DCHECK(tuple_val->getType()->getPointerElementType()->isStructTy());
-  LLVMContext& context = codegen_->context();
-  Function* fn = builder_->GetInsertBlock()->getParent();
+  llvm::LLVMContext& context = codegen_->context();
+  llvm::Function* fn = builder_->GetInsertBlock()->getParent();
 
   // Create new block that will come after conditional blocks if necessary
   if (insert_before == nullptr) {
-    insert_before = BasicBlock::Create(context, "end_write", fn);
+    insert_before = llvm::BasicBlock::Create(context, "end_write", fn);
   }
 
   // Create new basic blocks and br instruction
-  BasicBlock* non_null_block = BasicBlock::Create(context, "non_null", fn, insert_before);
-  BasicBlock* null_block = BasicBlock::Create(context, "null", fn, insert_before);
+  llvm::BasicBlock* non_null_block =
+      llvm::BasicBlock::Create(context, "non_null", fn, insert_before);
+  llvm::BasicBlock* null_block =
+      llvm::BasicBlock::Create(context, "null", fn, insert_before);
   builder_->CreateCondBr(GetIsNull(), null_block, non_null_block);
 
   // Non-null block: write slot
   builder_->SetInsertPoint(non_null_block);
-  Value* slot =
+  llvm::Value* slot =
       builder_->CreateStructGEP(nullptr, tuple_val, slot_desc.llvm_field_idx(), "slot");
   StoreToNativePtr(slot, pool_val);
   builder_->CreateBr(insert_before);
@@ -655,7 +664,7 @@ void CodegenAnyVal::WriteToSlot(const SlotDescriptor& slot_desc, Value* tuple_va
   builder_->SetInsertPoint(insert_before);
 }
 
-Value* CodegenAnyVal::Eq(CodegenAnyVal* other) {
+llvm::Value* CodegenAnyVal::Eq(CodegenAnyVal* other) {
   DCHECK_EQ(type_, other->type_);
   switch (type_.type) {
     case TYPE_BOOLEAN:
@@ -671,16 +680,18 @@ Value* CodegenAnyVal::Eq(CodegenAnyVal* other) {
     case TYPE_STRING:
     case TYPE_VARCHAR:
     case TYPE_FIXED_UDA_INTERMEDIATE: {
-      Function* eq_fn =
+      llvm::Function* eq_fn =
           codegen_->GetFunction(IRFunction::CODEGEN_ANYVAL_STRING_VAL_EQ, false);
-      return builder_->CreateCall(
-          eq_fn, ArrayRef<Value*>({GetUnloweredPtr(), other->GetUnloweredPtr()}), "eq");
+      return builder_->CreateCall(eq_fn,
+          llvm::ArrayRef<llvm::Value*>({GetUnloweredPtr(), other->GetUnloweredPtr()}),
+          "eq");
     }
     case TYPE_TIMESTAMP: {
-      Function* eq_fn =
+      llvm::Function* eq_fn =
           codegen_->GetFunction(IRFunction::CODEGEN_ANYVAL_TIMESTAMP_VAL_EQ, false);
-      return builder_->CreateCall(
-          eq_fn, ArrayRef<Value*>({GetUnloweredPtr(), other->GetUnloweredPtr()}), "eq");
+      return builder_->CreateCall(eq_fn,
+          llvm::ArrayRef<llvm::Value*>({GetUnloweredPtr(), other->GetUnloweredPtr()}),
+          "eq");
     }
     default:
       DCHECK(false) << "NYI: " << type_.DebugString();
@@ -688,8 +699,8 @@ Value* CodegenAnyVal::Eq(CodegenAnyVal* other) {
   }
 }
 
-Value* CodegenAnyVal::EqToNativePtr(Value* native_ptr) {
-  Value* val = NULL;
+llvm::Value* CodegenAnyVal::EqToNativePtr(llvm::Value* native_ptr) {
+  llvm::Value* val = NULL;
   if (!type_.IsStringType()) {
      val = builder_->CreateLoad(native_ptr);
   }
@@ -709,16 +720,16 @@ Value* CodegenAnyVal::EqToNativePtr(Value* native_ptr) {
     case TYPE_STRING:
     case TYPE_VARCHAR:
     case TYPE_FIXED_UDA_INTERMEDIATE: {
-      Function* eq_fn =
+      llvm::Function* eq_fn =
           codegen_->GetFunction(IRFunction::CODEGEN_ANYVAL_STRING_VALUE_EQ, false);
       return builder_->CreateCall(eq_fn,
-          ArrayRef<Value*>({GetUnloweredPtr(), native_ptr}), "cmp_raw");
+          llvm::ArrayRef<llvm::Value*>({GetUnloweredPtr(), native_ptr}), "cmp_raw");
     }
     case TYPE_TIMESTAMP: {
-      Function* eq_fn =
+      llvm::Function* eq_fn =
           codegen_->GetFunction(IRFunction::CODEGEN_ANYVAL_TIMESTAMP_VALUE_EQ, false);
       return builder_->CreateCall(eq_fn,
-          ArrayRef<Value*>({GetUnloweredPtr(), native_ptr}), "cmp_raw");
+          llvm::ArrayRef<llvm::Value*>({GetUnloweredPtr(), native_ptr}), "cmp_raw");
     }
     default:
       DCHECK(false) << "NYI: " << type_.DebugString();
@@ -726,35 +737,37 @@ Value* CodegenAnyVal::EqToNativePtr(Value* native_ptr) {
   }
 }
 
-Value* CodegenAnyVal::Compare(CodegenAnyVal* other, const char* name) {
+llvm::Value* CodegenAnyVal::Compare(CodegenAnyVal* other, const char* name) {
   DCHECK_EQ(type_, other->type_);
-  Value* v1 = ToNativePtr();
-  Value* void_v1 = builder_->CreateBitCast(v1, codegen_->ptr_type());
-  Value* v2 = other->ToNativePtr();
-  Value* void_v2 = builder_->CreateBitCast(v2, codegen_->ptr_type());
+  llvm::Value* v1 = ToNativePtr();
+  llvm::Value* void_v1 = builder_->CreateBitCast(v1, codegen_->ptr_type());
+  llvm::Value* v2 = other->ToNativePtr();
+  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'.
-  Type* col_type = codegen_->GetType(ColumnType::LLVM_CLASS_NAME);
-  Constant* type_ptr =
+  llvm::Type* col_type = codegen_->GetType(ColumnType::LLVM_CLASS_NAME);
+  llvm::Constant* type_ptr =
       codegen_->ConstantToGVPtr(col_type, type_.ToIR(codegen_), "type");
-  Function* compare_fn = codegen_->GetFunction(IRFunction::RAW_VALUE_COMPARE, false);
-  Value* args[] = { void_v1, void_v2, type_ptr };
+  llvm::Function* compare_fn =
+      codegen_->GetFunction(IRFunction::RAW_VALUE_COMPARE, false);
+  llvm::Value* args[] = {void_v1, void_v2, type_ptr};
   return builder_->CreateCall(compare_fn, args, name);
 }
 
-void CodegenAnyVal::CodegenBranchIfNull(LlvmBuilder* builder, BasicBlock* null_block) {
-  Value* is_null = GetIsNull();
-  BasicBlock* not_null_block = BasicBlock::Create(
+void CodegenAnyVal::CodegenBranchIfNull(
+    LlvmBuilder* builder, llvm::BasicBlock* null_block) {
+  llvm::Value* is_null = GetIsNull();
+  llvm::BasicBlock* not_null_block = llvm::BasicBlock::Create(
       codegen_->context(), "not_null", builder->GetInsertBlock()->getParent());
   builder->CreateCondBr(is_null, null_block, not_null_block);
   builder->SetInsertPoint(not_null_block);
 }
 
-Value* CodegenAnyVal::GetHighBits(int num_bits, Value* v, const char* name) {
+llvm::Value* CodegenAnyVal::GetHighBits(int num_bits, llvm::Value* v, const char* name) {
   DCHECK_EQ(v->getType()->getIntegerBitWidth(), num_bits * 2);
-  Value* shifted = builder_->CreateAShr(v, num_bits);
+  llvm::Value* shifted = builder_->CreateAShr(v, num_bits);
   return builder_->CreateTrunc(
-      shifted, IntegerType::get(codegen_->context(), num_bits));
+      shifted, llvm::IntegerType::get(codegen_->context(), num_bits));
 }
 
 // Example output: (num_bits = 8)
@@ -762,56 +775,57 @@ Value* CodegenAnyVal::GetHighBits(int num_bits, Value* v, const char* name) {
 // %2 = shl i16 %1, 8
 // %3 = and i16 %dst1 255 ; clear the top half of dst
 // %dst2 = or i16 %3, %2  ; set the top of half of dst to src
-Value* CodegenAnyVal::SetHighBits(int num_bits, Value* src, Value* dst,
-                                  const char* name) {
+llvm::Value* CodegenAnyVal::SetHighBits(
+    int num_bits, llvm::Value* src, llvm::Value* dst, const char* name) {
   DCHECK_LE(src->getType()->getIntegerBitWidth(), num_bits);
   DCHECK_EQ(dst->getType()->getIntegerBitWidth(), num_bits * 2);
-  Value* extended_src =
-      builder_->CreateZExt(src, IntegerType::get(codegen_->context(), num_bits * 2));
-  Value* shifted_src = builder_->CreateShl(extended_src, num_bits);
-  Value* masked_dst = builder_->CreateAnd(dst, (1LL << num_bits) - 1);
+  llvm::Value* extended_src = builder_->CreateZExt(
+      src, llvm::IntegerType::get(codegen_->context(), num_bits * 2));
+  llvm::Value* shifted_src = builder_->CreateShl(extended_src, num_bits);
+  llvm::Value* masked_dst = builder_->CreateAnd(dst, (1LL << num_bits) - 1);
   return builder_->CreateOr(masked_dst, shifted_src, name);
 }
 
-Value* CodegenAnyVal::GetNullVal(LlvmCodeGen* codegen, const ColumnType& type) {
-  Type* val_type = GetLoweredType(codegen, type);
+llvm::Value* CodegenAnyVal::GetNullVal(LlvmCodeGen* codegen, const ColumnType& type) {
+  llvm::Type* val_type = GetLoweredType(codegen, type);
   return GetNullVal(codegen, val_type);
 }
 
-Value* CodegenAnyVal::GetNullVal(LlvmCodeGen* codegen, Type* val_type) {
+llvm::Value* CodegenAnyVal::GetNullVal(LlvmCodeGen* codegen, llvm::Type* val_type) {
   if (val_type->isStructTy()) {
-    StructType* struct_type = cast<StructType>(val_type);
+    llvm::StructType* struct_type = llvm::cast<llvm::StructType>(val_type);
     if (struct_type->getNumElements() == 3) {
       DCHECK_EQ(val_type, codegen->GetType(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)
-      StructType* anyval_struct_type = cast<StructType>(struct_type->getElementType(0));
-      Type* is_null_type = anyval_struct_type->getElementType(0);
-      Value* null_anyval =
-          ConstantStruct::get(anyval_struct_type, ConstantInt::get(is_null_type, 1));
-      Type* type2 = struct_type->getElementType(1);
-      Type* type3 = struct_type->getElementType(2);
-      return ConstantStruct::get(struct_type, null_anyval, Constant::getNullValue(type2),
-                                 Constant::getNullValue(type3), NULL);
+      llvm::StructType* anyval_struct_type =
+          llvm::cast<llvm::StructType>(struct_type->getElementType(0));
+      llvm::Type* is_null_type = anyval_struct_type->getElementType(0);
+      llvm::Value* null_anyval = llvm::ConstantStruct::get(
+          anyval_struct_type, llvm::ConstantInt::get(is_null_type, 1));
+      llvm::Type* type2 = struct_type->getElementType(1);
+      llvm::Type* type3 = struct_type->getElementType(2);
+      return llvm::ConstantStruct::get(struct_type, null_anyval,
+          llvm::Constant::getNullValue(type2), llvm::Constant::getNullValue(type3), NULL);
     }
     // Return the struct { 1, 0 } (the 'is_null' byte, i.e. the first value's first byte,
     // is set to 1, the other bytes don't matter)
     DCHECK_EQ(struct_type->getNumElements(), 2);
-    Type* type1 = struct_type->getElementType(0);
+    llvm::Type* type1 = struct_type->getElementType(0);
     DCHECK(type1->isIntegerTy()) << LlvmCodeGen::Print(type1);
-    Type* type2 = struct_type->getElementType(1);
-    return ConstantStruct::get(
-        struct_type, ConstantInt::get(type1, 1), Constant::getNullValue(type2), NULL);
+    llvm::Type* type2 = struct_type->getElementType(1);
+    return llvm::ConstantStruct::get(struct_type, llvm::ConstantInt::get(type1, 1),
+        llvm::Constant::getNullValue(type2), NULL);
   }
   // Return the int 1 ('is_null' byte is 1, other bytes don't matter)
   DCHECK(val_type->isIntegerTy());
-  return ConstantInt::get(val_type, 1);
+  return llvm::ConstantInt::get(val_type, 1);
 }
 
 CodegenAnyVal CodegenAnyVal::GetNonNullVal(LlvmCodeGen* codegen, LlvmBuilder* builder,
     const ColumnType& type, const char* name) {
-  Type* val_type = GetLoweredType(codegen, type);
+  llvm::Type* val_type = GetLoweredType(codegen, type);
   // All zeros => 'is_null' = false
-  Value* value = Constant::getNullValue(val_type);
+  llvm::Value* value = llvm::Constant::getNullValue(val_type);
   return CodegenAnyVal(codegen, builder, type, value, name);
 }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/e98d2f1c/be/src/codegen/codegen-callgraph.cc
----------------------------------------------------------------------
diff --git a/be/src/codegen/codegen-callgraph.cc b/be/src/codegen/codegen-callgraph.cc
index 73f5d18..6cc2b60 100644
--- a/be/src/codegen/codegen-callgraph.cc
+++ b/be/src/codegen/codegen-callgraph.cc
@@ -25,7 +25,6 @@
 
 #include "common/names.h"
 
-using namespace llvm;
 using namespace strings;
 
 namespace impala {
@@ -37,21 +36,22 @@ bool CodegenCallGraph::IsDefinedInImpalad(const string& fn_name) {
   return status.ok();
 }
 
-void CodegenCallGraph::FindGlobalUsers(User* val, vector<GlobalObject*>* users) {
-  for (Use& u: val->uses()) {
-    User* user = u.getUser();
-    if (isa<Instruction>(user)) {
-      Instruction* inst = dyn_cast<Instruction>(u.getUser());
+void CodegenCallGraph::FindGlobalUsers(
+    llvm::User* val, vector<llvm::GlobalObject*>* users) {
+  for (llvm::Use& u: val->uses()) {
+    llvm::User* user = u.getUser();
+    if (llvm::isa<llvm::Instruction>(user)) {
+      llvm::Instruction* inst = llvm::dyn_cast<llvm::Instruction>(u.getUser());
       users->push_back(inst->getFunction());
-    } else if (isa<GlobalVariable>(user)) {
-      GlobalVariable* gv = cast<GlobalVariable>(user);
+    } else if (llvm::isa<llvm::GlobalVariable>(user)) {
+      llvm::GlobalVariable* gv = llvm::cast<llvm::GlobalVariable>(user);
       string val_name = gv->getName();
       // We strip global ctors and dtors out of the modules as they are not run.
       if (val_name.find("llvm.global_ctors") == string::npos &&
           val_name.find("llvm.global_dtors") == string::npos) {
         users->push_back(gv);;
       }
-    } else if (isa<Constant>(user)) {
+    } else if (llvm::isa<llvm::Constant>(user)) {
       FindGlobalUsers(user, users);
     } else {
       DCHECK(false) << "Unknown user's types for " << val->getName().str();
@@ -59,10 +59,10 @@ void CodegenCallGraph::FindGlobalUsers(User* val, vector<GlobalObject*>* users)
   }
 }
 
-void CodegenCallGraph::Init(Module* module) {
+void CodegenCallGraph::Init(llvm::Module* module) {
   DCHECK(!inited_);
   // Create a mapping of functions to their referenced functions.
-  for (Function& fn: module->functions()) {
+  for (llvm::Function& fn : module->functions()) {
     if (fn.isIntrinsic() || fn.isDeclaration()) continue;
     string fn_name = fn.getName();
     // Create an entry for a function if it doesn't exist already.
@@ -70,17 +70,17 @@ void CodegenCallGraph::Init(Module* module) {
     if (call_graph_.find(fn_name) == call_graph_.end()) {
       call_graph_.emplace(fn_name, unordered_set<string>());
     }
-    vector<GlobalObject*> users;
+    vector<llvm::GlobalObject*> users;
     FindGlobalUsers(&fn, &users);
-    for (GlobalValue* val: users) {
+    for (llvm::GlobalValue* val : users) {
       const string& caller_name = val->getName();
-      DCHECK(isa<GlobalVariable>(val) || isa<Function>(val));
+      DCHECK(llvm::isa<llvm::GlobalVariable>(val) || llvm::isa<llvm::Function>(val));
       // 'call_graph_' contains functions which need to be materialized when a certain
       // IR Function is materialized. We choose to include functions referenced by
       // another IR function in the map even if it's defined in Impalad binary so it
       // can be inlined for further optimization. This is not applicable for functions
       // referenced by global variables only.
-      if (isa<GlobalVariable>(val)) {
+      if (llvm::isa<llvm::GlobalVariable>(val)) {
         if (IsDefinedInImpalad(fn_name)) continue;
         fns_referenced_by_gv_.insert(fn_name);
       } else {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/e98d2f1c/be/src/codegen/codegen-symbol-emitter.cc
----------------------------------------------------------------------
diff --git a/be/src/codegen/codegen-symbol-emitter.cc b/be/src/codegen/codegen-symbol-emitter.cc
index a272f64..a81ec83 100644
--- a/be/src/codegen/codegen-symbol-emitter.cc
+++ b/be/src/codegen/codegen-symbol-emitter.cc
@@ -40,8 +40,6 @@
 
 #include "common/names.h"
 
-using namespace llvm;
-using namespace llvm::object;
 using std::hex;
 using std::rename;
 
@@ -51,8 +49,8 @@ SpinLock CodegenSymbolEmitter::perf_map_lock_;
 unordered_map<const void*, vector<CodegenSymbolEmitter::PerfMapEntry>>
     CodegenSymbolEmitter::perf_map_;
 
-void CodegenSymbolEmitter::NotifyObjectEmitted(const ObjectFile &obj,
-   const RuntimeDyld::LoadedObjectInfo &loaded_obj) {
+void CodegenSymbolEmitter::NotifyObjectEmitted(const llvm::object::ObjectFile& obj,
+    const llvm::RuntimeDyld::LoadedObjectInfo& loaded_obj) {
   vector<PerfMapEntry> perf_map_entries;
 
   ofstream asm_file;
@@ -65,12 +63,14 @@ void CodegenSymbolEmitter::NotifyObjectEmitted(const ObjectFile &obj,
     }
   }
 
-  OwningBinary<ObjectFile> debug_obj_owner = loaded_obj.getObjectForDebug(obj);
-  const ObjectFile &debug_obj = *debug_obj_owner.getBinary();
-  DWARFContextInMemory dwarf_ctx(debug_obj);
+  llvm::object::OwningBinary<llvm::object::ObjectFile> debug_obj_owner =
+      loaded_obj.getObjectForDebug(obj);
+  const llvm::object::ObjectFile& debug_obj = *debug_obj_owner.getBinary();
+  llvm::DWARFContextInMemory dwarf_ctx(debug_obj);
 
   // Use symbol info to iterate functions in the object.
-  for (const std::pair<SymbolRef, uint64_t> &pair: computeSymbolSizes(debug_obj)) {
+  for (const std::pair<llvm::object::SymbolRef, uint64_t>& pair :
+      computeSymbolSizes(debug_obj)) {
     ProcessSymbol(&dwarf_ctx, pair.first, pair.second, &perf_map_entries, asm_file);
   }
 
@@ -85,21 +85,21 @@ void CodegenSymbolEmitter::NotifyObjectEmitted(const ObjectFile &obj,
   }
 }
 
-void CodegenSymbolEmitter::NotifyFreeingObject(const ObjectFile &obj) {
+void CodegenSymbolEmitter::NotifyFreeingObject(const llvm::object::ObjectFile& obj) {
   lock_guard<SpinLock> perf_map_lock(perf_map_lock_);
   DCHECK(perf_map_.find(obj.getData().data()) != perf_map_.end());
   perf_map_.erase(obj.getData().data());
   WritePerfMapLocked();
 }
 
-void CodegenSymbolEmitter::ProcessSymbol(DIContext* debug_ctx,
-    const SymbolRef& symbol, uint64_t size, vector<PerfMapEntry>* perf_map_entries,
-    ofstream& asm_file) {
-  Expected<SymbolRef::Type> symType = symbol.getType();
-  if (!symType || symType.get() != SymbolRef::ST_Function) return;
+void CodegenSymbolEmitter::ProcessSymbol(llvm::DIContext* debug_ctx,
+    const llvm::object::SymbolRef& symbol, uint64_t size,
+    vector<PerfMapEntry>* perf_map_entries, ofstream& asm_file) {
+  llvm::Expected<llvm::object::SymbolRef::Type> symType = symbol.getType();
+  if (!symType || symType.get() != llvm::object::SymbolRef::ST_Function) return;
 
-  Expected<StringRef> name_or_err = symbol.getName();
-  Expected<uint64_t> addr_or_err = symbol.getAddress();
+  llvm::Expected<llvm::StringRef> name_or_err = symbol.getName();
+  llvm::Expected<uint64_t> addr_or_err = symbol.getAddress();
   if (!name_or_err || !addr_or_err) return;
 
   uint64_t addr = addr_or_err.get();
@@ -153,14 +153,14 @@ void CodegenSymbolEmitter::WritePerfMapLocked() {
   }
 }
 
-void CodegenSymbolEmitter::EmitFunctionAsm(DIContext* debug_ctx,
+void CodegenSymbolEmitter::EmitFunctionAsm(llvm::DIContext* debug_ctx,
     const string& fn_symbol, uint64_t addr, uint64_t size, ofstream& asm_file) {
   DCHECK(asm_file.is_open());
-  DILineInfoTable di_lines = debug_ctx->getLineInfoForAddressRange(addr, size);
+  llvm::DILineInfoTable di_lines = debug_ctx->getLineInfoForAddressRange(addr, size);
   auto di_line_it = di_lines.begin();
 
   // LLVM's C disassembler API is much simpler than the C++ API, so let's use it.
-  string triple = sys::getProcessTriple();
+  string triple = llvm::sys::getProcessTriple();
   LLVMDisasmContextRef disasm = LLVMCreateDisasm(triple.c_str(), NULL, 0, NULL, NULL);
   if (disasm == NULL) {
     LOG(WARNING) << "Could not create LLVM disassembler for target triple " << triple;
@@ -178,7 +178,7 @@ void CodegenSymbolEmitter::EmitFunctionAsm(DIContext* debug_ctx,
     uint64_t inst_addr = reinterpret_cast<uint64_t>(code);
     // Emit any debug symbols before instruction.
     for (; di_line_it != di_lines.end() && di_line_it->first <= inst_addr; ++di_line_it) {
-      DILineInfo line = di_line_it->second;
+      llvm::DILineInfo line = di_line_it->second;
       asm_file << "\t" << line.FileName << ":" << line.FileName << ":"
                << line.FunctionName << ":" << line.Line << ":" << line.Column << "\n";
     }
@@ -196,7 +196,7 @@ void CodegenSymbolEmitter::EmitFunctionAsm(DIContext* debug_ctx,
   }
 
   for (; di_line_it != di_lines.end(); ++di_line_it) {
-    DILineInfo line = di_line_it->second;
+    llvm::DILineInfo line = di_line_it->second;
     asm_file << "\t" << line.FileName << ":" << line.FileName << ":"
              << line.FunctionName << ":" << line.Line << ":" << line.Column << "\n";
   }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/e98d2f1c/be/src/codegen/codegen-util.cc
----------------------------------------------------------------------
diff --git a/be/src/codegen/codegen-util.cc b/be/src/codegen/codegen-util.cc
index 9890ac2..7e71b98 100644
--- a/be/src/codegen/codegen-util.cc
+++ b/be/src/codegen/codegen-util.cc
@@ -21,17 +21,16 @@
 
 #include "common/names.h"
 
-using namespace llvm;
 using std::isdigit;
 
 namespace impala {
 
-CallInst* CodeGenUtil::CreateCallWithBitCasts(LlvmBuilder* builder,
-    Function *callee, ArrayRef<Value*> args, const Twine& name) {
-  vector<Value*> bitcast_args;
+llvm::CallInst* CodeGenUtil::CreateCallWithBitCasts(LlvmBuilder* builder,
+    llvm::Function* callee, llvm::ArrayRef<llvm::Value*> args, const llvm::Twine& name) {
+  vector<llvm::Value*> bitcast_args;
   bitcast_args.reserve(args.size());
-  Function::arg_iterator fn_arg = callee->arg_begin();
-  for (Value* arg: args) {
+  llvm::Function::arg_iterator fn_arg = callee->arg_begin();
+  for (llvm::Value* arg : args) {
     bitcast_args.push_back(
         CheckedBitCast(builder, arg, fn_arg->getType(), "create_call_bitcast"));
     ++fn_arg;
@@ -39,14 +38,14 @@ CallInst* CodeGenUtil::CreateCallWithBitCasts(LlvmBuilder* builder,
   return builder->CreateCall(callee, bitcast_args, name);
 }
 
-Value* CodeGenUtil::CheckedBitCast(LlvmBuilder* builder, Value* value,
-    Type* dst_type, const Twine& name) {
+llvm::Value* CodeGenUtil::CheckedBitCast(LlvmBuilder* builder, llvm::Value* value,
+    llvm::Type* dst_type, const llvm::Twine& name) {
   DCHECK(TypesAreStructurallyIdentical(value->getType(), dst_type))
       << Print(value->getType()) << " " << Print(dst_type);
   return builder->CreateBitCast(value, dst_type, name);
 }
 
-bool CodeGenUtil::TypesAreStructurallyIdentical(Type* t1, Type* t2) {
+bool CodeGenUtil::TypesAreStructurallyIdentical(llvm::Type* t1, llvm::Type* t2) {
   // All primitive types are deduplicated by LLVM, so we can just compare the pointers.
   if (t1 == t2) return true;
   // Derived types are structurally identical if they are the same kind of compound type

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/e98d2f1c/be/src/codegen/instruction-counter-test.cc
----------------------------------------------------------------------
diff --git a/be/src/codegen/instruction-counter-test.cc b/be/src/codegen/instruction-counter-test.cc
index c40c551..d719cf3 100644
--- a/be/src/codegen/instruction-counter-test.cc
+++ b/be/src/codegen/instruction-counter-test.cc
@@ -29,13 +29,12 @@
 #include "testutil/gtest-util.h"
 
 #include "common/names.h"
-using namespace llvm;
 
 namespace impala {
 
 class InstructionCounterTest : public testing:: Test {
  protected:
-  LLVMContext context_;
+  llvm::LLVMContext context_;
 };
 
 // IR output from CodegenMullAdd
@@ -47,33 +46,33 @@ class InstructionCounterTest : public testing:: Test {
 // }
 // Create a module with one function, which multiplies two arguments, add a third and
 // then returns the result.
-Module* CodegenMulAdd(LLVMContext* context) {
-  Module* mod = new Module("test", *context);
-  Constant* c = mod->getOrInsertFunction("mul_add", IntegerType::get(*context, 32),
-      IntegerType::get(*context, 32), IntegerType::get(*context, 32),
-      IntegerType::get(*context, 32), NULL);
-  Function* mul_add = cast<Function>(c);
-  mul_add->setCallingConv(CallingConv::C);
-  Function::arg_iterator args = mul_add->arg_begin();
-  Value* x = &*args;
+llvm::Module* CodegenMulAdd(llvm::LLVMContext* context) {
+  llvm::Module* mod = new llvm::Module("test", *context);
+  llvm::Constant* c = mod->getOrInsertFunction("mul_add",
+      llvm::IntegerType::get(*context, 32), llvm::IntegerType::get(*context, 32),
+      llvm::IntegerType::get(*context, 32), llvm::IntegerType::get(*context, 32), NULL);
+  llvm::Function* mul_add = llvm::cast<llvm::Function>(c);
+  mul_add->setCallingConv(llvm::CallingConv::C);
+  llvm::Function::arg_iterator args = mul_add->arg_begin();
+  llvm::Value* x = &*args;
   ++args;
   x->setName("x");
-  Value* y = &*args;
+  llvm::Value* y = &*args;
   ++args;
   y->setName("y");
-  Value* z = &*args;
+  llvm::Value* z = &*args;
   ++args;
   z->setName("z");
-  BasicBlock* block = BasicBlock::Create(*context, "entry", mul_add);
-  IRBuilder<> builder(block);
-  Value* tmp = builder.CreateBinOp(Instruction::Mul, x, y, "tmp");
-  Value* tmp2 = builder.CreateBinOp(Instruction::Add, tmp, z, "tmp2");
+  llvm::BasicBlock* block = llvm::BasicBlock::Create(*context, "entry", mul_add);
+  llvm::IRBuilder<> builder(block);
+  llvm::Value* tmp = builder.CreateBinOp(llvm::Instruction::Mul, x, y, "tmp");
+  llvm::Value* tmp2 = builder.CreateBinOp(llvm::Instruction::Add, tmp, z, "tmp2");
   builder.CreateRet(tmp2);
   return mod;
 }
 
 TEST_F(InstructionCounterTest, Count) {
-  Module* MulAddModule = CodegenMulAdd(&context_);
+  llvm::Module* MulAddModule = CodegenMulAdd(&context_);
   InstructionCounter* instruction_counter = new InstructionCounter();
   instruction_counter->visit(*MulAddModule);
   instruction_counter->PrintCounters();
@@ -113,45 +112,46 @@ TEST_F(InstructionCounterTest, Count) {
 //   ret i32 %tmp6
 // LLVM IR module which contains one function to return the GCD of two numbers
 // }
-Module* CodegenGcd(LLVMContext* context) {
-  Module* mod = new Module("gcd", *context);
-  Constant* c = mod->getOrInsertFunction("gcd", IntegerType::get(*context, 32),
-      IntegerType::get(*context, 32), IntegerType::get(*context, 32), NULL);
-  Function* gcd = cast<Function>(c);
-  Function::arg_iterator args = gcd->arg_begin();
-  Value* x = &*args;
+llvm::Module* CodegenGcd(llvm::LLVMContext* context) {
+  llvm::Module* mod = new llvm::Module("gcd", *context);
+  llvm::Constant* c = mod->getOrInsertFunction("gcd",
+      llvm::IntegerType::get(*context, 32), llvm::IntegerType::get(*context, 32),
+      llvm::IntegerType::get(*context, 32), NULL);
+  llvm::Function* gcd = llvm::cast<llvm::Function>(c);
+  llvm::Function::arg_iterator args = gcd->arg_begin();
+  llvm::Value* x = &*args;
   ++args;
   x->setName("x");
-  Value* y = &*args;
+  llvm::Value* y = &*args;
   ++args;
   y->setName("y");
-  BasicBlock* entry = BasicBlock::Create(*context, "entry", gcd);
-  BasicBlock* ret = BasicBlock::Create(*context, "return", gcd);
-  BasicBlock* cond_false = BasicBlock::Create(*context, "cond_false", gcd);
-  BasicBlock* cond_true = BasicBlock::Create(*context, "cond_true", gcd);
-  BasicBlock* cond_false_2 = BasicBlock::Create(*context, "cond_false", gcd);
-  IRBuilder<> builder(entry);
-  Value* xEqualsY = builder.CreateICmpEQ(x, y, "tmp");
+  llvm::BasicBlock* entry = llvm::BasicBlock::Create(*context, "entry", gcd);
+  llvm::BasicBlock* ret = llvm::BasicBlock::Create(*context, "return", gcd);
+  llvm::BasicBlock* cond_false = llvm::BasicBlock::Create(*context, "cond_false", gcd);
+  llvm::BasicBlock* cond_true = llvm::BasicBlock::Create(*context, "cond_true", gcd);
+  llvm::BasicBlock* cond_false_2 = llvm::BasicBlock::Create(*context, "cond_false", gcd);
+  llvm::IRBuilder<> builder(entry);
+  llvm::Value* xEqualsY = builder.CreateICmpEQ(x, y, "tmp");
   builder.CreateCondBr(xEqualsY, ret, cond_false);  builder.SetInsertPoint(ret);
   builder.CreateRet(x);
   builder.SetInsertPoint(cond_false);
-  Value* xLessThanY = builder.CreateICmpULT(x, y, "tmp");
+  llvm::Value* xLessThanY = builder.CreateICmpULT(x, y, "tmp");
   builder.CreateCondBr(xLessThanY, cond_true, cond_false_2);
   builder.SetInsertPoint(cond_true);
-  Value* yMinusX = builder.CreateSub(y, x, "tmp");
-  Value* args1[2] =  {x , yMinusX};
-  Value* recur_1 = builder.CreateCall(gcd, args1, "tmp");
+  llvm::Value* yMinusX = builder.CreateSub(y, x, "tmp");
+  llvm::Value* args1[2] = {x, yMinusX};
+  llvm::Value* recur_1 = builder.CreateCall(gcd, args1, "tmp");
   builder.CreateRet(recur_1);
   builder.SetInsertPoint(cond_false_2);
-  Value* xMinusY = builder.CreateSub(x, y, "tmp");
-  Value* args2[2] = {xMinusY, y};
-  Value* recur_2 = builder.CreateCall(gcd, args2,  "tmp");
+  llvm::Value* xMinusY = builder.CreateSub(x, y, "tmp");
+  llvm::Value* args2[2] = {xMinusY, y};
+  llvm::Value* recur_2 = builder.CreateCall(gcd, args2, "tmp");
   builder.CreateRet(recur_2);
   return mod;
 }
 
 TEST_F(InstructionCounterTest, TestMemInstrCount) {
-  Module* GcdModule = CodegenGcd(&context_);
+  llvm::Module* GcdModule = CodegenGcd(&context_);
   InstructionCounter* instruction_counter = new InstructionCounter();
   instruction_counter->visit(*GcdModule);
   std::cout << instruction_counter->PrintCounters();

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/e98d2f1c/be/src/codegen/instruction-counter.cc
----------------------------------------------------------------------
diff --git a/be/src/codegen/instruction-counter.cc b/be/src/codegen/instruction-counter.cc
index 751e435..aefe5ef 100644
--- a/be/src/codegen/instruction-counter.cc
+++ b/be/src/codegen/instruction-counter.cc
@@ -22,7 +22,6 @@
 #include "common/names.h"
 
 using namespace impala;
-using namespace llvm;
 using std::make_pair;
 using std::max;
 
@@ -41,9 +40,9 @@ InstructionCounter::InstructionCounter() {
   counters_.insert(make_pair(TOTAL_BLOCKS, 0));
   counters_.insert(make_pair(TOTAL_FUNCTIONS, 0));
 
-  // Create all instruction counter and put them into counters_. Any InstructionCount that
-  // has instructions delegated to it in InstructionCounter::visit(const Instruction &I)
-  // must be created and inserted into counters_ here.
+  // Create all instruction counter and put them into counters_. Any InstructionCount
+  // that has instructions delegated to it in InstructionCounter::visit(const
+  // Instruction &I) must be created and inserted into counters_ here.
   counters_.insert(make_pair(TERMINATOR_INSTS, 0));
   counters_.insert(make_pair(BINARY_INSTS, 0));
   counters_.insert(make_pair(MEMORY_INSTS, 0));
@@ -51,16 +50,16 @@ InstructionCounter::InstructionCounter() {
   counters_.insert(make_pair(OTHER_INSTS, 0));
 }
 
-void InstructionCounter::visit(const Module& M) {
+void InstructionCounter::visit(const llvm::Module& M) {
   visit(M.begin(), M.end());
 }
 
-void InstructionCounter::visit(const Function& F) {
+void InstructionCounter::visit(const llvm::Function& F) {
   IncrementCount(TOTAL_FUNCTIONS);
   visit(F.begin(), F.end());
 }
 
-void InstructionCounter::visit(const BasicBlock& BB) {
+void InstructionCounter::visit(const llvm::BasicBlock& BB) {
   IncrementCount(TOTAL_BLOCKS);
   visit(BB.begin(), BB.end());
 }
@@ -71,7 +70,7 @@ int InstructionCounter::GetCount(const char* name) {
   return counter->second;
 }
 
-void InstructionCounter::visit(const Instruction& I) {
+void InstructionCounter::visit(const llvm::Instruction& I) {
   IncrementCount(TOTAL_INSTS);
   switch (I.getOpcode()) {
     case llvm::Instruction::Ret:

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/e98d2f1c/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 68a5ff8..af6245a 100644
--- a/be/src/codegen/llvm-codegen-test.cc
+++ b/be/src/codegen/llvm-codegen-test.cc
@@ -35,7 +35,6 @@
 
 #include "common/names.h"
 
-using namespace llvm;
 using std::unique_ptr;
 
 namespace impala {
@@ -64,9 +63,12 @@ class LlvmCodeGenTest : public testing:: Test {
       LlvmCodeGen object2(NULL, &pool, NULL, "Test");
       LlvmCodeGen object3(NULL, &pool, NULL, "Test");
 
-      ASSERT_OK(object1.Init(unique_ptr<Module>(new Module("Test", object1.context()))));
-      ASSERT_OK(object2.Init(unique_ptr<Module>(new Module("Test", object2.context()))));
-      ASSERT_OK(object3.Init(unique_ptr<Module>(new Module("Test", object3.context()))));
+      ASSERT_OK(object1.Init(
+          unique_ptr<llvm::Module>(new llvm::Module("Test", object1.context()))));
+      ASSERT_OK(object2.Init(
+          unique_ptr<llvm::Module>(new llvm::Module("Test", object2.context()))));
+      ASSERT_OK(object3.Init(
+          unique_ptr<llvm::Module>(new llvm::Module("Test", object3.context()))));
 
       object1.Close();
       object2.Close();
@@ -140,22 +142,24 @@ TEST_F(LlvmCodeGenTest, BadIRFile) {
 //   ret void
 // }
 // The random int in there is the address of jitted_counter
-Function* CodegenInnerLoop(LlvmCodeGen* codegen, int64_t* jitted_counter, int delta) {
-  LLVMContext& context = codegen->context();
+llvm::Function* CodegenInnerLoop(
+    LlvmCodeGen* codegen, int64_t* jitted_counter, int delta) {
+  llvm::LLVMContext& context = codegen->context();
   LlvmBuilder builder(context);
 
   LlvmCodeGen::FnPrototype fn_prototype(codegen, "JittedInnerLoop", codegen->void_type());
-  Function* jitted_loop_call = fn_prototype.GeneratePrototype();
-  BasicBlock* entry_block = BasicBlock::Create(context, "entry", jitted_loop_call);
+  llvm::Function* jitted_loop_call = fn_prototype.GeneratePrototype();
+  llvm::BasicBlock* entry_block =
+      llvm::BasicBlock::Create(context, "entry", jitted_loop_call);
   builder.SetInsertPoint(entry_block);
   codegen->CodegenDebugTrace(&builder, "Jitted\n");
 
   // Store &jitted_counter as a constant.
-  Value* const_delta = ConstantInt::get(context, APInt(64, delta));
-  Value* counter_ptr = codegen->CastPtrToLlvmPtr(codegen->GetPtrType(TYPE_BIGINT),
-      jitted_counter);
-  Value* loaded_counter = builder.CreateLoad(counter_ptr);
-  Value* incremented_value = builder.CreateAdd(loaded_counter, const_delta);
+  llvm::Value* const_delta = llvm::ConstantInt::get(context, llvm::APInt(64, delta));
+  llvm::Value* counter_ptr =
+      codegen->CastPtrToLlvmPtr(codegen->GetPtrType(TYPE_BIGINT), 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);
   builder.CreateRetVoid();
 
@@ -190,10 +194,10 @@ TEST_F(LlvmCodeGenTest, ReplaceFnCall) {
   ASSERT_OK(CreateFromFile(module_file.c_str(), &codegen));
   EXPECT_TRUE(codegen.get() != NULL);
 
-  Function* loop_call = codegen->GetFunction(loop_call_name, false);
+  llvm::Function* loop_call = codegen->GetFunction(loop_call_name, false);
   EXPECT_TRUE(loop_call != NULL);
   EXPECT_TRUE(loop_call->arg_empty());
-  Function* loop = codegen->GetFunction(loop_name, false);
+  llvm::Function* loop = codegen->GetFunction(loop_name, false);
   EXPECT_TRUE(loop != NULL);
   EXPECT_EQ(loop->arg_size(), 1);
 
@@ -207,19 +211,20 @@ TEST_F(LlvmCodeGenTest, ReplaceFnCall) {
   // }
   //
   int64_t jitted_counter = 0;
-  Function* jitted_loop_call = CodegenInnerLoop(codegen.get(), &jitted_counter, 1);
+  llvm::Function* jitted_loop_call = CodegenInnerLoop(codegen.get(), &jitted_counter, 1);
 
   // Part 3: Clone 'loop' and replace the call instruction to the normal function with a
   // call to the jitted one
-  Function* jitted_loop = codegen->CloneFunction(loop);
+  llvm::Function* jitted_loop = codegen->CloneFunction(loop);
   int num_replaced =
       codegen->ReplaceCallSites(jitted_loop, jitted_loop_call, loop_call_name);
   EXPECT_EQ(1, num_replaced);
   EXPECT_TRUE(VerifyFunction(codegen.get(), jitted_loop));
 
   // Part 4: Generate a new inner loop function and a new loop function
-  Function* jitted_loop_call2 = CodegenInnerLoop(codegen.get(), &jitted_counter, -2);
-  Function* jitted_loop2 = codegen->CloneFunction(loop);
+  llvm::Function* jitted_loop_call2 =
+      CodegenInnerLoop(codegen.get(), &jitted_counter, -2);
+  llvm::Function* jitted_loop2 = codegen->CloneFunction(loop);
   num_replaced = codegen->ReplaceCallSites(jitted_loop2, jitted_loop_call2, loop_call_name);
   EXPECT_EQ(1, num_replaced);
   EXPECT_TRUE(VerifyFunction(codegen.get(), jitted_loop2));
@@ -273,27 +278,28 @@ TEST_F(LlvmCodeGenTest, ReplaceFnCall) {
 //   store i32 1, i32* %len_ptr
 //   ret i32 %len
 // }
-Function* CodegenStringTest(LlvmCodeGen* codegen) {
-  PointerType* string_val_ptr_type = codegen->GetPtrType(TYPE_STRING);
+llvm::Function* CodegenStringTest(LlvmCodeGen* codegen) {
+  llvm::PointerType* string_val_ptr_type = codegen->GetPtrType(TYPE_STRING);
   EXPECT_TRUE(string_val_ptr_type != NULL);
 
   LlvmCodeGen::FnPrototype prototype(codegen, "StringTest", codegen->GetType(TYPE_INT));
   prototype.AddArgument(LlvmCodeGen::NamedVariable("str", string_val_ptr_type));
   LlvmBuilder builder(codegen->context());
 
-  Value* str;
-  Function* interop_fn = prototype.GeneratePrototype(&builder, &str);
+  llvm::Value* str;
+  llvm::Function* interop_fn = prototype.GeneratePrototype(&builder, &str);
 
   // strval->ptr[0] = 'A'
-  Value* str_ptr = builder.CreateStructGEP(NULL, str, 0, "str_ptr");
-  Value* ptr = builder.CreateLoad(str_ptr, "ptr");
-  Value* first_char_offset[] = { codegen->GetIntConstant(TYPE_INT, 0) };
-  Value* first_char_ptr = builder.CreateGEP(ptr, first_char_offset, "first_char_ptr");
+  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_ptr =
+      builder.CreateGEP(ptr, first_char_offset, "first_char_ptr");
   builder.CreateStore(codegen->GetIntConstant(TYPE_TINYINT, 'A'), first_char_ptr);
 
   // Update and return old len
-  Value* len_ptr = builder.CreateStructGEP(NULL, str, 1, "len_ptr");
-  Value* len = builder.CreateLoad(len_ptr, "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.CreateRet(len);
 
@@ -316,7 +322,7 @@ TEST_F(LlvmCodeGenTest, StringValue) {
   str_val.ptr = const_cast<char*>(str.c_str());
   str_val.len = str.length();
 
-  Function* string_test_fn = CodegenStringTest(codegen.get());
+  llvm::Function* string_test_fn = CodegenStringTest(codegen.get());
   EXPECT_TRUE(string_test_fn != NULL);
   EXPECT_TRUE(VerifyFunction(codegen.get(), string_test_fn));
 
@@ -360,8 +366,8 @@ TEST_F(LlvmCodeGenTest, MemcpyTest) {
   char src[] = "abcd";
   char dst[] = "aaaa";
 
-  Value* args[3];
-  Function* fn = prototype.GeneratePrototype(&builder, &args[0]);
+  llvm::Value* args[3];
+  llvm::Function* fn = prototype.GeneratePrototype(&builder, &args[0]);
   codegen->CodegenMemcpy(&builder, args[0], args[1], sizeof(src));
   builder.CreateRetVoid();
 
@@ -398,12 +404,12 @@ TEST_F(LlvmCodeGenTest, HashTest) {
     const auto close_codegen =
         MakeScopeExitTrigger([&codegen]() { codegen->Close(); });
 
-    Value* llvm_data1 =
+    llvm::Value* llvm_data1 =
         codegen->CastPtrToLlvmPtr(codegen->ptr_type(), const_cast<char*>(data1));
-    Value* llvm_data2 =
+    llvm::Value* llvm_data2 =
         codegen->CastPtrToLlvmPtr(codegen->ptr_type(), const_cast<char*>(data2));
-    Value* llvm_len1 = codegen->GetIntConstant(TYPE_INT, strlen(data1));
-    Value* llvm_len2 = codegen->GetIntConstant(TYPE_INT, strlen(data2));
+    llvm::Value* llvm_len1 = codegen->GetIntConstant(TYPE_INT, strlen(data1));
+    llvm::Value* llvm_len2 = codegen->GetIntConstant(TYPE_INT, strlen(data2));
 
     uint32_t expected_hash = 0;
     expected_hash = HashUtil::Hash(data1, strlen(data1), expected_hash);
@@ -417,22 +423,22 @@ TEST_F(LlvmCodeGenTest, HashTest) {
     LlvmBuilder builder(codegen->context());
 
     // Test both byte-size specific hash functions and the generic loop hash function
-    Function* fn_fixed = prototype.GeneratePrototype(&builder, NULL);
-    Function* data1_hash_fn = codegen->GetHashFunction(strlen(data1));
-    Function* data2_hash_fn = codegen->GetHashFunction(strlen(data2));
-    Function* generic_hash_fn = codegen->GetHashFunction();
+    llvm::Function* fn_fixed = prototype.GeneratePrototype(&builder, NULL);
+    llvm::Function* data1_hash_fn = codegen->GetHashFunction(strlen(data1));
+    llvm::Function* data2_hash_fn = codegen->GetHashFunction(strlen(data2));
+    llvm::Function* generic_hash_fn = codegen->GetHashFunction();
 
     ASSERT_TRUE(data1_hash_fn != NULL);
     ASSERT_TRUE(data2_hash_fn != NULL);
     ASSERT_TRUE(generic_hash_fn != NULL);
 
-    Value* seed = codegen->GetIntConstant(TYPE_INT, 0);
-    seed = builder.CreateCall(data1_hash_fn,
-        ArrayRef<Value*>({llvm_data1, llvm_len1, seed}));
-    seed = builder.CreateCall(data2_hash_fn,
-        ArrayRef<Value*>({llvm_data2, llvm_len2, seed}));
-    seed = builder.CreateCall(generic_hash_fn,
-        ArrayRef<Value*>({llvm_data1, llvm_len1, seed}));
+    llvm::Value* seed = codegen->GetIntConstant(TYPE_INT, 0);
+    seed = builder.CreateCall(
+        data1_hash_fn, llvm::ArrayRef<llvm::Value*>({llvm_data1, llvm_len1, seed}));
+    seed = builder.CreateCall(
+        data2_hash_fn, llvm::ArrayRef<llvm::Value*>({llvm_data2, llvm_len2, seed}));
+    seed = builder.CreateCall(
+        generic_hash_fn, llvm::ArrayRef<llvm::Value*>({llvm_data1, llvm_len1, seed}));
     builder.CreateRet(seed);
 
     fn_fixed = codegen->FinalizeFunction(fn_fixed);