Commit Graph

1708 Commits

Author SHA1 Message Date
Mehdi Amini d5397f4efe Return nullptr on Region::getContainingOperation()/getContainingFunction() instead of asserting
This avoids crashing when trying to dump an operation nested in a region that isn't yet attached to an operation, which is quite useful when debugging.

    This alone won't be enough to print an unlink Operation, it'll display `<<UNLINKED INSTRUCTION>>`.

--

PiperOrigin-RevId: 249496388
2019-06-01 19:56:43 -07:00
Alex Zinenko 29c7929b13 Make EDSC builder test more robust to the order of evaluation
EDSC builder test uses FileCheck to match the IR produced by EDSC in the
    textual order.  For mathematical operations, EDSC relies on overloaded
    operators.  Since they are essentially function calls, the order of evaluation
    of their operands is unspecified and differs between compilers.  Do not rely on
    a specific order of operands and just check they are all emitted before the
    last operation.  Give names to matched SSA values in order to make sure the
    right operands are used in relevant places.

--

PiperOrigin-RevId: 249494995
2019-06-01 19:56:34 -07:00
River Riddle d15d107da1 Refactor DialectConversion to operate on functions in-place *without* any cloning. This works by caching all of the requested pattern rewrite operations, e.g. replace operation, and only applying them on a completely successful conversion.
--

PiperOrigin-RevId: 249490306
2019-06-01 19:56:24 -07:00
River Riddle d16b470809 Update Attribute::getDialect/Type::getDialect to return a non-const dialect reference.
--

PiperOrigin-RevId: 249467245
2019-06-01 19:56:13 -07:00
River Riddle cf8f1ea918 NFC: Fix the name of a comment header block in Diagnostics.cpp.
--

PiperOrigin-RevId: 249466645
2019-06-01 19:56:03 -07:00
River Riddle 44014c870d Add a new interleaveComma that allows specifying a unary function for the container elements.
--

PiperOrigin-RevId: 249349269
2019-06-01 19:55:54 -07:00
Geoffrey Martin-Noble 099355524c Make static shape tensor container match other container types
Suffix with Of and take a list of types. Also give a better description that includes the element type information.

--

PiperOrigin-RevId: 249341159
2019-06-01 19:55:43 -07:00
Geoffrey Martin-Noble 7a4869e316 Simplify container type definitions
The passed element type description is usually unnecessary, and it's just as valid to want to pass a description for the entire container. In either case there's an alternative (Separate element type def or a TypeAlias) and we don't need to pollute the main API.

    To allow for this, I cleaned up the TF op definitions and added some additional utilities.

--

PiperOrigin-RevId: 249340979
2019-06-01 19:55:33 -07:00
River Riddle 3902cef954 Make the ParallelDiagnosticHandler used by the pass manager publicly available in Diagnostics.h. This provides a common utility for deterministically handling diagnostics in a multi-threaded environment.
--

PiperOrigin-RevId: 249325937
2019-06-01 19:55:24 -07:00
River Riddle 64a21667a9 Fix a bug in toy LateLowering where a type conversion was using 'cast' instead of 'dyn_cast'.
--

PiperOrigin-RevId: 249325111
2019-06-01 19:55:13 -07:00
Geoffrey Martin-Noble da37b0a536 Clean up container type names in OpBase
Establish the following convention:
    1. Container class types end in "Of" (e.g. TensorOf) and take a list of allowed types.
    2. An X container where only a single type is allowed is called TypeX (e.g. I32Tensor).
    3. An X container where any type is allowed is called AnyX (e.g. AnyTensor).

--

PiperOrigin-RevId: 249281018
2019-06-01 19:55:03 -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 e62a12316e SDBMExpr: factor uniqu'ing out of MLIRContext.cpp
SDBM expressions are designed as components of an attribute, similarly to
    affine expressions.  As such, they need to be unique'd in the MLIRContext.
    When SDBM 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 SDBMExpr uniqu'ing to use a newly
    introduced uniquer and remove SDBM construction from MLIRContext.cpp.

--

PiperOrigin-RevId: 249244739
2019-06-01 19:54:22 -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
Lei Zhang 35c1ef9926 Linalg: avoid deriving from MultiOperandTraitBase multiple times
The Op Definition Generator will automatically insert the VariadicOperands
    trait if an op has variadic operands or results. It already derives from
    MultiOperandTraitBase.

--

PiperOrigin-RevId: 249227268
2019-06-01 19:54:03 -07:00
Thomas Joerg 6c6f192b2c Small cleanup.
* Use `cast` rather than `dyn_cast` to get an assertion failure rather than a segfault in case of a type mismatch.
    * Use stream operators to `emitOpError`s.

--

