|
18 | 18 | #include "mlir/IR/Threading.h" |
19 | 19 | #include "mlir/IR/Verifier.h" |
20 | 20 | #include "mlir/Support/FileUtilities.h" |
| 21 | +#include "mlir/Support/IndentedOstream.h" |
21 | 22 | #include "llvm/ADT/Hashing.h" |
22 | 23 | #include "llvm/ADT/STLExtras.h" |
23 | 24 | #include "llvm/ADT/ScopeExit.h" |
@@ -80,14 +81,19 @@ void Pass::copyOptionValuesFrom(const Pass *other) { |
80 | 81 | } |
81 | 82 |
|
82 | 83 | /// Prints out the pass in the textual representation of pipelines. If this is |
83 | | -/// an adaptor pass, print its pass managers. |
84 | | -void Pass::printAsTextualPipeline(raw_ostream &os) { |
| 84 | +/// an adaptor pass, print its pass managers. When `pretty` is true, the |
| 85 | +/// printed pipeline is formatted for readability. |
| 86 | +void Pass::printAsTextualPipeline(raw_ostream &os, bool pretty) { |
85 | 87 | // Special case for adaptors to print its pass managers. |
86 | 88 | if (auto *adaptor = dyn_cast<OpToOpPassAdaptor>(this)) { |
87 | 89 | llvm::interleave( |
88 | 90 | adaptor->getPassManagers(), |
89 | | - [&](OpPassManager &pm) { pm.printAsTextualPipeline(os); }, |
90 | | - [&] { os << ","; }); |
| 91 | + [&](OpPassManager &pm) { pm.printAsTextualPipeline(os, pretty); }, |
| 92 | + [&] { |
| 93 | + os << ","; |
| 94 | + if (pretty) |
| 95 | + os << "\n"; |
| 96 | + }); |
91 | 97 | return; |
92 | 98 | } |
93 | 99 | // Otherwise, print the pass argument followed by its options. If the pass |
@@ -390,27 +396,51 @@ StringRef OpPassManager::getOpAnchorName() const { |
390 | 396 | } |
391 | 397 |
|
392 | 398 | /// Prints out the passes of the pass manager as the textual representation |
393 | | -/// of pipelines. |
| 399 | +/// of pipelines. When `pretty` is true, the printed pipeline is formatted for |
| 400 | +/// readability. |
394 | 401 | void printAsTextualPipeline( |
395 | | - raw_ostream &os, StringRef anchorName, |
396 | | - const llvm::iterator_range<OpPassManager::pass_iterator> &passes) { |
| 402 | + raw_indented_ostream &os, StringRef anchorName, |
| 403 | + const llvm::iterator_range<OpPassManager::pass_iterator> &passes, |
| 404 | + bool pretty = false) { |
397 | 405 | os << anchorName << "("; |
| 406 | + if (pretty) { |
| 407 | + os << "\n"; |
| 408 | + os.indent(); |
| 409 | + } |
398 | 410 | llvm::interleave( |
399 | | - passes, [&](mlir::Pass &pass) { pass.printAsTextualPipeline(os); }, |
400 | | - [&]() { os << ","; }); |
| 411 | + passes, |
| 412 | + [&](mlir::Pass &pass) { pass.printAsTextualPipeline(os, pretty); }, |
| 413 | + [&]() { |
| 414 | + os << ","; |
| 415 | + if (pretty) |
| 416 | + os << "\n"; |
| 417 | + }); |
| 418 | + if (pretty) { |
| 419 | + os << "\n"; |
| 420 | + os.unindent(); |
| 421 | + } |
401 | 422 | os << ")"; |
402 | 423 | } |
403 | | -void OpPassManager::printAsTextualPipeline(raw_ostream &os) const { |
| 424 | +void printAsTextualPipeline( |
| 425 | + raw_ostream &os, StringRef anchorName, |
| 426 | + const llvm::iterator_range<OpPassManager::pass_iterator> &passes, |
| 427 | + bool pretty) { |
| 428 | + raw_indented_ostream indentedOS(os); |
| 429 | + printAsTextualPipeline(indentedOS, anchorName, passes, pretty); |
| 430 | +} |
| 431 | +void OpPassManager::printAsTextualPipeline(raw_ostream &os, bool pretty) const { |
404 | 432 | StringRef anchorName = getOpAnchorName(); |
| 433 | + raw_indented_ostream indentedOS(os); |
405 | 434 | ::printAsTextualPipeline( |
406 | | - os, anchorName, |
| 435 | + indentedOS, anchorName, |
407 | 436 | {MutableArrayRef<std::unique_ptr<Pass>>{impl->passes}.begin(), |
408 | | - MutableArrayRef<std::unique_ptr<Pass>>{impl->passes}.end()}); |
| 437 | + MutableArrayRef<std::unique_ptr<Pass>>{impl->passes}.end()}, |
| 438 | + pretty); |
409 | 439 | } |
410 | 440 |
|
411 | 441 | void OpPassManager::dump() { |
412 | 442 | llvm::errs() << "Pass Manager with " << impl->passes.size() << " passes:\n"; |
413 | | - printAsTextualPipeline(llvm::errs()); |
| 443 | + printAsTextualPipeline(llvm::errs(), /*pretty=*/true); |
414 | 444 | llvm::errs() << "\n"; |
415 | 445 | } |
416 | 446 |
|
@@ -466,7 +496,6 @@ llvm::hash_code OpPassManager::hash() { |
466 | 496 | return hashCode; |
467 | 497 | } |
468 | 498 |
|
469 | | - |
470 | 499 | //===----------------------------------------------------------------------===// |
471 | 500 | // OpToOpPassAdaptor |
472 | 501 | //===----------------------------------------------------------------------===// |
@@ -871,7 +900,8 @@ LogicalResult PassManager::run(Operation *op) { |
871 | 900 | // Initialize all of the passes within the pass manager with a new generation. |
872 | 901 | llvm::hash_code newInitKey = context->getRegistryHash(); |
873 | 902 | llvm::hash_code pipelineKey = hash(); |
874 | | - if (newInitKey != initializationKey || pipelineKey != pipelineInitializationKey) { |
| 903 | + if (newInitKey != initializationKey || |
| 904 | + pipelineKey != pipelineInitializationKey) { |
875 | 905 | if (failed(initialize(context, impl->initializationGeneration + 1))) |
876 | 906 | return failure(); |
877 | 907 | initializationKey = newInitKey; |
|
0 commit comments