Commit Graph

125 Commits

Author SHA1 Message Date
Chris Lattner e1257e8978 Change unranked tensor syntax from tensor<??f32> to tensor<*xf32> per
discussion on the list.

PiperOrigin-RevId: 212838226
2019-03-29 13:13:42 -07:00
Uday Bondhugula 64812a56c7 Extend getConstantTripCount to deal with a larger subset of loop bounds; make loop
unroll/unroll-and-jam more powerful; add additional affine expr builder methods

- use previously added analysis/simplification to infer multiple of unroll
  factor trip counts, making loop unroll/unroll-and-jam more general.

- for loop unroll, support bounds that are single result affine map's with the
  same set of operands. For unknown loop bounds, loop unroll will now work as
  long as trip count can be determined to be a multiple of unroll factor.

- extend getConstantTripCount to deal with single result affine map's with the
  same operands. move it to mlir/Analysis/LoopAnalysis.cpp

- add additional builder utility methods for affine expr arithmetic
  (difference, mod/floordiv/ceildiv w.r.t postitive constant). simplify code to
  use the utility methods.

- move affine analysis routines to AffineAnalysis.cpp/.h from
  AffineStructures.cpp/.h.

- Rename LoopUnrollJam to LoopUnrollAndJam to match class name.

- add an additional simplification for simplifyFloorDiv, simplifyCeilDiv

- Rename AffineMap::getNumOperands() getNumInputs: an affine map by itself does
  not have operands. Operands are passed to it through affine_apply, from loop
  bounds/if condition's, etc., operands are stored in the latter.

This should be sufficiently powerful for now as far as unroll/unroll-and-jam go for TPU
code generation, and can move to other analyses/transformations.

Loop nests like these are now unrolled without any cleanup loop being generated.

  for %i = 1 to 100 {
    // unroll factor 4: no cleanup loop will be generated.
    for %j = (d0) -> (d0) (%i) to (d0) -> (5*d0 + 3) (%i) {
      %x = "foo"(%j) : (affineint) -> i32
    }
  }

  for %i = 1 to 100 {
    // unroll factor 4: no cleanup loop will be generated.
    for %j = (d0) -> (d0) (%i) to (d0) -> (d0 - d mod 4 - 1) (%i) {
      %y = "foo"(%j) : (affineint) -> i32
    }
  }

  for %i = 1 to 100 {
    for %j = (d0) -> (d0) (%i) to (d0) -> (d0 + 128) (%i) {
      %x = "foo"() : () -> i32
    }
  }

TODO(bondhugula): extend this to LoopUnrollAndJam as well in the next CL (with minor
changes).

PiperOrigin-RevId: 212661212
2019-03-29 13:13:00 -07:00
Chris Lattner 5f11f68405 Several minor infra improvements:
- Make the tf-lower-control flow handle error cases better.  Add a testcase
   that (currently) fails due to type mismatches.
 - Factor more code in the verifier for basic block argument checking, and
   check more invariants.
 - Fix a crasher in the asmprinter on null instructions (which only occurs on
   invalid code).
 - Fix a bug handling conditional branches with no block operands, it would
   access &operands[0] instead of using operands.data().
 - Enhance the mlir-opt driver to use the verifier() in a non-crashing mode,
   allowing issues to be reported as diagnostics.

PiperOrigin-RevId: 211818291
2019-03-29 13:10:11 -07:00
Tatiana Shpeisman 1a56ee7093 Implement operands for the 'if' statement.
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
2019-03-29 13:07:16 -07:00
Tatiana Shpeisman d32a28c520 Implement operands for the lower and upper bounds of the for statement.
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
2019-03-29 13:05:16 -07:00
Chris Lattner 84259c7def Implement call and call_indirect ops.
This also fixes an infinite recursion in VariadicOperands that this turned up.

PiperOrigin-RevId: 209692932
2019-03-29 13:03:51 -07:00
Uday Bondhugula 00bed4bd99 Extend loop unrolling to unroll by a given factor; add builder for affine
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
2019-03-29 13:03:38 -07:00
Chris Lattner 9265197c4e Implement initial support for function attributes, including parser, printer,
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
2019-03-29 13:02:44 -07:00
Chris Lattner ae79d69922 Implement a module-level symbol table for functions, enforcing uniqueness of
names across the module and auto-renaming conflicts.  Have the parser reject
malformed modules that have redefinitions.

PiperOrigin-RevId: 209227560
2019-03-29 13:02:30 -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
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
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
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
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
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
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 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
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
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
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
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
Chris Lattner 782c348c00 Change mlir-opt.cpp to take a list of passes to run, simplifying the driver
code.  Change printing of affine map's to not print a space between the dim and
symbol list.

