Commit Graph

5900 Commits

Author SHA1 Message Date
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
Jacques Pienaar bd11eff2d6 Remove undefined CFGFunction::print.
PiperOrigin-RevId: 205483944
2019-03-29 12:37:40 -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
Uday Bondhugula 8bbdd04365 Rename isSymbolic to isSymbolicOrConstant to avoid confusion.
PiperOrigin-RevId: 205288794
2019-03-29 12:36:33 -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
Chris Lattner e917c0a2ad Provide better factoring for the SSA types to allow type agnostic def/use
iterators, along with type specific ones.

Also provide mechanics to cast from Operation up to OperationStmt etc.

PiperOrigin-RevId: 205175333
2019-03-29 12:35:55 -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 fa75d6210e Adds ModuleState to support printing outlined AffineMaps.
PiperOrigin-RevId: 204999887
2019-03-29 12:35:00 -07:00
Jacques Pienaar 4293666bf7 Add no-trait base OpImpl::Base.
PiperOrigin-RevId: 204915682
2019-03-29 12:34:47 -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
Tatiana Shpeisman ad9894a2fd Use LLVM dynamic dispatch to disambiguate between StmtBlock subclasses.
PiperOrigin-RevId: 204614520
2019-03-29 12:33:41 -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
Uday Bondhugula b488a035aa Implement some simple affine expr canonicalization/simplification.
- fold constants when possible.
- for a mul expression, canonicalize to always keep the LHS as the
  constant/symbolic term, and similarly, the RHS for an add expression to keep
  it closer to the mathematical form. (Eg: f(x) = 3*x + 5)); other similar simplifications;
- verify binary op expressions at creation time.

TODO: we can completely drop AffineSubExpr, and instead use add and mul by -1.
This way something like x - 4 and -4 + x get canonicalized to x + -1 * 4
instead of being x - 4 and x + -4. (The other alternative if wanted to retain
AffineSubExpr would be to simplify x + -1*y to x - y and x + <neg number> to x
- <pos number>).
PiperOrigin-RevId: 204240258
2019-03-29 12:32:45 -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 178fd24813 AffineMap/AffineExpr: delete copy constructor/assignment, refactor
affine expr parsing.

- also make error messages uniform

PiperOrigin-RevId: 203822686
2019-03-29 12:31:17 -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
Chris Lattner a5a6c77e91 Introduce the start of IR builder APIs, which makes it easier and less error
prone to create things.

PiperOrigin-RevId: 203703229
2019-03-29 12:30:49 -07:00
Chris Lattner 67c03193de Implement a simple IR verifier, including support for custom ops adding their
own requirements.

PiperOrigin-RevId: 203497491
2019-03-29 12:29:55 -07:00
Chris Lattner 9e0e01b47a Implement Uday's suggestion to unique attribute lists across instructions,
reducing the memory impact on Operation to one word instead of 3 from an
std::vector.

Implement Jacques' suggestion to merge OpImpl::Storage into OpImpl::Base.

PiperOrigin-RevId: 203426518
2019-03-29 12:29:42 -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
Chris Lattner ccd8caee9e Implement IR support for attributes.
PiperOrigin-RevId: 203293376
2019-03-29 12:29:00 -07:00
Chris Lattner ad4ea23278 Clean up the implementation of Type, making it structurally more similar to
Instruction and AffineExpr.  NFC.

PiperOrigin-RevId: 203287117
2019-03-29 12:28:47 -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
Jacques Pienaar 2057b454dc Add default error reporter for parser.
Add a default error reporter for the parser that uses the SourceManager to print the error. Also and OptResult enum (mirroring ParseResult) to make the behavior self-documenting.

PiperOrigin-RevId: 203173647
2019-03-29 12:27:57 -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
Chris Lattner 6af866c58d Enhance the type system to support arbitrary precision integers, which are
important for low-bitwidth inference cases and hardware synthesis targets.

Rename 'int' to 'affineint' to avoid confusion between "the integers" and "the int
type".

PiperOrigin-RevId: 202751508
2019-03-29 12:27:32 -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
MLIR Team 8901448f14 Add some scaffolding for parsing affine maps:
- parsing affine map identifiers
- place-holder classes for AffineMap
- module contains a list of affine maps (defined at the top level).

PiperOrigin-RevId: 202336919
2019-03-29 12:26:28 -07:00
Jacques Pienaar b11a95350f Change Lexer and Parser to take diagnostic reporter function.
Add diagnostic reporter function to lexer/parser and use that from mlir-opt to report errors instead of having the lexer/parser print the errors.

PiperOrigin-RevId: 201892004
2019-03-29 12:25:48 -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
MLIR Team 642f3e8847 Add tensor type.
PiperOrigin-RevId: 201830793
2019-03-29 12:24:58 -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
Chris Lattner 49795d166f Introduce IR support for MLIRContext, primitive types, function types, and
vector types.

tensors and memref types are still TODO, and would be a good starter project
for someone.

PiperOrigin-RevId: 201782748
2019-03-29 12:24:32 -07:00
Chris Lattner 9b9f7ff5d4 Implement enough of a lexer and parser for MLIR to parse extfunc's without
arguments.

PiperOrigin-RevId: 201706570
2019-03-29 12:24:05 -07:00
Chris Lattner 5fc587ecf8 Continue sketching out basic infrastructure, including an input and output
filename, and printing of trivial stuff.  There is no parser yet, so the
input file is ignored.

PiperOrigin-RevId: 201596916
2019-03-29 12:23:51 -07:00
Chris Lattner 9603f9fe35 Sketch out a new repository for the mlir project (go/mlir).
PiperOrigin-RevId: 201540159
2019-03-29 12:23:24 -07:00