summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Transforms/Canonicalizer.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Add static pass registrationJacques Pienaar2019-03-291-0/+7
| | | | | | | | Add static pass registration and change mlir-opt to use it. Future work is needed to refactor the registration for PassManager usage. Change build targets to alwayslink to enforce registration. PiperOrigin-RevId: 220390178
* Introduce memref bound checking.Uday Bondhugula2019-03-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Introduce analysis to check memref accesses (in MLFunctions) for out of bound ones. It works as follows: $ mlir-opt -memref-bound-check test/Transforms/memref-bound-check.mlir /tmp/single.mlir:10:12: error: 'load' op memref out of upper bound access along dimension tensorflow/mlir#1 %x = load %A[%idxtensorflow/mlir#0, %idxtensorflow/mlir#1] : memref<9 x 9 x i32> ^ /tmp/single.mlir:10:12: error: 'load' op memref out of lower bound access along dimension tensorflow/mlir#1 %x = load %A[%idxtensorflow/mlir#0, %idxtensorflow/mlir#1] : memref<9 x 9 x i32> ^ /tmp/single.mlir:10:12: error: 'load' op memref out of upper bound access along dimension tensorflow/mlir#2 %x = load %A[%idxtensorflow/mlir#0, %idxtensorflow/mlir#1] : memref<9 x 9 x i32> ^ /tmp/single.mlir:10:12: error: 'load' op memref out of lower bound access along dimension tensorflow/mlir#2 %x = load %A[%idxtensorflow/mlir#0, %idxtensorflow/mlir#1] : memref<9 x 9 x i32> ^ /tmp/single.mlir:12:12: error: 'load' op memref out of upper bound access along dimension tensorflow/mlir#1 %y = load %B[%idy] : memref<128 x i32> ^ /tmp/single.mlir:12:12: error: 'load' op memref out of lower bound access along dimension tensorflow/mlir#1 %y = load %B[%idy] : memref<128 x i32> ^ #map0 = (d0, d1) -> (d0, d1) #map1 = (d0, d1) -> (d0 * 128 - d1) mlfunc @test() { %0 = alloc() : memref<9x9xi32> %1 = alloc() : memref<128xi32> for %i0 = -1 to 9 { for %i1 = -1 to 9 { %2 = affine_apply #map0(%i0, %i1) %3 = load %0[%2tensorflow/mlir#0, %2tensorflow/mlir#1] : memref<9x9xi32> %4 = affine_apply #map1(%i0, %i1) %5 = load %1[%4] : memref<128xi32> } } return } - Improves productivity while manually / semi-automatically developing MLIR for testing / prototyping; also provides an indirect way to catch errors in transformations. - This pass is an easy way to test the underlying affine analysis machinery including low level routines. Some code (in getMemoryRegion()) borrowed from @andydavis cl/218263256. While on this: - create mlir/Analysis/Passes.h; move Pass.h up from mlir/Transforms/ to mlir/ - fix a bug in AffineAnalysis.cpp::toAffineExpr TODO: extend to non-constant loop bounds (straightforward). Will transparently work for all accesses once floordiv, mod, ceildiv are supported in the AffineMap -> FlatAffineConstraints conversion. PiperOrigin-RevId: 219397961
* Simplify FunctionPass to eliminate the CFGFunctionPass/MLFunctionPassChris Lattner2019-03-291-12/+1
| | | | | | | distinction. FunctionPasses can now choose to get called on all functions, or have the driver split CFG/ML Functions up for them. NFC. PiperOrigin-RevId: 218775885
* Refactor all of the canonicalization patterns out of the Canonicalize pass, andChris Lattner2019-03-291-180/+7
| | | | | | | | | | make operations provide a list of canonicalizations that can be applied to them. This allows canonicalization to be general to any IR definition. As part of this, sink PatternMatch.h/cpp down to the IR library to fix a layering problem. PiperOrigin-RevId: 218773981
* Refactor the bulk of the worklist driver out of the canonicalizer into its ownChris Lattner2019-03-291-299/+30
| | | | | | | | | | helper function, in preparation for it being used by other passes. There is still a lot of room for improvement in its design, this patch is intended as an NFC refactoring, and the improvements will continue after this lands. PiperOrigin-RevId: 218737116
* Teach canonicalize pass to unique and hoist constants to the entry block. ThisChris Lattner2019-03-291-23/+77
| | | | | | | | | is a straight-forward change, but required adding missing moveBefore() methods on operations (requiring moving some traits around to make C++ happy). This also fixes a constness issue with the getBlock/getFunction() methods on Instruction, and adds a missing getFunction() method on MLFuncBuilder. PiperOrigin-RevId: 218523905
* Implement shape folding in the canonicalization pass:Chris Lattner2019-03-291-2/+110
| | | | | | | | | | | | | - Add a few canonicalization patterns to fold memref_cast into load/store/dealloc. - Canonicalize alloc(constant) into an alloc with a constant shape followed by a cast. - Add a new PatternRewriter::updatedRootInPlace API to make this more convenient. SimplifyAllocConst and the testcase is heavily based on Uday's implementation work, just in a different framework. PiperOrigin-RevId: 218361237
* Add a pattern (x+0) -> x, generalize Canonicalize to CFGFunc's, address a ↵Chris Lattner2019-03-291-42/+103
| | | | | | | | few TODOs, and add some casting support to Operation. PiperOrigin-RevId: 218219340
* Introduce a new Operation::erase helper to generalize some code inChris Lattner2019-03-291-7/+2
| | | | | | | the pattern matcher / canonicalizer, and rename existing eraseFromBlock methods to align with it. PiperOrigin-RevId: 218104455
* Introduce a new PatternRewriter class to help keep the worklist inChris Lattner2019-03-291-18/+82
| | | | | | | | | | | PatternMatcher clients up to date and provide a funnel point for newly added operations. This is also progress towards the canonicalizer supporting CFGFunctions. This paves the way for more complex patterns, but by itself doesn't do much useful, so no testcase. PiperOrigin-RevId: 218101737
* Rename Operation::getAs to Operation::dyn_castFeng Liu2019-03-291-5/+3
| | | | | | | | | Also rename Operation::is to Operation::isa Introduce Operation::cast All of these are for consistency with global dyn_cast/cast/isa operators. PiperOrigin-RevId: 217878786
* Use FuncBuilder instead of MLFuncBuilder in pattern matcher.Jacques Pienaar2019-03-291-4/+5
| | | | | | Use the general function buil wrapper instead of the CFG/ML specific one. PiperOrigin-RevId: 217335607
* Add constant folding and binary operator reassociation to the canonicalizeChris Lattner2019-03-291-8/+97
| | | | | | | pass, build up the worklist infra in anticipation of improving the pattern matcher to match more than one node. PiperOrigin-RevId: 217330579
* Move Pattern and related classes to a different fileFeng Liu2019-03-291-267/+2
| | | | | | So we can use it as a library. PiperOrigin-RevId: 217267049
* Various improvements to pattern matching and other infra:Chris Lattner2019-03-291-28/+121
| | | | | | | | | | | - Make it so OpPointer implicitly converts to SSAValue* when the underlying op has a single value. This eliminates a lot more ->getResult() calls and makes the behavior more LLVM-like - Fill out PatternBenefit to be typed instead of just a typedef for int with magic numbers. - Simplify various code due to these changes. PiperOrigin-RevId: 217020717
* Implement a super sketched out pattern match/rewrite framework and a sketchedChris Lattner2019-03-291-0/+311
out canonicalization pass to drive it, and a simple (x-x) === 0 pattern match as a test case. There is a tremendous number of improvements that need to land, and the matcher/rewriter and patterns will be split out of this file, but this is a starting point. PiperOrigin-RevId: 216788604
OpenPOWER on IntegriCloud