PiperOrigin-RevId: 206505419
2019-03-29 12:47:38 -07:00
Chris Lattner 9128a4aa87 Finish parser/printer support for AffineMapOp, implement operand iterators on
VariadicOperands, tidy up some code in the asmprinter, fill out more
verification logic in for LoadOp.

PiperOrigin-RevId: 206443020
2019-03-29 12:47:11 -07:00
Chris Lattner 6e89270b2d Implement support for predecessor iterators on basic blocks, use them to print
out predecessor information in the asmprinter.

PiperOrigin-RevId: 206343174
2019-03-29 12:46:44 -07:00
Jacques Pienaar 6a93e146c0 Add tf_control type and allow $ in bare-id.
* 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
2019-03-29 12:46:30 -07:00
Uday Bondhugula 0af97111d2 Stmt visitors and walkers.
- Update InnermostLoopGatherer to use a post order traversal (linear
  time/single traversal).
- Drop getNumNestedLoops().
- Update isInnermost() to use the StmtWalker.

When using return values in conjunction with walkers, the StmtWalker CRTP
pattern doesn't appear to be of any use. It just requires overriding nearly all
of the methods, which is what InnermostLoopGatherer currently does. Please see
FIXME/ENLIGHTENME comments. TODO: figure this out from this CL discussion.

Note
- Comments on visitor/walker base class are out of date; will update when this
  CL is finalized.

PiperOrigin-RevId: 206340901
2019-03-29 12:46:17 -07:00
Tatiana Shpeisman 9ebd3c7df8 Implement MLValue, statement operands, operation statement operands and values. ML functions now have full support for expressing operations. Induction variables, function arguments and return values are still todo.
PiperOrigin-RevId: 206253643
2019-03-29 12:46:04 -07:00
Chris Lattner f964bad6d1 Implement a proper function list in module, which auto-maintain the parent
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
2019-03-29 12:43:57 -07:00
Chris Lattner 50f89b4188 Fix FIXME's/TODOs:
- 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
2019-03-29 12:43:42 -07:00
Chris Lattner b5cdf60477 Expose custom asmprinter support to core operations and have them adopt it,
fixing the printing syntax for dim, constant, fadd, etc.

PiperOrigin-RevId: 205908627
2019-03-29 12:42:08 -07:00
James Molloy f7f70ee691 [mlir] Implement conditional branch
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
2019-03-29 12:41:55 -07:00
James Molloy 4db2ee5f1b [mlir] Fix a use-after-free iterator error found by asan
While fixing this the parser-affine-map.mlir test started failing due to ordering of the printed affine maps. Even the existing CHECK-DAGs weren't enough to disambiguate; a partial match on one line precluded a total match on a following line.

The fix for this was easy - print the affine maps in reference order rather than in DenseMap iteration order.

PiperOrigin-RevId: 205843770
2019-03-29 12:40:47 -07:00
James Molloy 0b2ec56d8f [mlir] clang-format
Mostly whitespace changes, but this makes these files clang-format clean.

PiperOrigin-RevId: 205697599
2019-03-29 12:39:25 -07:00
Chris Lattner 21ede32ff5 Implement support for branch instruction operands.
PiperOrigin-RevId: 205666777
2019-03-29 12:38:45 -07:00
Chris Lattner 3de07e5c53 Implement generic operand/result iterators that map through our implementation
details, returning things in terms of values (which is what most clients want).

Implement support for operands and results on Operation, and simplify the
asmprinter to use it.

PiperOrigin-RevId: 205608853
2019-03-29 12:38:32 -07:00
James Molloy 4144c302db [mlir] Add basic block arguments
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
2019-03-29 12:38:20 -07:00
Chris Lattner e402dcc47f Add support for operands to the return instructions, enhance verifier to 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
2019-03-29 12:38:07 -07:00
Chris Lattner 3d2a24635e Add support for multiple results to the printer/parser, add support
for forward references to the parser, add initial support for SSA
use-list iteration and RAUW.

PiperOrigin-RevId: 205484031
2019-03-29 12:37:54 -07:00
Chris Lattner 3b7b3302c7 Refactor the AsmParser to follow the pattern established in the parser:
there is now an explicit state class - which only has one instance per top
level FooThing::print call.  The FunctionPrinter's now subclass ModulePrinter
so they can just call print on their types and other global stuff.  This also
makes the contract strict that the global FooThing::print calls are the public
entrypoints and that the printer implementation is otherwise self contained.

No Functionality Change.

