示例#1
0
// Iterate over all valid rows in this batch
void RowBatch::Iterate(CodeGen &codegen, RowBatch::IterateCallback &cb) {
  // The starting position in the batch
  llvm::Value *start = codegen.Const32(0);

  // The ending position in the batch
  llvm::Value *end = GetNumValidRows(codegen);

  // Generating the loop
  std::vector<lang::Loop::LoopVariable> loop_vars = {
      {"readIdx", start}, {"writeIdx", codegen.Const32(0)}};
  llvm::Value *loop_cond = codegen->CreateICmpULT(start, end);
  lang::Loop batch_loop{codegen, loop_cond, loop_vars};
  {
    // Pull out loop vars for convenience
    auto *batch_pos = batch_loop.GetLoopVar(0);
    auto *write_pos = batch_loop.GetLoopVar(1);

    // Create an output tracker to track the final position of the row
    OutputTracker tracker{GetSelectionVector(), write_pos};

    // Get the current row
    RowBatch::Row row = GetRowAt(batch_pos, &tracker);

    // Invoke callback
    cb.ProcessRow(row);

    // The next read position is one next
    auto *next_read_pos = codegen->CreateAdd(batch_pos, codegen.Const32(1));

    // The write position from the output track
    auto *next_write_pos = tracker.GetFinalOutputPos();

    // Close up loop
    llvm::Value *loop_cond = codegen->CreateICmpULT(next_read_pos, end);
    batch_loop.LoopEnd(loop_cond, {next_read_pos, next_write_pos});
  }

  // After the batch loop, we need to reset the size of the selection vector
  std::vector<llvm::Value *> final_vals;
  batch_loop.CollectFinalLoopVariables(final_vals);

  // Mark the last position in the batch
  UpdateWritePosition(final_vals[1]);
}
示例#2
0
文件: table.cpp 项目: wy4515/peloton
// Generate a scan over all tile groups.
//
// @code
// column_layouts := alloca<peloton::ColumnLayoutInfo>(
//     table.GetSchema().GetColumnCount())
//
// oid_t tile_group_idx := 0
// num_tile_groups = GetTileGroupCount(table_ptr)
//
// for (; tile_group_idx < num_tile_groups; ++tile_group_idx) {
//   tile_group_ptr := GetTileGroup(table_ptr, tile_group_idx)
//   consumer.TileGroupStart(tile_group_ptr);
//   tile_group.TidScan(tile_group_ptr, column_layouts, vector_size, consumer);
//   consumer.TileGroupEnd(tile_group_ptr);
// }
//
// @endcode
void Table::GenerateScan(CodeGen &codegen, llvm::Value *table_ptr,
                         uint32_t batch_size, ScanCallback &consumer) const {
  // First get the columns from the table the consumer needs. For every column,
  // we'll need to have a ColumnInfoLayout struct
  const uint32_t num_columns =
      static_cast<uint32_t>(table_.GetSchema()->GetColumnCount());

  llvm::Value *column_layouts = codegen->CreateAlloca(
      RuntimeFunctionsProxy::_ColumnLayoutInfo::GetType(codegen),
      codegen.Const32(num_columns));

  // Get the number of tile groups in the given table
  llvm::Value *tile_group_idx = codegen.Const64(0);
  llvm::Value *num_tile_groups = GetTileGroupCount(codegen, table_ptr);

  // Iterate over all tile groups in the table
  lang::Loop loop{codegen,
                  codegen->CreateICmpULT(tile_group_idx, num_tile_groups),
                  {{"tileGroupIdx", tile_group_idx}}};
  {
    // Get the tile group with the given tile group ID
    tile_group_idx = loop.GetLoopVar(0);
    llvm::Value *tile_group_ptr =
        GetTileGroup(codegen, table_ptr, tile_group_idx);
    llvm::Value *tile_group_id =
        tile_group_.GetTileGroupId(codegen, tile_group_ptr);

    // Invoke the consumer to let her know that we're starting to iterate over
    // the tile group now
    consumer.TileGroupStart(codegen, tile_group_id, tile_group_ptr);

    // Generate the scan cover over the given tile group
    tile_group_.GenerateTidScan(codegen, tile_group_ptr, column_layouts,
                                batch_size, consumer);

    // Invoke the consumer to let her know that we're done with this tile group
    consumer.TileGroupFinish(codegen, tile_group_ptr);

    // Move to next tile group in the table
    tile_group_idx = codegen->CreateAdd(tile_group_idx, codegen.Const64(1));
    loop.LoopEnd(codegen->CreateICmpULT(tile_group_idx, num_tile_groups),
                 {tile_group_idx});
  }
}
示例#3
0
文件: sorter.cpp 项目: cmu-db/peloton
    void ProcessEntries(CodeGen &codegen, llvm::Value *start_index,
                        llvm::Value *end_index, SorterAccess &access) const {
      lang::Loop loop(codegen,
                      codegen->CreateICmpULT(start_index, end_index),
                      {{"start", start_index}});
      {
        llvm::Value *curr_index = loop.GetLoopVar(0);

        // Parse the row
        std::vector<codegen::Value> vals;
        auto &row = access.GetRow(curr_index);
        for (uint32_t i = 0; i < storage.GetNumElements(); i++) {
          vals.emplace_back(row.LoadColumn(codegen, i));
        }

        // Call the actual callback
        callback.ProcessEntry(codegen, vals);

        curr_index = codegen->CreateAdd(curr_index, codegen.Const32(1));
        loop.LoopEnd(codegen->CreateICmpULT(curr_index, end_index),
                     {curr_index});
      }
    }