http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/e98d2f1c/be/src/exec/hash-table.cc ---------------------------------------------------------------------- diff --git a/be/src/exec/hash-table.cc b/be/src/exec/hash-table.cc index a1d9c57..da9f195 100644 --- a/be/src/exec/hash-table.cc +++ b/be/src/exec/hash-table.cc @@ -37,16 +37,6 @@ #include "common/names.h" using namespace impala; -using llvm::APFloat; -using llvm::ArrayRef; -using llvm::BasicBlock; -using llvm::ConstantFP; -using llvm::Function; -using llvm::LLVMContext; -using llvm::PHINode; -using llvm::PointerType; -using llvm::Type; -using llvm::Value; using strings::Substitute; DEFINE_bool(enable_quadratic_probing, true, "Enable quadratic probing hash table"); @@ -588,19 +578,19 @@ string HashTable::PrintStats() const { // Helper function to store a value into the results buffer if the expr // evaluated to NULL. We don't want (NULL, 1) to hash to the same as (0,1) so // we'll pick a more random value. -static void CodegenAssignNullValue( - LlvmCodeGen* codegen, LlvmBuilder* builder, Value* dst, const ColumnType& type) { +static void CodegenAssignNullValue(LlvmCodeGen* codegen, LlvmBuilder* builder, + llvm::Value* dst, const ColumnType& type) { uint64_t fnv_seed = HashUtil::FNV_SEED; if (type.type == TYPE_STRING || type.type == TYPE_VARCHAR) { - Value* dst_ptr = builder->CreateStructGEP(NULL, dst, 0, "string_ptr"); - Value* dst_len = builder->CreateStructGEP(NULL, dst, 1, "string_len"); - Value* null_len = codegen->GetIntConstant(TYPE_INT, fnv_seed); - Value* null_ptr = builder->CreateIntToPtr(null_len, codegen->ptr_type()); + 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_ptr = builder->CreateIntToPtr(null_len, codegen->ptr_type()); builder->CreateStore(null_ptr, dst_ptr); builder->CreateStore(null_len, dst_len); } else { - Value* null_value = NULL; + llvm::Value* null_value = NULL; int byte_size = type.GetByteSize(); // Get a type specific representation of fnv_seed switch (type.type) { @@ -612,8 +602,8 @@ static void CodegenAssignNullValue( case TYPE_TIMESTAMP: { // Cast 'dst' to 'i128*' DCHECK_EQ(byte_size, 16); - PointerType* fnv_seed_ptr_type = - codegen->GetPtrType(Type::getIntNTy(codegen->context(), byte_size * 8)); + llvm::PointerType* fnv_seed_ptr_type = + codegen->GetPtrType(llvm::Type::getIntNTy(codegen->context(), byte_size * 8)); dst = builder->CreateBitCast(dst, fnv_seed_ptr_type); null_value = codegen->GetIntConstant(byte_size, fnv_seed, fnv_seed); break; @@ -628,13 +618,15 @@ static void CodegenAssignNullValue( case TYPE_FLOAT: { // Don't care about the value, just the bit pattern float fnv_seed_float = *reinterpret_cast<float*>(&fnv_seed); - null_value = ConstantFP::get(codegen->context(), APFloat(fnv_seed_float)); + null_value = + llvm::ConstantFP::get(codegen->context(), llvm::APFloat(fnv_seed_float)); break; } case TYPE_DOUBLE: { // Don't care about the value, just the bit pattern double fnv_seed_double = *reinterpret_cast<double*>(&fnv_seed); - null_value = ConstantFP::get(codegen->context(), APFloat(fnv_seed_double)); + null_value = + llvm::ConstantFP::get(codegen->context(), llvm::APFloat(fnv_seed_double)); break; } default: @@ -715,7 +707,8 @@ static void CodegenAssignNullValue( // Both the null and not null branch into the continue block. The continue block // becomes the start of the next block for codegen (either the next expr or just the // end of the function). -Status HashTableCtx::CodegenEvalRow(LlvmCodeGen* codegen, bool build, Function** fn) { +Status HashTableCtx::CodegenEvalRow( + LlvmCodeGen* codegen, bool build, llvm::Function** fn) { const vector<ScalarExpr*>& exprs = build ? build_exprs_ : probe_exprs_; for (int i = 0; i < exprs.size(); ++i) { // Disable codegen for CHAR @@ -725,12 +718,12 @@ Status HashTableCtx::CodegenEvalRow(LlvmCodeGen* codegen, bool build, Function** } // Get types to generate function prototype - Type* this_type = codegen->GetType(HashTableCtx::LLVM_CLASS_NAME); + llvm::Type* this_type = codegen->GetType(HashTableCtx::LLVM_CLASS_NAME); DCHECK(this_type != NULL); - PointerType* this_ptr_type = codegen->GetPtrType(this_type); - Type* tuple_row_type = codegen->GetType(TupleRow::LLVM_CLASS_NAME); + 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); - PointerType* tuple_row_ptr_type = codegen->GetPtrType(tuple_row_type); + llvm::PointerType* tuple_row_ptr_type = codegen->GetPtrType(tuple_row_type); LlvmCodeGen::FnPrototype prototype(codegen, build ? "EvalBuildRow" : "EvalProbeRow", codegen->GetType(TYPE_BOOLEAN)); prototype.AddArgument(LlvmCodeGen::NamedVariable("this_ptr", this_ptr_type)); @@ -739,20 +732,20 @@ Status HashTableCtx::CodegenEvalRow(LlvmCodeGen* codegen, bool build, Function** prototype.AddArgument( LlvmCodeGen::NamedVariable("expr_values_null", codegen->ptr_type())); - LLVMContext& context = codegen->context(); + llvm::LLVMContext& context = codegen->context(); LlvmBuilder builder(context); - Value* args[4]; + llvm::Value* args[4]; *fn = prototype.GeneratePrototype(&builder, args); - Value* this_ptr = args[0]; - Value* row = args[1]; - Value* expr_values = args[2]; - Value* expr_values_null = args[3]; - Value* has_null = codegen->false_value(); + llvm::Value* this_ptr = args[0]; + llvm::Value* row = args[1]; + llvm::Value* expr_values = args[2]; + llvm::Value* expr_values_null = args[3]; + llvm::Value* has_null = codegen->false_value(); // evaluator_vector = build_expr_evals_.data() / probe_expr_evals_.data() - Value* eval_vector = codegen->CodegenCallFunction(&builder, build ? - IRFunction::HASH_TABLE_GET_BUILD_EXPR_EVALUATORS : - IRFunction::HASH_TABLE_GET_PROBE_EXPR_EVALUATORS, + llvm::Value* eval_vector = codegen->CodegenCallFunction(&builder, + build ? IRFunction::HASH_TABLE_GET_BUILD_EXPR_EVALUATORS : + IRFunction::HASH_TABLE_GET_PROBE_EXPR_EVALUATORS, this_ptr, "eval_vector"); for (int i = 0; i < exprs.size(); ++i) { @@ -761,17 +754,17 @@ Status HashTableCtx::CodegenEvalRow(LlvmCodeGen* codegen, bool build, Function** // vector of exprs // Convert result buffer to llvm ptr type int offset = expr_values_cache_.expr_values_offsets(i); - Value* loc = builder.CreateInBoundsGEP( + llvm::Value* loc = builder.CreateInBoundsGEP( NULL, expr_values, codegen->GetIntConstant(TYPE_INT, offset), "loc_addr"); - Value* llvm_loc = builder.CreatePointerCast( - loc, codegen->GetPtrType(exprs[i]->type()), "loc"); + llvm::Value* llvm_loc = + builder.CreatePointerCast(loc, codegen->GetPtrType(exprs[i]->type()), "loc"); - BasicBlock* null_block = BasicBlock::Create(context, "null", *fn); - BasicBlock* not_null_block = BasicBlock::Create(context, "not_null", *fn); - BasicBlock* continue_block = BasicBlock::Create(context, "continue", *fn); + llvm::BasicBlock* null_block = llvm::BasicBlock::Create(context, "null", *fn); + llvm::BasicBlock* not_null_block = llvm::BasicBlock::Create(context, "not_null", *fn); + llvm::BasicBlock* continue_block = llvm::BasicBlock::Create(context, "continue", *fn); // Call expr - Function* expr_fn; + llvm::Function* expr_fn; Status status = exprs[i]->GetCodegendComputeFn(codegen, &expr_fn); if (!status.ok()) { (*fn)->eraseFromParent(); // deletes function @@ -785,15 +778,14 @@ Status HashTableCtx::CodegenEvalRow(LlvmCodeGen* codegen, bool build, Function** codegen->SetNoInline(expr_fn); } - Value* eval_arg = - codegen->CodegenArrayAt(&builder, eval_vector, i, "eval"); + llvm::Value* eval_arg = codegen->CodegenArrayAt(&builder, eval_vector, i, "eval"); CodegenAnyVal result = CodegenAnyVal::CreateCallWrapped( codegen, &builder, exprs[i]->type(), expr_fn, {eval_arg, row}, "result"); - Value* is_null = result.GetIsNull(); + llvm::Value* is_null = result.GetIsNull(); // Set null-byte result - Value* null_byte = builder.CreateZExt(is_null, codegen->GetType(TYPE_TINYINT)); - Value* llvm_null_byte_loc = builder.CreateInBoundsGEP( + llvm::Value* null_byte = builder.CreateZExt(is_null, codegen->GetType(TYPE_TINYINT)); + llvm::Value* llvm_null_byte_loc = builder.CreateInBoundsGEP( NULL, expr_values_null, codegen->GetIntConstant(TYPE_INT, i), "null_byte_loc"); builder.CreateStore(null_byte, llvm_null_byte_loc); builder.CreateCondBr(is_null, null_block, not_null_block); @@ -817,7 +809,8 @@ Status HashTableCtx::CodegenEvalRow(LlvmCodeGen* codegen, bool build, Function** builder.SetInsertPoint(continue_block); if (stores_nulls_) { // Update has_null - PHINode* is_null_phi = builder.CreatePHI(codegen->boolean_type(), 2, "is_null_phi"); + llvm::PHINode* is_null_phi = + builder.CreatePHI(codegen->boolean_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"); @@ -872,7 +865,8 @@ Status HashTableCtx::CodegenEvalRow(LlvmCodeGen* codegen, bool build, Function** // %hash_phi = phi i32 [ %string_hash, %not_null ], [ %str_null, %null ] // ret i32 %hash_phi // } -Status HashTableCtx::CodegenHashRow(LlvmCodeGen* codegen, bool use_murmur, Function** fn) { +Status HashTableCtx::CodegenHashRow( + LlvmCodeGen* codegen, bool use_murmur, llvm::Function** fn) { for (int i = 0; i < build_exprs_.size(); ++i) { // Disable codegen for CHAR if (build_exprs_[i]->type().type == TYPE_CHAR) { @@ -881,9 +875,9 @@ Status HashTableCtx::CodegenHashRow(LlvmCodeGen* codegen, bool use_murmur, Funct } // Get types to generate function prototype - Type* this_type = codegen->GetType(HashTableCtx::LLVM_CLASS_NAME); + llvm::Type* this_type = codegen->GetType(HashTableCtx::LLVM_CLASS_NAME); DCHECK(this_type != NULL); - PointerType* this_ptr_type = codegen->GetPtrType(this_type); + llvm::PointerType* this_ptr_type = codegen->GetPtrType(this_type); LlvmCodeGen::FnPrototype prototype( codegen, (use_murmur ? "MurmurHashRow" : "HashRow"), codegen->GetType(TYPE_INT)); @@ -892,39 +886,39 @@ Status HashTableCtx::CodegenHashRow(LlvmCodeGen* codegen, bool use_murmur, Funct prototype.AddArgument( LlvmCodeGen::NamedVariable("expr_values_null", codegen->ptr_type())); - LLVMContext& context = codegen->context(); + llvm::LLVMContext& context = codegen->context(); LlvmBuilder builder(context); - Value* args[3]; + llvm::Value* args[3]; *fn = prototype.GeneratePrototype(&builder, args); - Value* this_arg = args[0]; - Value* expr_values = args[1]; - Value* expr_values_null = args[2]; + llvm::Value* this_arg = args[0]; + llvm::Value* expr_values = args[1]; + llvm::Value* expr_values_null = args[2]; // Call GetHashSeed() to get seeds_[level_] - Value* seed = codegen->CodegenCallFunction(&builder, - IRFunction::HASH_TABLE_GET_HASH_SEED, this_arg, "seed"); + llvm::Value* seed = codegen->CodegenCallFunction( + &builder, IRFunction::HASH_TABLE_GET_HASH_SEED, this_arg, "seed"); - Value* hash_result = seed; + llvm::Value* hash_result = seed; const int var_result_offset = expr_values_cache_.var_result_offset(); const int expr_values_bytes_per_row = expr_values_cache_.expr_values_bytes_per_row(); if (var_result_offset == -1) { // No variable length slots, just hash what is in 'expr_expr_values_cache_' if (expr_values_bytes_per_row > 0) { - Function* hash_fn = use_murmur ? - codegen->GetMurmurHashFunction(expr_values_bytes_per_row) : - codegen->GetHashFunction(expr_values_bytes_per_row); - Value* len = codegen->GetIntConstant(TYPE_INT, expr_values_bytes_per_row); + 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); hash_result = builder.CreateCall( - hash_fn, ArrayRef<Value*>({expr_values, len, hash_result}), "hash"); + hash_fn, llvm::ArrayRef<llvm::Value*>({expr_values, len, hash_result}), "hash"); } } else { if (var_result_offset > 0) { - Function* hash_fn = use_murmur ? - codegen->GetMurmurHashFunction(var_result_offset) : - codegen->GetHashFunction(var_result_offset); - Value* len = codegen->GetIntConstant(TYPE_INT, var_result_offset); + 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); hash_result = builder.CreateCall( - hash_fn, ArrayRef<Value*>({expr_values, len, hash_result}), "hash"); + hash_fn, llvm::ArrayRef<llvm::Value*>({expr_values, len, hash_result}), "hash"); } // Hash string slots @@ -934,64 +928,65 @@ Status HashTableCtx::CodegenHashRow(LlvmCodeGen* codegen, bool use_murmur, Funct continue; } - BasicBlock* null_block = NULL; - BasicBlock* not_null_block = NULL; - BasicBlock* continue_block = NULL; - Value* str_null_result = NULL; + llvm::BasicBlock* null_block = NULL; + llvm::BasicBlock* not_null_block = NULL; + llvm::BasicBlock* continue_block = NULL; + llvm::Value* str_null_result = NULL; int offset = expr_values_cache_.expr_values_offsets(i); - Value* llvm_loc = builder.CreateInBoundsGEP( + llvm::Value* llvm_loc = builder.CreateInBoundsGEP( NULL, expr_values, codegen->GetIntConstant(TYPE_INT, offset), "loc_addr"); // If the hash table stores nulls, we need to check if the stringval // evaluated to NULL if (stores_nulls_) { - null_block = BasicBlock::Create(context, "null", *fn); - not_null_block = BasicBlock::Create(context, "not_null", *fn); - continue_block = BasicBlock::Create(context, "continue", *fn); - - Value* llvm_null_byte_loc = builder.CreateInBoundsGEP(NULL, expr_values_null, - codegen->GetIntConstant(TYPE_INT, i), "null_byte_loc"); - Value* null_byte = builder.CreateLoad(llvm_null_byte_loc, "null_byte"); - Value* is_null = builder.CreateICmpNE( + null_block = llvm::BasicBlock::Create(context, "null", *fn); + not_null_block = llvm::BasicBlock::Create(context, "not_null", *fn); + 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"); + 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"); builder.CreateCondBr(is_null, null_block, not_null_block); // For null, we just want to call the hash function on the portion of // the data builder.SetInsertPoint(null_block); - Function* null_hash_fn = use_murmur ? - codegen->GetMurmurHashFunction(sizeof(StringValue)) : - codegen->GetHashFunction(sizeof(StringValue)); - Value* len = codegen->GetIntConstant(TYPE_INT, sizeof(StringValue)); + llvm::Function* null_hash_fn = use_murmur ? + codegen->GetMurmurHashFunction(sizeof(StringValue)) : + codegen->GetHashFunction(sizeof(StringValue)); + llvm::Value* len = codegen->GetIntConstant(TYPE_INT, sizeof(StringValue)); str_null_result = builder.CreateCall(null_hash_fn, - ArrayRef<Value*>({llvm_loc, len, hash_result}), "str_null"); + llvm::ArrayRef<llvm::Value*>({llvm_loc, len, hash_result}), "str_null"); builder.CreateBr(continue_block); builder.SetInsertPoint(not_null_block); } // Convert expr_values_buffer_ loc to llvm value - Value* str_val = builder.CreatePointerCast(llvm_loc, - codegen->GetPtrType(TYPE_STRING), "str_val"); + llvm::Value* str_val = builder.CreatePointerCast( + llvm_loc, codegen->GetPtrType(TYPE_STRING), "str_val"); - Value* ptr = builder.CreateStructGEP(NULL, str_val, 0); - Value* len = builder.CreateStructGEP(NULL, str_val, 1); + llvm::Value* ptr = builder.CreateStructGEP(NULL, str_val, 0); + llvm::Value* len = builder.CreateStructGEP(NULL, str_val, 1); ptr = builder.CreateLoad(ptr, "ptr"); len = builder.CreateLoad(len, "len"); // Call hash(ptr, len, hash_result); - Function* general_hash_fn = use_murmur ? codegen->GetMurmurHashFunction() : - codegen->GetHashFunction(); - Value* string_hash_result = builder.CreateCall(general_hash_fn, - ArrayRef<Value*>({ptr, len, hash_result}), "string_hash"); + llvm::Function* general_hash_fn = + use_murmur ? codegen->GetMurmurHashFunction() : codegen->GetHashFunction(); + llvm::Value* string_hash_result = builder.CreateCall(general_hash_fn, + llvm::ArrayRef<llvm::Value*>({ptr, len, hash_result}), "string_hash"); if (stores_nulls_) { builder.CreateBr(continue_block); builder.SetInsertPoint(continue_block); // Use phi node to reconcile that we could have come from the string-null // path and string not null paths. - PHINode* phi_node = builder.CreatePHI(codegen->GetType(TYPE_INT), 2, "hash_phi"); + llvm::PHINode* phi_node = + builder.CreatePHI(codegen->GetType(TYPE_INT), 2, "hash_phi"); phi_node->addIncoming(string_hash_result, not_null_block); phi_node->addIncoming(str_null_result, null_block); hash_result = phi_node; @@ -1081,8 +1076,8 @@ Status HashTableCtx::CodegenHashRow(LlvmCodeGen* codegen, bool use_murmur, Funct // %"struct.impala_udf::StringVal"* %8, %"struct.impala::StringValue"* %row_val8) // br i1 %cmp_raw10, label %continue3, label %false_block // } -Status HashTableCtx::CodegenEquals(LlvmCodeGen* codegen, bool force_null_equality, - Function** fn) { +Status HashTableCtx::CodegenEquals( + LlvmCodeGen* codegen, bool force_null_equality, llvm::Function** fn) { for (int i = 0; i < build_exprs_.size(); ++i) { // Disable codegen for CHAR if (build_exprs_[i]->type().type == TYPE_CHAR) { @@ -1091,12 +1086,12 @@ Status HashTableCtx::CodegenEquals(LlvmCodeGen* codegen, bool force_null_equalit } // Get types to generate function prototype - Type* this_type = codegen->GetType(HashTableCtx::LLVM_CLASS_NAME); + llvm::Type* this_type = codegen->GetType(HashTableCtx::LLVM_CLASS_NAME); DCHECK(this_type != NULL); - PointerType* this_ptr_type = codegen->GetPtrType(this_type); - Type* tuple_row_type = codegen->GetType(TupleRow::LLVM_CLASS_NAME); + 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); - PointerType* tuple_row_ptr_type = codegen->GetPtrType(tuple_row_type); + llvm::PointerType* tuple_row_ptr_type = codegen->GetPtrType(tuple_row_type); LlvmCodeGen::FnPrototype prototype(codegen, "Equals", codegen->GetType(TYPE_BOOLEAN)); prototype.AddArgument(LlvmCodeGen::NamedVariable("this_ptr", this_ptr_type)); @@ -1105,27 +1100,27 @@ Status HashTableCtx::CodegenEquals(LlvmCodeGen* codegen, bool force_null_equalit prototype.AddArgument( LlvmCodeGen::NamedVariable("expr_values_null", codegen->ptr_type())); - LLVMContext& context = codegen->context(); + llvm::LLVMContext& context = codegen->context(); LlvmBuilder builder(context); - Value* args[4]; + llvm::Value* args[4]; *fn = prototype.GeneratePrototype(&builder, args); - Value* this_ptr = args[0]; - Value* row = args[1]; - Value* expr_values = args[2]; - Value* expr_values_null = args[3]; + llvm::Value* this_ptr = args[0]; + llvm::Value* row = args[1]; + llvm::Value* expr_values = args[2]; + llvm::Value* expr_values_null = args[3]; // eval_vector = build_expr_evals_.data() - Value* eval_vector = codegen->CodegenCallFunction(&builder, + llvm::Value* eval_vector = codegen->CodegenCallFunction(&builder, IRFunction::HASH_TABLE_GET_BUILD_EXPR_EVALUATORS, this_ptr, "eval_vector"); - BasicBlock* false_block = BasicBlock::Create(context, "false_block", *fn); + llvm::BasicBlock* false_block = llvm::BasicBlock::Create(context, "false_block", *fn); for (int i = 0; i < build_exprs_.size(); ++i) { - BasicBlock* null_block = BasicBlock::Create(context, "null", *fn); - BasicBlock* not_null_block = BasicBlock::Create(context, "not_null", *fn); - BasicBlock* continue_block = BasicBlock::Create(context, "continue", *fn); + llvm::BasicBlock* null_block = llvm::BasicBlock::Create(context, "null", *fn); + llvm::BasicBlock* not_null_block = llvm::BasicBlock::Create(context, "not_null", *fn); + llvm::BasicBlock* continue_block = llvm::BasicBlock::Create(context, "continue", *fn); // call GetValue on build_exprs[i] - Function* expr_fn; + llvm::Function* expr_fn; Status status = build_exprs_[i]->GetCodegendComputeFn(codegen, &expr_fn); if (!status.ok()) { (*fn)->eraseFromParent(); // deletes function @@ -1139,32 +1134,31 @@ Status HashTableCtx::CodegenEquals(LlvmCodeGen* codegen, bool force_null_equalit } // Load ScalarExprEvaluator*: eval = eval_vector[i]; - Value* eval_arg = - codegen->CodegenArrayAt(&builder, eval_vector, i, "eval"); + llvm::Value* eval_arg = codegen->CodegenArrayAt(&builder, eval_vector, i, "eval"); // Evaluate the expression. CodegenAnyVal result = CodegenAnyVal::CreateCallWrapped(codegen, &builder, build_exprs_[i]->type(), expr_fn, {eval_arg, row}, "result"); - Value* is_null = result.GetIsNull(); + llvm::Value* is_null = result.GetIsNull(); // Determine if row is null (i.e. expr_values_null[i] == true). In // the case where the hash table does not store nulls, this is always false. - Value* row_is_null = codegen->false_value(); + llvm::Value* row_is_null = codegen->false_value(); // We consider null values equal if we are comparing build rows or if the join // predicate is <=> if (force_null_equality || finds_nulls_[i]) { - Value* llvm_null_byte_loc = builder.CreateInBoundsGEP( + llvm::Value* llvm_null_byte_loc = builder.CreateInBoundsGEP( NULL, expr_values_null, codegen->GetIntConstant(TYPE_INT, i), "null_byte_loc"); - Value* null_byte = builder.CreateLoad(llvm_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)); } // Get llvm value for row_val from 'expr_values' int offset = expr_values_cache_.expr_values_offsets(i); - Value* loc = builder.CreateInBoundsGEP( + llvm::Value* loc = builder.CreateInBoundsGEP( NULL, expr_values, codegen->GetIntConstant(TYPE_INT, offset), "loc"); - Value* row_val = builder.CreatePointerCast( + llvm::Value* row_val = builder.CreatePointerCast( loc, codegen->GetPtrType(build_exprs_[i]->type()), "row_val"); // Branch for GetValue() returning NULL @@ -1177,13 +1171,13 @@ Status HashTableCtx::CodegenEquals(LlvmCodeGen* codegen, bool force_null_equalit // Not-null block builder.SetInsertPoint(not_null_block); if (stores_nulls_) { - BasicBlock* cmp_block = BasicBlock::Create(context, "cmp", *fn); + llvm::BasicBlock* cmp_block = llvm::BasicBlock::Create(context, "cmp", *fn); // First need to compare that row expr[i] is not null builder.CreateCondBr(row_is_null, false_block, cmp_block); builder.SetInsertPoint(cmp_block); } // Check result == row_val - Value* is_equal = result.EqToNativePtr(row_val); + llvm::Value* is_equal = result.EqToNativePtr(row_val); builder.CreateCondBr(is_equal, continue_block, false_block); builder.SetInsertPoint(continue_block); @@ -1206,9 +1200,8 @@ Status HashTableCtx::CodegenEquals(LlvmCodeGen* codegen, bool force_null_equalit } Status HashTableCtx::ReplaceHashTableConstants(LlvmCodeGen* codegen, - bool stores_duplicates, int num_build_tuples, Function* fn, + bool stores_duplicates, int num_build_tuples, llvm::Function* fn, HashTableReplacedConstants* replacement_counts) { - replacement_counts->stores_nulls = codegen->ReplaceCallSitesWithBoolConst( fn, stores_nulls(), "stores_nulls"); replacement_counts->finds_some_nulls = codegen->ReplaceCallSitesWithBoolConst(
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/e98d2f1c/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 dea51a9..3ec1f09 100644 --- a/be/src/exec/hdfs-avro-scanner.cc +++ b/be/src/exec/hdfs-avro-scanner.cc @@ -38,7 +38,6 @@ // Note: the Avro C++ library uses exceptions for error handling. Any Avro // function that may throw an exception must be placed in a try/catch block. using namespace impala; -using namespace llvm; using namespace strings; const char* HdfsAvroScanner::LLVM_CLASS_NAME = "class.impala::HdfsAvroScanner"; @@ -80,7 +79,7 @@ Status HdfsAvroScanner::Open(ScannerContext* context) { } Status HdfsAvroScanner::Codegen(HdfsScanNodeBase* node, - const vector<ScalarExpr*>& conjuncts, Function** decode_avro_data_fn) { + const vector<ScalarExpr*>& conjuncts, llvm::Function** decode_avro_data_fn) { *decode_avro_data_fn = nullptr; DCHECK(node->runtime_state()->ShouldCodegen()); LlvmCodeGen* codegen = node->runtime_state()->codegen(); @@ -755,26 +754,28 @@ void HdfsAvroScanner::SetStatusValueOverflow(TErrorCode::type error_code, int64_ // bail_out: ; preds = %entry // ret i1 false // } -Status HdfsAvroScanner::CodegenMaterializeTuple( - const HdfsScanNodeBase* node, LlvmCodeGen* codegen, Function** materialize_tuple_fn) { - LLVMContext& context = codegen->context(); +Status HdfsAvroScanner::CodegenMaterializeTuple(const HdfsScanNodeBase* node, + LlvmCodeGen* codegen, llvm::Function** materialize_tuple_fn) { + llvm::LLVMContext& context = codegen->context(); LlvmBuilder builder(context); - Type* this_type = codegen->GetType(HdfsAvroScanner::LLVM_CLASS_NAME); + llvm::Type* this_type = codegen->GetType(HdfsAvroScanner::LLVM_CLASS_NAME); DCHECK(this_type != nullptr); - PointerType* this_ptr_type = PointerType::get(this_type, 0); + llvm::PointerType* this_ptr_type = llvm::PointerType::get(this_type, 0); TupleDescriptor* tuple_desc = const_cast<TupleDescriptor*>(node->tuple_desc()); - StructType* tuple_type = tuple_desc->GetLlvmStruct(codegen); + llvm::StructType* tuple_type = tuple_desc->GetLlvmStruct(codegen); if (tuple_type == nullptr) return Status("Could not generate tuple struct."); - Type* tuple_ptr_type = PointerType::get(tuple_type, 0); + llvm::Type* tuple_ptr_type = llvm::PointerType::get(tuple_type, 0); - Type* tuple_opaque_type = codegen->GetType(Tuple::LLVM_CLASS_NAME); - PointerType* tuple_opaque_ptr_type = PointerType::get(tuple_opaque_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); - Type* data_ptr_type = PointerType::get(codegen->ptr_type(), 0); // char** - Type* mempool_type = PointerType::get(codegen->GetType(MemPool::LLVM_CLASS_NAME), 0); - Type* schema_element_type = codegen->GetPtrType(AvroSchemaElement::LLVM_CLASS_NAME); + 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); // Schema can be null if metadata is stale. See test in // queries/QueryTest/avro-schema-changes.test. @@ -788,7 +789,7 @@ Status HdfsAvroScanner::CodegenMaterializeTuple( // too many functions, it takes LLVM longer to optimize. If the functions // are too long, it takes LLVM longer too. int step_size = 200; - std::vector<Function*> helper_functions; + std::vector<llvm::Function*> helper_functions; // prototype re-used several times by amending with SetName() LlvmCodeGen::FnPrototype prototype(codegen, "", codegen->boolean_type()); @@ -802,22 +803,22 @@ Status HdfsAvroScanner::CodegenMaterializeTuple( // Generate helper functions for every step_size columns. for (int i = 0; i < num_children; i += step_size) { prototype.SetName("MaterializeTuple-helper" + std::to_string(i)); - Value* args[6]; - Function* helper_fn = prototype.GeneratePrototype(&builder, args); + llvm::Value* args[6]; + llvm::Function* helper_fn = prototype.GeneratePrototype(&builder, args); - Value* this_val = args[0]; - // Value* record_schema_val = args[1]; // don't need this - Value* pool_val = args[2]; - Value* data_val = args[3]; - Value* data_end_val = args[4]; - Value* opaque_tuple_val = args[5]; + llvm::Value* this_val = args[0]; + // llvm::Value* record_schema_val = args[1]; // don't need this + llvm::Value* pool_val = args[2]; + llvm::Value* data_val = args[3]; + llvm::Value* data_end_val = args[4]; + llvm::Value* opaque_tuple_val = args[5]; - Value* tuple_val = builder.CreateBitCast( - opaque_tuple_val, tuple_ptr_type, "tuple_ptr"); + llvm::Value* tuple_val = + builder.CreateBitCast(opaque_tuple_val, tuple_ptr_type, "tuple_ptr"); // Create a bail out block to handle decoding failures. - BasicBlock* bail_out_block = BasicBlock::Create( - context, "bail_out", helper_fn, nullptr); + llvm::BasicBlock* bail_out_block = + llvm::BasicBlock::Create(context, "bail_out", helper_fn, nullptr); Status status = CodegenReadRecord( SchemaPath(), node->avro_schema(), i, std::min(num_children, i + step_size), @@ -844,27 +845,28 @@ Status HdfsAvroScanner::CodegenMaterializeTuple( // Actual MaterializeTuple. Call all the helper functions. { - Value* args[6]; + llvm::Value* args[6]; prototype.SetName("MaterializeTuple"); - Function* fn = prototype.GeneratePrototype(&builder, args); + llvm::Function* fn = prototype.GeneratePrototype(&builder, args); // These are the blocks that we go to after the helper runs. - std::vector<BasicBlock*> helper_blocks; + std::vector<llvm::BasicBlock*> helper_blocks; for (int i = 0; i < helper_functions.size(); ++i) { - BasicBlock* helper_block = BasicBlock::Create( - context, "helper_" + std::to_string(i), fn, nullptr); + llvm::BasicBlock* helper_block = + llvm::BasicBlock::Create(context, "helper_" + std::to_string(i), fn, nullptr); helper_blocks.push_back(helper_block); } // Block for failures - BasicBlock* bail_out_block = BasicBlock::Create(context, "bail_out", fn, nullptr); + llvm::BasicBlock* bail_out_block = + llvm::BasicBlock::Create(context, "bail_out", fn, nullptr); // Call the helpers. for (int i = 0; i < helper_functions.size(); ++i) { if (i != 0) builder.SetInsertPoint(helper_blocks[i - 1]); - Function* fnHelper = helper_functions[i]; - Value* helper_ok = builder.CreateCall( - fnHelper, args, "helper_" + std::to_string(i)); + llvm::Function* fnHelper = helper_functions[i]; + llvm::Value* helper_ok = + builder.CreateCall(fnHelper, args, "helper_" + std::to_string(i)); builder.CreateCondBr(helper_ok, helper_blocks[i], bail_out_block); } @@ -887,19 +889,20 @@ Status HdfsAvroScanner::CodegenMaterializeTuple( Status HdfsAvroScanner::CodegenReadRecord(const SchemaPath& path, const AvroSchemaElement& record, int child_start, int child_end, - const HdfsScanNodeBase* node, LlvmCodeGen* codegen, void* void_builder, Function* fn, - BasicBlock* insert_before, BasicBlock* bail_out, Value* this_val, Value* pool_val, - Value* tuple_val, Value* data_val, Value* data_end_val) { + const HdfsScanNodeBase* node, LlvmCodeGen* codegen, void* void_builder, + llvm::Function* fn, llvm::BasicBlock* insert_before, llvm::BasicBlock* bail_out, + llvm::Value* this_val, llvm::Value* pool_val, llvm::Value* tuple_val, + llvm::Value* data_val, llvm::Value* data_end_val) { RETURN_IF_ERROR(CheckSchema(record)); DCHECK_EQ(record.schema->type, AVRO_RECORD); - LLVMContext& context = codegen->context(); + llvm::LLVMContext& context = codegen->context(); LlvmBuilder* builder = reinterpret_cast<LlvmBuilder*>(void_builder); // Codegen logic for parsing each field and, if necessary, populating a slot with the // result. // Used to store result of ReadUnionType() call - Value* is_null_ptr = nullptr; + llvm::Value* is_null_ptr = nullptr; for (int i = child_start; i < child_end; ++i) { const AvroSchemaElement* field = &record.children[i]; int col_idx = i; @@ -913,38 +916,41 @@ Status HdfsAvroScanner::CodegenReadRecord(const SchemaPath& path, nullptr : node->materialized_slots()[slot_idx]; // Block that calls appropriate Read<Type> function - BasicBlock* read_field_block = - BasicBlock::Create(context, "read_field", fn, insert_before); + llvm::BasicBlock* read_field_block = + llvm::BasicBlock::Create(context, "read_field", fn, insert_before); // Block that handles a nullptr value. We fill this in below if the field is nullable, // otherwise we leave this block nullptr. - BasicBlock* null_block = nullptr; + llvm::BasicBlock* null_block = nullptr; // This is where we should end up after we're finished processing this field. Used to // put the builder in the right place for the next field. - BasicBlock* end_field_block = - BasicBlock::Create(context, "end_field", fn, insert_before); + llvm::BasicBlock* end_field_block = + llvm::BasicBlock::Create(context, "end_field", fn, insert_before); if (field->nullable()) { // Field could be null. Create conditional branch based on ReadUnionType result. - Function* read_union_fn = codegen->GetFunction(IRFunction::READ_UNION_TYPE, false); - Value* null_union_pos_val = + 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); if (is_null_ptr == nullptr) { is_null_ptr = codegen->CreateEntryBlockAlloca(*builder, codegen->boolean_type(), "is_null_ptr"); } - Value* is_null_ptr_cast = builder->CreateBitCast(is_null_ptr, codegen->ptr_type()); - Value* read_union_ok = builder->CreateCall(read_union_fn, - ArrayRef<Value*>({this_val, null_union_pos_val, data_val, data_end_val, - is_null_ptr_cast}), "read_union_ok"); - BasicBlock* read_union_ok_block = BasicBlock::Create(context, "read_union_ok", fn, - read_field_block); + llvm::Value* is_null_ptr_cast = + builder->CreateBitCast(is_null_ptr, codegen->ptr_type()); + llvm::Value* read_union_ok = builder->CreateCall(read_union_fn, + llvm::ArrayRef<llvm::Value*>( + {this_val, null_union_pos_val, data_val, data_end_val, is_null_ptr_cast}), + "read_union_ok"); + llvm::BasicBlock* read_union_ok_block = + llvm::BasicBlock::Create(context, "read_union_ok", fn, read_field_block); builder->CreateCondBr(read_union_ok, read_union_ok_block, bail_out); builder->SetInsertPoint(read_union_ok_block); - null_block = BasicBlock::Create(context, "null_field", fn, end_field_block); - Value* is_null = builder->CreateLoad(is_null_ptr, "is_null"); + null_block = llvm::BasicBlock::Create(context, "null_field", fn, end_field_block); + llvm::Value* is_null = builder->CreateLoad(is_null_ptr, "is_null"); builder->CreateCondBr(is_null, null_block, read_field_block); // Write null field IR @@ -962,9 +968,9 @@ Status HdfsAvroScanner::CodegenReadRecord(const SchemaPath& path, // Write read_field_block IR builder->SetInsertPoint(read_field_block); - Value *ret_val = nullptr; + llvm::Value* ret_val = nullptr; if (field->schema->type == AVRO_RECORD) { - BasicBlock* insert_before_block = + llvm::BasicBlock* insert_before_block = (null_block != nullptr) ? null_block : end_field_block; RETURN_IF_ERROR(CodegenReadRecord(new_path, *field, 0, field->children.size(), node, codegen, builder, fn, @@ -983,11 +989,11 @@ Status HdfsAvroScanner::CodegenReadRecord(const SchemaPath& path, } Status HdfsAvroScanner::CodegenReadScalar(const AvroSchemaElement& element, - SlotDescriptor* slot_desc, LlvmCodeGen* codegen, void* void_builder, Value* this_val, - Value* pool_val, Value* tuple_val, Value* data_val, Value* data_end_val, - Value** ret_val) { + SlotDescriptor* slot_desc, LlvmCodeGen* codegen, void* void_builder, + llvm::Value* this_val, llvm::Value* pool_val, llvm::Value* tuple_val, + llvm::Value* data_val, llvm::Value* data_end_val, llvm::Value** ret_val) { LlvmBuilder* builder = reinterpret_cast<LlvmBuilder*>(void_builder); - Function* read_field_fn; + llvm::Function* read_field_fn; switch (element.schema->type) { case AVRO_BOOLEAN: read_field_fn = codegen->GetFunction(IRFunction::READ_AVRO_BOOLEAN, false); @@ -1024,9 +1030,9 @@ Status HdfsAvroScanner::CodegenReadScalar(const AvroSchemaElement& element, } // Call appropriate ReadAvro<Type> function - Value* write_slot_val = builder->getFalse(); - Value* slot_type_val = builder->getInt32(0); - Value* opaque_slot_val = codegen->null_ptr_value(); + llvm::Value* write_slot_val = builder->getFalse(); + llvm::Value* slot_type_val = builder->getInt32(0); + llvm::Value* opaque_slot_val = codegen->null_ptr_value(); if (slot_desc != nullptr) { // Field corresponds to a materialized column, fill in relevant arguments write_slot_val = builder->getTrue(); @@ -1036,8 +1042,8 @@ Status HdfsAvroScanner::CodegenReadScalar(const AvroSchemaElement& element, } else { slot_type_val = builder->getInt32(slot_desc->type().type); } - Value* slot_val = builder->CreateStructGEP(nullptr, tuple_val, slot_desc->llvm_field_idx(), - "slot"); + llvm::Value* slot_val = + builder->CreateStructGEP(nullptr, tuple_val, slot_desc->llvm_field_idx(), "slot"); opaque_slot_val = builder->CreateBitCast(slot_val, codegen->ptr_type(), "opaque_slot"); } @@ -1046,13 +1052,13 @@ Status HdfsAvroScanner::CodegenReadScalar(const AvroSchemaElement& element, if (slot_desc != nullptr && (slot_desc->type().type == TYPE_VARCHAR || slot_desc->type().type == TYPE_CHAR)) { // Need to pass an extra argument (the length) to the codegen function. - Value* fixed_len = builder->getInt32(slot_desc->type().len); - Value* read_field_args[] = {this_val, slot_type_val, fixed_len, data_val, - data_end_val, write_slot_val, opaque_slot_val, pool_val}; + llvm::Value* fixed_len = builder->getInt32(slot_desc->type().len); + llvm::Value* read_field_args[] = {this_val, slot_type_val, fixed_len, data_val, + data_end_val, write_slot_val, opaque_slot_val, pool_val}; *ret_val = builder->CreateCall(read_field_fn, read_field_args, "success"); } else { - Value* read_field_args[] = {this_val, slot_type_val, data_val, data_end_val, - write_slot_val, opaque_slot_val, pool_val}; + llvm::Value* read_field_args[] = {this_val, slot_type_val, data_val, data_end_val, + write_slot_val, opaque_slot_val, pool_val}; *ret_val = builder->CreateCall(read_field_fn, read_field_args, "success"); } return Status::OK(); @@ -1060,16 +1066,16 @@ Status HdfsAvroScanner::CodegenReadScalar(const AvroSchemaElement& element, Status HdfsAvroScanner::CodegenDecodeAvroData(const HdfsScanNodeBase* node, LlvmCodeGen* codegen, const vector<ScalarExpr*>& conjuncts, - Function** decode_avro_data_fn) { + llvm::Function** decode_avro_data_fn) { SCOPED_TIMER(codegen->codegen_timer()); - Function* materialize_tuple_fn; + llvm::Function* materialize_tuple_fn; RETURN_IF_ERROR(CodegenMaterializeTuple(node, codegen, &materialize_tuple_fn)); DCHECK(materialize_tuple_fn != nullptr); - Function* fn = codegen->GetFunction(IRFunction::DECODE_AVRO_DATA, true); + llvm::Function* fn = codegen->GetFunction(IRFunction::DECODE_AVRO_DATA, true); - Function* init_tuple_fn; + llvm::Function* init_tuple_fn; RETURN_IF_ERROR(CodegenInitTuple(node, codegen, &init_tuple_fn)); int replaced = codegen->ReplaceCallSites(fn, init_tuple_fn, "InitTuple"); DCHECK_EQ(replaced, 1); @@ -1077,13 +1083,13 @@ Status HdfsAvroScanner::CodegenDecodeAvroData(const HdfsScanNodeBase* node, replaced = codegen->ReplaceCallSites(fn, materialize_tuple_fn, "MaterializeTuple"); DCHECK_EQ(replaced, 1); - Function* eval_conjuncts_fn; + llvm::Function* eval_conjuncts_fn; RETURN_IF_ERROR(ExecNode::CodegenEvalConjuncts(codegen, conjuncts, &eval_conjuncts_fn)); replaced = codegen->ReplaceCallSites(fn, eval_conjuncts_fn, "EvalConjuncts"); DCHECK_EQ(replaced, 1); - Function* copy_strings_fn; + llvm::Function* copy_strings_fn; RETURN_IF_ERROR(Tuple::CodegenCopyStrings( codegen, *node->tuple_desc(), ©_strings_fn)); replaced = codegen->ReplaceCallSites(fn, copy_strings_fn, "CopyStrings"); http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/e98d2f1c/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 2897287..7fae959 100644 --- a/be/src/exec/hdfs-parquet-scanner.cc +++ b/be/src/exec/hdfs-parquet-scanner.cc @@ -33,10 +33,8 @@ #include "common/names.h" -using llvm::Function; using std::move; using namespace impala; -using namespace llvm; DEFINE_double(parquet_min_filter_reject_ratio, 0.1, "(Advanced) If the percentage of " "rows rejected by a runtime filter drops below this value, the filter is disabled."); @@ -1064,24 +1062,24 @@ int HdfsParquetScanner::TransferScratchTuples(RowBatch* dst_batch) { } Status HdfsParquetScanner::Codegen(HdfsScanNodeBase* node, - const vector<ScalarExpr*>& conjuncts, Function** process_scratch_batch_fn) { + const vector<ScalarExpr*>& conjuncts, llvm::Function** process_scratch_batch_fn) { DCHECK(node->runtime_state()->ShouldCodegen()); *process_scratch_batch_fn = NULL; LlvmCodeGen* codegen = node->runtime_state()->codegen(); DCHECK(codegen != NULL); SCOPED_TIMER(codegen->codegen_timer()); - Function* fn = codegen->GetFunction(IRFunction::PROCESS_SCRATCH_BATCH, true); + llvm::Function* fn = codegen->GetFunction(IRFunction::PROCESS_SCRATCH_BATCH, true); DCHECK(fn != NULL); - Function* eval_conjuncts_fn; + llvm::Function* eval_conjuncts_fn; RETURN_IF_ERROR(ExecNode::CodegenEvalConjuncts(codegen, conjuncts, &eval_conjuncts_fn)); DCHECK(eval_conjuncts_fn != NULL); int replaced = codegen->ReplaceCallSites(fn, eval_conjuncts_fn, "EvalConjuncts"); DCHECK_EQ(replaced, 1); - Function* eval_runtime_filters_fn; + llvm::Function* eval_runtime_filters_fn; RETURN_IF_ERROR(CodegenEvalRuntimeFilters( codegen, node->filter_exprs(), &eval_runtime_filters_fn)); DCHECK(eval_runtime_filters_fn != NULL); @@ -1110,7 +1108,8 @@ bool HdfsParquetScanner::EvalRuntimeFilters(TupleRow* row) { // %"class.impala::TupleRow"* %row) #34 { // entry: // %0 = call i1 @_ZN6impala18HdfsParquetScanner17EvalRuntimeFilterEiPNS_8TupleRowE.2( -// %"class.impala::HdfsParquetScanner"* %this, i32 0, %"class.impala::TupleRow"* %row) +// %"class.impala::HdfsParquetScanner"* %this, i32 0, %"class.impala::TupleRow"* +// %row) // br i1 %0, label %continue, label %bail_out // // bail_out: ; preds = %entry @@ -1122,41 +1121,41 @@ bool HdfsParquetScanner::EvalRuntimeFilters(TupleRow* row) { // // EvalRuntimeFilter() is the same as the cross-compiled version except EvalOneFilter() // is replaced with the one generated by CodegenEvalOneFilter(). -Status HdfsParquetScanner::CodegenEvalRuntimeFilters(LlvmCodeGen* codegen, - const vector<ScalarExpr*>& filter_exprs, Function** fn) { - LLVMContext& context = codegen->context(); +Status HdfsParquetScanner::CodegenEvalRuntimeFilters( + LlvmCodeGen* codegen, const vector<ScalarExpr*>& filter_exprs, llvm::Function** fn) { + llvm::LLVMContext& context = codegen->context(); LlvmBuilder builder(context); *fn = nullptr; - Type* this_type = codegen->GetPtrType(HdfsParquetScanner::LLVM_CLASS_NAME); - PointerType* tuple_row_ptr_type = codegen->GetPtrType(TupleRow::LLVM_CLASS_NAME); + llvm::Type* this_type = codegen->GetPtrType(HdfsParquetScanner::LLVM_CLASS_NAME); + llvm::PointerType* tuple_row_ptr_type = codegen->GetPtrType(TupleRow::LLVM_CLASS_NAME); LlvmCodeGen::FnPrototype prototype(codegen, "EvalRuntimeFilters", codegen->GetType(TYPE_BOOLEAN)); prototype.AddArgument(LlvmCodeGen::NamedVariable("this", this_type)); prototype.AddArgument(LlvmCodeGen::NamedVariable("row", tuple_row_ptr_type)); - Value* args[2]; - Function* eval_runtime_filters_fn = prototype.GeneratePrototype(&builder, args); - Value* this_arg = args[0]; - Value* row_arg = args[1]; + llvm::Value* args[2]; + llvm::Function* eval_runtime_filters_fn = prototype.GeneratePrototype(&builder, args); + llvm::Value* this_arg = args[0]; + llvm::Value* row_arg = args[1]; int num_filters = filter_exprs.size(); if (num_filters == 0) { builder.CreateRet(codegen->true_value()); } else { // row_rejected_block: jump target for when a filter is evaluated to false. - BasicBlock* row_rejected_block = - BasicBlock::Create(context, "row_rejected", eval_runtime_filters_fn); + llvm::BasicBlock* row_rejected_block = + llvm::BasicBlock::Create(context, "row_rejected", eval_runtime_filters_fn); DCHECK_GT(num_filters, 0); for (int i = 0; i < num_filters; ++i) { - Function* eval_runtime_filter_fn = + llvm::Function* eval_runtime_filter_fn = codegen->GetFunction(IRFunction::PARQUET_SCANNER_EVAL_RUNTIME_FILTER, true); DCHECK(eval_runtime_filter_fn != nullptr); // Codegen function for inlining filter's expression evaluation and constant fold // the type of the expression into the hashing function to avoid branches. - Function* eval_one_filter_fn; + llvm::Function* eval_one_filter_fn; DCHECK(filter_exprs[i] != nullptr); RETURN_IF_ERROR(FilterContext::CodegenEval(codegen, filter_exprs[i], &eval_one_filter_fn)); @@ -1166,12 +1165,12 @@ Status HdfsParquetScanner::CodegenEvalRuntimeFilters(LlvmCodeGen* codegen, "FilterContext4Eval"); DCHECK_EQ(replaced, 1); - Value* idx = codegen->GetIntConstant(TYPE_INT, i); - Value* passed_filter = builder.CreateCall( - eval_runtime_filter_fn, ArrayRef<Value*>({this_arg, idx, row_arg})); + llvm::Value* idx = codegen->GetIntConstant(TYPE_INT, i); + llvm::Value* passed_filter = builder.CreateCall( + eval_runtime_filter_fn, llvm::ArrayRef<llvm::Value*>({this_arg, idx, row_arg})); - BasicBlock* continue_block = - BasicBlock::Create(context, "continue", eval_runtime_filters_fn); + llvm::BasicBlock* continue_block = + llvm::BasicBlock::Create(context, "continue", eval_runtime_filters_fn); builder.CreateCondBr(passed_filter, continue_block, row_rejected_block); builder.SetInsertPoint(continue_block); } http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/e98d2f1c/be/src/exec/hdfs-scan-node-base.cc ---------------------------------------------------------------------- diff --git a/be/src/exec/hdfs-scan-node-base.cc b/be/src/exec/hdfs-scan-node-base.cc index 49c66b8..af01552 100644 --- a/be/src/exec/hdfs-scan-node-base.cc +++ b/be/src/exec/hdfs-scan-node-base.cc @@ -48,7 +48,6 @@ DECLARE_bool(skip_file_runtime_filtering); namespace filesystem = boost::filesystem; using namespace impala; -using namespace llvm; using namespace strings; const string HdfsScanNodeBase::HDFS_SPLIT_STATS_DESC = @@ -270,7 +269,7 @@ void HdfsScanNodeBase::Codegen(RuntimeState* state) { // Create reusable codegen'd functions for each file type type needed // TODO: do this for conjuncts_map_ - Function* fn; + llvm::Function* fn; Status status; switch (format) { case THdfsFileFormat::TEXT: http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/e98d2f1c/be/src/exec/hdfs-scanner.cc ---------------------------------------------------------------------- diff --git a/be/src/exec/hdfs-scanner.cc b/be/src/exec/hdfs-scanner.cc index 959aa91..0dbfc5f 100644 --- a/be/src/exec/hdfs-scanner.cc +++ b/be/src/exec/hdfs-scanner.cc @@ -35,7 +35,6 @@ #include "common/names.h" using namespace impala; -using namespace llvm; using namespace strings; const char* FieldLocation::LLVM_CLASS_NAME = "struct.impala::FieldLocation"; @@ -301,16 +300,16 @@ bool HdfsScanner::WriteCompleteTuple(MemPool* pool, FieldLocation* fields, // } Status HdfsScanner::CodegenWriteCompleteTuple(const HdfsScanNodeBase* node, LlvmCodeGen* codegen, const vector<ScalarExpr*>& conjuncts, - Function** write_complete_tuple_fn) { + llvm::Function** write_complete_tuple_fn) { *write_complete_tuple_fn = NULL; SCOPED_TIMER(codegen->codegen_timer()); RuntimeState* state = node->runtime_state(); // Cast away const-ness. The codegen only sets the cached typed llvm struct. TupleDescriptor* tuple_desc = const_cast<TupleDescriptor*>(node->tuple_desc()); - vector<Function*> slot_fns; + vector<llvm::Function*> slot_fns; for (int i = 0; i < node->materialized_slots().size(); ++i) { - Function *fn = nullptr; + llvm::Function* fn = nullptr; SlotDescriptor* slot_desc = node->materialized_slots()[i]; RETURN_IF_ERROR(TextConverter::CodegenWriteSlot(codegen, tuple_desc, slot_desc, &fn, node->hdfs_table()->null_column_value().data(), @@ -325,30 +324,31 @@ Status HdfsScanner::CodegenWriteCompleteTuple(const HdfsScanNodeBase* node, node->ComputeSlotMaterializationOrder(&materialize_order); // Get types to construct matching function signature to WriteCompleteTuple - PointerType* uint8_ptr_type = PointerType::get(codegen->GetType(TYPE_TINYINT), 0); + llvm::PointerType* uint8_ptr_type = + llvm::PointerType::get(codegen->GetType(TYPE_TINYINT), 0); - StructType* field_loc_type = reinterpret_cast<StructType*>( + llvm::StructType* field_loc_type = reinterpret_cast<llvm::StructType*>( codegen->GetType(FieldLocation::LLVM_CLASS_NAME)); - Type* tuple_row_type = codegen->GetType(TupleRow::LLVM_CLASS_NAME); - Type* tuple_opaque_type = codegen->GetType(Tuple::LLVM_CLASS_NAME); - Type* mem_pool_type = codegen->GetType(MemPool::LLVM_CLASS_NAME); - Type* hdfs_scanner_type = codegen->GetType(HdfsScanner::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); - PointerType* field_loc_ptr_type = PointerType::get(field_loc_type, 0); - PointerType* tuple_opaque_ptr_type = PointerType::get(tuple_opaque_type, 0); - PointerType* tuple_row_ptr_type = PointerType::get(tuple_row_type, 0); - PointerType* mem_pool_ptr_type = PointerType::get(mem_pool_type, 0); - PointerType* hdfs_scanner_ptr_type = PointerType::get(hdfs_scanner_type, 0); + 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); // Generate the typed llvm struct for the output tuple - StructType* tuple_type = tuple_desc->GetLlvmStruct(codegen); + llvm::StructType* tuple_type = tuple_desc->GetLlvmStruct(codegen); if (tuple_type == NULL) return Status("Could not generate tuple struct."); - PointerType* tuple_ptr_type = PointerType::get(tuple_type, 0); + llvm::PointerType* tuple_ptr_type = llvm::PointerType::get(tuple_type, 0); // Initialize the function prototype. This needs to match // HdfsScanner::WriteCompleteTuple's signature identically. @@ -363,36 +363,38 @@ Status HdfsScanner::CodegenWriteCompleteTuple(const HdfsScanNodeBase* node, prototype.AddArgument(LlvmCodeGen::NamedVariable("error_fields", uint8_ptr_type)); prototype.AddArgument(LlvmCodeGen::NamedVariable("error_in_row", uint8_ptr_type)); - LLVMContext& context = codegen->context(); + llvm::LLVMContext& context = codegen->context(); LlvmBuilder builder(context); - Value* args[8]; - Function* fn = prototype.GeneratePrototype(&builder, &args[0]); + llvm::Value* args[8]; + llvm::Function* fn = prototype.GeneratePrototype(&builder, &args[0]); - BasicBlock* parse_block = BasicBlock::Create(context, "parse", fn); - BasicBlock* eval_fail_block = BasicBlock::Create(context, "eval_fail", fn); + llvm::BasicBlock* parse_block = llvm::BasicBlock::Create(context, "parse", fn); + llvm::BasicBlock* eval_fail_block = llvm::BasicBlock::Create(context, "eval_fail", fn); // Extract the input args - Value* this_arg = args[0]; - Value* fields_arg = args[2]; - Value* opaque_tuple_arg = args[3]; - Value* tuple_arg = builder.CreateBitCast(opaque_tuple_arg, tuple_ptr_type, "tuple_ptr"); - Value* tuple_row_arg = args[4]; - Value* opaque_template_arg = args[5]; - Value* errors_arg = args[6]; - Value* error_in_row_arg = args[7]; + llvm::Value* this_arg = args[0]; + llvm::Value* fields_arg = args[2]; + llvm::Value* opaque_tuple_arg = args[3]; + llvm::Value* tuple_arg = + builder.CreateBitCast(opaque_tuple_arg, tuple_ptr_type, "tuple_ptr"); + llvm::Value* tuple_row_arg = args[4]; + llvm::Value* opaque_template_arg = args[5]; + llvm::Value* errors_arg = args[6]; + llvm::Value* error_in_row_arg = args[7]; // Codegen for function body - Value* error_in_row = codegen->false_value(); + llvm::Value* error_in_row = codegen->false_value(); - Function* init_tuple_fn; + llvm::Function* init_tuple_fn; RETURN_IF_ERROR(CodegenInitTuple(node, codegen, &init_tuple_fn)); builder.CreateCall(init_tuple_fn, {this_arg, opaque_template_arg, opaque_tuple_arg}); // Put tuple in tuple_row - Value* tuple_row_typed = - builder.CreateBitCast(tuple_row_arg, PointerType::get(tuple_ptr_type, 0)); - Value* tuple_row_idxs[] = {codegen->GetIntConstant(TYPE_INT, node->tuple_idx())}; - Value* tuple_in_row_addr = builder.CreateInBoundsGEP(tuple_row_typed, tuple_row_idxs); + 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_in_row_addr = + builder.CreateInBoundsGEP(tuple_row_typed, tuple_row_idxs); builder.CreateStore(tuple_arg, tuple_in_row_addr); builder.CreateBr(parse_block); @@ -418,23 +420,24 @@ Status HdfsScanner::CodegenWriteCompleteTuple(const HdfsScanNodeBase* node, // materialized by prior iterations through the outer loop // Extract ptr/len from fields - Value* data_idxs[] = { - codegen->GetIntConstant(TYPE_INT, slot_idx), - codegen->GetIntConstant(TYPE_INT, 0), + llvm::Value* data_idxs[] = { + codegen->GetIntConstant(TYPE_INT, slot_idx), + codegen->GetIntConstant(TYPE_INT, 0), }; - Value* len_idxs[] = { - codegen->GetIntConstant(TYPE_INT, slot_idx), - codegen->GetIntConstant(TYPE_INT, 1), + llvm::Value* len_idxs[] = { + codegen->GetIntConstant(TYPE_INT, slot_idx), + codegen->GetIntConstant(TYPE_INT, 1), }; - Value* error_idxs[] = { + llvm::Value* error_idxs[] = { codegen->GetIntConstant(TYPE_INT, slot_idx), }; - Value* data_ptr = builder.CreateInBoundsGEP(fields_arg, data_idxs, "data_ptr"); - Value* len_ptr = builder.CreateInBoundsGEP(fields_arg, len_idxs, "len_ptr"); - Value* error_ptr = + llvm::Value* data_ptr = + builder.CreateInBoundsGEP(fields_arg, data_idxs, "data_ptr"); + llvm::Value* len_ptr = builder.CreateInBoundsGEP(fields_arg, len_idxs, "len_ptr"); + llvm::Value* error_ptr = builder.CreateInBoundsGEP(errors_arg, error_idxs, "slot_error_ptr"); - Value* data = builder.CreateLoad(data_ptr, "data"); - Value* len = builder.CreateLoad(len_ptr, "len"); + llvm::Value* data = builder.CreateLoad(data_ptr, "data"); + llvm::Value* len = builder.CreateLoad(len_ptr, "len"); // Convert length to positive if it is negative. Negative lengths are assigned to // slots that contain escape characters. @@ -442,20 +445,19 @@ Status HdfsScanner::CodegenWriteCompleteTuple(const HdfsScanNodeBase* node, // However, if it is modified to handle that case, we need to detect it here and // send a 'need_escape' bool to CodegenWriteSlot(), since we are making the length // positive here. - Value* len_lt_zero = builder.CreateICmpSLT(len, - codegen->GetIntConstant(TYPE_INT, 0), "len_lt_zero"); - Value* ones_compliment_len = builder.CreateNot(len, "ones_compliment_len"); - Value* positive_len = builder.CreateAdd( - ones_compliment_len, codegen->GetIntConstant(TYPE_INT, 1), - "positive_len"); + llvm::Value* len_lt_zero = + builder.CreateICmpSLT(len, codegen->GetIntConstant(TYPE_INT, 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"); len = builder.CreateSelect(len_lt_zero, positive_len, len, "select_positive_len"); // Call slot parse function - Function* slot_fn = slot_fns[slot_idx]; - Value* slot_parsed = builder.CreateCall(slot_fn, - ArrayRef<Value*>({tuple_arg, data, len})); - Value* slot_error = builder.CreateNot(slot_parsed, "slot_parse_error"); + llvm::Function* slot_fn = slot_fns[slot_idx]; + llvm::Value* slot_parsed = builder.CreateCall( + 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)); builder.CreateStore(slot_error, error_ptr); @@ -465,14 +467,15 @@ Status HdfsScanner::CodegenWriteCompleteTuple(const HdfsScanNodeBase* node, // In this branch, we've just materialized slots not referenced by any conjunct. // 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. - Value* error_ret = builder.CreateZExt(error_in_row, codegen->GetType(TYPE_TINYINT)); + llvm::Value* error_ret = + builder.CreateZExt(error_in_row, codegen->GetType(TYPE_TINYINT)); builder.CreateStore(error_ret, error_in_row_arg); builder.CreateRet(codegen->true_value()); } else { // All slots for conjuncts[conjunct_idx] are materialized, evaluate the partial // tuple against that conjunct and start a new parse_block for the next conjunct - parse_block = BasicBlock::Create(context, "parse", fn, eval_fail_block); - Function* conjunct_fn; + parse_block = llvm::BasicBlock::Create(context, "parse", fn, eval_fail_block); + llvm::Function* conjunct_fn; Status status = conjuncts[conjunct_idx]->GetCodegendComputeFn(codegen, &conjunct_fn); if (!status.ok()) { @@ -487,12 +490,13 @@ Status HdfsScanner::CodegenWriteCompleteTuple(const HdfsScanNodeBase* node, codegen->SetNoInline(conjunct_fn); } - Function* get_eval_fn = + llvm::Function* get_eval_fn = codegen->GetFunction(IRFunction::HDFS_SCANNER_GET_CONJUNCT_EVALUATOR, false); - Value* eval = builder.CreateCall(get_eval_fn, - ArrayRef<Value*>({this_arg, codegen->GetIntConstant(TYPE_INT, conjunct_idx)})); + llvm::Value* eval = builder.CreateCall( + get_eval_fn, llvm::ArrayRef<llvm::Value*>( + {this_arg, codegen->GetIntConstant(TYPE_INT, conjunct_idx)})); - Value* conjunct_args[] = {eval, tuple_row_arg}; + llvm::Value* conjunct_args[] = {eval, tuple_row_arg}; CodegenAnyVal result = CodegenAnyVal::CreateCallWrapped( codegen, &builder, TYPE_BOOLEAN, conjunct_fn, conjunct_args, "conjunct_eval"); builder.CreateCondBr(result.GetVal(), parse_block, eval_fail_block); @@ -516,13 +520,13 @@ Status HdfsScanner::CodegenWriteCompleteTuple(const HdfsScanNodeBase* node, } Status HdfsScanner::CodegenWriteAlignedTuples(const HdfsScanNodeBase* node, - LlvmCodeGen* codegen, Function* write_complete_tuple_fn, - Function** write_aligned_tuples_fn) { + LlvmCodeGen* codegen, llvm::Function* write_complete_tuple_fn, + llvm::Function** write_aligned_tuples_fn) { *write_aligned_tuples_fn = NULL; SCOPED_TIMER(codegen->codegen_timer()); DCHECK(write_complete_tuple_fn != NULL); - Function* write_tuples_fn = + llvm::Function* write_tuples_fn = codegen->GetFunction(IRFunction::HDFS_SCANNER_WRITE_ALIGNED_TUPLES, true); DCHECK(write_tuples_fn != NULL); @@ -530,7 +534,7 @@ Status HdfsScanner::CodegenWriteAlignedTuples(const HdfsScanNodeBase* node, "WriteCompleteTuple"); DCHECK_EQ(replaced, 1); - Function* copy_strings_fn; + llvm::Function* copy_strings_fn; RETURN_IF_ERROR(Tuple::CodegenCopyStrings( codegen, *node->tuple_desc(), ©_strings_fn)); replaced = codegen->ReplaceCallSites( @@ -550,7 +554,7 @@ Status HdfsScanner::CodegenWriteAlignedTuples(const HdfsScanNodeBase* node, } Status HdfsScanner::CodegenInitTuple( - const HdfsScanNodeBase* node, LlvmCodeGen* codegen, Function** init_tuple_fn) { + const HdfsScanNodeBase* node, LlvmCodeGen* codegen, llvm::Function** init_tuple_fn) { *init_tuple_fn = codegen->GetFunction(IRFunction::HDFS_SCANNER_INIT_TUPLE, true); DCHECK(*init_tuple_fn != nullptr); http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/e98d2f1c/be/src/exec/hdfs-sequence-scanner.cc ---------------------------------------------------------------------- diff --git a/be/src/exec/hdfs-sequence-scanner.cc b/be/src/exec/hdfs-sequence-scanner.cc index 1c248bb..67f598c 100644 --- a/be/src/exec/hdfs-sequence-scanner.cc +++ b/be/src/exec/hdfs-sequence-scanner.cc @@ -32,7 +32,6 @@ #include "common/names.h" using namespace impala; -using namespace llvm; const char* const HdfsSequenceScanner::SEQFILE_VALUE_CLASS_NAME = "org.apache.hadoop.io.Text"; @@ -50,12 +49,12 @@ HdfsSequenceScanner::~HdfsSequenceScanner() { // Codegen for materialized parsed data into tuples. Status HdfsSequenceScanner::Codegen(HdfsScanNodeBase* node, - const vector<ScalarExpr*>& conjuncts, Function** write_aligned_tuples_fn) { + const vector<ScalarExpr*>& conjuncts, llvm::Function** write_aligned_tuples_fn) { *write_aligned_tuples_fn = nullptr; DCHECK(node->runtime_state()->ShouldCodegen()); LlvmCodeGen* codegen = node->runtime_state()->codegen(); DCHECK(codegen != nullptr); - Function* write_complete_tuple_fn; + llvm::Function* write_complete_tuple_fn; RETURN_IF_ERROR(CodegenWriteCompleteTuple(node, codegen, conjuncts, &write_complete_tuple_fn)); DCHECK(write_complete_tuple_fn != nullptr); http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/e98d2f1c/be/src/exec/hdfs-text-scanner.cc ---------------------------------------------------------------------- diff --git a/be/src/exec/hdfs-text-scanner.cc b/be/src/exec/hdfs-text-scanner.cc index 1cbc6f5..d633734 100644 --- a/be/src/exec/hdfs-text-scanner.cc +++ b/be/src/exec/hdfs-text-scanner.cc @@ -40,7 +40,6 @@ using boost::algorithm::ends_with; using boost::algorithm::to_lower; using namespace impala; -using namespace llvm; using namespace strings; const char* HdfsTextScanner::LLVM_CLASS_NAME = "class.impala::HdfsTextScanner"; @@ -739,12 +738,12 @@ Status HdfsTextScanner::CheckForSplitDelimiter(bool* split_delimiter) { // codegen'd using the IRBuilder for the specific tuple description. This function // is then injected into the cross-compiled driving function, WriteAlignedTuples(). Status HdfsTextScanner::Codegen(HdfsScanNodeBase* node, - const vector<ScalarExpr*>& conjuncts, Function** write_aligned_tuples_fn) { + const vector<ScalarExpr*>& conjuncts, llvm::Function** write_aligned_tuples_fn) { *write_aligned_tuples_fn = nullptr; DCHECK(node->runtime_state()->ShouldCodegen()); LlvmCodeGen* codegen = node->runtime_state()->codegen(); DCHECK(codegen != nullptr); - Function* write_complete_tuple_fn; + llvm::Function* write_complete_tuple_fn; RETURN_IF_ERROR(CodegenWriteCompleteTuple(node, codegen, conjuncts, &write_complete_tuple_fn)); DCHECK(write_complete_tuple_fn != nullptr); http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/e98d2f1c/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 4eaebb6..623fe7f 100644 --- a/be/src/exec/partitioned-aggregation-node.cc +++ b/be/src/exec/partitioned-aggregation-node.cc @@ -53,7 +53,6 @@ #include "common/names.h" using namespace impala; -using namespace llvm; using namespace strings; namespace impala { @@ -1476,17 +1475,17 @@ void PartitionedAggregationNode::ClosePartitions() { // ret void // } // -Status PartitionedAggregationNode::CodegenUpdateSlot(LlvmCodeGen* codegen, - int agg_fn_idx, SlotDescriptor* slot_desc, Function** fn) { - PointerType* agg_fn_eval_type = +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); - StructType* tuple_struct = intermediate_tuple_desc_->GetLlvmStruct(codegen); + llvm::StructType* tuple_struct = intermediate_tuple_desc_->GetLlvmStruct(codegen); if (tuple_struct == NULL) { return Status("PartitionedAggregationNode::CodegenUpdateSlot(): failed to generate " "intermediate tuple desc"); } - PointerType* tuple_ptr_type = codegen->GetPtrType(tuple_struct); - PointerType* tuple_row_ptr_type = codegen->GetPtrType(TupleRow::LLVM_CLASS_NAME); + llvm::PointerType* tuple_ptr_type = codegen->GetPtrType(tuple_struct); + llvm::PointerType* tuple_row_ptr_type = codegen->GetPtrType(TupleRow::LLVM_CLASS_NAME); LlvmCodeGen::FnPrototype prototype(codegen, "UpdateSlot", codegen->void_type()); prototype.AddArgument( @@ -1495,14 +1494,14 @@ Status PartitionedAggregationNode::CodegenUpdateSlot(LlvmCodeGen* codegen, prototype.AddArgument(LlvmCodeGen::NamedVariable("row", tuple_row_ptr_type)); LlvmBuilder builder(codegen->context()); - Value* args[3]; + llvm::Value* args[3]; *fn = prototype.GeneratePrototype(&builder, &args[0]); - Value* agg_fn_eval_arg = args[0]; - Value* agg_tuple_arg = args[1]; - Value* row_arg = args[2]; + llvm::Value* agg_fn_eval_arg = args[0]; + llvm::Value* agg_tuple_arg = args[1]; + llvm::Value* row_arg = args[2]; // Get the vector of input expressions' evaluators. - Value* input_evals_vector = codegen->CodegenCallFunction(&builder, + llvm::Value* input_evals_vector = codegen->CodegenCallFunction(&builder, IRFunction::AGG_FN_EVALUATOR_INPUT_EVALUATORS, agg_fn_eval_arg, "input_evals_vector"); @@ -1512,17 +1511,17 @@ Status PartitionedAggregationNode::CodegenUpdateSlot(LlvmCodeGen* codegen, vector<CodegenAnyVal> input_vals; for (int i = 0; i < num_inputs; ++i) { ScalarExpr* input_expr = agg_fn->GetChild(i); - Function* input_expr_fn; + llvm::Function* input_expr_fn; RETURN_IF_ERROR(input_expr->GetCodegendComputeFn(codegen, &input_expr_fn)); DCHECK(input_expr_fn != NULL); // Call input expr function with the matching evaluator to get src slot value. - Value* input_eval = + llvm::Value* input_eval = codegen->CodegenArrayAt(&builder, input_evals_vector, i, "input_eval"); string input_name = Substitute("input$0", i); CodegenAnyVal input_val = CodegenAnyVal::CreateCallWrapped(codegen, &builder, - input_expr->type(), input_expr_fn, ArrayRef<Value*>({input_eval, row_arg}), - input_name.c_str()); + input_expr->type(), input_expr_fn, + llvm::ArrayRef<llvm::Value*>({input_eval, row_arg}), input_name.c_str()); input_vals.push_back(input_val); } @@ -1532,7 +1531,7 @@ Status PartitionedAggregationNode::CodegenUpdateSlot(LlvmCodeGen* codegen, || dst_type.IsFloatingPointType() || dst_type.IsBooleanType(); bool dst_is_numeric_or_bool = dst_is_int_or_float_or_bool || dst_type.IsDecimalType(); - BasicBlock* ret_block = BasicBlock::Create(codegen->context(), "ret", *fn); + llvm::BasicBlock* ret_block = llvm::BasicBlock::Create(codegen->context(), "ret", *fn); // Emit the code to compute 'result' and set the NULL indicator if needed. First check // for special cases where we can emit a very simple instruction sequence, then fall @@ -1540,25 +1539,25 @@ Status PartitionedAggregationNode::CodegenUpdateSlot(LlvmCodeGen* codegen, CodegenAnyVal& src = input_vals[0]; // 'dst_slot_ptr' points to the slot in the aggregate tuple to update. - Value* dst_slot_ptr = builder.CreateStructGEP( + llvm::Value* dst_slot_ptr = builder.CreateStructGEP( NULL, agg_tuple_arg, slot_desc->llvm_field_idx(), "dst_slot_ptr"); // TODO: consider moving the following codegen logic to AggFn. if (agg_op == AggFn::COUNT) { src.CodegenBranchIfNull(&builder, ret_block); - Value* dst_value = builder.CreateLoad(dst_slot_ptr, "dst_val"); - Value* result = agg_fn->is_merge() - ? builder.CreateAdd(dst_value, src.GetVal(), "count_sum") - : builder.CreateAdd( + llvm::Value* dst_value = builder.CreateLoad(dst_slot_ptr, "dst_val"); + 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"); 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) { bool is_min = agg_op == AggFn::MIN; src.CodegenBranchIfNull(&builder, ret_block); - Function* min_max_fn = codegen->CodegenMinMax(slot_desc->type(), is_min); - Value* dst_value = builder.CreateLoad(dst_slot_ptr, "dst_val"); - Value* min_max_args[] = {dst_value, src.GetVal()}; - Value* result = + llvm::Function* min_max_fn = codegen->CodegenMinMax(slot_desc->type(), is_min); + llvm::Value* dst_value = builder.CreateLoad(dst_slot_ptr, "dst_val"); + llvm::Value* min_max_args[] = {dst_value, src.GetVal()}; + llvm::Value* result = builder.CreateCall(min_max_fn, min_max_args, is_min ? "min_value" : "max_value"); builder.CreateStore(result, dst_slot_ptr); // Dst may have been NULL, make sure to unset the NULL bit. @@ -1567,10 +1566,10 @@ Status PartitionedAggregationNode::CodegenUpdateSlot(LlvmCodeGen* codegen, codegen, &builder, agg_tuple_arg, codegen->false_value()); } else if (agg_op == AggFn::SUM && dst_is_int_or_float_or_bool) { src.CodegenBranchIfNull(&builder, ret_block); - Value* dst_value = builder.CreateLoad(dst_slot_ptr, "dst_val"); - Value* result = dst_type.IsFloatingPointType() - ? builder.CreateFAdd(dst_value, src.GetVal()) - : builder.CreateAdd(dst_value, src.GetVal()); + llvm::Value* dst_value = builder.CreateLoad(dst_slot_ptr, "dst_val"); + llvm::Value* result = dst_type.IsFloatingPointType() ? + builder.CreateFAdd(dst_value, src.GetVal()) : + builder.CreateAdd(dst_value, src.GetVal()); builder.CreateStore(result, dst_slot_ptr); if (slot_desc->is_nullable()) { @@ -1608,10 +1607,10 @@ Status PartitionedAggregationNode::CodegenUpdateSlot(LlvmCodeGen* codegen, dst.LoadFromNativePtr(dst_slot_ptr); // Get the FunctionContext object for the AggFnEvaluator. - Function* get_agg_fn_ctx_fn = + llvm::Function* get_agg_fn_ctx_fn = codegen->GetFunction(IRFunction::AGG_FN_EVALUATOR_AGG_FN_CTX, false); DCHECK(get_agg_fn_ctx_fn != NULL); - Value* agg_fn_ctx_val = + llvm::Value* agg_fn_ctx_val = builder.CreateCall(get_agg_fn_ctx_fn, {agg_fn_eval_arg}, "agg_fn_ctx"); // Call the UDA to update/merge 'src' into 'dst', with the result stored in @@ -1627,7 +1626,7 @@ Status PartitionedAggregationNode::CodegenUpdateSlot(LlvmCodeGen* codegen, if (slot_desc->is_nullable() && !special_null_handling) { // Set NULL bit in the slot based on the return value. - Value* result_is_null = updated_dst_val.GetIsNull("result_is_null"); + llvm::Value* result_is_null = updated_dst_val.GetIsNull("result_is_null"); slot_desc->CodegenSetNullIndicator( codegen, &builder, agg_tuple_arg, result_is_null); } @@ -1654,15 +1653,15 @@ Status PartitionedAggregationNode::CodegenUpdateSlot(LlvmCodeGen* codegen, } Status PartitionedAggregationNode::CodegenCallUda(LlvmCodeGen* codegen, - LlvmBuilder* builder, AggFn* agg_fn, Value* agg_fn_ctx_val, + LlvmBuilder* builder, AggFn* agg_fn, llvm::Value* agg_fn_ctx_val, const vector<CodegenAnyVal>& input_vals, const CodegenAnyVal& dst_val, CodegenAnyVal* updated_dst_val) { - Function* uda_fn; + llvm::Function* uda_fn; RETURN_IF_ERROR(agg_fn->CodegenUpdateOrMergeFunction(codegen, &uda_fn)); // Set up arguments for call to UDA, which are the FunctionContext*, followed by // pointers to all input values, followed by a pointer to the destination value. - vector<Value*> uda_fn_args; + vector<llvm::Value*> uda_fn_args; uda_fn_args.push_back(agg_fn_ctx_val); // Create pointers to input args to pass to uda_fn. We must use the unlowered type, @@ -1675,10 +1674,11 @@ Status PartitionedAggregationNode::CodegenCallUda(LlvmCodeGen* codegen, // Create pointer to dst to pass to uda_fn. We must use the unlowered type for the // same reason as above. - Value* dst_lowered_ptr = dst_val.GetLoweredPtr("dst_lowered_ptr"); + llvm::Value* dst_lowered_ptr = dst_val.GetLoweredPtr("dst_lowered_ptr"); const ColumnType& dst_type = agg_fn->intermediate_type(); - Type* dst_unlowered_ptr_type = CodegenAnyVal::GetUnloweredPtrType(codegen, dst_type); - Value* dst_unlowered_ptr = builder->CreateBitCast( + llvm::Type* dst_unlowered_ptr_type = + CodegenAnyVal::GetUnloweredPtrType(codegen, dst_type); + llvm::Value* dst_unlowered_ptr = builder->CreateBitCast( dst_lowered_ptr, dst_unlowered_ptr_type, "dst_unlowered_ptr"); uda_fn_args.push_back(dst_unlowered_ptr); @@ -1686,7 +1686,7 @@ Status PartitionedAggregationNode::CodegenCallUda(LlvmCodeGen* codegen, builder->CreateCall(uda_fn, uda_fn_args); // Convert intermediate 'dst_arg' back to the native type. - Value* anyval_result = builder->CreateLoad(dst_lowered_ptr, "anyval_result"); + llvm::Value* anyval_result = builder->CreateLoad(dst_lowered_ptr, "anyval_result"); *updated_dst_val = CodegenAnyVal(codegen, builder, dst_type, anyval_result); return Status::OK(); @@ -1724,7 +1724,7 @@ Status PartitionedAggregationNode::CodegenCallUda(LlvmCodeGen* codegen, // } // Status PartitionedAggregationNode::CodegenUpdateTuple( - LlvmCodeGen* codegen, Function** fn) { + LlvmCodeGen* codegen, llvm::Function** fn) { SCOPED_TIMER(codegen->codegen_timer()); for (const SlotDescriptor* slot_desc : intermediate_tuple_desc_->slots()) { @@ -1740,17 +1740,18 @@ Status PartitionedAggregationNode::CodegenUpdateTuple( } // Get the types to match the UpdateTuple signature - Type* agg_node_type = codegen->GetType(PartitionedAggregationNode::LLVM_CLASS_NAME); - Type* tuple_type = codegen->GetType(Tuple::LLVM_CLASS_NAME); - Type* tuple_row_type = codegen->GetType(TupleRow::LLVM_CLASS_NAME); - - PointerType* agg_node_ptr_type = codegen->GetPtrType(agg_node_type); - PointerType* evals_type = codegen->GetPtrPtrType(AggFnEvaluator::LLVM_CLASS_NAME); - PointerType* tuple_ptr_type = codegen->GetPtrType(tuple_type); - PointerType* tuple_row_ptr_type = codegen->GetPtrType(tuple_row_type); - - StructType* tuple_struct = intermediate_tuple_desc_->GetLlvmStruct(codegen); - PointerType* tuple_ptr = codegen->GetPtrType(tuple_struct); + 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::StructType* tuple_struct = intermediate_tuple_desc_->GetLlvmStruct(codegen); + llvm::PointerType* tuple_ptr = codegen->GetPtrType(tuple_struct); LlvmCodeGen::FnPrototype prototype(codegen, "UpdateTuple", codegen->void_type()); prototype.AddArgument(LlvmCodeGen::NamedVariable("this_ptr", agg_node_ptr_type)); prototype.AddArgument(LlvmCodeGen::NamedVariable("agg_fn_evals", evals_type)); @@ -1759,11 +1760,11 @@ Status PartitionedAggregationNode::CodegenUpdateTuple( prototype.AddArgument(LlvmCodeGen::NamedVariable("is_merge", codegen->boolean_type())); LlvmBuilder builder(codegen->context()); - Value* args[5]; + llvm::Value* args[5]; *fn = prototype.GeneratePrototype(&builder, &args[0]); - Value* agg_fn_evals_arg = args[1]; - Value* tuple_arg = args[2]; - Value* row_arg = args[3]; + llvm::Value* agg_fn_evals_arg = args[1]; + llvm::Value* tuple_arg = args[2]; + llvm::Value* row_arg = args[3]; // Cast the parameter types to the internal llvm runtime types. // TODO: get rid of this by using right type in function signature @@ -1779,21 +1780,23 @@ 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(); - Value* const_one = codegen->GetIntConstant(TYPE_BIGINT, 1); - Value* slot_ptr = builder.CreateStructGEP(NULL, tuple_arg, field_idx, "src_slot"); - Value* slot_loaded = builder.CreateLoad(slot_ptr, "count_star_val"); - Value* count_inc = builder.CreateAdd(slot_loaded, const_one, "count_star_inc"); + llvm::Value* const_one = codegen->GetIntConstant(TYPE_BIGINT, 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"); + llvm::Value* count_inc = + builder.CreateAdd(slot_loaded, const_one, "count_star_inc"); builder.CreateStore(count_inc, slot_ptr); } else { - Function* update_slot_fn; + llvm::Function* update_slot_fn; RETURN_IF_ERROR(CodegenUpdateSlot(codegen, i, slot_desc, &update_slot_fn)); // Load agg_fn_evals_[i] - Value* agg_fn_eval_val = + llvm::Value* agg_fn_eval_val = codegen->CodegenArrayAt(&builder, agg_fn_evals_arg, i, "agg_fn_eval"); // Call UpdateSlot(agg_fn_evals_[i], tuple, row); - Value* update_slot_args[] = {agg_fn_eval_val, tuple_arg, row_arg}; + llvm::Value* update_slot_args[] = {agg_fn_eval_val, tuple_arg, row_arg}; builder.CreateCall(update_slot_fn, update_slot_args); } } @@ -1818,14 +1821,14 @@ Status PartitionedAggregationNode::CodegenProcessBatch(LlvmCodeGen* codegen, TPrefetchMode::type prefetch_mode) { SCOPED_TIMER(codegen->codegen_timer()); - Function* update_tuple_fn; + llvm::Function* update_tuple_fn; RETURN_IF_ERROR(CodegenUpdateTuple(codegen, &update_tuple_fn)); // Get the cross compiled update row batch function IRFunction::Type ir_fn = (!grouping_exprs_.empty() ? IRFunction::PART_AGG_NODE_PROCESS_BATCH_UNAGGREGATED : IRFunction::PART_AGG_NODE_PROCESS_BATCH_NO_GROUPING); - Function* process_batch_fn = codegen->GetFunction(ir_fn, true); + llvm::Function* process_batch_fn = codegen->GetFunction(ir_fn, true); DCHECK(process_batch_fn != NULL); int replaced; @@ -1833,21 +1836,21 @@ Status PartitionedAggregationNode::CodegenProcessBatch(LlvmCodeGen* codegen, // Codegen for grouping using hash table // Replace prefetch_mode with constant so branches can be optimised out. - Value* prefetch_mode_arg = codegen->GetArgument(process_batch_fn, 3); - prefetch_mode_arg->replaceAllUsesWith( - ConstantInt::get(Type::getInt32Ty(codegen->context()), prefetch_mode)); + 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)); // The codegen'd ProcessBatch function is only used in Open() with level_ = 0, // so don't use murmur hash - Function* hash_fn; + llvm::Function* hash_fn; RETURN_IF_ERROR(ht_ctx_->CodegenHashRow(codegen, /* use murmur */ false, &hash_fn)); // Codegen HashTable::Equals<true> - Function* build_equals_fn; + llvm::Function* build_equals_fn; RETURN_IF_ERROR(ht_ctx_->CodegenEquals(codegen, true, &build_equals_fn)); // Codegen for evaluating input rows - Function* eval_grouping_expr_fn; + llvm::Function* eval_grouping_expr_fn; RETURN_IF_ERROR(ht_ctx_->CodegenEvalRow(codegen, false, &eval_grouping_expr_fn)); // Replace call sites @@ -1893,32 +1896,32 @@ Status PartitionedAggregationNode::CodegenProcessBatchStreaming( SCOPED_TIMER(codegen->codegen_timer()); IRFunction::Type ir_fn = IRFunction::PART_AGG_NODE_PROCESS_BATCH_STREAMING; - Function* process_batch_streaming_fn = codegen->GetFunction(ir_fn, true); + llvm::Function* process_batch_streaming_fn = codegen->GetFunction(ir_fn, true); DCHECK(process_batch_streaming_fn != NULL); // Make needs_serialize arg constant so dead code can be optimised out. - Value* needs_serialize_arg = codegen->GetArgument(process_batch_streaming_fn, 2); - needs_serialize_arg->replaceAllUsesWith( - ConstantInt::get(Type::getInt1Ty(codegen->context()), needs_serialize_)); + 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_)); // Replace prefetch_mode with constant so branches can be optimised out. - Value* prefetch_mode_arg = codegen->GetArgument(process_batch_streaming_fn, 3); + llvm::Value* prefetch_mode_arg = codegen->GetArgument(process_batch_streaming_fn, 3); prefetch_mode_arg->replaceAllUsesWith( - ConstantInt::get(Type::getInt32Ty(codegen->context()), prefetch_mode)); + llvm::ConstantInt::get(llvm::Type::getInt32Ty(codegen->context()), prefetch_mode)); - Function* update_tuple_fn; + llvm::Function* update_tuple_fn; RETURN_IF_ERROR(CodegenUpdateTuple(codegen, &update_tuple_fn)); // We only use the top-level hash function for streaming aggregations. - Function* hash_fn; + llvm::Function* hash_fn; RETURN_IF_ERROR(ht_ctx_->CodegenHashRow(codegen, false, &hash_fn)); // Codegen HashTable::Equals - Function* equals_fn; + llvm::Function* equals_fn; RETURN_IF_ERROR(ht_ctx_->CodegenEquals(codegen, true, &equals_fn)); // Codegen for evaluating input rows - Function* eval_grouping_expr_fn; + llvm::Function* eval_grouping_expr_fn; RETURN_IF_ERROR(ht_ctx_->CodegenEvalRow(codegen, false, &eval_grouping_expr_fn)); // Replace call sites
