Commit Graph

158 Commits

Author SHA1 Message Date
Lei Zhang 5a7014c390 Add missing link dependency to MLIRTableGenTests
PiperOrigin-RevId: 266561495
2019-08-31 09:50:33 -07:00
Rob Suderman 140757050b Fix StructsGenTest.cpp CMakeFile build error
PiperOrigin-RevId: 266452719
2019-08-30 14:10:17 -07:00
Rob Suderman 8f90a442c3 Added a TableGen generator for structured data
Similar to enum, added a generator for structured data. This provide Dictionary that stores a fixed set of values and guarantees the values are valid. It is intended to store a fixed number of values by a given name.

PiperOrigin-RevId: 266437460
2019-08-30 12:52:13 -07:00
River Riddle 29099e03ce Generalize the analysis manager framework to work on any operation at any nesting.
The pass manager is moving towards being able to run on operations at arbitrary nesting. An operation may have both parent and child operations, and the AnalysisManager must be able to handle this generalization. The AnalysisManager class now contains generic 'getCachedParentAnalysis' and 'getChildAnalysis/getCachedChildAnalysis' functions to query analyses on parent/child operations. This removes the hard coded nesting relationship between Module/Function.

PiperOrigin-RevId: 266003636
2019-08-28 15:11:17 -07:00
Lei Zhang 3af6b53381 [spirv] Fix the entry block to start with OpLabel
Each basic block in SPIR-V must start with an OpLabel instruction.
We don't support control flow yet, so this CL just makes sure that
the entry block follows this rule and is valid.

PiperOrigin-RevId: 265718841
2019-08-27 10:51:26 -07:00
Denis Khalikov 8f2dfb51d4 [spirv] Add Block decoration for spv.struct.
Add Block decoration for top-level spv.struct.

Closes tensorflow/mlir#102

PiperOrigin-RevId: 265716241
2019-08-27 10:41:42 -07:00
River Riddle 2f59f76876 NFC: Remove the explicit context from Operation::create and OperationState.
The context can easily be recovered from the Location in these situations.

PiperOrigin-RevId: 265578574
2019-08-26 17:34:48 -07:00
River Riddle ba0fa92524 NFC: Move LLVMIR, SDBM, and StandardOps to the Dialect/ directory.
PiperOrigin-RevId: 264193915
2019-08-19 11:01:25 -07:00
Mahesh Ravishankar 3867ed86eb Add missing include file to StringExtrasTest.cpp
Use of std::isupper and std::islower need <cctype> header file. Fix
that and also fix the header of a file to match the file name.

PiperOrigin-RevId: 260816852
2019-07-30 16:11:40 -07:00
Mahesh Ravishankar 1de519a753 Add support for (de)serialization of SPIR-V Op Decorations
All non-argument attributes specified for an operation are treated as
decorations on the result value and (de)serialized using OpDecorate
instruction. An error is generated if an attribute is not an argument,
and the name doesn't correspond to a Decoration enum. Name of the
attributes that represent decoerations are to be the snake-case-ified
version of the Decoration name.
Add utility methods to convert to snake-case and camel-case.

PiperOrigin-RevId: 260792638
2019-07-30 14:15:03 -07:00
Lei Zhang 4a55bd5f28 [spirv] Add basic infrastructure for negative deserializer tests
We are relying on serializer to construct positive cases to drive
the test for deserializer. This leaves negative cases untested.

This CL adds a basic test fixture for covering the negative
corner cases to enforce a more robust deserializer.

Refactored common SPIR-V building methods out of serializer to
share it with the deserialization test.

PiperOrigin-RevId: 260742733
2019-07-30 11:55:33 -07:00
River Riddle fec20e590f NFC: Rename Module to ModuleOp.
Module is a legacy name that only exists as a typedef of ModuleOp.

PiperOrigin-RevId: 257427248
2019-07-10 10:11:21 -07:00
River Riddle 6b6dc59f30 Update ModuleOp::create(...) to take a Location instead of a context.
This allows for giving a Module a more interesting location than 'Unknown'.

