Commit Graph

1967 Commits

Author SHA1 Message Date
River Riddle 4958ec2414 Apply operation rewrites before updating arguments.
--

PiperOrigin-RevId: 249678839
2019-06-01 19:58:14 -07:00
River Riddle 14d1cfbccb Decouple running a conversion from the DialectConversion class. The DialectConversion class is only necessary for type signature changes(block arguments or function arguments). This isn't always desired when performing a dialect conversion. This allows for those conversions without this need to run per function instead of per module.
--

PiperOrigin-RevId: 249657549
2019-06-01 19:58:04 -07:00
Nicolas Vasilache c0f41e5bb3 Fix Linalg lowering to loops
This CL makes lowering to loops always be a:
    ```
    %D = linalg.dim %view, constant : !linalg.view<...>
    affine.for %ix = %c0 to %D {
      ...
    }
    ```

    This form composes correctly with tiling and is also the proper way to emit loops from views that across function boundaries.
    The previous version that would extract the range_min/max/step was composing incorrectly with tiling (i.e. would shift by range_min both in the loop bounds and in the slice) and would not work across function boundaries.

    The relevant tests are updated and a new test `dot_view`---which lowers to loops from views passed as function parameters---is added.

    When additional context is available, the linalg.dim operations should be folded away but this is left for a future CL.

--

PiperOrigin-RevId: 249634712
2019-06-01 19:57:54 -07:00
Thomas Joerg 6a31f9a7e3 Automated rollback of changelist 247713812.
PiperOrigin-RevId: 249605627
2019-06-01 19:57:44 -07:00
Stephan Herhut b52112275d Add LLVM::IntToPtrOp and LLVM::PtrToIntOp to LLVM dialect.
--

PiperOrigin-RevId: 249604199
2019-06-01 19:57:34 -07:00
Rob Suderman 51feed5518 Automated rollback of changelist 249538085.
PiperOrigin-RevId: 249550805
2019-06-01 19:57:23 -07:00
Rob Suderman ca9bd9d3af Added the ability to run a mapping function across the values of an elements
attr. This supports both the SplatElementsAttr and DenseElementsAttr for both
    float and integer inputs / outputs.

--

PiperOrigin-RevId: 249538085
2019-06-01 19:57:13 -07:00
River Riddle 5953d12b95 Add thread-safe utilities to LLVMType to allow constructing llvm types in a multi-threaded environment. The LLVMContext is not thread-safe and directly constructing a raw llvm::Type can create situations where the LLVMContext is modified by multiple threads at the same time.
--

PiperOrigin-RevId: 249526233
2019-06-01 19:57:03 -07:00
River Riddle c33862b0ed Refactor FunctionAttr to hold the internal function reference by name instead of pointer. The one downside to this is that the function reference held by a FunctionAttr needs to be explicitly looked up from the parent module. This provides several benefits though:
* There is no longer a need to explicitly remap function attrs.
      - This removes a potentially expensive call from the destructor of Function.
      - This will enable some interprocedural transformations to now run intraprocedurally.
      - This wasn't scalable and forces dialect defined attributes to override
        a virtual function.
    * Replacing a function is now a trivial operation.
    * This is a necessary first step to representing functions as operations.

--

PiperOrigin-RevId: 249510802
2019-06-01 19:56:54 -07:00
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