summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [mlir] NFC: Remove Value::operator* and Value::operator-> now that Value is ↵River Riddle2020-01-111-4/+4
| | | | | | | | | | properly value-typed. Summary: These were temporary methods used to simplify the transition. Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D72548
* NFC: Replace ValuePtr with Value and remove it now that Value is value-typed.River Riddle2019-12-231-2/+2
| | | | | | ValuePtr was a temporary typedef during the transition to a value-typed Value. PiperOrigin-RevId: 286945714
* Adjust License.txt file to use the LLVM licenseMehdi Amini2019-12-231-13/+4
| | | | PiperOrigin-RevId: 286906740
* NFC: Introduce new ValuePtr/ValueRef typedefs to simplify the transition to ↵River Riddle2019-12-221-4/+4
| | | | | | | | | | 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
* Make OpBuilder::insert virtual instead of OpBuilder::createOperation.River Riddle2019-12-111-6/+5
| | | | | | It is sometimes useful to create operations separately from the builder before insertion as it may be easier to erase them in isolation if necessary. One example use case for this is folding, as we will only want to insert newly generated constant operations on success. This has the added benefit of fixing some silent PatternRewriter failures related to cloning, as the OpBuilder 'clone' methods don't call createOperation. PiperOrigin-RevId: 285086242
* Merge DCE and unreachable block elimination into a new utility ↵River Riddle2019-11-201-53/+2
| | | | | | | | 'simplifyRegions'. This moves the different canonicalizations of regions into one place and invokes them in the fixed-point iteration of the canonicalizer. PiperOrigin-RevId: 281617072
* Add support to GreedyPatternRewriter for erasing unreachable blocks.River Riddle2019-10-301-0/+56
| | | | | | Rewrite patterns may make modifications to the CFG, including dropping edges between blocks. This change adds a simple unreachable block elimination run at the end of each iteration to ensure that the CFG remains valid. PiperOrigin-RevId: 277545805
* Bugfix: Keep worklistMap in sync with worklist in GreedyPatternRewriterDiego Caballero2019-10-291-0/+1
| | | | | | | | | | | When we removed a pattern, we removed it from worklist but not from worklistMap. Then, when we tried to add a new pattern on the same Operation again, the pattern wasn't added since it already existed in the worklistMap (but not in the worklist). Closes tensorflow/mlir#211 PiperOrigin-RevId: 277319669
* Add support for canonicalizing callable regions during inlining.River Riddle2019-10-101-8/+23
| | | | | | This will allow for inlining newly devirtualized calls, as well as give a more accurate cost model(when we have one). Currently canonicalization will only run for nodes that have no child edges, as the child nodes may be erased during canonicalization. We can support this in the future, but it requires more intricate deletion tracking. PiperOrigin-RevId: 274011386
* Add a new dialect interface for the OperationFolder `OpFolderDialectInterface`.River Riddle2019-09-011-1/+1
| | | | | | This interface will allow for providing hooks to interrop with operation folding. The first hook, 'shouldMaterializeInto', will allow for controlling which region to insert materialized constants into. The folder will generally materialize constants into the top-level isolated region, this allows for materializing into a lower level ancestor region if it is more profitable/correct. PiperOrigin-RevId: 266702972
* Support folding of ops with inner ops in GreedyPatternRewriteDriver.Andy Ly2019-08-261-8/+7
| | | | | | This fixes a bug when folding ops with inner ops and inner ops are still being visited. PiperOrigin-RevId: 265475780
* NFC: Add a note to 'applyPatternsGreedily' that it also performs folding/dce.River Riddle2019-08-231-3/+2
| | | | | | Fixes tensorflow/mlir#72 PiperOrigin-RevId: 265097597
* NFC: Move LLVMIR, SDBM, and StandardOps to the Dialect/ directory.River Riddle2019-08-191-1/+1
| | | | PiperOrigin-RevId: 264193915
* NFC: Update pattern rewrite API to pass OwningRewritePatternList by const ↵River Riddle2019-08-111-2/+2
| | | | | | | | reference. The pattern list is not modified by any of these APIs and should thus be passed with const. PiperOrigin-RevId: 262844002
* NFC: Update usages of OwningRewritePatternList to pass by & instead of &&.River Riddle2019-08-091-1/+1
| | | | | | This will allow for reusing the same pattern list, which may be costly to continually reconstruct, on multiple invocations. PiperOrigin-RevId: 262664599
* Remove ops in regions/blocks from worklist when parent op is being removed ↵Andy Ly2019-08-061-0/+4
| | | | | | | | via GreedyPatternRewriteDriver::replaceOp. This fixes a bug where ops inside the parent op are visited even though the parent op has been removed. PiperOrigin-RevId: 261953580
* NFC: Implement OwningRewritePatternList as a class instead of a using directive.River Riddle2019-08-051-3/+3
| | | | | | This allows for proper forward declaration, as opposed to leaking the internal implementation via a using directive. This also allows for all pattern building to go through 'insert' methods on the OwningRewritePatternList, replacing uses of 'push_back' and 'RewriteListBuilder'. PiperOrigin-RevId: 261816316
* Update 'applyPatternsGreedily' to work on the regions of any operations.River Riddle2019-07-161-20/+24
| | | | | | 'applyPatternsGreedily' is a useful utility outside of just function regions. PiperOrigin-RevId: 258182937
* Update the PatternRewriter constructor to take a context instead of a region.River Riddle2019-07-121-3/+3
| | | | | | This will allow for cleanly using a rewriter for multiple different regions. PiperOrigin-RevId: 257845371
* Remove the 'region' field from OpBuilder.River Riddle2019-07-121-5/+5
| | | | | | This field wasn't updated as the insertion point changed, making it potentially dangerous given the multi-level of MLIR(e.g. 'createBlock' would always insert the new block in 'region'). This also allows for building an OpBuilder with just a context. PiperOrigin-RevId: 257829135
* Fix a bug in the canonicalizer when replacing constants via patterns.River Riddle2019-07-121-3/+6
| | | | | | The GreedyPatternRewriteDriver currently does not notify the OperationFolder when constants are removed as part of a pattern match. This materializes in a nasty bug where a different operation may be allocated to the same address. This causes an assertion in the OperationFolder when it gets notified of the new operations removal. PiperOrigin-RevId: 257817627
* Rename FunctionAttr to SymbolRefAttr.River Riddle2019-07-121-0/+1
| | | | | | This allows for the attribute to hold symbolic references to other operations than FuncOp. This also allows for removing the dependence on FuncOp from the base Builder. PiperOrigin-RevId: 257650017
* NFC: Rename Function to FuncOp.River Riddle2019-07-101-2/+2
| | | | PiperOrigin-RevId: 257293379
* NFC: Refactor Function to be value typed.River Riddle2019-07-011-2/+2
| | | | | | 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
* Update the OperationFolder to find a valid insertion point when ↵River Riddle2019-06-251-3/+1
| | | | | | | | materializing constants. The OperationFolder currently just inserts into the entry block of a Function, but regions may be isolated above, i.e. explicit capture only, and blindly inserting constants may break the invariants of these regions. PiperOrigin-RevId: 254987796
* Add a new dialect hook 'materializeConstant' to create a constant operation ↵River Riddle2019-06-221-2/+5
| | | | | | that materializes an attribute value with the given type. This effectively adds support for dialect specific constant values that have different invariants than std.constant. 'OperationFolder' is updated to use this new hook, or attempt to default to std.constant when legal. PiperOrigin-RevId: 254570153
* NFC: Rename FuncBuilder to OpBuilder and refactor to take a top level region ↵River Riddle2019-06-091-5/+7
| | | | | | instead of a function. PiperOrigin-RevId: 251563898
* NFC: Rename FoldHelper to OperationFolder and split a large function in two.River Riddle2019-06-091-3/+3
| | | | PiperOrigin-RevId: 251485843
* Add user iterators to IRObjects, i.e. Values.River Riddle2019-05-201-8/+5
| | | | | | -- PiperOrigin-RevId: 248877752
* Rewrite the DialectOpConversion patterns to inherit from RewritePattern ↵River Riddle2019-05-201-2/+2
| | | | | | | | instead of Pattern. This simplifies the infrastructure a bit by being able to reuse PatternRewriter and the RewritePatternMatcher, but also starts to lay the groundwork for a more generalized legalization framework that can operate on DialectOpConversions as well as normal RewritePatterns. -- PiperOrigin-RevId: 248836492
* Refactor PatternRewriter to inherit from FuncBuilder instead of Builder. ↵River Riddle2019-05-201-8/+4
| | | | | | | | This is necessary for allowing more complicated rewrites in the future that may do things like update the insertion point (e.g. for rewrites involving regions). -- PiperOrigin-RevId: 248803153
* Unify the 'constantFold' and 'fold' hooks on an operation into just ↵River Riddle2019-05-201-48/+12
| | | | | | | | 'fold'. This new unified fold hook will take constant attributes as operands, and may return an existing 'Value *' or a constant 'Attribute' when folding. This removes the awkward situation where a simple canonicalization like "sub(x,x)->0" had to be written as a canonicalization pattern as opposed to a fold. -- PiperOrigin-RevId: 248582024
* Replace Operation::isa with llvm::isa.River Riddle2019-05-201-1/+1
| | | | | | -- PiperOrigin-RevId: 247789235
* Remove extra `;` after function definition (NFC)Mehdi Amini2019-05-101-1/+1
| | | | | | | | Fix a GCC warning -- PiperOrigin-RevId: 247670176
* Fix up some mixed sign warnings.Jacques Pienaar2019-05-061-2/+2
| | | | | | -- PiperOrigin-RevId: 246614498
* Apply patterns repeatly if the function is modifiedFeng Liu2019-04-231-87/+117
| | | | | | | | | | | | | | | | | | During the pattern rewrite, if the function is changed, i.e. ops created, deleted or swapped, the pattern rewriter needs to re-scan the function entirely and apply the patterns again, so the patterns whose root ops have been popped out from the working list nor an immediate users of the changed ops can be reconsidered. A command line flag is added to set the max number of iterations rescanning the function for pattern match. If the rewrite doesn' converge after this number, this compiling will continue and the result can be sub-optimal. One unit test is updated because this change fixed the missing optimization opportunities. -- PiperOrigin-RevId: 244754190
* Deduplicate constant folding logic in ConstantFold and ↵Lei Zhang2019-04-051-89/+19
| | | | | | | | | | | | | | | | | | | | | GreedyPatternRewriteDriver There are two places containing constant folding logic right now: the ConstantFold pass and the GreedyPatternRewriteDriver. The logic was not shared and started to drift apart. We were testing constant folding logic using the ConstantFold pass, but lagged behind the GreedyPatternRewriteDriver, where we really want the constant folding to happen. This CL pulled the logic into utility functions and classes for sharing between these two places. A new ConstantFoldHelper class is created to help constant fold and de-duplication. Also, renamed the ConstantFold pass to TestConstantFold to make it clear that it is intended for testing purpose. -- PiperOrigin-RevId: 241971681
* Rename InstOperand to OpOperand.River Riddle2019-03-291-1/+1
| | | | PiperOrigin-RevId: 240814651
* Replace usages of Instruction with Operation in the Transforms/ directory.River Riddle2019-03-291-14/+14
| | | | PiperOrigin-RevId: 240636130
* Replace usages of Instruction with Operation in the /IR directory.River Riddle2019-03-291-1/+1
| | | | | | This is step 2/N to renaming Instruction to Operation. PiperOrigin-RevId: 240459216
* Make FunctionPass::getFunction() return a reference to the function, instead ofChris Lattner2019-03-291-5/+5
| | | | | | | a pointer. This makes it consistent with all the other methods in FunctionPass, as well as with ModulePass::getModule(). NFC. PiperOrigin-RevId: 240257910
* Replace usages of "Op::operator->" with ".".River Riddle2019-03-291-7/+7
| | | | | | This is step 2/N of removing the temporary operator-> method as part of the de-const transition. PiperOrigin-RevId: 240200792
* Refactor the Pattern framework to allow for combined match/rewrite patterns. ↵River Riddle2019-03-291-11/+7
| | | | | | | | | | This is done by adding a new 'matchAndRewrite' function to RewritePattern that performs the match and rewrite in one step. The default behavior simply calls into the existing 'match' and 'rewrite' functions. The 'PatternMatcher' class has now been specialized for RewritePatterns and has been rewritten to make use of the new matchAndRewrite functionality. This combined match/rewrite functionality allows simplifying the majority of existing RewritePatterns, as they do not benefit from separate match and rewrite functions. Some of the existing canonicalization patterns in StandardOps have been modified to take advantage of this functionality. PiperOrigin-RevId: 240187856
* Update the constantFold/fold API to use LogicalResult instead of bool.River Riddle2019-03-291-2/+2
| | | | PiperOrigin-RevId: 237719658
* NFC. Move all of the remaining operations left in BuiltinOps to StandardOps. ↵River Riddle2019-03-291-1/+1
| | | | | | The only thing left in BuiltinOps are the core MLIR types. The standard types can't be moved because they are referenced within the IR directory, e.g. in things like Builder. PiperOrigin-RevId: 236403665
* Add a generic pattern matcher for matching constant values produced by an ↵River Riddle2019-03-291-9/+4
| | | | | | operation with zero operands and a single result. PiperOrigin-RevId: 234616691
* Modify the canonicalizations of select and muli to use the fold hook.River Riddle2019-03-291-17/+33
| | | | | | This also extends the greedy pattern rewrite driver to add the operands of folded operations back to the worklist. PiperOrigin-RevId: 232878959
* When canonicalizing only erase the operation after calling the 'fold' hook ↵River Riddle2019-03-291-2/+2
| | | | | | if replacement results were supplied. This fixes a bug where the operation would always get erased, even if it was modified in place. PiperOrigin-RevId: 232757964
* Remove remaining usages of OperationInst in lib/Transforms.River Riddle2019-03-291-22/+16
| | | | PiperOrigin-RevId: 232323671
* Replace the walkOps/visitOperationInst variants from the InstWalkers with ↵River Riddle2019-03-291-1/+1
| | | | | | the Instruction variants. PiperOrigin-RevId: 232322030
OpenPOWER on IntegriCloud