10
10
#include < cassert>
11
11
#include < mlir/Analysis/DataFlow/LivenessAnalysis.h>
12
12
13
- #include < llvm/Support/Debug .h>
13
+ #include < llvm/Support/DebugLog .h>
14
14
#include < mlir/Analysis/DataFlow/SparseAnalysis.h>
15
15
#include < mlir/Analysis/DataFlow/Utils.h>
16
16
#include < mlir/Analysis/DataFlowFramework.h>
22
22
23
23
#define DEBUG_TYPE " liveness-analysis"
24
24
#define DBGS () (llvm::dbgs() << ' [' << DEBUG_TYPE << " ] " )
25
- #define LDBG (X ) LLVM_DEBUG(DBGS() << X << " \n " )
26
25
27
26
using namespace mlir ;
28
27
using namespace mlir ::dataflow;
@@ -86,11 +85,11 @@ LivenessAnalysis::visitOperation(Operation *op, ArrayRef<Liveness *> operands,
86
85
llvm::dbgs () << " \n " );
87
86
// This marks values of type (1.a) and (4) liveness as "live".
88
87
if (!isMemoryEffectFree (op) || op->hasTrait <OpTrait::ReturnLike>()) {
89
- LDBG (" [visitOperation] Operation has memory effects or is "
90
- " return-like, marking operands live" ) ;
88
+ LDBG () << " [visitOperation] Operation has memory effects or is "
89
+ " return-like, marking operands live" ;
91
90
for (auto *operand : operands) {
92
- LDBG (" [visitOperation] Marking operand live: "
93
- << operand << " ( " << operand->isLive << " )" ) ;
91
+ LDBG () << " [visitOperation] Marking operand live: " << operand << " ( "
92
+ << operand->isLive << " )" ;
94
93
propagateIfChanged (operand, operand->markLive ());
95
94
}
96
95
}
@@ -99,28 +98,28 @@ LivenessAnalysis::visitOperation(Operation *op, ArrayRef<Liveness *> operands,
99
98
bool foundLiveResult = false ;
100
99
for (const Liveness *r : results) {
101
100
if (r->isLive && !foundLiveResult) {
102
- LDBG (" [visitOperation] Found live result, "
103
- " meeting all operands with result: "
104
- << r) ;
101
+ LDBG () << " [visitOperation] Found live result, "
102
+ " meeting all operands with result: "
103
+ << r;
105
104
// It is assumed that each operand is used to compute each result of an
106
105
// op. Thus, if at least one result is live, each operand is live.
107
106
for (Liveness *operand : operands) {
108
- LDBG (" [visitOperation] Meeting operand: " << operand
109
- << " with result: " << r) ;
107
+ LDBG () << " [visitOperation] Meeting operand: " << operand
108
+ << " with result: " << r;
110
109
meet (operand, *r);
111
110
}
112
111
foundLiveResult = true ;
113
112
}
114
- LDBG (" [visitOperation] Adding dependency for result: " << r << " after op: "
115
- << *op) ;
113
+ LDBG () << " [visitOperation] Adding dependency for result: " << r
114
+ << " after op: " << *op;
116
115
addDependency (const_cast <Liveness *>(r), getProgramPointAfter (op));
117
116
}
118
117
return success ();
119
118
}
120
119
121
120
void LivenessAnalysis::visitBranchOperand (OpOperand &operand) {
122
- LDBG (" Visiting branch operand: " << operand.get ()
123
- << " in op: " << *operand.getOwner () );
121
+ LDBG () << " Visiting branch operand: " << operand.get ()
122
+ << " in op: " << *operand.getOwner ();
124
123
// We know (at the moment) and assume (for the future) that `operand` is a
125
124
// non-forwarded branch operand of a `RegionBranchOpInterface`,
126
125
// `BranchOpInterface`, `RegionBranchTerminatorOpInterface` or return-like op.
@@ -152,9 +151,9 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
152
151
for (Value result : op->getResults ()) {
153
152
if (getLatticeElement (result)->isLive ) {
154
153
mayLive = true ;
155
- LDBG (" [visitBranchOperand] Non-forwarded branch "
156
- " operand may be live due to live result: "
157
- << result) ;
154
+ LDBG () << " [visitBranchOperand] Non-forwarded branch "
155
+ " operand may be live due to live result: "
156
+ << result;
158
157
break ;
159
158
}
160
159
}
@@ -174,8 +173,8 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
174
173
// Therefore, we conservatively consider the non-forwarded operand of the
175
174
// branch operation may live.
176
175
mayLive = true ;
177
- LDBG (" [visitBranchOperand] Non-forwarded branch operand may "
178
- " be live due to branch op interface" ) ;
176
+ LDBG () << " [visitBranchOperand] Non-forwarded branch operand may "
177
+ " be live due to branch op interface" ;
179
178
} else {
180
179
Operation *parentOp = op->getParentOp ();
181
180
assert (isa<RegionBranchOpInterface>(parentOp) &&
@@ -191,9 +190,9 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
191
190
for (Value result : parentOp->getResults ()) {
192
191
if (getLatticeElement (result)->isLive ) {
193
192
mayLive = true ;
194
- LDBG (" [visitBranchOperand] Non-forwarded branch "
195
- " operand may be live due to parent live result: "
196
- << result) ;
193
+ LDBG () << " [visitBranchOperand] Non-forwarded branch "
194
+ " operand may be live due to parent live result: "
195
+ << result;
197
196
break ;
198
197
}
199
198
}
@@ -214,17 +213,17 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
214
213
for (Operation &nestedOp : *block) {
215
214
if (!isMemoryEffectFree (&nestedOp)) {
216
215
mayLive = true ;
217
- LDBG (" Non-forwarded branch operand may be "
218
- " live due to memory effect in block: "
219
- << block) ;
216
+ LDBG () << " Non-forwarded branch operand may be "
217
+ " live due to memory effect in block: "
218
+ << block;
220
219
break ;
221
220
}
222
221
}
223
222
}
224
223
225
224
if (mayLive) {
226
225
Liveness *operandLiveness = getLatticeElement (operand.get ());
227
- LDBG (" Marking branch operand live: " << operand.get () );
226
+ LDBG () << " Marking branch operand live: " << operand.get ();
228
227
propagateIfChanged (operandLiveness, operandLiveness->markLive ());
229
228
}
230
229
@@ -236,7 +235,7 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
236
235
SmallVector<const Liveness *, 4 > resultsLiveness;
237
236
for (const Value result : op->getResults ())
238
237
resultsLiveness.push_back (getLatticeElement (result));
239
- LDBG (" Visiting operation for non-forwarded branch operand: " << *op) ;
238
+ LDBG () << " Visiting operation for non-forwarded branch operand: " << *op;
240
239
(void )visitOperation (op, operandLiveness, resultsLiveness);
241
240
242
241
// We also visit the parent op with the parent's results and this operand if
@@ -249,14 +248,14 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
249
248
SmallVector<const Liveness *, 4 > parentResultsLiveness;
250
249
for (const Value parentResult : parentOp->getResults ())
251
250
parentResultsLiveness.push_back (getLatticeElement (parentResult));
252
- LDBG (" Visiting parent operation for non-forwarded branch operand: "
253
- << *parentOp) ;
251
+ LDBG () << " Visiting parent operation for non-forwarded branch operand: "
252
+ << *parentOp;
254
253
(void )visitOperation (parentOp, operandLiveness, parentResultsLiveness);
255
254
}
256
255
257
256
void LivenessAnalysis::visitCallOperand (OpOperand &operand) {
258
- LDBG (" Visiting call operand: " << operand.get ()
259
- << " in op: " << *operand.getOwner () );
257
+ LDBG () << " Visiting call operand: " << operand.get ()
258
+ << " in op: " << *operand.getOwner ();
260
259
// We know (at the moment) and assume (for the future) that `operand` is a
261
260
// non-forwarded call operand of an op implementing `CallOpInterface`.
262
261
assert (isa<CallOpInterface>(operand.getOwner ()) &&
@@ -269,18 +268,18 @@ void LivenessAnalysis::visitCallOperand(OpOperand &operand) {
269
268
// This marks values of type (1.c) liveness as "live". A non-forwarded
270
269
// call operand is live.
271
270
Liveness *operandLiveness = getLatticeElement (operand.get ());
272
- LDBG (" Marking call operand live: " << operand.get () );
271
+ LDBG () << " Marking call operand live: " << operand.get ();
273
272
propagateIfChanged (operandLiveness, operandLiveness->markLive ());
274
273
}
275
274
276
275
void LivenessAnalysis::setToExitState (Liveness *lattice) {
277
- LDBG (" setToExitState for lattice: " << lattice) ;
276
+ LDBG () << " setToExitState for lattice: " << lattice;
278
277
if (lattice->isLive ) {
279
- LDBG (" Lattice already live, nothing to do" ) ;
278
+ LDBG () << " Lattice already live, nothing to do" ;
280
279
return ;
281
280
}
282
281
// This marks values of type (2) liveness as "live".
283
- LDBG (" Marking lattice live due to exit state" ) ;
282
+ LDBG () << " Marking lattice live due to exit state" ;
284
283
(void )lattice->markLive ();
285
284
propagateIfChanged (lattice, ChangeResult::Change);
286
285
}
@@ -290,14 +289,14 @@ void LivenessAnalysis::setToExitState(Liveness *lattice) {
290
289
// ===----------------------------------------------------------------------===//
291
290
292
291
RunLivenessAnalysis::RunLivenessAnalysis (Operation *op) {
293
- LDBG (" Constructing RunLivenessAnalysis for op: " << op->getName () );
292
+ LDBG () << " Constructing RunLivenessAnalysis for op: " << op->getName ();
294
293
SymbolTableCollection symbolTable;
295
294
296
295
loadBaselineAnalyses (solver);
297
296
solver.load <LivenessAnalysis>(symbolTable);
298
- LDBG (" Initializing and running solver" ) ;
297
+ LDBG () << " Initializing and running solver" ;
299
298
(void )solver.initializeAndRun (op);
300
- LDBG (" Dumping liveness state for op" ) ;
299
+ LDBG () << " Dumping liveness state for op" ;
301
300
}
302
301
303
302
const Liveness *RunLivenessAnalysis::getLiveness (Value val) {
0 commit comments