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); }