summaryrefslogtreecommitdiffstats
path: root/mlir/lib/IR
Commit message (Collapse)AuthorAgeFilesLines
...
* Continue revising diagnostic handling to simplify and generalize it, and ↵Chris Lattner2019-03-291-3/+9
| | | | | | | | | | | | | | | | | | | improve related infra. - Add a new -verify mode to the mlir-opt tool that allows writing test cases for optimization and other passes that produce diagnostics. - Refactor existing the -check-parser-errors flag to mlir-opt into a new -split-input-file option which is orthogonal to -verify. - Eliminate the special error hook the parser maintained and use the standard MLIRContext's one instead. - Enhance the default MLIRContext error reporter to print file/line/col of errors when it is available. - Add new createChecked() methods to the builder that create ops and invoke the verify hook on them, use this to detected unhandled code in the RaiseControlFlow pass. - Teach mlir-opt about expected-error @+, it previously only worked with @- PiperOrigin-RevId: 211305770
* Fix the underlying cause for the asan test failure introduced by cl/210618122.Tatiana Shpeisman2019-03-291-1/+2
| | | | | | Restored the order of deleting then-clause before else-clause in if-statement destructor, since it does not and should not matter. PiperOrigin-RevId: 211273720
* Fix asan failure introduced by cl/210618122 and statement walker crash for ↵Tatiana Shpeisman2019-03-291-1/+2
| | | | | | if statements without else clause. PiperOrigin-RevId: 211186361
* Add builders for memory ops that did not have them (tested in forthcoming CL).MLIR Team2019-03-291-0/+19
| | | | PiperOrigin-RevId: 211147994
* Affine expression analysis and simplification.Uday Bondhugula2019-03-292-10/+59
| | | | | | | | | | | | | | | | | | | | | | | Outside of IR/ - simplify a MutableAffineMap by flattening the affine expressions - add a simplify affine expression pass that uses this analysis - update the FlatAffineConstraints API (to be used in the next CL) In IR: - add isMultipleOf and getKnownGCD for AffineExpr, and make the in-IR simplication of simplifyMod simpler and more powerful. - rename the AffineExpr visitor methods to distinguish b/w visiting and walking, and to simplify API names based on context. The next CL will use some of these for the loop unrolling/unroll-jam to make the detection for the need of cleanup loop powerful/non-trivial. A future CL will finally move this simplification to FlatAffineConstraints to make it more powerful. For eg., currently, even if a mod expr appearing in a part of the expression tree can't be simplified, the whole thing won't be simplified. PiperOrigin-RevId: 211012256
* Implement operands for the 'if' statement.Tatiana Shpeisman2019-03-294-18/+50
| | | | | | | | This CL also includes two other minor changes: - change the implemented syntax from 'if (cond)' to 'if cond', as specified by MLIR spec. - a minor fix to the implementation of the ForStmt. PiperOrigin-RevId: 210618122
* Introduce a new Location abstraction to represent location data in a structuredChris Lattner2019-03-295-21/+86
| | | | | | | | (and more useful) way rather than hacking up a pile of attributes for it. In the future this will grow to represent inlined locations, fusion cases etc, but for now we start with simple Unknown and File/Line/Col locations. NFC. PiperOrigin-RevId: 210485775
* Avoid hardcoded 4096 constantNicolas Vasilache2019-03-291-0/+1
| | | | | | | | | | | This commit creates a static constexpr limit for the IntegerType bitwidth and uses it. The check had to be moved because Token is not aware of IR/Type and it was a sign the abstraction leaked: bitwidth limit is not a property of the Token but of the IntegerType. Added a positive and a negative test at the limit. PiperOrigin-RevId: 210388192
* Implement operands for the lower and upper bounds of the for statement.Tatiana Shpeisman2019-03-297-43/+315
| | | | | | | | | | | | | | | This revamps implementation of the loop bounds in the ForStmt, using general representation that supports operands. The frequent case of constant bounds is supported via special access methods. This also includes: - Operand iterators for the Statement class. - OpPointer::is() method to query the class of the Operation. - Support for the bound shorthand notation parsing and printing. - Validity checks for the bound operands used as dim ids and symbols I didn't mean this CL to be so large. It just happened this way, as one thing led to another. PiperOrigin-RevId: 210204858
* First steps towards TF/XLA control flow lowering: functional if lowering.Chris Lattner2019-03-293-11/+60
| | | | | | | | | | - Implement support for the TensorFlow 'If' op, the first TF op definition. - Fill in some missing basic infra, including the ability to split a basic block, the ability to create a branch with operands, etc. - Implement basic lowering for some simple forms of If, where the condition is a zero-D bool tensor and when all the types line up. Future patches will generalize this. There is still much to be done here. I'd like to get some example graphs coming from the converter to play with to direct this work. PiperOrigin-RevId: 210198760
* Push location information more tightly into the IR, providing space for everyChris Lattner2019-03-294-43/+130
| | | | | | | | | | | | | | operation and statement to have a location, and make it so a location is required to be specified whenever you make one (though a null location is still allowed). This is to encourage compiler authors to propagate loc info properly, allowing our failability story to work well. This is still a WIP - it isn't clear if we want to continue abusing Attribute for location information, or whether we should introduce a new class heirarchy to do so. This is good step along the way, and unblocks some of the tf/xla work that builds upon it. PiperOrigin-RevId: 210001406
* Introduce a new extract_element operation that does what it says. Introduce aChris Lattner2019-03-293-15/+109
| | | | | | | | | | new VectorOrTensorType class that provides a common interface between vector and tensor since a number of operations will be uniform across them (including extract_element). Improve the LoadOp verifier. I also updated the MLIR spec doc as well. PiperOrigin-RevId: 209953189
* Clean up the op builder APIs, and simplify the implementation of ops by makingChris Lattner2019-03-291-51/+35
| | | | | | | OperationState contain a context and have the generic builder mechanics handle the job of initializing the OperationState and setting the op name. NFC. PiperOrigin-RevId: 209869948
* Implement call and call_indirect ops.Chris Lattner2019-03-294-12/+170
| | | | | | This also fixes an infinite recursion in VariadicOperands that this turned up. PiperOrigin-RevId: 209692932
* Extend loop unrolling to unroll by a given factor; add builder for affineUday Bondhugula2019-03-294-8/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | apply op. - add builder for AffineApplyOp (first one for an operation that has non-zero operands) - add support for loop unrolling by a given factor; uses the affine apply op builder. While on this, change 'step' of ForStmt to be 'unsigned' instead of AffineConstantExpr *. Add setters for ForStmt lb, ub, step. Sample Input: // CHECK-LABEL: mlfunc @loop_nest_unroll_cleanup() { mlfunc @loop_nest_unroll_cleanup() { for %i = 1 to 100 { for %j = 0 to 17 { %x = "addi32"(%j, %j) : (affineint, affineint) -> i32 %y = "addi32"(%x, %x) : (i32, i32) -> i32 } } return } Output: $ mlir-opt -loop-unroll -unroll-factor=4 /tmp/single2.mlir #map0 = (d0) -> (d0 + 1) #map1 = (d0) -> (d0 + 2) #map2 = (d0) -> (d0 + 3) mlfunc @loop_nest_unroll_cleanup() { for %i0 = 1 to 100 { for %i1 = 0 to 17 step 4 { %0 = "addi32"(%i1, %i1) : (affineint, affineint) -> i32 %1 = "addi32"(%0, %0) : (i32, i32) -> i32 %2 = affine_apply #map0(%i1) %3 = "addi32"(%2, %2) : (affineint, affineint) -> i32 %4 = affine_apply #map1(%i1) %5 = "addi32"(%4, %4) : (affineint, affineint) -> i32 %6 = affine_apply #map2(%i1) %7 = "addi32"(%6, %6) : (affineint, affineint) -> i32 } for %i2 = 16 to 17 { %8 = "addi32"(%i2, %i2) : (affineint, affineint) -> i32 %9 = "addi32"(%8, %8) : (i32, i32) -> i32 } } return } PiperOrigin-RevId: 209676220
* Sketch out affine analysis structures: AffineValueMap, IntegerValueSet,Uday Bondhugula2019-03-291-10/+23
| | | | | | | | | | | | | FlatAffineConstraints, and MutableAffineMap. All four classes introduced reside in lib/Analysis and are not meant to be used in the IR (from lib/IR or lib/Parser/). They are all mutable, alloc'ed, dealloc'ed - although with their fields pointing to immutable affine expressions (AffineExpr *). While on this, update simplifyMod to fold mod to a zero when possible. PiperOrigin-RevId: 209618437
* Finish support for function attributes, and improve lots of things:Chris Lattner2019-03-293-47/+118
| | | | | | | | | | | | | | | | | | | | | | | - Have the parser rewrite forward references to their resolved values at the end of parsing. - Implement verifier support for detecting malformed function attrs. - Add efficient query for (in general, recursive) attributes to tell if they contain a function. As part of this, improve other general infrastructure: - Implement support for verifying OperationStmt's in ml functions, refactoring and generalizing support for operations in the verifier. - Refactor location handling code in mlir-opt to have the non-error expecting form of mlir-opt invocations to report error locations precisely. - Fix parser to detect verifier failures and report them through errorReporter instead of printing the error and crashing. This regresses the location info for verifier errors in the parser that were previously ascribed to the function. This will get resolved in future patches by adding support for function attributes, which we can use to manage location information. PiperOrigin-RevId: 209600980
* Implement initial support for function attributes, including parser, printer,Chris Lattner2019-03-296-10/+76
| | | | | | | | | | resolver support. Still TODO are verifier support (to make sure you don't use an attribute for a function in another module) and the TODO in ModuleParser::finalizeModule that I will handle in the next patch. PiperOrigin-RevId: 209361648
* Implement a module-level symbol table for functions, enforcing uniqueness ofChris Lattner2019-03-293-10/+48
| | | | | | | names across the module and auto-renaming conflicts. Have the parser reject malformed modules that have redefinitions. PiperOrigin-RevId: 209227560
* Rephrasing last statement invariant check in ReturnOp::verify() to be moreTatiana Shpeisman2019-03-291-2/+2
| | | | | | elegant. PiperOrigin-RevId: 209094070
* Add support for floating point constants, fixing b/112707848. This also ↵Chris Lattner2019-03-291-0/+26
| | | | | | adds string attribute support. PiperOrigin-RevId: 209074362
* Adds dealloc MLIR memory operation to StandardOps.MLIR Team2019-03-291-2/+24
| | | | PiperOrigin-RevId: 208896071
* AffineMap::isIdentity clean up from previous CL review.MLIR Team2019-03-291-4/+3
| | | | PiperOrigin-RevId: 208891864
* Escape and unescape strings in the parser and printer so they can roundtrip,Chris Lattner2019-03-291-18/+62
| | | | | | | | | | | print floating point in a structured form that we know can round trip, enumerate attributes in the visitor so we print affine mapping attributes symbolically (the majority of the testcase updates). We still have an issue where the hexadecimal floating point syntax is reparsed as an integer, but that can evolve in subsequent patches. PiperOrigin-RevId: 208828876
* Add AffineMap::isIdentity helper function.MLIR Team2019-03-291-0/+13
| | | | PiperOrigin-RevId: 208694482
* Move Pass.{h,cpp} from lib/IR/ to lib/Transforms/.Uday Bondhugula2019-03-291-38/+0
| | | | PiperOrigin-RevId: 208571437
* Add MLFunction::getReturnStmt.Uday Bondhugula2019-03-291-0/+8
| | | | PiperOrigin-RevId: 208514441
* Add convenience builder for MemRefType.Jacques Pienaar2019-03-291-0/+6
| | | | PiperOrigin-RevId: 208245701
* Minor improvements to the return operation implementation.Tatiana Shpeisman2019-03-291-7/+4
| | | | PiperOrigin-RevId: 208166863
* Implement return statement as RetOp operation. Add verification of the ↵Tatiana Shpeisman2019-03-293-4/+117
| | | | | | | | return statement placement and operands. Add parser and parsing error tests for return statements with non-zero number of operands. Add a few missing tests for ForStmt parsing errors. Prior to this CL, return statement had no explicit representation in MLIR. Now, it is represented as ReturnOp standard operation and is pretty printed according to the return statement syntax. This way statement walkers can process ML function return operands without making special case for them. PiperOrigin-RevId: 208092424
* Rework the cloning infrastructure for statements to be able to take and updateChris Lattner2019-03-293-97/+79
| | | | | | | | an operand mapping, which simplifies it a bit. Implement cloning for IfStmt, rename getThenClause() to getThen() which is unambiguous and less repetitive in use cases. PiperOrigin-RevId: 207915990
* More grooming of custom op parser APIs to allow many of them to use a singleChris Lattner2019-03-291-42/+27
| | | | | | parsing chain and resolve TODOs. NFC. PiperOrigin-RevId: 207913754
* Support for affine integer setsUday Bondhugula2019-03-295-7/+210
| | | | | | | | | | | | | - introduce affine integer sets into the IR - parse and print affine integer sets (both inline or outlined) similar to affine maps - use integer set for IfStmt's conditional, and implement parsing of IfStmt's conditional - fixed an affine expr paren omission bug while one this. TODO: parse/represent/print MLValue operands to affine integer set references. PiperOrigin-RevId: 207779408
* Use OperationState to simplify the create<Op> methods, move them out of line,Chris Lattner2019-03-292-7/+28
| | | | | | | and simplify some other things. Change ConstantIntOp to not match affine integers, since we now have ConstantAffineIntOp. PiperOrigin-RevId: 207756316
* Refactor the asmparser hook to work with a new OperationState type that fullyChris Lattner2019-03-293-84/+100
| | | | | | | | encapsulates an operation that is yet to be created. This is a patch towards custom ops providing create methods that don't need to be templated, allowing them to move out of line in the future. PiperOrigin-RevId: 207725557
* Loop unrolling pass updateUday Bondhugula2019-03-291-5/+51
| | | | | | | | | | | | - fix/complete forStmt cloning for unrolling to work for outer loops - create IV const's only when needed - test outer loop unrolling by creating a short trip count unroll pass for loops with trip counts <= <parameter> - add unrolling test cases for multiple op results, outer loop unrolling - fix/clean up StmtWalker class while on this - switch unroll loop iterator values from i32 to affineint PiperOrigin-RevId: 207645967
* Implement ML function arguments. Add representation for argument list in ML ↵Tatiana Shpeisman2019-03-294-28/+75
| | | | | | | | Function using TrailingObjects template. Implement argument iterators, parsing and printing. Unrelated minor change - remove OperationStmt::dropReferences(). Since MLFunction does not have cyclic operand references (it's an AST) destruction can be safely done w/o a special pass to drop references. PiperOrigin-RevId: 207583024
* Continue wiring up diagnostic reporting infrastructure, still WIP.Chris Lattner2019-03-293-39/+107
| | | | | | | | | | | | - Implement a diagnostic hook in one of the paths in mlir-opt which captures and reports the diagnostics nicely. - Have the parser capture simple location information from the parser indicating where each op came from in the source .mlir file. - Add a verifyDominance() method to MLFuncVerifier to demo this, resolving b/112086163 - Add some PrettyStackTrace handlers to make crashes in the testsuite easier to track down. PiperOrigin-RevId: 207488548
* Loop unrolling update.Uday Bondhugula2019-03-292-0/+36
| | | | | | | | | | | | | | | | - deal with non-operation stmt's (if/for stmt's) in loops being unrolled (unrolling of non-innermost loops works). - update uses in unrolled bodies to use results of new operations that may be introduced in the unrolled bodies. Unrolling now works for all kinds of loop nests - perfect nests, imperfect nests, loops at any depth, and with any kind of operation in the body. (IfStmt support not done, hence untested there). Added missing dump/print method for StmtBlock. TODO: add test case for outer loop unrolling. PiperOrigin-RevId: 207314286
* Fix segfaults when printing unlinked statements, instructions and blocks. ↵Tatiana Shpeisman2019-03-294-6/+27
| | | | | | Fancy printing requires a pointer to the function since SSA values get function-specific names. This CL adds checks to ensure that we don't dereference null pointers in unliked objects. Unlinked statements, instructions and blocks are printed as <<UNLINKED STATEMENT>> etc. PiperOrigin-RevId: 207293992
* [mlir] Correctly indent block terminatorsJames Molloy2019-03-291-0/+1
| | | | | | These were non-indented, which I thought was deliberate until Chris corrected me in cl/207115253 :) PiperOrigin-RevId: 207246887
* [mlir] Add a TypeAttr class, allow type attributesJames Molloy2019-03-293-0/+18
| | | | PiperOrigin-RevId: 207235956
* Have the asmprinter give true/false constants nice names, add a dump/printChris Lattner2019-03-291-3/+29
| | | | | | method to SSAValue. PiperOrigin-RevId: 207193088
* Give custom ops the ability to also access general additional attributes in theChris Lattner2019-03-292-45/+93
| | | | | | parser and printer. Fix the spelling of 'delimeter' PiperOrigin-RevId: 207189892
* [mlir] Fix ReturnInst printing for zero operandsJames Molloy2019-03-291-2/+3
| | | | | | No longer prints a trailing ':'. PiperOrigin-RevId: 207103812
* MLStmt cloning and IV replacement for loop unrolling, add constant pool toUday Bondhugula2019-03-292-4/+35
| | | | | | | | | | | | | | MLFunctions. - MLStmt cloning and IV replacement - While at this, fix the innermostLoopGatherer to actually gather all the innermost loops (it was stopping its walk at the first innermost loop it found) - Improve comments for MLFunction statement classes, fix inheritance order. - Fixed StmtBlock destructor. PiperOrigin-RevId: 207049173
* More simplification for affine binary op expr's.Uday Bondhugula2019-03-292-31/+131
| | | | | | | | | | | | | | | - simplify operations with identity elements (multiply by 1, add with 0). - simplify successive add/mul: fold constants, propagate constants to the right. - simplify floordiv and ceildiv when divisors are constants, and the LHS is a multiply expression with RHS constant. - fix an affine expression printing bug on paren emission. - while on this, fix affine-map test cases file (memref's using layout maps that were duplicates of existing ones should be emitted pointing to the unique'd one). PiperOrigin-RevId: 207046738
* [mlir] Add a string typeJames Molloy2019-03-293-4/+13
| | | | PiperOrigin-RevId: 206977161
* [mlir] Add initial graphdef->mlir generationJames Molloy2019-03-291-1/+2
| | | | | | | | | | This CL adds: * One graphdef extracted from the TF test suite. More will come. * Scaffolding for the "graphdef2mlir" tool. * Importing of simple graphs. Type inference is not yet working, and attributes do not work either. * A fix for CFGFunction::~CFGFunction to not die if the function was destroyed without a terminator (for example if we exit early due to an error). PiperOrigin-RevId: 206965992
* Use SFINAE to generalize << overloads, give 'constant' a pretty form,Chris Lattner2019-03-295-38/+152
| | | | | | | | | generalize the asmprinters handling of pretty names to allow arbitrary sugar to be dumped on various constructs. Give CFG function arguments nice "arg0" names like MLFunctions get, and give constant integers pretty names like %c37 for a constant 377 PiperOrigin-RevId: 206953080
OpenPOWER on IntegriCloud