A method to code-gen for TupleSorter::SortHelper().
| 1626 | |
| 1627 | // A method to code-gen for TupleSorter::SortHelper(). |
| 1628 | Status Sorter::TupleSorter::Codegen(FragmentState* state, llvm::Function* compare_fn, |
| 1629 | int tuple_size, CodegenFnPtr<SortHelperFn>* codegened_fn) { |
| 1630 | LlvmCodeGen* codegen = state->codegen(); |
| 1631 | DCHECK(codegen != nullptr); |
| 1632 | |
| 1633 | llvm::Function* fn = codegen->GetFunction(IRFunction::TUPLE_SORTER_SORT_HELPER, true); |
| 1634 | DCHECK(fn != NULL); |
| 1635 | |
| 1636 | // There are 8 calls to Less() and Compare() which calls |
| 1637 | // comparator_.Less() and comparator_.Compare() respectively once in each. |
| 1638 | int replaced = |
| 1639 | codegen->ReplaceCallSites(fn, compare_fn, TupleRowComparator::COMPARE_SYMBOL); |
| 1640 | DCHECK_REPLACE_COUNT(replaced, 8) << LlvmCodeGen::Print(fn); |
| 1641 | |
| 1642 | // There are 2 recursive calls within SorterHelper() to replace with. |
| 1643 | replaced = codegen->ReplaceCallSites(fn, fn, SORTER_HELPER_SYMBOL); |
| 1644 | DCHECK_REPLACE_COUNT(replaced, 2) << LlvmCodeGen::Print(fn); |
| 1645 | |
| 1646 | replaced = codegen->ReplaceCallSitesWithValue(fn, |
| 1647 | codegen->GetI32Constant(tuple_size), "get_tuple_size"); |
| 1648 | DCHECK_REPLACE_COUNT(replaced, 3) << LlvmCodeGen::Print(fn); |
| 1649 | |
| 1650 | fn = codegen->FinalizeFunction(fn); |
| 1651 | if (fn == nullptr) { |
| 1652 | return Status("Sorter::TupleSorter::Codegen(): failed to finalize function"); |
| 1653 | } |
| 1654 | codegen->AddFunctionToJit(fn, codegened_fn); |
| 1655 | |
| 1656 | return Status::OK(); |
| 1657 | } |
| 1658 | |
| 1659 | } // namespace impala |
no test coverage detected