PiperOrigin-RevId: 257310117
2019-07-10 10:11:00 -07:00
River Riddle 8c44367891 NFC: Rename Function to FuncOp.
PiperOrigin-RevId: 257293379
2019-07-10 10:10:53 -07:00
River Riddle 206e55cc16 NFC: Refactor Module to be value typed.
As with Functions, Module will soon become an operation, which are value-typed. This eases the transition from Module to ModuleOp. A new class, OwningModuleRef is provided to allow for owning a reference to a Module, and will auto-delete the held module on destruction.

PiperOrigin-RevId: 256196193
2019-07-02 16:43:36 -07:00
Lei Zhang 509411c229 [ODS] NFC: Rename EnumAttr to StrEnumAttr to be consistent with IntEnumAttr
PiperOrigin-RevId: 256169019
2019-07-02 10:28:36 -07:00
River Riddle 54cd6a7e97 NFC: Refactor Function to be value typed.
Move the data members out of Function and into a new impl storage class 'FunctionStorage'. This allows for Function to become value typed, which will greatly simplify the transition of Function to FuncOp(given that FuncOp is also value typed).

PiperOrigin-RevId: 255983022
2019-07-01 11:39:00 -07:00
Lei Zhang 9dd182e0fa [ODS] Introduce IntEnumAttr
In ODS, right now we use StringAttrs to emulate enum attributes. It is
suboptimal if the op actually can and wants to store the enum as a
single integer value; we are paying extra cost on storing and comparing
the attribute value.

This CL introduces a new enum attribute subclass that are backed by
IntegerAttr. The downside with IntegerAttr-backed enum attributes is
that the assembly form now uses integer values, which is less obvious
than the StringAttr-backed ones. However, that can be remedied by
defining custom assembly form with the help of the conversion utility
functions generated via EnumsGen.

Choices are given to the dialect writers to decide which one to use for
their enum attributes.

PiperOrigin-RevId: 255935542
2019-07-01 09:55:47 -07:00
River Riddle 30bbd91056 Simplify usages of SplatElementsAttr now that it inherits from DenseElementsAttr.
PiperOrigin-RevId: 253910543
2019-06-19 23:07:34 -07:00
River Riddle 2b67821b90 Fix the detection of boolean splat values in DenseElementsAttr for arrays with <=15 values.
PiperOrigin-RevId: 253711372
2019-06-19 23:05:19 -07:00
River Riddle 5624bc289e Add an overloaded 'get' method to DenseElementsAttr that accepts an initializer_list.
PiperOrigin-RevId: 253234385
2019-06-19 23:02:21 -07:00
Alex Zinenko b582338f62 Explicitly construct ArrayRef in AttributeTest.cpp
Some compilers find initializer list constructors from boolean literals
ambiguous between ArrayRef<bool> and ArrayRef<Attribute>.  Call the
ArrayRef<bool> constructor explicitly to disambiguate.

PiperOrigin-RevId: 253224859
2019-06-19 23:02:12 -07:00
River Riddle 6a0555a875 Refactor SplatElementsAttr to inherit from DenseElementsAttr as opposed to being a separate Attribute type. DenseElementsAttr provides a better internal representation for splat values as well as better API for accessing elements.
PiperOrigin-RevId: 253138287
2019-06-19 23:01:52 -07:00
River Riddle 2c9269124a NFC: Fix a narrowing conversion from size_t to int64_t when constructing a VectorType.
PiperOrigin-RevId: 253125435
2019-06-19 23:01:42 -07:00
River Riddle d8cd96bc8b Refactor DenseElementsAttr to support auto-splatting the dense data on construction. This essentially means that we always auto-detect splat data and only store the minimum amount of data necessary. Support for parsing dense splats, and removing SplatElementsAttr(now that it is redundant) will come in followup cls
PiperOrigin-RevId: 252720561
2019-06-19 22:59:15 -07:00
Lei Zhang 1be9fc6611 [TableGen] Generating enum definitions and utility functions
Enum attributes can be defined using `EnumAttr`, which requires all its cases
to be defined with `EnumAttrCase`. To facilitate the interaction between
`EnumAttr`s and their C++ consumers, add a new EnumsGen TableGen backend
to generate a few common utilities, including an enum class, `llvm::DenseMapInfo`
for the enum class, conversion functions from/to strings.

This is controlled via the `-gen-enum-decls` and `-gen-enum-defs` command-line
options of `mlir-tblgen`.

