Пример #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});
  }
}