PiperOrigin-RevId: 249208135
2019-06-01 19:53:53 -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 37d0d097a9 Drop AffineExpr::Null
Similarly to other value-type wrappers, the default constructor of AffineExpr
    constructs a null object and removes the need for an explicit ::Null
    constructor.  Drop it and remove the only user which can trivially rely on the
    default constructor.

--

PiperOrigin-RevId: 249207502
2019-06-01 19:53:33 -07:00
Youlong Cheng 75f1a4fcc3 Change getParent() to be a const function. This is only necessary because ilist_node_with_parent specifically requires a 'getParent() const' method. If/When ilist_node removes this constraint we should drop the const to fit the rest of the MLIR const model.
--

PiperOrigin-RevId: 249193257
2019-06-01 19:53:22 -07:00
Stella Laurenzo 5065839da7 Upstream the Quantizer tool (part 4).
This adds the basic passes needed and ties them into mlir-opt. Also adds two specific unit tests that exercise them.

    Next step is a standalone quantizer tool and additional cleanup.
    Tested:
      ninja check-mlir

--

PiperOrigin-RevId: 249167690
2019-06-01 19:53:12 -07:00
River Riddle d48ff10f01 When changing the type of a Function, also update the type of the respective FunctionAttr.
--

PiperOrigin-RevId: 249137558
2019-06-01 19:53:02 -07:00
MLIR Team 80884d28ac [LoopFusion] Don't count terminator op in compute cost.
--

PiperOrigin-RevId: 249124895
2019-06-01 19:52:52 -07:00
Nicolas Vasilache fdbbb3c274 Use lambdas for nesting edsc constructs.
Using ArrayRef introduces issues with the order of evaluation between a constructor and
    the arguments of the subsequent calls to the `operator()`.
    As a consequence the order of captures is not well-defined can go wrong with certain compilers (e.g. gcc-6.4).
    This CL fixes the issue by using lambdas in lieu of ArrayRef.

--

PiperOrigin-RevId: 249114775
2019-05-20 13:50:28 -07:00
Mehdi Amini 70f85c0bbf Fix MacOS test: use %shlibext in lit command line to expand to .dylib on MacOS and .so on Linux
--

PiperOrigin-RevId: 249113478
2019-05-20 13:50:19 -07:00
Geoffrey Martin-Noble c3777ea103 Define a string join tablegen utility
--

PiperOrigin-RevId: 249083600
2019-05-20 13:50:10 -07:00
Nicolas Vasilache bedff17ec8 Add CMakeLists.txt entry for Linalg/Transforms/LowerToLoops
--

PiperOrigin-RevId: 249080647
2019-05-20 13:50:01 -07:00
Geoffrey Martin-Noble 62b4c997e6 Fix automatic description for AnyTypeOf
Unfortunately, this now gives a segfault if you pass it an empty list, similar to stringify. Given how fiddly this is, we should probably have a string join helper. I'll fix both of these using better tablegen helpers in a follow-up.

--

PiperOrigin-RevId: 249076849
2019-05-20 13:49:53 -07:00
Geoffrey Martin-Noble 3be4346cdf Rename "AnyOf" and "AllOf" combined predicates to "Or" and "And", respectively.
This reduces conflict between these and other type names, where we're moving towards "Of" indicating a container type containing certain types. It also better matches the "Neg" predicate modifier and generally is pretty understandable/readable for predicates.

--

PiperOrigin-RevId: 249076508
2019-05-20 13:49:44 -07:00
Geoffrey Martin-Noble f6590eeaa0 Delete IntegerBase and FloatBase tablegen classes
These don't have any behavior and just delegate to Type. The only references are in OpBase.td Since the tablegen type hierarchy is not realized in the generated C++ these also aren't providing value for examining the type hierarchy

--

PiperOrigin-RevId: 249073939
2019-05-20 13:49:36 -07:00
Lei Zhang 20e0cedfbd [ODS] Allow dialect to specify C++ namespaces
Previously we force the C++ namespaces to be `NS` if `SomeOp` is defined as
    `NS_SomeOp`. This is too rigid as it does not support nested namespaces
    well. This CL adds a "namespace" field into the Dialect class to allow
    flexible namespaces.

--

PiperOrigin-RevId: 249064981
2019-05-20 13:49:27 -07:00
Nicolas Vasilache aabb44f66d Fix Linalg/llvm_ir test
--

PiperOrigin-RevId: 249057043
2019-05-20 13:49:19 -07:00
Nicolas Vasilache 05df9d121a Fix stride computation bug when lowering linalg.view to llvm
--