PiperOrigin-RevId: 252209623
2019-06-09 16:24:08 -07:00
River Riddle b790a2f396 Remove the explicit attribute kinds for DenseIntElementsAttr and DenseFPElementsAttr in favor of just one DenseElementsAttr. Now that attribute has the ability to define 'classof(Attribute attr)' methods, these derived classes can just be specializations of the main attribute class.
PiperOrigin-RevId: 251948820
2019-06-09 16:22:05 -07:00
Jacques Pienaar 8b4c214046 Use TestDialect to test traits instead of unittest.
--

PiperOrigin-RevId: 249916947
2019-06-01 20:01:12 -07:00
Alex Zinenko 6aae7b2e9a CMake build: force-link SDBM lib into SDBM unit tests
Otherwise, GCC < 7 does not link in the dialect registration, fails to look up
    the dialect in the context and cannot construct SDBM objects.

--

PiperOrigin-RevId: 249259758
2019-06-01 19:54:53 -07:00
Alex Zinenko 3b500c694d Move SDBM uniquer into the SDBM dialect
MLIRContext does not have to be aware of the SDBM unique data structures
    directly.  Move the SDBM storage uniquer from MLIRContext to the SDBM dialect
    instance.  Expressions that previously required a context to be constructed now
    require an instance of the dialect in order to access the uniquer.  While they
    could look up the dialect in the context, it would have introduced a rather
    expensive lookup into each construction.  Instead, the caller is expected to
    obtain the dialect instance and cache it.

--

PiperOrigin-RevId: 249245199
2019-06-01 19:54:43 -07:00
Alex Zinenko 6804cf2429 Move SDBM infrastructure into a new SDBM dialect
We now have sufficient extensibility in dialects to move attribute components
    such as SDBM out of the core IR into a dedicated dialect and make them
    optional.  Introduce an SDBM dialect and move the code.  This is a mostly
    non-functional change.

--

PiperOrigin-RevId: 249244802
2019-06-01 19:54:33 -07:00
Alex Zinenko 1b94395ed8 Fix -Wsign-compare in OperationSupportTest.cpp
A couple of warnings was produced when compiling this test due to comaprisons
    with a signed literal.  Used unsigned literals instead.

--

PiperOrigin-RevId: 249242970
2019-06-01 19:54:13 -07:00
Alex Zinenko c74996d199 AffineExpr: factor uniqu'ing out of MLIRContext.cpp
Affine expressions are designed as components of an attribute and are unique'd
    in the MLIRContext.  When affine expressions were implemented, uniqu'ing
    objects in a context required to modify MLIRContext implementation.  This is no
    longer the case as generic StorageUniquer has been introduced.  Port the
    AffineExpr construction to use the new infrastructure by introducing an
    affineUniquer into the MLIRContext.

--

PiperOrigin-RevId: 249207539
2019-06-01 19:53:43 -07:00
Alex Zinenko 34cbd26d64 Use FileCheck to test SDBM
SDBM has an output format representing the unterlying matrix and stripe
    expressions.  Move the SDBM tests from unit testing framework to
    FileCheck-based tests, printing them to the standard output and using FileCheck
    to test the output.  Tests that check the API proper (e.g. that SDBM
    expressions have a specific subtype) and that rely on non-syntatic properties
    (equality of the set of constraints) are not ported.

--

PiperOrigin-RevId: 249006055
2019-05-20 13:48:53 -07:00
Alex Zinenko 69ef8642df Overload arithmetic operators for SDBM expressions
Provide an "unsafe" version of the overloaded arithmetic operators for SDBM
    expressions.  These operators expect the operands to be of the right SDBM
    expression subtype and assert if they are not.  They also perform simple
    folding operations as well as some semantically correct operations that
    construct an SDBM expression of a different subtype, e.g., a difference
    expression if the RHS of an operator+ is a negated variable.  These operators
    are scoped in a namespace to allow for a future "safe" version of the operators
    that propagates null expressions to denote the error state when expressions
    have wrong subtypes.

--

PiperOrigin-RevId: 248704153
2019-05-20 13:45:34 -07:00
Alex Zinenko f06ab26acf Implement SDBM and conversion between SDBM and lists of SDBMExpr
Implement the storage class for striped difference-bound matrices (SDBM) as a
    container with a difference bounds matrix and a list of stripe expressions.  An
    SDBM defines an integer set.  Provide conversion mechanisms between lists of
    SDBM expressions treated as equalities with zero or less-than-or-equal
    inequalities with zero.