PiperOrigin-RevId: 205409317
2019-03-29 12:37:14 -07:00
Chris Lattner a798b021f9 Teach the asmprinter to print out operands for OperationInst's. This
is still limited in several ways, which i'll build out in subsequent patches.

Rename the accessor for inst operands/results to make the Operand/Result
versions of these more obscure, allowing getOperand/getResult to traffic
in values (which is what - by far - most clients actually care about).

PiperOrigin-RevId: 205408439
2019-03-29 12:37:00 -07:00
Uday Bondhugula 6d242fcf4b Simplify affine binary op expression class hierarchy
- Drop sub-classing of affine binary op expressions.
- Drop affine expr op kind sub. Represent it as multiply by -1 and add. This
  will also be in line with the math form when we'll need to represent a system of
  linear equalities/inequalities: the negative number goes into the coefficient
  of an affine form. (For eg. x_1 + (-1)*x_2 + 3*x_3 + (-2) >= 0). The folding
  simplification will transparently deal with multiplying the -1 with any other
  constants. This also means we won't need to simplify a multiply expression
  like in x_1 + (-2)*x_2 to a subtract expression (x_1 - 2*x_2) for
  canonicalization/uniquing.
- When we print the IR, we will still pretty print to a subtract when possible.

PiperOrigin-RevId: 205298958
2019-03-29 12:36:46 -07:00
Tatiana Shpeisman 6ada91db02 Parse ML function arguments, return statement operands, and for statement loop header.
Loop bounds and presumed to be constants for now and are stored in ForStmt as affine constant expressions.  ML function arguments, return statement operands and loop variable name are dropped for now.

PiperOrigin-RevId: 205256208
2019-03-29 12:36:20 -07:00
Chris Lattner 72c24e3e71 Add basic parser support for operands:
- This introduces a new FunctionParser base class to handle logic common
   between the kinds of functions we have, e.g. ssa operand/def parsing.
 - This introduces a basic symbol table (without support for forward
   references!) and links defs and uses.
 - CFG functions now parse and build operand lists for operations.  The printer
   isn't set up for them yet tho.

PiperOrigin-RevId: 205246110
2019-03-29 12:36:08 -07:00
MLIR Team f1e039617b Support for AffineMapAttr.
PiperOrigin-RevId: 205157390
2019-03-29 12:35:40 -07:00
Chris Lattner b3fa7d0e9f Initial support for operands and results and SSA constructs, first on
the instruction side of the house.

This has a number of limitations, including that we are still dropping
operands on the floor in the parser.  Also, most of the convenience methods
aren't wired up yet.  This is enough to get result type lists round tripping
through.

PiperOrigin-RevId: 205148223
2019-03-29 12:35:28 -07:00
MLIR Team 321f8c5443 Address AsmPrinter changes from last CL.
PiperOrigin-RevId: 205096519
2019-03-29 12:35:15 -07:00
MLIR Team fa75d6210e Adds ModuleState to support printing outlined AffineMaps.
PiperOrigin-RevId: 204999887
2019-03-29 12:35:00 -07:00
Tatiana Shpeisman fc7d6dbe5e Parse operations in ML functions. Add builder class for ML functions.
Refactors operation parsing to share functionality between CFG and ML functions. ML function construction now goes through a builder, similar to the way it is done for
CFG functions.

PiperOrigin-RevId: 204779279
2019-03-29 12:34:34 -07:00
MLIR Team 8e8114a96d Adds MemRef type and adds support for parsing memref affine map composition.
PiperOrigin-RevId: 204756982
2019-03-29 12:34:20 -07:00
Jacques Pienaar 1d0d9968ee Move newline printed with op to function/basic block printer.
Allows printing the instruction to string without trailing newline. Making it easier to reuse print to annotate instructions during lowering. And removes need for newline in the print functions of ops.

PiperOrigin-RevId: 204630791
2019-03-29 12:34:07 -07:00
Tatiana Shpeisman 8efc06dc2c Refactor implementation of Statement class heirarchy to use statement block.
Use LLVM double-link with parent list to store statements within a block.

PiperOrigin-RevId: 204515541
2019-03-29 12:33:28 -07:00
Uday Bondhugula 8fbaf79afb Parse affine map range sizes.
PiperOrigin-RevId: 204240947
2019-03-29 12:32:59 -07:00
Chris Lattner d6c4c5dbb8 Add attributes and affine expr/map to the Builder, switch the parser over to
use it.

This also removes "operand" from the affine expr classes: it is unnecessary
verbosity and "operand" will mean something very specific for SSA stuff (we
will have an Operand type).

