llvm.org GIT mirror llvm / 90edfc7
[Dominators] Take fast path when applying <=1 updates Summary: This patch teaches `DT.applyUpdates` to take the fast when applying zero or just one update and makes it not run the internal batch updater machinery. With this patch, it should no longer make sense to have a special check in user's code that checks the update sequence size before applying them, e.g. ``` if (!MyUpdates.empty()) DT.applyUpdates(MyUpdates); ``` or ``` if (MyUpdates.size() == 1) if (...) DT.insertEdge(...) else DT.deleteEdge(...) ``` Reviewers: dberlin, brzycki, davide, grosser, sanjoy Reviewed By: dberlin, davide Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D38541 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314917 91177308-0d34-0410-b5e6-96231b3b80d8 Jakub Kuderski 2 years ago
2 changed file(s) with 19 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
521521 ///
522522 /// Batch updates should be generally faster when performing longer sequences
523523 /// of updates than calling insertEdge/deleteEdge manually multiple times, as
524 /// they can reorder the updates and remove redundant ones internally.
524 /// it can reorder the updates and remove redundant ones internally.
525 /// The batch updater is also able to detect sequences of zero and exactly one
526 /// update -- it's optimized to do less work in these cases.
525527 ///
526528 /// Note that for postdominators it automatically takes care of applying
527529 /// updates on reverse edges internally (so there's no need to swap the
11211121 //~~
11221122
11231123 static void ApplyUpdates(DomTreeT &DT, ArrayRef Updates) {
1124 const size_t NumUpdates = Updates.size();
1125 if (NumUpdates == 0)
1126 return;
1127
1128 // Take the fast path for a single update and avoid running the batch update
1129 // machinery.
1130 if (NumUpdates == 1) {
1131 const auto &Update = Updates.front();
1132 if (Update.getKind() == UpdateKind::Insert)
1133 DT.insertEdge(Update.getFrom(), Update.getTo());
1134 else
1135 DT.deleteEdge(Update.getFrom(), Update.getTo());
1136
1137 return;
1138 }
1139
11241140 BatchUpdateInfo BUI;
11251141 LegalizeUpdates(Updates, BUI.Updates);
11261142