// Iterate over the tuples in the sorter in batches/vectors of the given size void Sorter::VectorizedIterate( CodeGen &codegen, llvm::Value *sorter_ptr, uint32_t vector_size, uint64_t offset, Sorter::VectorizedIterateCallback &callback) const { llvm::Value *start_pos = codegen.Load(SorterProxy::tuples_start, sorter_ptr); llvm::Value *num_tuples = NumTuples(codegen, sorter_ptr); num_tuples = codegen->CreateTrunc(num_tuples, codegen.Int32Type()); if (offset != 0) { start_pos = codegen->CreateConstInBoundsGEP1_32(codegen.CharPtrType(), start_pos, offset); num_tuples = codegen->CreateSub(num_tuples, codegen.Const32(offset)); } lang::VectorizedLoop loop(codegen, num_tuples, vector_size, {}); { // Current loop range auto curr_range = loop.GetCurrentRange(); // Provide an accessor into the sorted space SorterAccess sorter_access(*this, start_pos); // Issue the callback callback.ProcessEntries(codegen, curr_range.start, curr_range.end, sorter_access); // That's it loop.LoopEnd(codegen, {}); } }
llvm::Value *Sorter::GetNumberOfStoredTuples(CodeGen &codegen, llvm::Value *sorter_ptr) const { // TODO: util::Sorter has a function to handle this ... llvm::Value *start_pos = GetStartPosition(codegen, sorter_ptr); llvm::Value *end_pos = GetEndPosition(codegen, sorter_ptr); llvm::Value *tuple_size = codegen->CreateZExt(GetTupleSize(codegen), codegen.Int64Type()); llvm::Value *diff_bytes = codegen->CreatePtrDiff(end_pos, start_pos); llvm::Value *num_tuples = codegen->CreateUDiv(diff_bytes, tuple_size); return codegen->CreateTruncOrBitCast(num_tuples, codegen.Int32Type()); }
void RowBatch::Row::SetValidity(CodeGen &codegen, llvm::Value *valid) { if (valid->getType() != codegen.BoolType()) { std::string error_msg; llvm::raw_string_ostream rso{error_msg}; rso << "Validity of row must be a boolean value. Received type: " << valid->getType(); throw Exception{error_msg}; } if (output_tracker_ == nullptr) { throw Exception{"You didn't provide an output tracker for the row!"}; } // Append this row to the output llvm::Value *delta = codegen->CreateZExt(valid, codegen.Int32Type()); output_tracker_->AppendRowToOutput(codegen, *this, delta); }
void Varchar::GetTypeForMaterialization(CodeGen &codegen, llvm::Type *&val_type, llvm::Type *&len_type) const { val_type = codegen.CharPtrType(); len_type = codegen.Int32Type(); }
void Date::GetTypeForMaterialization(CodeGen &codegen, llvm::Type *&val_type, llvm::Type *&len_type) const { val_type = codegen.Int32Type(); len_type = nullptr; }