1010#include < cassert>
1111#include < mlir/Analysis/DataFlow/LivenessAnalysis.h>
1212
13- #include < llvm/Support/Debug .h>
13+ #include < llvm/Support/DebugLog .h>
1414#include < mlir/Analysis/DataFlow/SparseAnalysis.h>
1515#include < mlir/Analysis/DataFlow/Utils.h>
1616#include < mlir/Analysis/DataFlowFramework.h>
2222
2323#define DEBUG_TYPE " liveness-analysis"
2424#define DBGS () (llvm::dbgs() << ' [' << DEBUG_TYPE << " ] " )
25- #define LDBG (X ) LLVM_DEBUG(DBGS() << X << " \n " )
2625
2726using namespace mlir ;
2827using namespace mlir ::dataflow;
@@ -86,11 +85,11 @@ LivenessAnalysis::visitOperation(Operation *op, ArrayRef<Liveness *> operands,
8685 llvm::dbgs () << " \n " );
8786 // This marks values of type (1.a) and (4) liveness as "live".
8887 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" ;
9190 for (auto *operand : operands) {
92- LDBG (" [visitOperation] Marking operand live: "
93- << operand << " ( " << operand->isLive << " )" ) ;
91+ LDBG () << " [visitOperation] Marking operand live: " << operand << " ( "
92+ << operand->isLive << " )" ;
9493 propagateIfChanged (operand, operand->markLive ());
9594 }
9695 }
@@ -99,28 +98,28 @@ LivenessAnalysis::visitOperation(Operation *op, ArrayRef<Liveness *> operands,
9998 bool foundLiveResult = false ;
10099 for (const Liveness *r : results) {
101100 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;
105104 // It is assumed that each operand is used to compute each result of an
106105 // op. Thus, if at least one result is live, each operand is live.
107106 for (Liveness *operand : operands) {
108- LDBG (" [visitOperation] Meeting operand: " << operand
109- << " with result: " << r) ;
107+ LDBG () << " [visitOperation] Meeting operand: " << operand
108+ << " with result: " << r;
110109 meet (operand, *r);
111110 }
112111 foundLiveResult = true ;
113112 }
114- LDBG (" [visitOperation] Adding dependency for result: " << r << " after op: "
115- << *op) ;
113+ LDBG () << " [visitOperation] Adding dependency for result: " << r
114+ << " after op: " << *op;
116115 addDependency (const_cast <Liveness *>(r), getProgramPointAfter (op));
117116 }
118117 return success ();
119118}
120119
121120void 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 ();
124123 // We know (at the moment) and assume (for the future) that `operand` is a
125124 // non-forwarded branch operand of a `RegionBranchOpInterface`,
126125 // `BranchOpInterface`, `RegionBranchTerminatorOpInterface` or return-like op.
@@ -152,9 +151,9 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
152151 for (Value result : op->getResults ()) {
153152 if (getLatticeElement (result)->isLive ) {
154153 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;
158157 break ;
159158 }
160159 }
@@ -174,8 +173,8 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
174173 // Therefore, we conservatively consider the non-forwarded operand of the
175174 // branch operation may live.
176175 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" ;
179178 } else {
180179 Operation *parentOp = op->getParentOp ();
181180 assert (isa<RegionBranchOpInterface>(parentOp) &&
@@ -191,9 +190,9 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
191190 for (Value result : parentOp->getResults ()) {
192191 if (getLatticeElement (result)->isLive ) {
193192 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;
197196 break ;
198197 }
199198 }
@@ -214,17 +213,17 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
214213 for (Operation &nestedOp : *block) {
215214 if (!isMemoryEffectFree (&nestedOp)) {
216215 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;
220219 break ;
221220 }
222221 }
223222 }
224223
225224 if (mayLive) {
226225 Liveness *operandLiveness = getLatticeElement (operand.get ());
227- LDBG (" Marking branch operand live: " << operand.get () );
226+ LDBG () << " Marking branch operand live: " << operand.get ();
228227 propagateIfChanged (operandLiveness, operandLiveness->markLive ());
229228 }
230229
@@ -236,7 +235,7 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
236235 SmallVector<const Liveness *, 4 > resultsLiveness;
237236 for (const Value result : op->getResults ())
238237 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;
240239 (void )visitOperation (op, operandLiveness, resultsLiveness);
241240
242241 // We also visit the parent op with the parent's results and this operand if
@@ -249,14 +248,14 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
249248 SmallVector<const Liveness *, 4 > parentResultsLiveness;
250249 for (const Value parentResult : parentOp->getResults ())
251250 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;
254253 (void )visitOperation (parentOp, operandLiveness, parentResultsLiveness);
255254}
256255
257256void 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 ();
260259 // We know (at the moment) and assume (for the future) that `operand` is a
261260 // non-forwarded call operand of an op implementing `CallOpInterface`.
262261 assert (isa<CallOpInterface>(operand.getOwner ()) &&
@@ -269,18 +268,18 @@ void LivenessAnalysis::visitCallOperand(OpOperand &operand) {
269268 // This marks values of type (1.c) liveness as "live". A non-forwarded
270269 // call operand is live.
271270 Liveness *operandLiveness = getLatticeElement (operand.get ());
272- LDBG (" Marking call operand live: " << operand.get () );
271+ LDBG () << " Marking call operand live: " << operand.get ();
273272 propagateIfChanged (operandLiveness, operandLiveness->markLive ());
274273}
275274
276275void LivenessAnalysis::setToExitState (Liveness *lattice) {
277- LDBG (" setToExitState for lattice: " << lattice) ;
276+ LDBG () << " setToExitState for lattice: " << lattice;
278277 if (lattice->isLive ) {
279- LDBG (" Lattice already live, nothing to do" ) ;
278+ LDBG () << " Lattice already live, nothing to do" ;
280279 return ;
281280 }
282281 // 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" ;
284283 (void )lattice->markLive ();
285284 propagateIfChanged (lattice, ChangeResult::Change);
286285}
@@ -290,14 +289,14 @@ void LivenessAnalysis::setToExitState(Liveness *lattice) {
290289// ===----------------------------------------------------------------------===//
291290
292291RunLivenessAnalysis::RunLivenessAnalysis (Operation *op) {
293- LDBG (" Constructing RunLivenessAnalysis for op: " << op->getName () );
292+ LDBG () << " Constructing RunLivenessAnalysis for op: " << op->getName ();
294293 SymbolTableCollection symbolTable;
295294
296295 loadBaselineAnalyses (solver);
297296 solver.load <LivenessAnalysis>(symbolTable);
298- LDBG (" Initializing and running solver" ) ;
297+ LDBG () << " Initializing and running solver" ;
299298 (void )solver.initializeAndRun (op);
300- LDBG (" Dumping liveness state for op" ) ;
299+ LDBG () << " Dumping liveness state for op" ;
301300}
302301
303302const Liveness *RunLivenessAnalysis::getLiveness (Value val) {
0 commit comments