|
15 | 15 | #include "mlir/IR/Builders.h" |
16 | 16 | #include "mlir/IR/BuiltinTypes.h" |
17 | 17 | #include "mlir/IR/IRMapping.h" |
| 18 | +#include "mlir/IR/Iterators.h" |
18 | 19 | #include "mlir/IR/SymbolTable.h" |
19 | 20 |
|
20 | 21 | #define DEBUG_TYPE "iree-constexpr" |
@@ -328,29 +329,24 @@ class HoistIntoGlobalsPass |
328 | 329 |
|
329 | 330 | // Since we are mutating the const-expr ops, the ConstExprAnalysis will no |
330 | 331 | // longer be valid after this point. |
331 | | - SmallVector<Operation *> worklist; |
332 | | - worklist.reserve(allOps.size()); |
333 | | - bool madeChanges = true; |
334 | | - while (madeChanges) { |
335 | | - madeChanges = false; |
336 | | - |
337 | | - // Prepare worklist. |
338 | | - worklist.clear(); |
339 | | - worklist.append(allOps.begin(), allOps.end()); |
340 | | - |
341 | | - for (Operation *checkOp : worklist) { |
342 | | - if (checkOp->use_empty()) { |
343 | | - // Bingo. |
344 | | - LLVM_DEBUG({ |
345 | | - llvm::dbgs() << "[HoistIntoGlobals] erase dead op: "; |
346 | | - checkOp->print(llvm::dbgs(), constExprs.getAsmState()); |
347 | | - llvm::dbgs() << "\n"; |
| 332 | + for (auto funcOp : getOperation().getOps<FunctionOpInterface>()) { |
| 333 | + // Ignore initializers. |
| 334 | + if (isa<IREE::Util::InitializerOpInterface>(funcOp.getOperation())) |
| 335 | + continue; |
| 336 | + funcOp.walk<WalkOrder::PostOrder, ReverseIterator>( |
| 337 | + [&](Operation *iterOp) { |
| 338 | + if (allOps.contains(iterOp) && iterOp->use_empty()) { |
| 339 | + // Bingo. |
| 340 | + LLVM_DEBUG({ |
| 341 | + llvm::dbgs() << "[HoistIntoGlobals] erase dead op: "; |
| 342 | + iterOp->print(llvm::dbgs(), constExprs.getAsmState()); |
| 343 | + llvm::dbgs() << "\n"; |
| 344 | + }); |
| 345 | + allOps.erase(iterOp); |
| 346 | + iterOp->erase(); |
| 347 | + } |
| 348 | + return WalkResult::advance(); |
348 | 349 | }); |
349 | | - madeChanges = true; |
350 | | - allOps.erase(checkOp); |
351 | | - checkOp->erase(); |
352 | | - } |
353 | | - } |
354 | 350 | } |
355 | 351 | } |
356 | 352 |
|
|
0 commit comments