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