Commit Graph

3216 Commits

Author SHA1 Message Date
James Molloy ab2aa65511 [mlir] Fix tests after Chris implemented string escaping in MLIR
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
2019-03-29 13:01:08 -07:00
MLIR Team f962e628e3 Adds dealloc MLIR memory operation to StandardOps.
PiperOrigin-RevId: 208896071
2019-03-29 13:00:50 -07:00
MLIR Team 2487f2dc73 AffineMap::isIdentity clean up from previous CL review.
PiperOrigin-RevId: 208891864
2019-03-29 13:00:22 -07:00
Chris Lattner d6c4c748d7 Escape and unescape strings in the parser and printer so they can roundtrip,
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
2019-03-29 13:00:05 -07:00
MLIR Team 6b61409164 Add AffineMap::isIdentity helper function.
PiperOrigin-RevId: 208694482
2019-03-29 12:59:47 -07:00
James Molloy ab60afb234 [mlir] Allow C-style escapes in Lexer
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
2019-03-29 12:59:32 -07:00
Uday Bondhugula 3e92be9c71 Move Pass.{h,cpp} from lib/IR/ to lib/Transforms/.
PiperOrigin-RevId: 208571437
2019-03-29 12:59:07 -07:00
Uday Bondhugula 95c1bf445a Add MLFunction::getReturnStmt.
PiperOrigin-RevId: 208514441
2019-03-29 12:58:45 -07:00
Jacques Pienaar 067d70f20d Add convenience builder for MemRefType.
PiperOrigin-RevId: 208245701
2019-03-29 12:58:32 -07:00
Tatiana Shpeisman 22ae97cffc Minor improvements to the return operation implementation.
PiperOrigin-RevId: 208166863
2019-03-29 12:58:18 -07:00
Tatiana Shpeisman 4e289a4700 Implement return statement as RetOp operation. Add verification of the 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
2019-03-29 12:58:04 -07:00
Chris Lattner 8159186f57 Rework the cloning infrastructure for statements to be able to take and update
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
2019-03-29 12:57:38 -07:00
Chris Lattner 01915ad0a0 More grooming of custom op parser APIs to allow many of them to use a single
parsing chain and resolve TODOs.  NFC.

PiperOrigin-RevId: 207913754
2019-03-29 12:57:24 -07:00
Uday Bondhugula b1b0d938b7 Make MLIRContext class members' declaration order consistent.
PiperOrigin-RevId: 207810250
2019-03-29 12:57:11 -07:00
Uday Bondhugula 8a663870e8 Support for affine integer sets
- 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
2019-03-29 12:56:58 -07:00
Chris Lattner 9d29310882 Use OperationState to simplify the create<Op> methods, move them out of line,
and simplify some other things.  Change ConstantIntOp to not match affine
integers, since we now have ConstantAffineIntOp.

PiperOrigin-RevId: 207756316
2019-03-29 12:56:44 -07:00
Chris Lattner 17ef97bf7e Refactor the asmparser hook to work with a new OperationState type that fully
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
2019-03-29 12:56:30 -07:00
Uday Bondhugula d8490d8d4f Loop unrolling pass update
- 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
2019-03-29 12:56:16 -07:00
Chris Lattner cbdcacdbd9 Fix b/112189633, where we'd produce errors but not return failure from the
parser.  I'm not sure how to write a (non-ridiculous) testcase for this.

PiperOrigin-RevId: 207606942
2019-03-29 12:56:01 -07:00
Tatiana Shpeisman a0a6414ca2 Implement ML function arguments. Add representation for argument list in ML 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
2019-03-29 12:55:47 -07:00
Chris Lattner ed9fa46413 Continue wiring up diagnostic reporting infrastructure, still WIP.
- 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
2019-03-29 12:55:34 -07:00
Uday Bondhugula 65b6e73245 Loop unrolling update.
- 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
2019-03-29 12:55:19 -07:00
Tatiana Shpeisman 2dcdec8910 Fix segfaults when printing unlinked statements, instructions and blocks. 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
2019-03-29 12:55:06 -07:00
Uday Bondhugula b4dea892f2 Fix oversight while refactoring code in 207198873 (Fix ForStmt and StmtBlock
destructors).

getStatements().clear() should have been clear() in Statements.h.

PiperOrigin-RevId: 207270417
2019-03-29 12:54:52 -07:00
Jacques Pienaar fcf15a680b Add op create helper on CFG and ML builder.
Add create function on builder to make it easier to create ops of registered types. Enables doing `builder.create<AddFOp>(lhs, rhs)` as well as having default values on the build method.

This CL does not add a default build method (i.e., create<DimOp>(...) would fail).

PiperOrigin-RevId: 207268882
2019-03-29 12:54:39 -07:00
James Molloy 2cf3d22932 [mlir] Correctly indent block terminators
These were non-indented, which I thought was deliberate until Chris corrected me in cl/207115253 :)