PiperOrigin-RevId: 203976504
2019-03-29 12:32:08 -07:00
Tatiana Shpeisman 6d93615678 Implement OperationStmt. Refactor function printing to use FunctionState class for operation printing. FunctionState class is a base class for CFGFunctionState and MLFunctionState classes. No parsing yet - will add once cl/203785893 is in.
PiperOrigin-RevId: 203862427
2019-03-29 12:31:30 -07:00
Uday Bondhugula fc46bcf51d Complete affine expr parsing support
- check for non-affine expressions
- handle negative numbers and negation of id's, expressions
- functions to check if a map is pure affine or semi-affine
- simplify/clean up affine map parsing code
- report more errors messages, more accurate error messages

PiperOrigin-RevId: 203773633
2019-03-29 12:31:03 -07:00
Jacques Pienaar f9da10ce45 Change to assert(0,x) to llvm_unreachable(x)
This avoids fall-through error in opt mode:
error: unannotated fall-through between switch labels
[-Werror,-Wimplicit-fallthrough]
PiperOrigin-RevId: 203616256
2019-03-29 12:30:10 -07:00
Chris Lattner 1928e20a56 Add the ability to have "Ops" defined as small C++ classes, with some nice
properties:
 - They allow type checked dynamic casting from their base Operation.
 - They allow nice accessors for C++ clients, e.g. a "getIndex()" method on
   'dim' that returns an unsigned.
 - They work with both OperationInst/OperationStmt (once OperationStmt is
   implemented).
 - They get custom printing logic.  They will eventually get custom parsing,
   verifier, and builder logic as well.
 - Out of tree clients can register their own operation set without having to
   change MLIR core, e.g. for TensorFlow or custom target instructions.

This registers addf and dim as examples.

PiperOrigin-RevId: 203382993
2019-03-29 12:29:29 -07:00
Chris Lattner b0dabbd67f Add parsing for attributes and attibutes on operations. Add IR representation
for attributes on operations.  Split Operation out from OperationInst so it
can be shared with OperationStmt one day.

PiperOrigin-RevId: 203325366
2019-03-29 12:29:16 -07:00
Uday Bondhugula 3dc4fb6f0f Parsing support for affine maps and affine expressions
A recursive descent parser for affine maps/expressions with operator precedence and
associativity. (While on this, sketch out uniqui'ing functionality for affine maps
and affine binary op expressions (partly).)

PiperOrigin-RevId: 203222063
2019-03-29 12:28:22 -07:00
Tatiana Shpeisman 177ce7215c Basic representation and parsing of if and for statements. Loop headers and if statement conditions are not yet supported.
PiperOrigin-RevId: 203211526
2019-03-29 12:28:10 -07:00
Chris Lattner 789ba6319e Improve management of instructions and basic blocks by having their inclusion
in a container automatically maintain their parent pointers, and change storage
from std::vector to the proper llvm::iplist type.

PiperOrigin-RevId: 202889037
2019-03-29 12:27:44 -07:00
Uday Bondhugula fdf7bc4e25 [WIP] Sketching IR and parsing support for affine maps, affine expressions
Run test case:

$ mlir-opt test/IR/parser-affine-map.mlir
test/IR/parser-affine-map.mlir:3:30: error: expect '(' at start of map range
#hello_world2 (i, j) [s0] -> i+s0, j)
                             ^

PiperOrigin-RevId: 202736856
2019-03-29 12:27:20 -07:00
Chris Lattner 1734d78f88 Sketch out parser/IR support for OperationInst, and a new Instruction base
class.

Introduce an Identifier class to MLIRContext to represent uniqued identifiers,
introduce string literal support to the lexer, introducing parser and printer
support etc.

PiperOrigin-RevId: 202592007
2019-03-29 12:26:53 -07:00
Tatiana Shpeisman 3609599af6 Introduce IR and parser support for ML functions.
Representing function arguments is still TODO.
Supporting instructions other than return is also TODO.

PiperOrigin-RevId: 202570934
2019-03-29 12:26:41 -07:00
Chris Lattner 2b6684cfbe Add the unconditional branch instruction, improve diagnostics for block
references.

PiperOrigin-RevId: 201872745
2019-03-29 12:25:35 -07:00
Chris Lattner 80b6bd24b3 Implement parser/IR support for CFG functions, basic blocks and return instruction.
This is pretty much minimal scaffolding for this step.  Basic block arguments,
instructions, other terminators, a proper IR representation for
blocks/instructions, etc are all coming.

PiperOrigin-RevId: 201826439
2019-03-29 12:24:45 -07:00