Skip to content

Commit 68fc036

Browse files
committed
[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 llvm-svn: 314917
1 parent b47b3f2 commit 68fc036

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

llvm/include/llvm/Support/GenericDomTree.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,9 @@ class DominatorTreeBase {
522522
///
523523
/// Batch updates should be generally faster when performing longer sequences
524524
/// of updates than calling insertEdge/deleteEdge manually multiple times, as
525-
/// they can reorder the updates and remove redundant ones internally.
525+
/// it can reorder the updates and remove redundant ones internally.
526+
/// The batch updater is also able to detect sequences of zero and exactly one
527+
/// update -- it's optimized to do less work in these cases.
526528
///
527529
/// Note that for postdominators it automatically takes care of applying
528530
/// updates on reverse edges internally (so there's no need to swap the

llvm/include/llvm/Support/GenericDomTreeConstruction.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,22 @@ struct SemiNCAInfo {
11221122
//~~
11231123

11241124
static void ApplyUpdates(DomTreeT &DT, ArrayRef<UpdateT> Updates) {
1125+
const size_t NumUpdates = Updates.size();
1126+
if (NumUpdates == 0)
1127+
return;
1128+
1129+
// Take the fast path for a single update and avoid running the batch update
1130+
// machinery.
1131+
if (NumUpdates == 1) {
1132+
const auto &Update = Updates.front();
1133+
if (Update.getKind() == UpdateKind::Insert)
1134+
DT.insertEdge(Update.getFrom(), Update.getTo());
1135+
else
1136+
DT.deleteEdge(Update.getFrom(), Update.getTo());
1137+
1138+
return;
1139+
}
1140+
11251141
BatchUpdateInfo BUI;
11261142
LegalizeUpdates(Updates, BUI.Updates);
11271143

0 commit comments

Comments
 (0)