PiperOrigin-RevId: 249053115
2019-05-20 13:49:10 -07:00
Nicolas Vasilache 9b58691e74 Add lowering of LinalgLibraryOps to linalg.load + linalg.store.
This CL adds a pass to lower out of dot,matvec,matmul etc and into a combination of affine.for, linalg.load and linalg.store operations.
    Such operations can then later lowered to LLVM.
    This CL essentially performs op expansion using EDSCs and factors out a few common utils from Tiling.cpp.

--

PiperOrigin-RevId: 249049518
2019-05-20 13:49:02 -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 4408228269 ExecutionEngine: drop PassManager integration
Originally, ExecutionEngine was created before MLIR had a proper pass
    management infrastructure or an LLVM IR dialect (using the LLVM target
    directly).  It has been running a bunch of lowering passes to convert the input
    IR from Standard+Affine dialects to LLVM IR and, later, to the LLVM IR dialect.
    This is no longer necessary and is even undesirable for compilation flows that
    perform their own conversion to the LLVM IR dialect.  Drop this integration and
    make ExecutionEngine accept only the LLVM IR dialect.  Users of the
    ExecutionEngine can call the relevant passes themselves.

--

PiperOrigin-RevId: 249004676
2019-05-20 13:48:45 -07:00
Mehdi Amini 164c3c7ac5 Fix debug build: static constexpr data member must have a definition (until C++17)
--

PiperOrigin-RevId: 248990338
2019-05-20 13:48:36 -07:00
River Riddle 039800bfb6 Add support for streaming an OperationName into a Diagnostic.
--

PiperOrigin-RevId: 248987646
2019-05-20 13:48:28 -07:00
River Riddle 68250edbfa NFC: Tidy up DialectConversion.cpp and rename DialectOpConversion to DialectConversionPattern.
--

PiperOrigin-RevId: 248980810
2019-05-20 13:48:19 -07:00
River Riddle 6241cf132e Refactor the DialectConversion process to clone each function and then operate in-place, as opposed to incrementally constructing a new function. This is crucial to allowing the use of non type-conversion patterns(normal RewritePatterns) as part of the conversion process.
The converter now works by inserting fake producer operations when replacing the results of an existing operation with values of a different, now legal, type. These fake operations are guaranteed to never escape the converter.

--

PiperOrigin-RevId: 248969130
2019-05-20 13:48:10 -07:00
River Riddle a23b728034 Allow a function to take the name of another existing function.
--

PiperOrigin-RevId: 248968285
2019-05-20 13:48:02 -07:00
River Riddle 7ffdf2cddd Add support for streaming Operations into Diagnostics.
--

PiperOrigin-RevId: 248967563
2019-05-20 13:47:53 -07:00
River Riddle 3090a651b7 Update the rewrite methods of each of the DialectConversion patterns to notify the PatternRewriter that the operation is being replaced.
--

PiperOrigin-RevId: 248965082
2019-05-20 13:47:44 -07:00
River Riddle 1e2d2f5d66 Add a utility function 'Operation::replaceUsesOfWith' to replace uses of a value within a single operation.
--

PiperOrigin-RevId: 248961779
2019-05-20 13:47:36 -07:00
River Riddle 1966d34da4 Move the ConversionListBuilder utility to PatternMatch.h and rename it to RewriteListBuilder. It has no specific functionality for DialectOpConversion patterns and can be useful for RewritePatterns in general.
--

PiperOrigin-RevId: 248884466
2019-05-20 13:47:28 -07:00
River Riddle 8780d8d8eb Add user iterators to IRObjects, i.e. Values.
--

PiperOrigin-RevId: 248877752
2019-05-20 13:47:19 -07:00
Geoffrey Martin-Noble 22a8bc6ec3 Make shape matching work for any shaped type.
The current implementation makes some assumptions about what can be a shaped type, which aren't really necessary. It also has strange behavior for types that aren't in the limited set it handles (e.g. dialect-defined types)

    Updated the comment to match the implementation.

    This is partially motivated by the desire to make MemRef a subclass of ShapedType

--

PiperOrigin-RevId: 248859674
2019-05-20 13:47:09 -07:00
River Riddle 3de0c7696b Rewrite the DialectOpConversion patterns to inherit from RewritePattern instead of Pattern. This simplifies the infrastructure a bit by being able to reuse PatternRewriter and the RewritePatternMatcher, but also starts to lay the groundwork for a more generalized legalization framework that can operate on DialectOpConversions as well as normal RewritePatterns.
--

PiperOrigin-RevId: 248836492
2019-05-20 13:47:01 -07:00
Geoffrey Martin-Noble b5ecbb7fd6 Clean up tablegen vector and tensor types
There was a weird mix of names, styles, and inheritance here. I think this makes it cleaner and more consistent. We can also have a more principled and far-reaching refactor of some of this naming, but this seems like a good improvement regardless

--

PiperOrigin-RevId: 248827005
2019-05-20 13:46:52 -07:00