@@ -73,33 +73,36 @@ class BufferPlacementAllocs {
73
73
AllocEntryList allocs;
74
74
};
75
75
76
+ // / Finds a common dominator for the given value while taking the positions
77
+ // / of the values in the value set into account. It supports dominator and
78
+ // / post-dominator analyses via template arguments. If no common dominator
79
+ // / can be found, this function will return "nullptr".
80
+ template <typename DominatorT>
81
+ Block *findCommonDominator (Value value,
82
+ const BufferViewFlowAnalysis::ValueSetT &values,
83
+ const DominatorT &doms) {
84
+ // Store blocks in a set before querying `DominanceInfo` to filter out
85
+ // duplicate blocks (for performance reasons).
86
+ llvm::SmallPtrSet<Block *, 16 > blocks;
87
+ // Start with the current block the value is defined in.
88
+ blocks.insert (value.getParentBlock ());
89
+ for (Value childValue : values) {
90
+ for (Operation *user : childValue.getUsers ()) {
91
+ // Find an appropriate dominator block that takes the current use into
92
+ // account.
93
+ blocks.insert (user->getBlock ());
94
+ }
95
+ // Take values without any users into account.
96
+ blocks.insert (childValue.getParentBlock ());
97
+ }
98
+ return doms.findNearestCommonDominator (blocks);
99
+ }
100
+
76
101
// / The base class for all BufferPlacement transformations.
77
102
class BufferPlacementTransformationBase {
78
103
public:
79
104
using ValueSetT = BufferViewFlowAnalysis::ValueSetT;
80
105
81
- // / Finds a common dominator for the given value while taking the positions
82
- // / of the values in the value set into account. It supports dominator and
83
- // / post-dominator analyses via template arguments.
84
- template <typename DominatorT>
85
- static Block *findCommonDominator (Value value, const ValueSetT &values,
86
- const DominatorT &doms) {
87
- // Start with the current block the value is defined in.
88
- Block *dom = value.getParentBlock ();
89
- // Iterate over all aliases and their uses to find a safe placement block
90
- // according to the given dominator information.
91
- for (Value childValue : values) {
92
- for (Operation *user : childValue.getUsers ()) {
93
- // Move upwards in the dominator tree to find an appropriate
94
- // dominator block that takes the current use into account.
95
- dom = doms.findNearestCommonDominator (dom, user->getBlock ());
96
- }
97
- // Take values without any users into account.
98
- dom = doms.findNearestCommonDominator (dom, childValue.getParentBlock ());
99
- }
100
- return dom;
101
- }
102
-
103
106
// / Constructs a new operation base using the given root operation.
104
107
BufferPlacementTransformationBase (Operation *op);
105
108
0 commit comments