// 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, Sorter::VectorizedIterateCallback &callback) const { llvm::Value *start_pos = GetStartPosition(codegen, sorter_ptr); llvm::Value *num_tuples = GetNumberOfStoredTuples(codegen, sorter_ptr); // Determine the number of bytes to skip per vector llvm::Value *vec_sz = codegen.Const32(vector_size); llvm::Value *tuple_size = GetTupleSize(codegen); llvm::Value *skip = codegen->CreateMul(vec_sz, tuple_size); lang::VectorizedLoop loop{ codegen, num_tuples, vector_size, {{"pos", start_pos}}}; { llvm::Value *curr_pos = loop.GetLoopVar(0); 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); // Bump the pointer by the size of a tuple llvm::Value *next_pos = codegen->CreateInBoundsGEP(curr_pos, skip); loop.LoopEnd(codegen, {next_pos}); } }
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()); }
int64_t PlanContext::GetAggregatedDatasize() const { const unsigned tuple_size = GetTupleSize(); return plan_partitioner_.GetAggregatedDataCardinality() * tuple_size; }