@@ -79,9 +79,17 @@ void Executable::onUpdate(DataFlowSolver *solver) const {
79
79
void PredecessorState::print (raw_ostream &os) const {
80
80
if (allPredecessorsKnown ())
81
81
os << " (all) " ;
82
- os << " predecessors:\n " ;
83
- for (Operation *op : getKnownPredecessors ())
84
- os << " " << *op << " \n " ;
82
+ os << " predecessors:" ;
83
+ if (getKnownPredecessors ().empty ())
84
+ os << " (none)" ;
85
+ else
86
+ os << " \n " ;
87
+ llvm::interleave (
88
+ getKnownPredecessors (), os,
89
+ [&](Operation *op) {
90
+ os << " " << OpWithFlags (op, OpPrintingFlags ().skipRegions ());
91
+ },
92
+ " \n " );
85
93
}
86
94
87
95
ChangeResult PredecessorState::join (Operation *predecessor) {
@@ -128,15 +136,16 @@ DeadCodeAnalysis::DeadCodeAnalysis(DataFlowSolver &solver)
128
136
129
137
LogicalResult DeadCodeAnalysis::initialize (Operation *top) {
130
138
LDBG () << " Initializing DeadCodeAnalysis for top-level op: "
131
- << top-> getName ( );
139
+ << OpWithFlags ( top, OpPrintingFlags (). skipRegions () );
132
140
// Mark the top-level blocks as executable.
133
141
for (Region ®ion : top->getRegions ()) {
134
142
if (region.empty ())
135
143
continue ;
136
144
auto *state =
137
145
getOrCreate<Executable>(getProgramPointBefore (®ion.front ()));
138
146
propagateIfChanged (state, state->setToLive ());
139
- LDBG () << " Marked entry block live for region in op: " << top->getName ();
147
+ LDBG () << " Marked entry block live for region in op: "
148
+ << OpWithFlags (top, OpPrintingFlags ().skipRegions ());
140
149
}
141
150
142
151
// Mark as overdefined the predecessors of symbol callables with potentially
@@ -151,14 +160,16 @@ void DeadCodeAnalysis::initializeSymbolCallables(Operation *top) {
151
160
<< OpWithFlags (top, OpPrintingFlags ().skipRegions ());
152
161
analysisScope = top;
153
162
auto walkFn = [&](Operation *symTable, bool allUsesVisible) {
154
- LDBG () << " [init] Processing symbol table op: " << symTable->getName ();
163
+ LDBG () << " [init] Processing symbol table op: "
164
+ << OpWithFlags (symTable, OpPrintingFlags ().skipRegions ());
155
165
Region &symbolTableRegion = symTable->getRegion (0 );
156
166
Block *symbolTableBlock = &symbolTableRegion.front ();
157
167
158
168
bool foundSymbolCallable = false ;
159
169
for (auto callable : symbolTableBlock->getOps <CallableOpInterface>()) {
160
170
LDBG () << " [init] Found CallableOpInterface: "
161
- << callable.getOperation ()->getName ();
171
+ << OpWithFlags (callable.getOperation (),
172
+ OpPrintingFlags ().skipRegions ());
162
173
Region *callableRegion = callable.getCallableRegion ();
163
174
if (!callableRegion)
164
175
continue ;
@@ -173,7 +184,8 @@ void DeadCodeAnalysis::initializeSymbolCallables(Operation *top) {
173
184
getOrCreate<PredecessorState>(getProgramPointAfter (callable));
174
185
propagateIfChanged (state, state->setHasUnknownPredecessors ());
175
186
LDBG () << " [init] Marked callable as having unknown predecessors: "
176
- << callable.getOperation ()->getName ();
187
+ << OpWithFlags (callable.getOperation (),
188
+ OpPrintingFlags ().skipRegions ());
177
189
}
178
190
foundSymbolCallable = true ;
179
191
}
@@ -196,7 +208,8 @@ void DeadCodeAnalysis::initializeSymbolCallables(Operation *top) {
196
208
propagateIfChanged (state, state->setHasUnknownPredecessors ());
197
209
LDBG () << " [init] Marked nested callable as "
198
210
" having unknown predecessors: "
199
- << callable.getOperation ()->getName ();
211
+ << OpWithFlags (callable.getOperation (),
212
+ OpPrintingFlags ().skipRegions ());
200
213
});
201
214
}
202
215
@@ -212,7 +225,7 @@ void DeadCodeAnalysis::initializeSymbolCallables(Operation *top) {
212
225
propagateIfChanged (state, state->setHasUnknownPredecessors ());
213
226
LDBG () << " [init] Found non-call use for symbol, "
214
227
" marked as having unknown predecessors: "
215
- << symbol-> getName ( );
228
+ << OpWithFlags ( symbol, OpPrintingFlags (). skipRegions () );
216
229
}
217
230
};
218
231
SymbolTable::walkSymbolTables (top, /* allSymUsesVisible=*/ !top->getBlock (),
@@ -235,7 +248,8 @@ LogicalResult DeadCodeAnalysis::initializeRecursively(Operation *op) {
235
248
// Initialize the analysis by visiting every op with control-flow semantics.
236
249
if (op->getNumRegions () || op->getNumSuccessors () ||
237
250
isRegionOrCallableReturn (op) || isa<CallOpInterface>(op)) {
238
- LDBG () << " [init] Visiting op with control-flow semantics: " << *op;
251
+ LDBG () << " [init] Visiting op with control-flow semantics: "
252
+ << OpWithFlags (op, OpPrintingFlags ().skipRegions ());
239
253
// When the liveness of the parent block changes, make sure to
240
254
// re-invoke the analysis on the op.
241
255
if (op->getBlock ())
@@ -247,7 +261,8 @@ LogicalResult DeadCodeAnalysis::initializeRecursively(Operation *op) {
247
261
}
248
262
// Recurse on nested operations.
249
263
for (Region ®ion : op->getRegions ()) {
250
- LDBG () << " [init] Recursing into region of op: " << op->getName ();
264
+ LDBG () << " [init] Recursing into region of op: "
265
+ << OpWithFlags (op, OpPrintingFlags ().skipRegions ());
251
266
for (Operation &nestedOp : region.getOps ()) {
252
267
LDBG () << " [init] Recursing into nested op: "
253
268
<< OpWithFlags (&nestedOp, OpPrintingFlags ().skipRegions ());
@@ -270,14 +285,16 @@ void DeadCodeAnalysis::markEdgeLive(Block *from, Block *to) {
270
285
}
271
286
272
287
void DeadCodeAnalysis::markEntryBlocksLive (Operation *op) {
273
- LDBG () << " Marking entry blocks live for op: " << op->getName ();
288
+ LDBG () << " Marking entry blocks live for op: "
289
+ << OpWithFlags (op, OpPrintingFlags ().skipRegions ());
274
290
for (Region ®ion : op->getRegions ()) {
275
291
if (region.empty ())
276
292
continue ;
277
293
auto *state =
278
294
getOrCreate<Executable>(getProgramPointBefore (®ion.front ()));
279
295
propagateIfChanged (state, state->setToLive ());
280
- LDBG () << " Marked entry block live for region in op: " << op->getName ();
296
+ LDBG () << " Marked entry block live for region in op: "
297
+ << OpWithFlags (op, OpPrintingFlags ().skipRegions ());
281
298
}
282
299
}
283
300
@@ -286,32 +303,37 @@ LogicalResult DeadCodeAnalysis::visit(ProgramPoint *point) {
286
303
if (point->isBlockStart ())
287
304
return success ();
288
305
Operation *op = point->getPrevOp ();
289
- LDBG () << " Visiting operation: " << *op;
306
+ LDBG () << " Visiting operation: "
307
+ << OpWithFlags (op, OpPrintingFlags ().skipRegions ());
290
308
291
309
// If the parent block is not executable, there is nothing to do.
292
310
if (op->getBlock () != nullptr &&
293
311
!getOrCreate<Executable>(getProgramPointBefore (op->getBlock ()))
294
312
->isLive ()) {
295
- LDBG () << " Parent block not live, skipping op: " << *op;
313
+ LDBG () << " Parent block not live, skipping op: "
314
+ << OpWithFlags (op, OpPrintingFlags ().skipRegions ());
296
315
return success ();
297
316
}
298
317
299
318
// We have a live call op. Add this as a live predecessor of the callee.
300
319
if (auto call = dyn_cast<CallOpInterface>(op)) {
301
- LDBG () << " Visiting call operation: " << *op;
320
+ LDBG () << " Visiting call operation: "
321
+ << OpWithFlags (op, OpPrintingFlags ().skipRegions ());
302
322
visitCallOperation (call);
303
323
}
304
324
305
325
// Visit the regions.
306
326
if (op->getNumRegions ()) {
307
327
// Check if we can reason about the region control-flow.
308
328
if (auto branch = dyn_cast<RegionBranchOpInterface>(op)) {
309
- LDBG () << " Visiting region branch operation: " << *op;
329
+ LDBG () << " Visiting region branch operation: "
330
+ << OpWithFlags (op, OpPrintingFlags ().skipRegions ());
310
331
visitRegionBranchOperation (branch);
311
332
312
333
// Check if this is a callable operation.
313
334
} else if (auto callable = dyn_cast<CallableOpInterface>(op)) {
314
- LDBG () << " Visiting callable operation: " << *op;
335
+ LDBG () << " Visiting callable operation: "
336
+ << OpWithFlags (op, OpPrintingFlags ().skipRegions ());
315
337
const auto *callsites = getOrCreateFor<PredecessorState>(
316
338
getProgramPointAfter (op), getProgramPointAfter (callable));
317
339
@@ -323,19 +345,22 @@ LogicalResult DeadCodeAnalysis::visit(ProgramPoint *point) {
323
345
324
346
// Otherwise, conservatively mark all entry blocks as executable.
325
347
} else {
326
- LDBG () << " Marking all entry blocks live for op: " << *op;
348
+ LDBG () << " Marking all entry blocks live for op: "
349
+ << OpWithFlags (op, OpPrintingFlags ().skipRegions ());
327
350
markEntryBlocksLive (op);
328
351
}
329
352
}
330
353
331
354
if (isRegionOrCallableReturn (op)) {
332
355
if (auto branch = dyn_cast<RegionBranchOpInterface>(op->getParentOp ())) {
333
- LDBG () << " Visiting region terminator: " << *op;
356
+ LDBG () << " Visiting region terminator: "
357
+ << OpWithFlags (op, OpPrintingFlags ().skipRegions ());
334
358
// Visit the exiting terminator of a region.
335
359
visitRegionTerminator (op, branch);
336
360
} else if (auto callable =
337
361
dyn_cast<CallableOpInterface>(op->getParentOp ())) {
338
- LDBG () << " Visiting callable terminator: " << *op;
362
+ LDBG () << " Visiting callable terminator: "
363
+ << OpWithFlags (op, OpPrintingFlags ().skipRegions ());
339
364
// Visit the exiting terminator of a callable.
340
365
visitCallableTerminator (op, callable);
341
366
}
@@ -344,12 +369,14 @@ LogicalResult DeadCodeAnalysis::visit(ProgramPoint *point) {
344
369
if (op->getNumSuccessors ()) {
345
370
// Check if we can reason about the control-flow.
346
371
if (auto branch = dyn_cast<BranchOpInterface>(op)) {
347
- LDBG () << " Visiting branch operation: " << *op;
372
+ LDBG () << " Visiting branch operation: "
373
+ << OpWithFlags (op, OpPrintingFlags ().skipRegions ());
348
374
visitBranchOperation (branch);
349
375
350
376
// Otherwise, conservatively mark all successors as exectuable.
351
377
} else {
352
- LDBG () << " Marking all successors live for op: " << *op;
378
+ LDBG () << " Marking all successors live for op: "
379
+ << OpWithFlags (op, OpPrintingFlags ().skipRegions ());
353
380
for (Block *successor : op->getSuccessors ())
354
381
markEdgeLive (op->getBlock (), successor);
355
382
}
@@ -359,7 +386,8 @@ LogicalResult DeadCodeAnalysis::visit(ProgramPoint *point) {
359
386
}
360
387
361
388
void DeadCodeAnalysis::visitCallOperation (CallOpInterface call) {
362
- LDBG () << " visitCallOperation: " << call.getOperation ()->getName ();
389
+ LDBG () << " visitCallOperation: "
390
+ << OpWithFlags (call.getOperation (), OpPrintingFlags ().skipRegions ());
363
391
Operation *callableOp = call.resolveCallableInTable (&symbolTable);
364
392
365
393
// A call to a externally-defined callable has unknown predecessors.
@@ -442,7 +470,8 @@ void DeadCodeAnalysis::visitBranchOperation(BranchOpInterface branch) {
442
470
443
471
void DeadCodeAnalysis::visitRegionBranchOperation (
444
472
RegionBranchOpInterface branch) {
445
- LDBG () << " visitRegionBranchOperation: " << branch.getOperation ()->getName ();
473
+ LDBG () << " visitRegionBranchOperation: "
474
+ << OpWithFlags (branch.getOperation (), OpPrintingFlags ().skipRegions ());
446
475
// Try to deduce which regions are executable.
447
476
std::optional<SmallVector<Attribute>> operands = getOperandValues (branch);
448
477
if (!operands)
@@ -519,14 +548,14 @@ void DeadCodeAnalysis::visitCallableTerminator(Operation *op,
519
548
if (canResolve) {
520
549
propagateIfChanged (predecessors, predecessors->join (op));
521
550
LDBG () << " Added callable terminator as predecessor for callsite: "
522
- << predecessor-> getName ( );
551
+ << OpWithFlags ( predecessor, OpPrintingFlags (). skipRegions () );
523
552
} else {
524
553
// If the terminator is not a return-like, then conservatively assume we
525
554
// can't resolve the predecessor.
526
555
propagateIfChanged (predecessors,
527
556
predecessors->setHasUnknownPredecessors ());
528
557
LDBG () << " Could not resolve callable terminator for callsite: "
529
- << predecessor-> getName ( );
558
+ << OpWithFlags ( predecessor, OpPrintingFlags (). skipRegions () );
530
559
}
531
560
}
532
561
}
0 commit comments