--

PiperOrigin-RevId: 248702871
2019-05-20 13:45:26 -07:00
Jacques Pienaar e489e59246 Don't fail verifying unranked shapes as being the same as this could be valid at runtime.
tensor<*xf32> could be a tensor<1xf32> at runtime but this verifyShapeMatch would return failure and say function is invalid.

--

PiperOrigin-RevId: 248583038
2019-05-20 13:44:33 -07:00
Geoffrey Martin-Noble 090662c5f3 Rename VectorOrTensorType to ShapedType
This is in preparation for making it also support/be a parent class of MemRefType. MemRefs have similar shape/rank/element semantics and it would be useful to be able to use these same utilities for them.

    This CL should not change any semantics and only change variables, types, string literals, and comments. In follow-up CLs I will prepare all callers to handle MemRef types or remove their dependence on ShapedType.

    Discussion/Rationale in https://groups.google.com/a/tensorflow.org/forum/#!topic/mlir/cHLoyfGu8y8

--

PiperOrigin-RevId: 248476449
2019-05-20 13:43:58 -07:00
Stella Laurenzo d4d8dc8db9 Start to introduce the "Quantizer" tool, which is responsible for transforming a computation expressed in floating point to one operating in terms of quantized types (where possible), either using quant-aware-training hints where available or post-training statistics.
This is being integrated from an experimental side repository piece by piece over the course of several patches and will ultimately include full build support, documentation and e2e tests.

--

PiperOrigin-RevId: 248259895
2019-05-20 13:42:30 -07:00
Stella Laurenzo d4dcf7de9e Move Quantization -> Dialect/QuantOps, FxpMathOps -> Dialect/FxpMathOps.
Adding the additional layer of directory was discussed offline and matches the Target/ tree. The names match the defacto convention we seem to be following where the C++ namespace is ^(.+)Ops/$ matched against the directory name.

    This is in preparation for patching the Quantizer into this tree, which would have been confusing without moving the Quantization dialect to its more proper home. It is left to others to move other dialects if desired.

    Tested:
      ninja check-mlir

--

PiperOrigin-RevId: 248171982
2019-05-20 13:41:55 -07:00
River Riddle d39a30626e Use the DialectSymbolRegistry to reserve space in the Attribute::Kind enum to allow for dialects to define attribute kinds. The currently defined attributes kinds have now been moved to StandardAttributes.
--

PiperOrigin-RevId: 247988373
2019-05-20 13:40:03 -07:00
Jacques Pienaar dcab80115f Add SameOperandsAndResultElementType trait.
This trait only works for tensor and vector types at the moment, verifying that the element type of an op with only tensor and vector types match. Added a unit test for it as there is no op currently in core that uses this trait.

--

PiperOrigin-RevId: 246661697
2019-05-06 08:28:59 -07:00
Alex Zinenko 9de199676f Implement the conversion between SDBMExpr and AffineExpr
Since SDBM expressions are a subset of affine expressions, they can be
    converted to affine expressions in a straightforward way.  The inverse
    conversion may fail when the affine expression is not an SDBM.  Implement the
    inverse convresion assuming affine expressions are simplified and
    canonicalizied, detect subtractive and multiplicative forms of the stripe
    operation.

--

PiperOrigin-RevId: 245494735
2019-05-06 08:18:31 -07:00
Alex Zinenko 24d0f60d31 Start building SDBM infrastructure
Striped difference-bound matrix expressions are a subset of affine expressions
    supporting low-complexity algorithms that can be useful for loop
    transformations.  This introduces the basic data data structures for building
    such expressions and unique'ing them in a MLIRContext.

--

PiperOrigin-RevId: 245380206
2019-05-06 08:17:42 -07:00
Lei Zhang 05dfb1c7e0 Fix MLIRTableGenTests target_link_libraries typo
--

