Rebuild the |node| eliminating, if it exists, the recurrent term which belongs to the |loop|.
| 431 | // Rebuild the |node| eliminating, if it exists, the recurrent term which |
| 432 | // belongs to the |loop|. |
| 433 | SENode* ScalarEvolutionAnalysis::BuildGraphWithoutRecurrentTerm( |
| 434 | SENode* node, const Loop* loop) { |
| 435 | // If the node is already a recurrent expression belonging to loop then just |
| 436 | // return the offset. |
| 437 | SERecurrentNode* recurrent = node->AsSERecurrentNode(); |
| 438 | if (recurrent) { |
| 439 | if (recurrent->GetLoop() == loop) { |
| 440 | return recurrent->GetOffset(); |
| 441 | } else { |
| 442 | return node; |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | std::vector<SENode*> new_children; |
| 447 | // Otherwise find the recurrent node in the children of this node. |
| 448 | for (auto itr : *node) { |
| 449 | recurrent = itr->AsSERecurrentNode(); |
| 450 | if (recurrent && recurrent->GetLoop() == loop) { |
| 451 | new_children.push_back(recurrent->GetOffset()); |
| 452 | } else { |
| 453 | new_children.push_back(itr); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | std::unique_ptr<SENode> add_node{new SEAddNode(this)}; |
| 458 | for (SENode* child : new_children) { |
| 459 | add_node->AddChild(child); |
| 460 | } |
| 461 | |
| 462 | return SimplifyExpression(GetCachedOrAdd(std::move(add_node))); |
| 463 | } |
| 464 | |
| 465 | // Return the recurrent term belonging to |loop| if it appears in the graph |
| 466 | // starting at |node| or null if it doesn't. |
no test coverage detected