| 495 | } |
| 496 | |
| 497 | void ActionsDAG::compileFunctions(size_t min_count_to_compile_expression, const std::unordered_set<const ActionsDAG::Node *> & lazy_executed_nodes) |
| 498 | { |
| 499 | struct Data |
| 500 | { |
| 501 | bool is_compilable_in_isolation = false; |
| 502 | bool all_parents_compilable = true; |
| 503 | size_t compilable_children_size = 0; |
| 504 | size_t children_size = 0; |
| 505 | }; |
| 506 | |
| 507 | std::unordered_map<const Node *, Data> node_to_data; |
| 508 | |
| 509 | /// Check which nodes can be compiled in isolation |
| 510 | |
| 511 | for (const auto & node : nodes) |
| 512 | { |
| 513 | bool node_is_compilable_in_isolation = isCompilableFunction(node, lazy_executed_nodes) && !isCompilableConstant(node); |
| 514 | node_to_data[&node].is_compilable_in_isolation = node_is_compilable_in_isolation; |
| 515 | } |
| 516 | |
| 517 | struct Frame |
| 518 | { |
| 519 | const Node * node; |
| 520 | size_t next_child_to_visit = 0; |
| 521 | }; |
| 522 | |
| 523 | std::stack<Frame> stack; |
| 524 | std::unordered_set<const Node *> visited_nodes; |
| 525 | |
| 526 | /** Algorithm is to iterate over each node in ActionsDAG, and update node compilable_children_size. |
| 527 | * After this procedure data for each node is initialized. |
| 528 | */ |
| 529 | |
| 530 | for (auto & node : nodes) |
| 531 | { |
| 532 | if (visited_nodes.contains(&node)) |
| 533 | continue; |
| 534 | |
| 535 | stack.emplace(Frame{.node = &node}); |
| 536 | |
| 537 | while (!stack.empty()) |
| 538 | { |
| 539 | auto & current_frame = stack.top(); |
| 540 | auto & current_node = current_frame.node; |
| 541 | |
| 542 | while (current_frame.next_child_to_visit < current_node->children.size()) |
| 543 | { |
| 544 | const auto & child = current_node->children[current_frame.next_child_to_visit]; |
| 545 | |
| 546 | if (visited_nodes.contains(child)) |
| 547 | { |
| 548 | ++current_frame.next_child_to_visit; |
| 549 | continue; |
| 550 | } |
| 551 | |
| 552 | stack.emplace(Frame{.node=child}); |
| 553 | break; |
| 554 | } |
nothing calls this directly
no test coverage detected