aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/Pass/IRPrinting.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-04-30[mlir] Fix `--mlir-print-ir-tree-dir` when the symbol name contains `/` (or ↵Mehdi Amini1-5/+10
`\` on windows) (#137686) Fixes #137622
2024-10-22[mlir] Avoid repeated hash lookups (NFC) (#113249)Kazu Hirata1-4/+1
2024-06-20[mlir] Apply ClangTidy finding.Adrian Kuegel1-1/+1
2024-05-24[mlir][Pass] Add new FileTreeIRPrinterConfig (#67840)Christopher Bate1-1/+161
This change expands the existing instrumentation that prints the IR before/after each pass to an output stream (usually stderr). It adds a new configuration that will print the output of each pass to a separate file. The files will be organized into a directory tree rooted at a specified directory. For existing tools, a CL option `-mlir-print-ir-tree-dir` is added to specify this directory and activate the new printing config. The created directory tree mirrors the nesting structure of the IR. For example, if the IR is congruent to the pass-pipeline "builtin.module(pass1,pass2,func.func(pass3,pass4),pass5)", and `-mlir-print-ir-tree-dir=/tmp/pipeline_output`, then then the tree file tree created will look like: ``` /tmp/pass_output ├── builtin_module_the_symbol_name │ ├── 0_pass1.mlir │ ├── 1_pass2.mlir │ ├── 2_pass5.mlir │ ├── func_func_my_func_name │ │ ├── 1_0_pass3.mlir │ │ ├── 1_1_pass4.mlir │ ├── func_func_my_other_func_name │ │ ├── 1_0_pass3.mlir │ │ ├── 1_1_pass4.mlir ``` The subdirectories are named by concatenating the relevant parent operation names and symbol name (if present). The printer keeps a counter associated with ops that are targeted by passes and their isolated-from-above parents. Each filename is given a numeric prefix using the counter value for the op that the pass is targeting and then prepending the counter values for each parent. This gives a naming where it is easy to distinguish which passes may have run concurrently vs. which have a clear ordering. In the above example, for both `1_1_pass4.mlir` files, the first `1` refers to the counter for the parent op, and the second refers to the counter for the respective function.
2024-01-14[mlir] fix IRPrinterInstrumentation to use the user-provided IRPrinting ↵Yuanqiang Liu1-1/+2
config (#70023)
2022-11-02[mlir] Make `OperationFingerPrint` class publicIvan Butygin1-55/+0
It can be useful to external users as well for detecting if there were any changes in IR between passes. Differential Revision: https://reviews.llvm.org/D137078
2022-07-15Example:Stella Laurenzo1-3/+6
``` // -----// IR Dump Before LowerLinalgMicrokernels (iree-vmvx-lower-linalg-microkernels) //----- // ``` I've been meaning to suggest this for a long time, and I think the only reason we don't have it is because we didn't used to have the `getArgument()` handy when printing these comments. When debugging or putting a pipeline together based on such dumps, I often find myself grepping for the argument name of the pass (which is often related but not universally).
2022-07-14[mlir] (NFC) run clang-format on all filesJeff Niu1-1/+2
2022-04-19Print custom assembly on pass failure by defaultMehdi Amini1-2/+1
The printer is now resilient to invalid IR and will already automatically fallback to the generic form on invalid IR. Using the generic printer on pass failure was a conservative option before the printer was made failsafe. Reviewed By: lattner, rriddle, jpienaar, bondhugula Differential Revision: https://reviews.llvm.org/D123915
2022-04-17Revert "[MLIR] Provide a way to print ops in custom form on pass failure"Mehdi Amini1-12/+7
This reverts commit daabcf5f04bbd13ac53f76ca3cc43b0d1ef64f5a. This patch still had on-going discussion that should be closed before committing.
2022-04-17[MLIR] Provide a way to print ops in custom form on pass failureUday Bondhugula1-7/+12
The generic form of the op is too verbose and in some cases not readable. On pass failure, ops have been so far printed in generic form to provide a (stronger) guarantee that the IR print succeeds. However, in a large number of pass failure cases, the IR is still valid and the custom printers for the ops will succeed. In fact, readability is highly desirable post pass failure. This revision provides an option to print ops in their custom/pretty-printed form on IR failure -- this option is unsafe and there is no guarantee it will succeed. It's disabled by default and can be turned on only if needed. Differential Revision: https://reviews.llvm.org/D123893
2022-04-07[mlir][NFC] Drop a few unnecessary includes from Pass.hRiver Riddle1-0/+1
2022-04-05[Support/Hash functions] Change the `final()` and `result()` of the hashing ↵Argyrios Kyrtzidis1-1/+1
functions to return an array of bytes Returning `std::array<uint8_t, N>` is better ergonomics for the hashing functions usage, instead of a `StringRef`: * When returning `StringRef`, client code is "jumping through hoops" to do string manipulations instead of dealing with fixed array of bytes directly, which is more natural * Returning `std::array<uint8_t, N>` avoids the need for the hasher classes to keep a field just for the purpose of wrapping it and returning it as a `StringRef` As part of this patch also: * Introduce `TruncatedBLAKE3` which is useful for using BLAKE3 as the hasher type for `HashBuilder` with non-default hash sizes. * Make `MD5Result` inherit from `std::array<uint8_t, 16>` which improves & simplifies its API. Differential Revision: https://reviews.llvm.org/D123100
2022-01-02Apply clang-tidy fixes for performance-unnecessary-value-param to MLIR (NFC)Mehdi Amini1-3/+3
Reviewed By: Mogball Differential Revision: https://reviews.llvm.org/D116250
2021-12-22Fix more clang-tidy cleanups in mlir/ (NFC)Mehdi Amini1-1/+1
2021-12-08Adjust "end namespace" comment in MLIR to match new agree'd coding styleMehdi Amini1-2/+2
See D115115 and this mailing list discussion: https://lists.llvm.org/pipermail/llvm-dev/2021-December/154199.html Differential Revision: https://reviews.llvm.org/D115309
2021-06-10[mlir-ir-printing] Prefix the dump message with the split marker(// -----)River Riddle1-5/+5
This allows for better interaction with tools (such as mlir-lsp-server), as it separates the IR into separate modules for consecutive dumps. Differential Revision: https://reviews.llvm.org/D104073
2021-05-19[mlir] Add a new `print-ir-after-failure` IR pass printing flagRiver Riddle1-4/+14
This flag will print the IR after a pass only in the case where the pass failed. This can be useful to more easily view the invalid IR, without needing to print after every pass in the pipeline. Differential Revision: https://reviews.llvm.org/D101853
2020-12-17[mlir] Remove the MutableDictionaryAttr classRiver Riddle1-1/+1
This class used to serve a few useful purposes: * Allowed containing a null DictionaryAttr * Provided some simple mutable API around a DictionaryAttr The first of which is no longer an issue now that there is much better caching support for attributes in general, and a cache in the context for empty dictionaries. The second results in more trouble than it's worth because it mutates the internal dictionary on every action, leading to a potentially large number of dictionary copies. NamedAttrList is a much better alternative for the second use case, and should be modified as needed to better fit it's usage as a DictionaryAttrBuilder. Differential Revision: https://reviews.llvm.org/D93442
2020-12-03[mlir][Pass] Remove the restriction that PassManager can only run on ModuleOpRiver Riddle1-15/+4
This was a somewhat important restriction in the past when ModuleOp was distinctly the top-level container operation, as well as before the pass manager had support for running nested pass managers natively. With these two issues fading away, there isn't really a good reason to enforce that a ModuleOp is the thing running within a pass manager. As such, this revision removes the restriction and allows for users to pass in the name of the operation that the pass manager will be scheduled on. The only remaining dependency on BuiltinOps from Pass after this revision is due to FunctionPass, which will be resolved in a followup revision. Differential Revision: https://reviews.llvm.org/D92450
2020-11-19[mlir][BuiltinDialect] Resolve comments from D91571River Riddle1-1/+1
* Move ops to a BuiltinOps.h * Add file comments
2020-11-17[mlir][NFC] Remove references to Module.h and Function.hRiver Riddle1-1/+1
These includes have been deprecated in favor of BuiltinDialect.h, which contains the definitions of ModuleOp and FuncOp. Differential Revision: https://reviews.llvm.org/D91572
2020-11-12[mlir][Pass] Remove the verifierPass now that verification is run during ↵River Riddle1-7/+2
normal pass execution A recent refactoring removed the need to interleave verifier passes and instead opted to verify during the normal execution of passes instead. As such, the old verify pass is no longer necessary and can be removed. Differential Revision: https://reviews.llvm.org/D91212
2020-07-16[MLIR] Add OpPrintingFlags to IRPrinterConfig.Rahul Joshi1-8/+15
- This will enable tweaking IR printing options when enabling printing (for ex, tweak elideLargeElementsAttrs to create smaller IR logs) Differential Revision: https://reviews.llvm.org/D83930
2020-06-24[MLIR][NFC] Adopt variadic isa<>Rahul Joshi1-1/+1
Differential Revision: https://reviews.llvm.org/D82489
2020-05-07[mlir] Add NamedAttrListJacques Pienaar1-3/+1
This is a wrapper around vector of NamedAttributes that keeps track of whether sorted and does some minimal effort to remain sorted (doing more, e.g., appending attributes in sorted order, could be done in follow up). It contains whether sorted and if a DictionaryAttr is queried, it caches the returned DictionaryAttr along with whether sorted. Change MutableDictionaryAttr to always return a non-null Attribute even when empty (reserve null cases for errors). To this end change the getter to take a context as input so that the empty DictionaryAttr could be queried. Also create one instance of the empty dictionary attribute that could be reused without needing to lock context etc. Update infer type op interface to use DictionaryAttr and use NamedAttrList to avoid incurring multiple conversion costs. Fix bug in sorting helper function. Differential Revision: https://reviews.llvm.org/D79463
2020-05-02[mlir] Add a new context flag for disabling/enabling multi-threadingRiver Riddle1-1/+2
This is useful for several reasons: * In some situations the user can guarantee that thread-safety isn't necessary and don't want to pay the cost of synchronization, e.g., when parsing a very large module. * For things like logging threading is not desirable as the output is not guaranteed to be in stable order. This flag also subsumes the pass manager flag for multi-threading. Differential Revision: https://reviews.llvm.org/D79266
2020-04-29[mlir][Pass][NFC] Merge OpToOpPassAdaptor and OpToOpPassAdaptorParallelRiver Riddle1-2/+2
This moves the threading check to runOnOperation. This produces a much cleaner interface for the adaptor pass, and will allow for the ability to enable/disable threading in a much cleaner way in the future. Differential Revision: https://reviews.llvm.org/D78313
2020-04-29Rename NamedAttributeList to MutableDictionaryAttrJacques Pienaar1-2/+3
Makes the relationship and function clearer. Accordingly rename getAttrList to getMutableAttrDict. Differential Revision: https://reviews.llvm.org/D79125
2020-04-22Add `//` before the banner displayed in `--print-ir-before/after-all`Mehdi Amini1-3/+3
This is making the output file (when the stream is a file) a valid MLIR file. Differential Revision: https://reviews.llvm.org/D78604
2020-02-29Ensure that multi-threading is disabled when enabling IRPrinting with module ↵Mehdi Amini1-0/+3
scope This is avoid the user to shoot themselves in the foot and encounter strange crashes that are confusing until one run with TSAN. Differential Revision: https://reviews.llvm.org/D75399
2020-01-26Mass update the MLIR license header to mention "Part of the LLVM project"Mehdi Amini1-1/+1
This is an artifact from merging MLIR into LLVM, the file headers are now aligned with the rest of the project.
2019-12-23NFC: Replace ValuePtr with Value and remove it now that Value is value-typed.River Riddle1-2/+2
ValuePtr was a temporary typedef during the transition to a value-typed Value. PiperOrigin-RevId: 286945714
2019-12-23Adjust License.txt file to use the LLVM licenseMehdi Amini1-13/+4
PiperOrigin-RevId: 286906740
2019-12-22NFC: Introduce new ValuePtr/ValueRef typedefs to simplify the transition to ↵River Riddle1-2/+2
Value being value-typed. This is an initial step to refactoring the representation of OpResult as proposed in: https://groups.google.com/a/tensorflow.org/g/mlir/c/XXzzKhqqF_0/m/v6bKb08WCgAJ This change will make it much simpler to incrementally transition all of the existing code to use value-typed semantics. PiperOrigin-RevId: 286844725
2019-12-06Add a flag to the IRPrinter instrumentation to only print after a pass if ↵River Riddle1-8/+93
there is a change to the IR. This adds an additional filtering mode for printing after a pass that checks to see if the pass actually changed the IR before printing it. This "change" detection is implemented using a SHA1 hash of the current operation and its children. PiperOrigin-RevId: 284291089
2019-12-05Refactor the IRPrinting instrumentation to take a derivable config.River Riddle1-43/+98
This allows for more interesting behavior from users, e.g. enabling the ability to dump the IR to a separate file for each pass invocation. PiperOrigin-RevId: 284059447
2019-11-12Add a printer flag to use local scope when printing IR.River Riddle1-1/+1
This causes the AsmPrinter to use a local value numbering when printing the IR, allowing for the printer to be used safely in a local context, e.g. to ensure thread-safety when printing the IR. This means that the IR printing instrumentation can also be used during multi-threading when module-scope is disabled. Operation::dump and DiagnosticArgument(Operation*) are also updated to always print local scope, as this is the most common use case when debugging. PiperOrigin-RevId: 279988203
2019-10-10NFC: Print the generic op form after pass failure.River Riddle1-8/+9
On failure, the IR is likely to be in an invalid state, meaning the custom printer for some operations may now crash. Using the generic op form prevents this from happening. PiperOrigin-RevId: 274104146
2019-09-14Update the IRPrinter instrumentation to work on non function/module operations.River Riddle1-21/+27
This is necessary now that the pass manager may work on different types of operations. PiperOrigin-RevId: 269139669
2019-09-14NFC: Pass PassInstrumentations by unique_ptr instead of raw pointer.River Riddle1-1/+1
This makes the ownership model explicit, and removes potential user errors. PiperOrigin-RevId: 269122834
2019-09-02Refactor the pass manager to support operations other than FuncOp/ModuleOp.River Riddle1-1/+1
This change generalizes the structure of the pass manager to allow arbitrary nesting pass managers for other operations, at any level. The only user visible change to existing code is the fact that a PassManager must now provide an MLIRContext on construction. A new class `OpPassManager` has been added that represents a pass manager on a specific operation type. `PassManager` will remain the top-level entry point into the pipeline, with OpPassManagers being nested underneath. OpPassManagers will still be implicitly nested if the operation type on the pass differs from the pass manager. To explicitly build a pipeline, the 'nest' methods on OpPassManager may be used: // Pass manager for the top-level module. PassManager pm(ctx); // Nest a pipeline operating on FuncOp. OpPassManager &fpm = pm.nest<FuncOp>(); fpm.addPass(...); // Nest a pipeline under the FuncOp pipeline that operates on spirv::ModuleOp OpPassManager &spvModulePM = pm.nest<spirv::ModuleOp>(); // Nest a pipeline on FuncOps inside of the spirv::ModuleOp. OpPassManager &spvFuncPM = spvModulePM.nest<FuncOp>(); To help accomplish this a new general OperationPass is added that operates on opaque Operations. This pass can be inserted in a pass manager of any type to operate on any operation opaquely. An example of this opaque OperationPass is a VerifierPass, that simply runs the verifier opaquely on the current operation. /// Pass to verify an operation and signal failure if necessary. class VerifierPass : public OperationPass<VerifierPass> { void runOnOperation() override { Operation *op = getOperation(); if (failed(verify(op))) signalPassFailure(); markAllAnalysesPreserved(); } }; PiperOrigin-RevId: 266840344
2019-08-16NFC: Refactor the PassInstrumentation framework to operate on Operation ↵River Riddle1-23/+20
instead of llvm::Any. Now that functions and modules are operations, Operation makes more sense as the opaque object to refer to both. PiperOrigin-RevId: 263883913
2019-07-12Change the IR printing pass instrumentation to ignore the verifier passes on ↵River Riddle1-2/+10
non-failure. The verifier passes are NO-OP and are only useful to print after in the case of failure. This removes a lot of unnecessary clutter when printing after/before all passes. PiperOrigin-RevId: 257836310
2019-07-12NFC: Remove Function::getModule.River Riddle1-1/+1
There is already a more general 'getParentOfType' method, and 'getModule' is likely to be misused as functions get placed within different regions than ModuleOp. PiperOrigin-RevId: 257442243
2019-07-10NFC: Rename Module to ModuleOp.River Riddle1-2/+2
Module is a legacy name that only exists as a typedef of ModuleOp. PiperOrigin-RevId: 257427248
2019-07-10NFC: Rename Function to FuncOp.River Riddle1-4/+4
PiperOrigin-RevId: 257293379
2019-07-02NFC: Refactor Module to be value typed.River Riddle1-3/+3
As with Functions, Module will soon become an operation, which are value-typed. This eases the transition from Module to ModuleOp. A new class, OwningModuleRef is provided to allow for owning a reference to a Module, and will auto-delete the held module on destruction. PiperOrigin-RevId: 256196193
2019-07-01NFC: Refactor Function to be value typed.River Riddle1-6/+6
Move the data members out of Function and into a new impl storage class 'FunctionStorage'. This allows for Function to become value typed, which will greatly simplify the transition of Function to FuncOp(given that FuncOp is also value typed). PiperOrigin-RevId: 255983022
2019-03-29Add an instrumentation for conditionally printing the IR before and after ↵River Riddle1-0/+128
pass execution. This instrumentation can be added directly to the PassManager via 'enableIRPrinting'. mlir-opt exposes access to this instrumentation via the following flags: * print-ir-before=(comma-separated-pass-list) - Print the IR before each of the passes provided within the pass list. * print-ir-before-all - Print the IR before every pass in the pipeline. * print-ir-after=(comma-separated-pass-list) - Print the IR after each of the passes provided within the pass list. * print-ir-after-all - Print the IR after every pass in the pipeline. * print-ir-module-scope - Always print the Module IR, even for non module passes. PiperOrigin-RevId: 238523649