@@ -79,14 +79,15 @@ struct SemiNCAInfo {
79
79
using UpdateKind = typename DomTreeT::UpdateKind;
80
80
struct BatchUpdateInfo {
81
81
// Note: Updates inside PreViewCFG are aleady legalized.
82
- BatchUpdateInfo (GraphDiffT &PreViewCFG)
83
- : PreViewCFG(PreViewCFG),
82
+ BatchUpdateInfo (GraphDiffT &PreViewCFG, GraphDiffT *PostViewCFG = nullptr )
83
+ : PreViewCFG(PreViewCFG), PostViewCFG(PostViewCFG),
84
84
NumLegalized (PreViewCFG.getNumLegalizedUpdates()) {}
85
85
86
86
// Remembers if the whole tree was recalculated at some point during the
87
87
// current batch update.
88
88
bool IsRecalculated = false ;
89
89
GraphDiffT &PreViewCFG;
90
+ GraphDiffT *PostViewCFG;
90
91
const size_t NumLegalized;
91
92
};
92
93
@@ -560,12 +561,21 @@ struct SemiNCAInfo {
560
561
auto *Parent = DT.Parent ;
561
562
DT.reset ();
562
563
DT.Parent = Parent;
563
- SemiNCAInfo SNCA (nullptr ); // Since we are rebuilding the whole tree,
564
- // there's no point doing it incrementally.
564
+ // If the update is using the actual CFG, BUI is null. If it's using a view,
565
+ // BUI is non-null and the PreCFGView is used. When calculating from
566
+ // scratch, make the PreViewCFG equal to the PostCFGView, so Post is used.
567
+ BatchUpdatePtr PostViewBUI = nullptr ;
568
+ if (BUI && BUI->PostViewCFG ) {
569
+ BUI->PreViewCFG = *BUI->PostViewCFG ;
570
+ PostViewBUI = BUI;
571
+ }
572
+ // This is rebuilding the whole tree, not incrementally, but PostViewBUI is
573
+ // used in case the caller needs a DT update with a CFGView.
574
+ SemiNCAInfo SNCA (PostViewBUI);
565
575
566
576
// Step #0: Number blocks in depth-first order and initialize variables used
567
577
// in later stages of the algorithm.
568
- DT.Roots = FindRoots (DT, nullptr );
578
+ DT.Roots = FindRoots (DT, PostViewBUI );
569
579
SNCA.doFullDFSWalk (DT, AlwaysDescend);
570
580
571
581
SNCA.runSemiNCA (DT);
@@ -1139,7 +1149,10 @@ struct SemiNCAInfo {
1139
1149
// ===--------------------- DomTree Batch Updater --------------------------===
1140
1150
// ~~
1141
1151
1142
- static void ApplyUpdates (DomTreeT &DT, GraphDiffT &PreViewCFG) {
1152
+ static void ApplyUpdates (DomTreeT &DT, GraphDiffT &PreViewCFG,
1153
+ GraphDiffT *PostViewCFG) {
1154
+ // Note: the PostViewCFG is only used when computing from scratch. It's data
1155
+ // should already included in the PreViewCFG for incremental updates.
1143
1156
const size_t NumUpdates = PreViewCFG.getNumLegalizedUpdates ();
1144
1157
if (NumUpdates == 0 )
1145
1158
return ;
@@ -1148,14 +1161,22 @@ struct SemiNCAInfo {
1148
1161
// machinery.
1149
1162
if (NumUpdates == 1 ) {
1150
1163
UpdateT Update = PreViewCFG.popUpdateForIncrementalUpdates ();
1151
- if (Update.getKind () == UpdateKind::Insert)
1152
- InsertEdge (DT, /* BUI=*/ nullptr , Update.getFrom (), Update.getTo ());
1153
- else
1154
- DeleteEdge (DT, /* BUI=*/ nullptr , Update.getFrom (), Update.getTo ());
1164
+ if (!PostViewCFG) {
1165
+ if (Update.getKind () == UpdateKind::Insert)
1166
+ InsertEdge (DT, /* BUI=*/ nullptr , Update.getFrom (), Update.getTo ());
1167
+ else
1168
+ DeleteEdge (DT, /* BUI=*/ nullptr , Update.getFrom (), Update.getTo ());
1169
+ } else {
1170
+ BatchUpdateInfo BUI (*PostViewCFG, PostViewCFG);
1171
+ if (Update.getKind () == UpdateKind::Insert)
1172
+ InsertEdge (DT, &BUI, Update.getFrom (), Update.getTo ());
1173
+ else
1174
+ DeleteEdge (DT, &BUI, Update.getFrom (), Update.getTo ());
1175
+ }
1155
1176
return ;
1156
1177
}
1157
1178
1158
- BatchUpdateInfo BUI (PreViewCFG);
1179
+ BatchUpdateInfo BUI (PreViewCFG, PostViewCFG );
1159
1180
// Recalculate the DominatorTree when the number of updates
1160
1181
// exceeds a threshold, which usually makes direct updating slower than
1161
1182
// recalculation. We select this threshold proportional to the
@@ -1571,8 +1592,10 @@ void DeleteEdge(DomTreeT &DT, typename DomTreeT::NodePtr From,
1571
1592
template <class DomTreeT >
1572
1593
void ApplyUpdates (DomTreeT &DT,
1573
1594
GraphDiff<typename DomTreeT::NodePtr,
1574
- DomTreeT::IsPostDominator> &PreViewCFG) {
1575
- SemiNCAInfo<DomTreeT>::ApplyUpdates (DT, PreViewCFG);
1595
+ DomTreeT::IsPostDominator> &PreViewCFG,
1596
+ GraphDiff<typename DomTreeT::NodePtr,
1597
+ DomTreeT::IsPostDominator> *PostViewCFG) {
1598
+ SemiNCAInfo<DomTreeT>::ApplyUpdates (DT, PreViewCFG, PostViewCFG);
1576
1599
}
1577
1600
1578
1601
template <class DomTreeT >
0 commit comments