Add and remove loops which have been marked for addition and removal to maintain the state of the loop descriptor class.
| 942 | // Add and remove loops which have been marked for addition and removal to |
| 943 | // maintain the state of the loop descriptor class. |
| 944 | void LoopDescriptor::PostModificationCleanup() { |
| 945 | LoopContainerType loops_to_remove_; |
| 946 | for (Loop* loop : loops_) { |
| 947 | if (loop->IsMarkedForRemoval()) { |
| 948 | loops_to_remove_.push_back(loop); |
| 949 | if (loop->HasParent()) { |
| 950 | loop->GetParent()->RemoveChildLoop(loop); |
| 951 | } |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | for (Loop* loop : loops_to_remove_) { |
| 956 | loops_.erase(std::find(loops_.begin(), loops_.end(), loop)); |
| 957 | delete loop; |
| 958 | } |
| 959 | |
| 960 | for (auto& pair : loops_to_add_) { |
| 961 | Loop* parent = pair.first; |
| 962 | std::unique_ptr<Loop> loop = std::move(pair.second); |
| 963 | |
| 964 | if (parent) { |
| 965 | loop->SetParent(nullptr); |
| 966 | parent->AddNestedLoop(loop.get()); |
| 967 | |
| 968 | for (uint32_t block_id : loop->GetBlocks()) { |
| 969 | parent->AddBasicBlock(block_id); |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | loops_.emplace_back(loop.release()); |
| 974 | } |
| 975 | |
| 976 | loops_to_add_.clear(); |
| 977 | } |
| 978 | |
| 979 | void LoopDescriptor::ClearLoops() { |
| 980 | for (Loop* loop : loops_) { |
no test coverage detected