@@ -63,21 +63,16 @@ struct BlockInfoBuilder {
63
63
for (Value result : operation.getResults ())
64
64
gatherOutValues (result);
65
65
66
- // Mark all nested operation results as defined.
66
+ // Mark all nested operation results as defined, and nested operation
67
+ // operands as used. All defined value will be removed from the used set
68
+ // at the end.
67
69
block->walk ([&](Operation *op) {
68
70
for (Value result : op->getResults ())
69
71
defValues.insert (result);
72
+ for (Value operand : op->getOperands ())
73
+ useValues.insert (operand);
70
74
});
71
-
72
- // Check all operations for used operands.
73
- block->walk ([&](Operation *op) {
74
- for (Value operand : op->getOperands ()) {
75
- // If the operand is already defined in the scope of this
76
- // block, we can skip the value in the use set.
77
- if (!defValues.count (operand))
78
- useValues.insert (operand);
79
- }
80
- });
75
+ llvm::set_subtract (useValues, defValues);
81
76
}
82
77
83
78
// / Updates live-in information of the current block. To do so it uses the
@@ -94,16 +89,16 @@ struct BlockInfoBuilder {
94
89
if (newIn.size () == inValues.size ())
95
90
return false ;
96
91
97
- inValues = newIn;
92
+ inValues = std::move ( newIn) ;
98
93
return true ;
99
94
}
100
95
101
96
// / Updates live-out information of the current block. It iterates over all
102
97
// / successors and unifies their live-in values with the current live-out
103
98
// / values.
104
- template < typename SourceT> void updateLiveOut (SourceT &source ) {
99
+ void updateLiveOut (const DenseMap<Block *, BlockInfoBuilder> &builders ) {
105
100
for (Block *succ : block->getSuccessors ()) {
106
- BlockInfoBuilder &builder = source[ succ] ;
101
+ const BlockInfoBuilder &builder = builders. find ( succ)-> second ;
107
102
llvm::set_union (outValues, builder.inValues );
108
103
}
109
104
}
@@ -138,7 +133,7 @@ static void buildBlockMapping(Operation *operation,
138
133
toProcess.insert (block->pred_begin (), block->pred_end ());
139
134
});
140
135
141
- // Propagate the in and out-value sets (fixpoint iteration)
136
+ // Propagate the in and out-value sets (fixpoint iteration).
142
137
while (!toProcess.empty ()) {
143
138
Block *current = toProcess.pop_back_val ();
144
139
BlockInfoBuilder &builder = builders[current];
@@ -162,7 +157,6 @@ Liveness::Liveness(Operation *op) : operation(op) { build(); }
162
157
163
158
// / Initializes the internal mappings.
164
159
void Liveness::build () {
165
-
166
160
// Build internal block mapping.
167
161
DenseMap<Block *, BlockInfoBuilder> builders;
168
162
buildBlockMapping (operation, builders);
@@ -242,9 +236,8 @@ const Liveness::ValueSetT &Liveness::getLiveOut(Block *block) const {
242
236
return getLiveness (block)->out ();
243
237
}
244
238
245
- // / Returns true if the given operation represent the last use of the given
246
- // / value.
247
- bool Liveness::isLastUse (Value value, Operation *operation) const {
239
+ // / Returns true if `value` is not live after `operation`.
240
+ bool Liveness::isDeadAfter (Value value, Operation *operation) const {
248
241
Block *block = operation->getBlock ();
249
242
const LivenessBlockInfo *blockInfo = getLiveness (block);
250
243
0 commit comments