Example #1
0
void BufferAccessor::Iterate(CodeGen &codegen, llvm::Value *buffer_ptr,
                             BufferAccessor::IterateCallback &callback) const {
  auto *start = codegen.Load(BufferProxy::buffer_start, buffer_ptr);
  auto *end = codegen.Load(BufferProxy::buffer_pos, buffer_ptr);
  lang::Loop loop{codegen, codegen->CreateICmpNE(start, end), {{"pos", start}}};
  {
    auto *pos = loop.GetLoopVar(0);

    // Read
    std::vector<codegen::Value> vals;
    UpdateableStorage::NullBitmap null_bitmap(codegen, storage_format_, pos);
    for (uint32_t col_id = 0; col_id < storage_format_.GetNumElements();
         col_id++) {
      auto val = storage_format_.GetValue(codegen, pos, col_id, null_bitmap);
      vals.emplace_back(val);
    }

    // Invoke callback
    callback.ProcessEntry(codegen, vals);

    // Move along
    auto *next = codegen->CreateConstInBoundsGEP1_64(
        pos, storage_format_.GetStorageSize());
    loop.LoopEnd(codegen->CreateICmpNE(next, end), {next});
  }
}
Example #2
0
llvm::Value *Sorter::NumTuples(CodeGen &codegen,
                               llvm::Value *sorter_ptr) const {
  // Pull out start and end (char **)
  auto *start = codegen.Load(SorterProxy::tuples_start, sorter_ptr);
  auto *end = codegen.Load(SorterProxy::tuples_end, sorter_ptr);

  // Convert both to uint64_t
  start = codegen->CreatePtrToInt(start, codegen.Int64Type());
  end = codegen->CreatePtrToInt(end, codegen.Int64Type());

  // Subtract (end - start)
  auto *diff = codegen->CreateSub(end, start);

  // Divide by pointer size (diff >> 3, or div / 8)
  return codegen->CreateAShr(diff, 3, "numTuples", true);
}
Example #3
0
// 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, {});
  }
}