PiperOrigin-RevId: 244168112
2019-04-18 11:50:19 -07:00
Lei Zhang 48a6aa6c51 [TableGen] Better support for predicate and rewrite rule specification
Currently predicates are written with positional placeholders `{N}` and rely on
    `formatv` as the engine to do substitution. The problem with this approach is that
    the definitions of those positional placeholders are not consistent; they are
    entirely up to the defining predicate of question. For example, `{0}` in various
    attribute constraints is used to mean the attribute, while it is used to main the
    builder for certain attribute transformations. This can become very confusing.

    This CL introduces `tgfmt` as a new mechanism to better support for predicate and
    rewrite rule specification. Instead of entirely relying on positional placeholders,
    `tgfmt` support both positional and special placeholders. The former is used for
    DAG operands. The latter, including $_builder, $_op, $_self, are used as special
    "hooks" to entities in the context. With this, the predicate and rewrite rules
    specification can be more consistent is more readable.

--

PiperOrigin-RevId: 243249671
2019-04-18 11:47:27 -07:00
Stella Laurenzo 13bb8f491a Initial release of the Quantization dialect
Includes a draft of documentation for the quantization setup.

Given how many comments such docs have garnered in the past, I've biased towards a lightly edited first-draft so that people can argue about terminology, approach and structure without having spent too much time on it.

Note that the sections under "Uniform quantization" were cribbed nearly verbatim from internal documentation that Daniel wrote.

PiperOrigin-RevId: 241768668
2019-04-03 19:20:12 -07:00
River Riddle dfc58742a2 Rename the 'namePrefix' field in the Dialect class to 'name' and tidy some comments to make it clear that 'name' refers to the dialect namespace.
--

PiperOrigin-RevId: 241103116
2019-03-30 11:23:55 -07:00
Jacques Pienaar 1273af232c Add build files and update README.
* Add initial version of build files;
    * Update README with instructions to download and build MLIR from github;

--

PiperOrigin-RevId: 241102092
2019-03-30 11:23:22 -07:00
River Riddle 6f24bf82f9 Assert that registered dialects have unique names. This creates a guarantee that the namespace of a dialect can be used a unique key.
--

PiperOrigin-RevId: 241049578
2019-03-29 17:57:41 -07:00
River Riddle af9760fe18 Replace remaining usages of the Instruction class with Operation.
PiperOrigin-RevId: 240777521
2019-03-29 17:50:04 -07:00
River Riddle 9ffdc930c0 Rename the Instruction class to Operation. This just renames the class, usages of Instruction will still refer to a typedef in the interim.
This is step 1/N to renaming Instruction to Operation.

PiperOrigin-RevId: 240431520
2019-03-29 17:42:50 -07:00
Lei Zhang eeadfbc170 Change getBroadcastedShape() to return result shape via parameter
This is a more efficient way than returning SmallVector directly.

PiperOrigin-RevId: 239407024
2019-03-29 17:25:38 -07:00
Lei Zhang 7972dcef84 Pull shape broadcast out as a stand-alone utility function
So that we can use this function to deduce broadcasted shapes elsewhere.

Also added support for unknown dimensions, by following TensorFlow behavior.

PiperOrigin-RevId: 237846065
2019-03-29 17:12:11 -07:00
River Riddle 2d2b40bce5 Add basic infrastructure for instrumenting pass execution and analysis computation. A virtual class, PassInstrumentation, is provided to allow for different parts of the pass manager infrastructure. The currently available hooks allow for instrumenting:
* before/after pass execution
* after a pass fails
* before/after an analysis is computed

After getting this infrastructure in place, we can start providing common developer utilities like pass timing, IR printing after pass execution, etc.

PiperOrigin-RevId: 237709692
2019-03-29 17:10:06 -07:00
River Riddle d43f630de8 NFC: Remove 'Result' from the analysis manager api to better reflect the implementation. There is no distinction between analysis computation and result.
PiperOrigin-RevId: 237093101
2019-03-29 17:02:12 -07:00
River Riddle 1d87b62afe Add support for preserving specific analyses in the analysis manager. Passes can now preserve specific analyses via 'markAnalysesPreserved'.
Example:

markAnalysesPreserved<DominanceInfo>();
markAnalysesPreserved<DominanceInfo, PostDominanceInfo>();

PiperOrigin-RevId: 237081454
2019-03-29 17:01:41 -07:00
River Riddle 7b0b344c5e Add a unittests directory for MLIR and start adding tests for OperandStorage from InstructionSupport.h.
PiperOrigin-RevId: 236911640
2019-03-29 16:58:05 -07:00