Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
//===- DomTreeUpdater.h - DomTree/Post DomTree Updater ----------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the DomTreeUpdater class, which provides a uniform way to
|
|
|
|
// update dominator tree related data structures.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-02-06 03:52:52 +01:00
|
|
|
#ifndef LLVM_ANALYSIS_DOMTREEUPDATER_H
|
|
|
|
#define LLVM_ANALYSIS_DOMTREEUPDATER_H
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
|
2020-06-07 17:56:09 +02:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
#include "llvm/IR/Dominators.h"
|
|
|
|
#include "llvm/IR/ValueHandle.h"
|
2020-06-07 17:56:09 +02:00
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include <cstddef>
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
#include <functional>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llvm {
|
2020-06-07 18:17:21 +02:00
|
|
|
class PostDominatorTree;
|
|
|
|
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
class DomTreeUpdater {
|
|
|
|
public:
|
|
|
|
enum class UpdateStrategy : unsigned char { Eager = 0, Lazy = 1 };
|
|
|
|
|
|
|
|
explicit DomTreeUpdater(UpdateStrategy Strategy_) : Strategy(Strategy_) {}
|
|
|
|
DomTreeUpdater(DominatorTree &DT_, UpdateStrategy Strategy_)
|
|
|
|
: DT(&DT_), Strategy(Strategy_) {}
|
[Dominators] Add DomTreeUpdater constructor from DT* and PDT*
Summary:
Previously, if a function accepts an optional DT pointer,
```
void Foo (.., DominatorTree * DT = nullptr) {
...
if(DT)
DomTreeUpdater(*DT, ...).insertEdge(A, B);
if(DT){
DomTreeUpdater DTU(*DT, ...);
... // Construct the update vector and applyUpdates
}
...
if(DT){
DomTreeUpdater DTU(*DT, ...);
... // Construct the update vector and applyUpdates
}
}
```
After this patch, it can be simplified as
```
void Foo (.., DominatorTree * DT = nullptr) {
DomTreeUpdater DTU(DT, ...);
...
DTU.insertEdge(A, B);
if(DT){
... // Construct the update vector and applyUpdates
}
...
if(DT){
... // Construct the update vector and applyUpdates
}
}
```
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen
Reviewed By: kuhar
Author: NutshellySima
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D48923
llvm-svn: 336294
2018-07-04 20:37:15 +02:00
|
|
|
DomTreeUpdater(DominatorTree *DT_, UpdateStrategy Strategy_)
|
|
|
|
: DT(DT_), Strategy(Strategy_) {}
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
DomTreeUpdater(PostDominatorTree &PDT_, UpdateStrategy Strategy_)
|
|
|
|
: PDT(&PDT_), Strategy(Strategy_) {}
|
[Dominators] Add DomTreeUpdater constructor from DT* and PDT*
Summary:
Previously, if a function accepts an optional DT pointer,
```
void Foo (.., DominatorTree * DT = nullptr) {
...
if(DT)
DomTreeUpdater(*DT, ...).insertEdge(A, B);
if(DT){
DomTreeUpdater DTU(*DT, ...);
... // Construct the update vector and applyUpdates
}
...
if(DT){
DomTreeUpdater DTU(*DT, ...);
... // Construct the update vector and applyUpdates
}
}
```
After this patch, it can be simplified as
```
void Foo (.., DominatorTree * DT = nullptr) {
DomTreeUpdater DTU(DT, ...);
...
DTU.insertEdge(A, B);
if(DT){
... // Construct the update vector and applyUpdates
}
...
if(DT){
... // Construct the update vector and applyUpdates
}
}
```
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen
Reviewed By: kuhar
Author: NutshellySima
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D48923
llvm-svn: 336294
2018-07-04 20:37:15 +02:00
|
|
|
DomTreeUpdater(PostDominatorTree *PDT_, UpdateStrategy Strategy_)
|
|
|
|
: PDT(PDT_), Strategy(Strategy_) {}
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
DomTreeUpdater(DominatorTree &DT_, PostDominatorTree &PDT_,
|
|
|
|
UpdateStrategy Strategy_)
|
|
|
|
: DT(&DT_), PDT(&PDT_), Strategy(Strategy_) {}
|
[Dominators] Add DomTreeUpdater constructor from DT* and PDT*
Summary:
Previously, if a function accepts an optional DT pointer,
```
void Foo (.., DominatorTree * DT = nullptr) {
...
if(DT)
DomTreeUpdater(*DT, ...).insertEdge(A, B);
if(DT){
DomTreeUpdater DTU(*DT, ...);
... // Construct the update vector and applyUpdates
}
...
if(DT){
DomTreeUpdater DTU(*DT, ...);
... // Construct the update vector and applyUpdates
}
}
```
After this patch, it can be simplified as
```
void Foo (.., DominatorTree * DT = nullptr) {
DomTreeUpdater DTU(DT, ...);
...
DTU.insertEdge(A, B);
if(DT){
... // Construct the update vector and applyUpdates
}
...
if(DT){
... // Construct the update vector and applyUpdates
}
}
```
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen
Reviewed By: kuhar
Author: NutshellySima
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D48923
llvm-svn: 336294
2018-07-04 20:37:15 +02:00
|
|
|
DomTreeUpdater(DominatorTree *DT_, PostDominatorTree *PDT_,
|
|
|
|
UpdateStrategy Strategy_)
|
|
|
|
: DT(DT_), PDT(PDT_), Strategy(Strategy_) {}
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
|
|
|
|
~DomTreeUpdater() { flush(); }
|
|
|
|
|
2018-07-12 06:08:14 +02:00
|
|
|
/// Returns true if the current strategy is Lazy.
|
|
|
|
bool isLazy() const { return Strategy == UpdateStrategy::Lazy; };
|
|
|
|
|
|
|
|
/// Returns true if the current strategy is Eager.
|
|
|
|
bool isEager() const { return Strategy == UpdateStrategy::Eager; };
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
|
|
|
|
/// Returns true if it holds a DominatorTree.
|
|
|
|
bool hasDomTree() const { return DT != nullptr; }
|
|
|
|
|
|
|
|
/// Returns true if it holds a PostDominatorTree.
|
|
|
|
bool hasPostDomTree() const { return PDT != nullptr; }
|
|
|
|
|
|
|
|
/// Returns true if there is BasicBlock awaiting deletion.
|
|
|
|
/// The deletion will only happen until a flush event and
|
|
|
|
/// all available trees are up-to-date.
|
|
|
|
/// Returns false under Eager UpdateStrategy.
|
|
|
|
bool hasPendingDeletedBB() const { return !DeletedBBs.empty(); }
|
|
|
|
|
|
|
|
/// Returns true if DelBB is awaiting deletion.
|
|
|
|
/// Returns false under Eager UpdateStrategy.
|
|
|
|
bool isBBPendingDeletion(BasicBlock *DelBB) const;
|
|
|
|
|
|
|
|
/// Returns true if either of DT or PDT is valid and the tree has at
|
|
|
|
/// least one update pending. If DT or PDT is nullptr it is treated
|
|
|
|
/// as having no pending updates. This function does not check
|
|
|
|
/// whether there is BasicBlock awaiting deletion.
|
|
|
|
/// Returns false under Eager UpdateStrategy.
|
|
|
|
bool hasPendingUpdates() const;
|
|
|
|
|
|
|
|
/// Returns true if there are DominatorTree updates queued.
|
2018-07-13 06:02:13 +02:00
|
|
|
/// Returns false under Eager UpdateStrategy or DT is nullptr.
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
bool hasPendingDomTreeUpdates() const;
|
|
|
|
|
|
|
|
/// Returns true if there are PostDominatorTree updates queued.
|
2018-07-13 06:02:13 +02:00
|
|
|
/// Returns false under Eager UpdateStrategy or PDT is nullptr.
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
bool hasPendingPostDomTreeUpdates() const;
|
|
|
|
|
2019-02-20 06:49:01 +01:00
|
|
|
///@{
|
|
|
|
/// \name Mutation APIs
|
|
|
|
///
|
|
|
|
/// These methods provide APIs for submitting updates to the DominatorTree and
|
|
|
|
/// the PostDominatorTree.
|
|
|
|
///
|
|
|
|
/// Note: There are two strategies to update the DominatorTree and the
|
|
|
|
/// PostDominatorTree:
|
|
|
|
/// 1. Eager UpdateStrategy: Updates are submitted and then flushed
|
|
|
|
/// immediately.
|
|
|
|
/// 2. Lazy UpdateStrategy: Updates are submitted but only flushed when you
|
|
|
|
/// explicitly call Flush APIs. It is recommended to use this update strategy
|
|
|
|
/// when you submit a bunch of updates multiple times which can then
|
|
|
|
/// add up to a large number of updates between two queries on the
|
|
|
|
/// DominatorTree. The incremental updater can reschedule the updates or
|
|
|
|
/// decide to recalculate the dominator tree in order to speedup the updating
|
|
|
|
/// process depending on the number of updates.
|
|
|
|
///
|
|
|
|
/// Although GenericDomTree provides several update primitives,
|
|
|
|
/// it is not encouraged to use these APIs directly.
|
|
|
|
|
[DTU] Refine the interface and logic of applyUpdates
Summary:
This patch separates two semantics of `applyUpdates`:
1. User provides an accurate CFG diff and the dominator tree is updated according to the difference of `the number of edge insertions` and `the number of edge deletions` to infer the status of an edge before and after the update.
2. User provides a sequence of hints. Updates mentioned in this sequence might never happened and even duplicated.
Logic changes:
Previously, removing invalid updates is considered a side-effect of deduplication and is not guaranteed to be reliable. To handle the second semantic, `applyUpdates` does validity checking before deduplication, which can cause updates that have already been applied to be submitted again. Then, different calls to `applyUpdates` might cause unintended consequences, for example,
```
DTU(Lazy) and Edge A->B exists.
1. DTU.applyUpdates({{Delete, A, B}, {Insert, A, B}}) // User expects these 2 updates result in a no-op, but {Insert, A, B} is queued
2. Remove A->B
3. DTU.applyUpdates({{Delete, A, B}}) // DTU cancels this update with {Insert, A, B} mentioned above together (Unintended)
```
But by restricting the precondition that updates of an edge need to be strictly ordered as how CFG changes were made, we can infer the initial status of this edge to resolve this issue.
Interface changes:
The second semantic of `applyUpdates` is separated to `applyUpdatesPermissive`.
These changes enable DTU(Lazy) to use the first semantic if needed, which is quite useful in `transforms/utils`.
Reviewers: kuhar, brzycki, dmgreen, grosser
Reviewed By: brzycki
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58170
llvm-svn: 354669
2019-02-22 14:48:38 +01:00
|
|
|
/// Submit updates to all available trees.
|
|
|
|
/// The Eager Strategy flushes updates immediately while the Lazy Strategy
|
|
|
|
/// queues the updates.
|
|
|
|
///
|
|
|
|
/// Note: The "existence" of an edge in a CFG refers to the CFG which DTU is
|
|
|
|
/// in sync with + all updates before that single update.
|
|
|
|
///
|
|
|
|
/// CAUTION!
|
|
|
|
/// 1. It is required for the state of the LLVM IR to be updated
|
|
|
|
/// *before* submitting the updates because the internal update routine will
|
|
|
|
/// analyze the current state of the CFG to determine whether an update
|
|
|
|
/// is valid.
|
|
|
|
/// 2. It is illegal to submit any update that has already been submitted,
|
|
|
|
/// i.e., you are supposed not to insert an existent edge or delete a
|
|
|
|
/// nonexistent edge.
|
|
|
|
void applyUpdates(ArrayRef<DominatorTree::UpdateType> Updates);
|
|
|
|
|
|
|
|
/// Submit updates to all available trees. It will also
|
2019-02-20 06:49:01 +01:00
|
|
|
/// 1. discard duplicated updates,
|
|
|
|
/// 2. remove invalid updates. (Invalid updates means deletion of an edge that
|
|
|
|
/// still exists or insertion of an edge that does not exist.)
|
|
|
|
/// The Eager Strategy flushes updates immediately while the Lazy Strategy
|
|
|
|
/// queues the updates.
|
|
|
|
///
|
|
|
|
/// Note: The "existence" of an edge in a CFG refers to the CFG which DTU is
|
|
|
|
/// in sync with + all updates before that single update.
|
|
|
|
///
|
|
|
|
/// CAUTION!
|
|
|
|
/// 1. It is required for the state of the LLVM IR to be updated
|
|
|
|
/// *before* submitting the updates because the internal update routine will
|
|
|
|
/// analyze the current state of the CFG to determine whether an update
|
|
|
|
/// is valid.
|
|
|
|
/// 2. It is illegal to submit any update that has already been submitted,
|
|
|
|
/// i.e., you are supposed not to insert an existent edge or delete a
|
|
|
|
/// nonexistent edge.
|
[DTU] Refine the interface and logic of applyUpdates
Summary:
This patch separates two semantics of `applyUpdates`:
1. User provides an accurate CFG diff and the dominator tree is updated according to the difference of `the number of edge insertions` and `the number of edge deletions` to infer the status of an edge before and after the update.
2. User provides a sequence of hints. Updates mentioned in this sequence might never happened and even duplicated.
Logic changes:
Previously, removing invalid updates is considered a side-effect of deduplication and is not guaranteed to be reliable. To handle the second semantic, `applyUpdates` does validity checking before deduplication, which can cause updates that have already been applied to be submitted again. Then, different calls to `applyUpdates` might cause unintended consequences, for example,
```
DTU(Lazy) and Edge A->B exists.
1. DTU.applyUpdates({{Delete, A, B}, {Insert, A, B}}) // User expects these 2 updates result in a no-op, but {Insert, A, B} is queued
2. Remove A->B
3. DTU.applyUpdates({{Delete, A, B}}) // DTU cancels this update with {Insert, A, B} mentioned above together (Unintended)
```
But by restricting the precondition that updates of an edge need to be strictly ordered as how CFG changes were made, we can infer the initial status of this edge to resolve this issue.
Interface changes:
The second semantic of `applyUpdates` is separated to `applyUpdatesPermissive`.
These changes enable DTU(Lazy) to use the first semantic if needed, which is quite useful in `transforms/utils`.
Reviewers: kuhar, brzycki, dmgreen, grosser
Reviewed By: brzycki
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58170
llvm-svn: 354669
2019-02-22 14:48:38 +01:00
|
|
|
/// 3. It is only legal to submit updates to an edge in the order CFG changes
|
|
|
|
/// are made. The order you submit updates on different edges is not
|
|
|
|
/// restricted.
|
|
|
|
void applyUpdatesPermissive(ArrayRef<DominatorTree::UpdateType> Updates);
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
|
2019-02-20 06:49:01 +01:00
|
|
|
/// Notify DTU that the entry block was replaced.
|
|
|
|
/// Recalculate all available trees and flush all BasicBlocks
|
|
|
|
/// awaiting deletion immediately.
|
|
|
|
void recalculate(Function &F);
|
|
|
|
|
|
|
|
/// \deprecated { Submit an edge insertion to all available trees. The Eager
|
|
|
|
/// Strategy flushes this update immediately while the Lazy Strategy queues
|
|
|
|
/// the update. An internal function checks if the edge exists in the CFG in
|
|
|
|
/// DEBUG mode. CAUTION! This function has to be called *after* making the
|
|
|
|
/// update on the actual CFG. It is illegal to submit any update that has
|
|
|
|
/// already been applied. }
|
2019-02-22 06:41:43 +01:00
|
|
|
LLVM_ATTRIBUTE_DEPRECATED(void insertEdge(BasicBlock *From, BasicBlock *To),
|
|
|
|
"Use applyUpdates() instead.");
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
|
2019-02-20 06:49:01 +01:00
|
|
|
/// \deprecated {Submit an edge insertion to all available trees.
|
|
|
|
/// Under either Strategy, an invalid update will be discard silently.
|
|
|
|
/// Invalid update means inserting an edge that does not exist in the CFG.
|
|
|
|
/// The Eager Strategy flushes this update immediately while the Lazy Strategy
|
|
|
|
/// queues the update. It is only recommended to use this method when you
|
|
|
|
/// want to discard an invalid update.
|
|
|
|
/// CAUTION! It is illegal to submit any update that has already been
|
|
|
|
/// submitted. }
|
2019-02-22 06:41:43 +01:00
|
|
|
LLVM_ATTRIBUTE_DEPRECATED(void insertEdgeRelaxed(BasicBlock *From,
|
|
|
|
BasicBlock *To),
|
[DTU] Refine the interface and logic of applyUpdates
Summary:
This patch separates two semantics of `applyUpdates`:
1. User provides an accurate CFG diff and the dominator tree is updated according to the difference of `the number of edge insertions` and `the number of edge deletions` to infer the status of an edge before and after the update.
2. User provides a sequence of hints. Updates mentioned in this sequence might never happened and even duplicated.
Logic changes:
Previously, removing invalid updates is considered a side-effect of deduplication and is not guaranteed to be reliable. To handle the second semantic, `applyUpdates` does validity checking before deduplication, which can cause updates that have already been applied to be submitted again. Then, different calls to `applyUpdates` might cause unintended consequences, for example,
```
DTU(Lazy) and Edge A->B exists.
1. DTU.applyUpdates({{Delete, A, B}, {Insert, A, B}}) // User expects these 2 updates result in a no-op, but {Insert, A, B} is queued
2. Remove A->B
3. DTU.applyUpdates({{Delete, A, B}}) // DTU cancels this update with {Insert, A, B} mentioned above together (Unintended)
```
But by restricting the precondition that updates of an edge need to be strictly ordered as how CFG changes were made, we can infer the initial status of this edge to resolve this issue.
Interface changes:
The second semantic of `applyUpdates` is separated to `applyUpdatesPermissive`.
These changes enable DTU(Lazy) to use the first semantic if needed, which is quite useful in `transforms/utils`.
Reviewers: kuhar, brzycki, dmgreen, grosser
Reviewed By: brzycki
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58170
llvm-svn: 354669
2019-02-22 14:48:38 +01:00
|
|
|
"Use applyUpdatesPermissive() instead.");
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
|
2019-02-20 06:49:01 +01:00
|
|
|
/// \deprecated { Submit an edge deletion to all available trees. The Eager
|
|
|
|
/// Strategy flushes this update immediately while the Lazy Strategy queues
|
|
|
|
/// the update. An internal function checks if the edge doesn't exist in the
|
|
|
|
/// CFG in DEBUG mode.
|
|
|
|
/// CAUTION! This function has to be called *after* making the update on the
|
|
|
|
/// actual CFG. It is illegal to submit any update that has already been
|
|
|
|
/// submitted. }
|
2019-02-22 06:41:43 +01:00
|
|
|
LLVM_ATTRIBUTE_DEPRECATED(void deleteEdge(BasicBlock *From, BasicBlock *To),
|
|
|
|
"Use applyUpdates() instead.");
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
|
2019-02-20 06:49:01 +01:00
|
|
|
/// \deprecated { Submit an edge deletion to all available trees.
|
|
|
|
/// Under either Strategy, an invalid update will be discard silently.
|
|
|
|
/// Invalid update means deleting an edge that exists in the CFG.
|
|
|
|
/// The Eager Strategy flushes this update immediately while the Lazy Strategy
|
|
|
|
/// queues the update. It is only recommended to use this method when you
|
|
|
|
/// want to discard an invalid update.
|
|
|
|
/// CAUTION! It is illegal to submit any update that has already been
|
|
|
|
/// submitted. }
|
2019-02-22 06:41:43 +01:00
|
|
|
LLVM_ATTRIBUTE_DEPRECATED(void deleteEdgeRelaxed(BasicBlock *From,
|
|
|
|
BasicBlock *To),
|
[DTU] Refine the interface and logic of applyUpdates
Summary:
This patch separates two semantics of `applyUpdates`:
1. User provides an accurate CFG diff and the dominator tree is updated according to the difference of `the number of edge insertions` and `the number of edge deletions` to infer the status of an edge before and after the update.
2. User provides a sequence of hints. Updates mentioned in this sequence might never happened and even duplicated.
Logic changes:
Previously, removing invalid updates is considered a side-effect of deduplication and is not guaranteed to be reliable. To handle the second semantic, `applyUpdates` does validity checking before deduplication, which can cause updates that have already been applied to be submitted again. Then, different calls to `applyUpdates` might cause unintended consequences, for example,
```
DTU(Lazy) and Edge A->B exists.
1. DTU.applyUpdates({{Delete, A, B}, {Insert, A, B}}) // User expects these 2 updates result in a no-op, but {Insert, A, B} is queued
2. Remove A->B
3. DTU.applyUpdates({{Delete, A, B}}) // DTU cancels this update with {Insert, A, B} mentioned above together (Unintended)
```
But by restricting the precondition that updates of an edge need to be strictly ordered as how CFG changes were made, we can infer the initial status of this edge to resolve this issue.
Interface changes:
The second semantic of `applyUpdates` is separated to `applyUpdatesPermissive`.
These changes enable DTU(Lazy) to use the first semantic if needed, which is quite useful in `transforms/utils`.
Reviewers: kuhar, brzycki, dmgreen, grosser
Reviewed By: brzycki
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58170
llvm-svn: 354669
2019-02-22 14:48:38 +01:00
|
|
|
"Use applyUpdatesPermissive() instead.");
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
|
|
|
|
/// Delete DelBB. DelBB will be removed from its Parent and
|
|
|
|
/// erased from available trees if it exists and finally get deleted.
|
|
|
|
/// Under Eager UpdateStrategy, DelBB will be processed immediately.
|
|
|
|
/// Under Lazy UpdateStrategy, DelBB will be queued until a flush event and
|
2018-07-25 08:18:33 +02:00
|
|
|
/// all available trees are up-to-date. Assert if any instruction of DelBB is
|
|
|
|
/// modified while awaiting deletion. When both DT and PDT are nullptrs, DelBB
|
|
|
|
/// will be queued until flush() is called.
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
void deleteBB(BasicBlock *DelBB);
|
|
|
|
|
|
|
|
/// Delete DelBB. DelBB will be removed from its Parent and
|
|
|
|
/// erased from available trees if it exists. Then the callback will
|
|
|
|
/// be called. Finally, DelBB will be deleted.
|
|
|
|
/// Under Eager UpdateStrategy, DelBB will be processed immediately.
|
|
|
|
/// Under Lazy UpdateStrategy, DelBB will be queued until a flush event and
|
2018-07-25 08:18:33 +02:00
|
|
|
/// all available trees are up-to-date. Assert if any instruction of DelBB is
|
|
|
|
/// modified while awaiting deletion. Multiple callbacks can be queued for one
|
|
|
|
/// DelBB under Lazy UpdateStrategy.
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
void callbackDeleteBB(BasicBlock *DelBB,
|
|
|
|
std::function<void(BasicBlock *)> Callback);
|
|
|
|
|
2019-02-20 06:49:01 +01:00
|
|
|
///@}
|
|
|
|
|
|
|
|
///@{
|
|
|
|
/// \name Flush APIs
|
|
|
|
///
|
|
|
|
/// CAUTION! By the moment these flush APIs are called, the current CFG needs
|
|
|
|
/// to be the same as the CFG which DTU is in sync with + all updates
|
|
|
|
/// submitted.
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
|
|
|
|
/// Flush DomTree updates and return DomTree.
|
2019-02-20 06:49:01 +01:00
|
|
|
/// It flushes Deleted BBs if both trees are up-to-date.
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
/// It must only be called when it has a DomTree.
|
|
|
|
DominatorTree &getDomTree();
|
|
|
|
|
|
|
|
/// Flush PostDomTree updates and return PostDomTree.
|
2019-02-20 06:49:01 +01:00
|
|
|
/// It flushes Deleted BBs if both trees are up-to-date.
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
/// It must only be called when it has a PostDomTree.
|
|
|
|
PostDominatorTree &getPostDomTree();
|
|
|
|
|
|
|
|
/// Apply all pending updates to available trees and flush all BasicBlocks
|
|
|
|
/// awaiting deletion.
|
2019-02-20 06:49:01 +01:00
|
|
|
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
void flush();
|
|
|
|
|
2019-02-20 06:49:01 +01:00
|
|
|
///@}
|
|
|
|
|
Reappl "[Dominators] Add the DomTreeUpdater class"
Summary:
This patch is the first in a series of patches related to the [[ http://lists.llvm.org/pipermail/llvm-dev/2018-June/123883.html | RFC - A new dominator tree updater for LLVM ]].
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
—After the patch—
Patch by Chijun Sima <simachijun@gmail.com>.
Reviewers: kuhar, brzycki, dmgreen, grosser, davide
Reviewed By: kuhar, brzycki
Author: NutshellySima
Subscribers: vsk, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48383
llvm-svn: 336163
2018-07-03 04:06:23 +02:00
|
|
|
/// Debug method to help view the internal state of this class.
|
|
|
|
LLVM_DUMP_METHOD void dump() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
class CallBackOnDeletion final : public CallbackVH {
|
|
|
|
public:
|
|
|
|
CallBackOnDeletion(BasicBlock *V,
|
|
|
|
std::function<void(BasicBlock *)> Callback)
|
|
|
|
: CallbackVH(V), DelBB(V), Callback_(Callback) {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
BasicBlock *DelBB = nullptr;
|
|
|
|
std::function<void(BasicBlock *)> Callback_;
|
|
|
|
|
|
|
|
void deleted() override {
|
|
|
|
Callback_(DelBB);
|
|
|
|
CallbackVH::deleted();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SmallVector<DominatorTree::UpdateType, 16> PendUpdates;
|
|
|
|
size_t PendDTUpdateIndex = 0;
|
|
|
|
size_t PendPDTUpdateIndex = 0;
|
|
|
|
DominatorTree *DT = nullptr;
|
|
|
|
PostDominatorTree *PDT = nullptr;
|
|
|
|
const UpdateStrategy Strategy;
|
|
|
|
SmallPtrSet<BasicBlock *, 8> DeletedBBs;
|
|
|
|
std::vector<CallBackOnDeletion> Callbacks;
|
|
|
|
bool IsRecalculatingDomTree = false;
|
|
|
|
bool IsRecalculatingPostDomTree = false;
|
|
|
|
|
|
|
|
/// First remove all the instructions of DelBB and then make sure DelBB has a
|
|
|
|
/// valid terminator instruction which is necessary to have when DelBB still
|
|
|
|
/// has to be inside of its parent Function while awaiting deletion under Lazy
|
|
|
|
/// UpdateStrategy to prevent other routines from asserting the state of the
|
|
|
|
/// IR is inconsistent. Assert if DelBB is nullptr or has predecessors.
|
|
|
|
void validateDeleteBB(BasicBlock *DelBB);
|
|
|
|
|
|
|
|
/// Returns true if at least one BasicBlock is deleted.
|
|
|
|
bool forceFlushDeletedBB();
|
|
|
|
|
|
|
|
/// Helper function to apply all pending DomTree updates.
|
|
|
|
void applyDomTreeUpdates();
|
|
|
|
|
|
|
|
/// Helper function to apply all pending PostDomTree updates.
|
|
|
|
void applyPostDomTreeUpdates();
|
|
|
|
|
|
|
|
/// Helper function to flush deleted BasicBlocks if all available
|
|
|
|
/// trees are up-to-date.
|
|
|
|
void tryFlushDeletedBB();
|
|
|
|
|
|
|
|
/// Drop all updates applied by all available trees and delete BasicBlocks if
|
|
|
|
/// all available trees are up-to-date.
|
|
|
|
void dropOutOfDateUpdates();
|
|
|
|
|
|
|
|
/// Erase Basic Block node that has been unlinked from Function
|
|
|
|
/// in the DomTree and PostDomTree.
|
|
|
|
void eraseDelBBNode(BasicBlock *DelBB);
|
|
|
|
|
|
|
|
/// Returns true if the update appears in the LLVM IR.
|
|
|
|
/// It is used to check whether an update is valid in
|
|
|
|
/// insertEdge/deleteEdge or is unnecessary in the batch update.
|
|
|
|
bool isUpdateValid(DominatorTree::UpdateType Update) const;
|
|
|
|
|
|
|
|
/// Returns true if the update is self dominance.
|
|
|
|
bool isSelfDominance(DominatorTree::UpdateType Update) const;
|
|
|
|
};
|
|
|
|
} // namespace llvm
|
|
|
|
|
2019-02-06 03:52:52 +01:00
|
|
|
#endif // LLVM_ANALYSIS_DOMTREEUPDATER_H
|