summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Parser
Commit message (Collapse)AuthorAgeFilesLines
...
* Avoid hardcoded 4096 constantNicolas Vasilache2019-03-292-3/+5
| | | | | | | | | | | 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
* Uniformize access pattern to state.Nicolas Vasilache2019-03-291-8/+8
| | | | | | | | | | We seem to be using *& quite consistently across the codebase. Replacing 2 occurences of **. With this, `grep -R "\*\*" .` does not return instances of accesses to state anymore. PiperOrigin-RevId: 210385345
* Remove dead declarationNicolas Vasilache2019-03-291-1/+0
| | | | | | Stumbled upon this while I was reading code PiperOrigin-RevId: 210385303
* Implement operands for the lower and upper bounds of the for statement.Tatiana Shpeisman2019-03-292-24/+147
| | | | | | | | | | | | | | | 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
* Two unrelated API cleanups: remove the location processing stuff from custom opChris Lattner2019-03-291-30/+14
| | | | | | | | parser hooks, as it has been subsumed by a simpler and cleaner mechanism. Second, remove the "Inst" suffixes from a few methods in CFGFuncBuilder since they are redundant and this is inconsistent with the other builders. NFC. PiperOrigin-RevId: 210006263
* Push location information more tightly into the IR, providing space for everyChris Lattner2019-03-291-22/+43
| | | | | | | | | | | | | | 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
* Clean up the op builder APIs, and simplify the implementation of ops by makingChris Lattner2019-03-291-3/+3
| | | | | | | 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-291-21/+64
| | | | | | 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-291-6/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Finish support for function attributes, and improve lots of things:Chris Lattner2019-03-291-24/+146
| | | | | | | | | | | | | | | | | | | | | | | - 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-291-4/+70
| | | | | | | | | | 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-291-7/+24
| | | | | | | names across the module and auto-renaming conflicts. Have the parser reject malformed modules that have redefinitions. PiperOrigin-RevId: 209227560
* [mlir] Fix tests after Chris implemented string escaping in MLIRJames Molloy2019-03-291-1/+1
| | | | | | We don't need to C-escape any more, so don't. Also, change the expected escaping syntax to be the slightly noisier version that LLVM emits. PiperOrigin-RevId: 208989483
* Escape and unescape strings in the parser and printer so they can roundtrip,Chris Lattner2019-03-292-6/+48
| | | | | | | | | | | 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
* [mlir] Allow C-style escapes in LexerJames Molloy2019-03-292-3/+8
| | | | | | This patch passes the raw, unescaped value through to the rest of the stack. Partial escaping is a total pain to deal with, so we either need to implement escaping properly (ideally using a third party library like absl, I don't think LLVM has one that can handle the proper gamut of escape codes) or don't escape. I chose the latter for this patch. PiperOrigin-RevId: 208608945
* Implement return statement as RetOp operation. Add verification of the ↵Tatiana Shpeisman2019-03-291-17/+13
| | | | | | | | 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-291-7/+7
| | | | | | | | 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-3/+6
| | | | | | parsing chain and resolve TODOs. NFC. PiperOrigin-RevId: 207913754
* Support for affine integer setsUday Bondhugula2019-03-294-42/+223
| | | | | | | | | | | | | - 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-291-27/+14
| | | | | | | 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-291-5/+8
| | | | | | | | 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
* Fix b/112189633, where we'd produce errors but not return failure from theChris Lattner2019-03-291-3/+5
| | | | | | parser. I'm not sure how to write a (non-ridiculous) testcase for this. PiperOrigin-RevId: 207606942
* Implement ML function arguments. Add representation for argument list in ML ↵Tatiana Shpeisman2019-03-291-5/+13
| | | | | | | | 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-291-0/+14
| | | | | | | | | | | | - 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
* [mlir] Add a TypeAttr class, allow type attributesJames Molloy2019-03-291-7/+12
| | | | PiperOrigin-RevId: 207235956
* Give custom ops the ability to also access general additional attributes in theChris Lattner2019-03-291-17/+37
| | | | | | parser and printer. Fix the spelling of 'delimeter' PiperOrigin-RevId: 207189892
* [mlir] Add a string typeJames Molloy2019-03-292-0/+4
| | | | PiperOrigin-RevId: 206977161
* Enhance MLIRContext and operations with the ability to register diagnosticChris Lattner2019-03-291-1/+1
| | | | | | | | | | | | handlers and to feed them with errors and warnings produced by the compiler. Enhance Operation to be able to get its own MLIRContext on demand, simplifying some clients. Change the verifier to emit certain errors with the diagnostic handler. This is steps towards reworking the verifier and diagnostic propagation but is itself not particularly useful. More to come. PiperOrigin-RevId: 206948643
* Clean up and extend MLFuncBuilder to allow creating statements in the middle ↵Tatiana Shpeisman2019-03-291-4/+6
| | | | | | | | of a statement block. Rename Statement::getFunction() and StmtBlock()::getFunction() to findFunction() to make it clear that this is not a constant time getter. Fix b/112039912 - we were recording 'i' instead of '%i' for loop induction variables causing "use of undefined SSA value" error. PiperOrigin-RevId: 206884644
* Add parsing for floating point attributes.Jacques Pienaar2019-03-295-7/+49
| | | | | | This is doing it in a suboptimal manner by recombining [integer period literal] into a string literal and parsing that via to_float. PiperOrigin-RevId: 206855106
* Add . to bare-id to allow custom ops such as tf.addJacques Pienaar2019-03-291-3/+3
| | | | PiperOrigin-RevId: 206840659
* Use for statement directly as an operand instead of having it pretend to be ↵Tatiana Shpeisman2019-03-291-1/+1
| | | | | | an induction variable. PiperOrigin-RevId: 206759180
* Implement induction variables. Pretty print induction variable operands as ↵Tatiana Shpeisman2019-03-291-6/+13
| | | | | | | | | | %i<ssa value number>. Add support for future pretty printing of ML function arguments as %arg<ssa value number>. Induction variables are implemented by inheriting ForStmt from MLValue. ForStmt provides APIs that make this design decision invisible to the ForStmt users. This CL in combination with cl/206253643 resolves http://b/111769060. PiperOrigin-RevId: 206655937
* Prepare for implementation of TensorFlow passes:Chris Lattner2019-03-291-1/+5
| | | | | | | | | | - Sketch out a TensorFlow/IR directory that will hold op definitions and common TF support logic. We will eventually have TensorFlow/TF2HLO, TensorFlow/Grappler, TensorFlow/TFLite, etc. - Add sketches of a Switch/Merge op definition, including some missing stuff like the TwoResults trait. Add a skeleton of a pass to raise this form. - Beef up the Pass/FunctionPass definitions slightly, moving the common code out of LoopUnroll.cpp into a new IR/Pass.cpp file. - Switch ConvertToCFG.cpp to be a ModulePass. - Allow _ to start bare identifiers, since this is important for TF attributes. PiperOrigin-RevId: 206502517
* Finish parser/printer support for AffineMapOp, implement operand iterators onChris Lattner2019-03-291-1/+12
| | | | | | | VariadicOperands, tidy up some code in the asmprinter, fill out more verification logic in for LoadOp. PiperOrigin-RevId: 206443020
* Eliminate "primitive" types from being a thing, splitting them into FloatTypeChris Lattner2019-03-291-57/+49
| | | | | | | | | | | | | | and OtherType. Other type is now the thing that holds AffineInt, Control, eventually Resource, Variant, String, etc. FloatType holds the floating point types, and allows convenient query of isa<FloatType>(). This fixes issues where we allowed control to be the element type of tensor, memref, vector. At the same time, ban AffineInt from being an element of a vector/memref/tensor as well since we don't need it. I updated the spec to match this as well. PiperOrigin-RevId: 206361942
* Add tf_control type and allow $ in bare-id.Jacques Pienaar2019-03-293-4/+8
| | | | | | | * Add tf_control as primitive type; * Allow $ in bare-id to allow attributes with $ (to make it trivially to mangle a TF attribute); PiperOrigin-RevId: 206342642
* Implement MLValue, statement operands, operation statement operands and ↵Tatiana Shpeisman2019-03-291-15/+30
| | | | | | values. ML functions now have full support for expressing operations. Induction variables, function arguments and return values are still todo. PiperOrigin-RevId: 206253643
* Implement a proper function list in module, which auto-maintain the parentChris Lattner2019-03-291-8/+7
| | | | | | | | | pointer, and ensure that functions are deleted when the module is destroyed. This exposed the fact that MLFunction had no dtor, and that the dtor in CFGFunction was broken with cyclic references. Fix both of these problems. PiperOrigin-RevId: 206051666
* Fix FIXME's/TODOs:Chris Lattner2019-03-291-67/+54
| | | | | | | | | | | - Enhance memref type to allow omission of mappings and address spaces (implying a default mapping). - Fix printing of function types to properly recurse with printType so mappings are printed by name. - Simplify parsing of AffineMaps a bit now that we have isSymbolicOrConstant() PiperOrigin-RevId: 206039755
* Implement custom parser support for operations, enhance dim/addf to use it, ↵Chris Lattner2019-03-293-42/+229
| | | | | | | | | | and add a new load op. This regresses parser error recovery in some cases (in invalid.mlir) which I'll consider in a follow-up patch. The important thing in this patch is that the parse methods in StandardOps.cpp are nice and simple. PiperOrigin-RevId: 206023308
* [mlir] Implement conditional branchJames Molloy2019-03-292-8/+51
| | | | | | | | | This looks heavyweight but most of the code is in the massive number of operand accessors! We need to be able to iterate over all operands to the condbr (all live-outs) but also just the true/just the false operands too. PiperOrigin-RevId: 205897704
* Enhance the customizable "Op" implementations in a bunch of ways:Chris Lattner2019-03-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | - Op classes can now provide customized matchers, allowing specializations beyond just a name match. - We now provide default implementations of verify/print hooks, so Op classes only need to implement them if they're doing custom stuff, and only have to implement the ones they're interested in. - "Base" now takes a variadic list of template template arguments, allowing concrete Op types to avoid passing the Concrete type multiple times. - Add new ZeroOperands trait. - Add verification hooks to Zero/One/Two operands and OneResult to check that ops using them are correctly formed. - Implement getOperand hooks to zero/one/two operand traits, and getResult/getType hook to OneResult trait. - Add a new "constant" op to show some of this off, with a specialization for the constant case. This patch also splits op validity checks out to a new test/IR/invalid-ops.mlir file. This stubs out support for default asmprinter support. My next planned patch building on top of this will make asmprinter hooks real and will revise this. PiperOrigin-RevId: 205833214
* Introduce a Parser::parseToken method to encapsulate a common pattern withChris Lattner2019-03-291-113/+108
| | | | | | consumeIf+emitError. NFC. PiperOrigin-RevId: 205753212
* [mlir] clang-format Parser.cppJames Molloy2019-03-291-25/+26
| | | | PiperOrigin-RevId: 205748638
* Switch return instruction to take its operand list separated from its typeChris Lattner2019-03-291-50/+54
| | | | | | | list, for consistency with the rest of the language. Consolidate some parsing logic, add operand iterators to BranchInst. PiperOrigin-RevId: 205699457
* Implement support for branch instruction operands.Chris Lattner2019-03-291-3/+52
| | | | PiperOrigin-RevId: 205666777
* [mlir] Add basic block argumentsJames Molloy2019-03-291-12/+48
| | | | | | | | This patch adds support for basic block arguments including parsing and printing. In doing so noticed that `ssa-id-and-type` is undefined in the MLIR spec; suggested an implementation in the spec doc. PiperOrigin-RevId: 205593369
* Add support for operands to the return instructions, enhance verifier to ↵Chris Lattner2019-03-291-47/+88
| | | | | | report errors through the diagnostics system when invoked by the parser. It doesn't have perfect location info, but it is close enough to be testable. PiperOrigin-RevId: 205534392
* Add support for multiple results to the printer/parser, add supportChris Lattner2019-03-293-31/+143
| | | | | | | for forward references to the parser, add initial support for SSA use-list iteration and RAUW. PiperOrigin-RevId: 205484031
OpenPOWER on IntegriCloud