PiperOrigin-RevId: 207246887
2019-03-29 12:54:24 -07:00
James Molloy 72645b31b8 [mlir] Add a TypeAttr class, allow type attributes
PiperOrigin-RevId: 207235956
2019-03-29 12:54:11 -07:00
Uday Bondhugula 8520562c34 Fix ForStmt and StmtBlock destructors.
Comments included are self-explanatory.

PiperOrigin-RevId: 207198873
2019-03-29 12:53:58 -07:00
Chris Lattner fc1f223447 Have the asmprinter give true/false constants nice names, add a dump/print
method to SSAValue.

PiperOrigin-RevId: 207193088
2019-03-29 12:53:44 -07:00
Chris Lattner 316e884367 Give custom ops the ability to also access general additional attributes in the
parser and printer.  Fix the spelling of 'delimeter'

PiperOrigin-RevId: 207189892
2019-03-29 12:53:31 -07:00
James Molloy 6472f5fbbb [mlir] Fix ReturnInst printing for zero operands
No longer prints a trailing ':'.

PiperOrigin-RevId: 207103812
2019-03-29 12:53:17 -07:00
Uday Bondhugula 2a003256ae MLStmt cloning and IV replacement for loop unrolling, add constant pool to
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
2019-03-29 12:53:02 -07:00
Uday Bondhugula b92378e8fa More simplification for affine binary op expr's.
- 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
2019-03-29 12:52:48 -07:00
James Molloy 1e793eb8dc [mlir] Add a string type
PiperOrigin-RevId: 206977161
2019-03-29 12:52:35 -07:00
James Molloy f376d3c6c4 [mlir] Add initial graphdef->mlir generation
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
2019-03-29 12:52:20 -07:00
Chris Lattner 8eaf382734 Use SFINAE to generalize << overloads, give 'constant' a pretty form,
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
2019-03-29 12:52:07 -07:00
Chris Lattner 48dbfb48d5 Enhance MLIRContext and operations with the ability to register diagnostic
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
2019-03-29 12:51:52 -07:00
Tatiana Shpeisman 8189a12bce Clean up and extend MLFuncBuilder to allow creating statements in the middle 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
2019-03-29 12:51:38 -07:00
Chris Lattner 5228ec3146 Fix some issues where we weren't printing affine map references symbolically.
Two problems: 1) we didn't visit the types in ops correctly, and 2) the
general "T" version of the OpAsmPrinter inserter would match things like
MemRefType& and print it directly.

PiperOrigin-RevId: 206863642
2019-03-29 12:51:25 -07:00
Jacques Pienaar 1015a0dded Add parsing for floating point attributes.
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
2019-03-29 12:51:12 -07:00
Chris Lattner ace4df1200 Revise the AffineExpr printing logic to be more careful about paren emission.
This is still (intentionally) generating redundant parens for nested tightly
binding expressions, but I think that is reasonable for readability sake.

This also print x-y instead of x-(y*1)

PiperOrigin-RevId: 206847212
2019-03-29 12:50:59 -07:00
Jacques Pienaar 9ff86e6fc5 Add . to bare-id to allow custom ops such as tf.add
PiperOrigin-RevId: 206840659
2019-03-29 12:50:45 -07:00
MLIR Team 6cfb09409f Make MemRefType::getNumDynamicDims const.
PiperOrigin-RevId: 206834416
2019-03-29 12:50:32 -07:00
Uday Bondhugula cdefcc86e5 Fix MLFuncBuilder::createOperation.
createOperation needs to insert the operation at 'insertPoint', which can be
anywhere (not necessarily at the end of 'statements').

PiperOrigin-RevId: 206827159
2019-03-29 12:50:19 -07:00
MLIR Team d86068203b Adds a standard op for MLIR 'store' instruction.
PiperOrigin-RevId: 206824609
2019-03-29 12:50:06 -07:00
Tatiana Shpeisman 43e2a13605 Use for statement directly as an operand instead of having it pretend to be an induction variable.
PiperOrigin-RevId: 206759180
2019-03-29 12:49:50 -07:00
Tatiana Shpeisman c8b0273f19 Implement induction variables. Pretty print induction variable operands as %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
2019-03-29 12:49:36 -07:00
MLIR Team fe7356c43b Internal change
PiperOrigin-RevId: 206652744
2019-03-29 12:49:23 -07:00
MLIR Team d48790cc52 Add standard op for MLIR 'alloc' instruction (with parser and associated tests).
Adds field to MemRefType to query number of dynamic dimensions.

PiperOrigin-RevId: 206633162
2019-03-29 12:49:10 -07:00
Jacques Pienaar 483a6d5cf8 Add AtleastNOperands trait and update tf-ops test
* TensorFlow Control Flow supports variadic number of control inputs, add variant of NOperands to support at least N operands;
* Update example:
  - All ops will produce control output;
  - Use tf$name for mapping back to TensorFlow (a op can have a name as well as an attribute _name, using tf$name disambiguates that);

PiperOrigin-RevId: 206621280
2019-03-29 12:48:56 -07:00