Commit Graph

364 Commits

Author SHA1 Message Date
River Riddle 6da343ecfc NFC: Replace Module::getNamedFunction with lookupSymbol<FuncOp>.
This allows for removing the last direct reference to FuncOp from ModuleOp.

PiperOrigin-RevId: 257498296
2019-07-12 08:43:03 -07:00
River Riddle b3e28fca53 NFC: Remove Function::getModule.
There is already a more general 'getParentOfType' method, and 'getModule' is likely to be misused as functions get placed within different regions than ModuleOp.

PiperOrigin-RevId: 257442243
2019-07-12 08:42:21 -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 89bc449cee Standardize the value numbering in the AsmPrinter.
Change the AsmPrinter to number values breadth-first so that values in adjacent regions can have the same name. This allows for ModuleOp to contain operations that produce results. This also standardizes the special name of region entry arguments to "arg[0-9+]" now that Functions are also operations.

PiperOrigin-RevId: 257225069
2019-07-09 10:41:00 -07:00
River Riddle 626b8b6a5d NFC: Remove `Module::getFunctions` in favor of a general `getOps<T>`.
Modules can now contain more than just Functions, this just updates the iteration API to reflect that. The 'begin'/'end' methods have also been updated to iterate over opaque Operations.

PiperOrigin-RevId: 257099084
2019-07-08 18:28:17 -07:00
River Riddle ce502af9cd NFC: Remove the various "::getFunction" methods.
These methods assume that a function is a valid builtin top-level operation, and removing these methods allows for decoupling FuncOp and IR/. Utility "getParentOfType" methods have been added to Operation/OpState to allow for querying the first parent operation of a given type.

PiperOrigin-RevId: 257018913
2019-07-08 12:40:08 -07:00
Jacques Pienaar 01d042a123 Remove std::move of trivially-copyable type.
Address ClangTidy finding:

* std::move of the expression of the trivially-copyable type 'mlir::Module' (aka 'mlir::ModuleOp') has no effect; remove std::move()

PiperOrigin-RevId: 256981849
2019-07-08 12:39:21 -07:00
River Riddle e7d594bb1c Replace the implementation of Function and Module with FuncOp and ModuleOp.
This is an important step in allowing for the top-level of the IR to be extensible. FuncOp and ModuleOp contain all of the necessary functionality, while using the existing operation infrastructure. As an interim step, many of the usages of Function and Module, including the name, will remain the same. In the future, many of these will be relaxed to allow for many different types of top-level operations to co-exist.

PiperOrigin-RevId: 256427100
2019-07-03 14:37:18 -07:00
River Riddle d3f743252d NFC: Move the Function/Module/Operation::verify methods out-of-line.
As Functions/Modules becomes operations, these methods will conflict with the 'verify' hook already on derived operation types.

PiperOrigin-RevId: 256246112
2019-07-02 16:43:36 -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
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
River Riddle 8c47e2ed5c Extract the automatic function renaming and symbol table out of Module.
This functionality is now moved to a new class, ModuleManager. This class allows for inserting functions into a module, and will auto-rename them on insert to ensure a unique name. This now means that users adding new functions to a module must ensure that the function name is unique, as the Module will no longer do it automatically. This also means that Module::getNamedFunction now operates in O(N) instead of the O(c) time it did before. This simplifies the move of Modules to Operations as the ModuleOp will not be able to have this functionality.

PiperOrigin-RevId: 255846088
2019-07-01 09:55:13 -07:00
River Riddle 7c755d06aa Refactor DialectConversion to use 'materializeConversion' when a type conversion must persist after the conversion has finished.
During conversion, if a type conversion has dangling uses a type conversion must persist after conversion has finished to maintain valid IR. In these cases, we now query the TypeConverter to materialize a conversion for us. This allows for the default case of a full conversion to continue working as expected, but also handle the degenerate cases more robustly.

PiperOrigin-RevId: 255637171
2019-06-28 11:29:04 -07:00
River Riddle 260d3e39ad Standardize and refactor Attribute type printing.
Remove the ability to print an attribute without a type, but allow for attributes to elide the type under certain circumstances. This fixes a bug where attributes within ArrayAttr, and other collection attributes, would never print the type.

PiperOrigin-RevId: 255306974
2019-06-26 18:29:54 -07:00
River Riddle a4c3a6455c Move the emitError/Warning/Remark utility methods out of MLIRContext and into the mlir namespace.
Now that Locations are attributes, they have direct access to the MLIR context. This allows for simplifying error emission by removing unnecessary context lookups.

PiperOrigin-RevId: 255112791
2019-06-25 21:32:23 -07:00
River Riddle 679a3b4191 Change the attribute dictionary syntax to separate name and value with '='.
The current syntax separates the name and value with ':', but ':' is already overloaded by several other things(e.g. trailing types). This makes the syntax difficult to parse in some situtations:

Old:
  "foo: 10 : i32"

New:
  "foo = 10 : i32"
PiperOrigin-RevId: 255097928
2019-06-25 19:06:34 -07:00
River Riddle 49162524d8 NFC: Uniformize the return of the LocationAttr 'get' methods to 'Location'.
PiperOrigin-RevId: 255078768
2019-06-25 16:57:56 -07:00
Nicolas Vasilache f08dcfaf89 Internal change
PiperOrigin-RevId: 255018853
2019-06-25 12:03:29 -07:00
Nicolas Vasilache 594c826578 Add missing dependence to MLIRLLVMIR
PiperOrigin-RevId: 254957980
2019-06-25 09:19:59 -07:00
Jacques Pienaar 257a654b72 Split out mlir-opt main into separate file.
Enable reusing the real mlir-opt main from unit tests and in case where
additional initialization needs to happen before main is invoked (e.g., when
using different command line flag libraries).

PiperOrigin-RevId: 254764575
2019-06-24 13:45:39 -07:00
Jacques Pienaar af9bc7e50d Linalg1LLVMConversion should depend on MLIRLLVMIR to ensure ops generated.
PiperOrigin-RevId: 254578530
2019-06-24 13:44:06 -07:00
River Riddle 48d6cf1ced NFC: Remove the 'context' parameter from OperationState.
Now that Locations are Attributes they contain a direct reference to the MLIRContext, i.e. the context can be directly accessed from the given location instead of being explicitly passed in.

PiperOrigin-RevId: 254568329
2019-06-22 13:05:10 -07:00
Jacques Pienaar dbc96d6775 Add missing build dep.
PiperOrigin-RevId: 254557652
2019-06-22 09:19:06 -07:00
Nicolas Vasilache 0804750c9b Uniformize usage of OpBuilder& (NFC)
Historically the pointer-based version of builders was used.
This CL uniformizes to OpBuilder &

PiperOrigin-RevId: 254280885
2019-06-22 09:14:49 -07:00
River Riddle dee282c7da Replace usages of 'UniquedFilename' with 'Identifier' and remove it. Identifier already contains all of the necessary functionality/verification, so having a separate class for filenames is unnecessary.
PiperOrigin-RevId: 253855505
2019-06-19 23:07:05 -07:00
Jacques Pienaar 79ea320c75 Add missing cmake dependency from Linalg to MLIRStandardToLLVM.
PiperOrigin-RevId: 253788170
2019-06-19 23:06:16 -07:00
Alex Zinenko b9beff0384 Make examples/Linalg3 depend on the new standard to LLVM conversion library.
PiperOrigin-RevId: 253767820
2019-06-19 23:05:57 -07:00
Jing Pu 580a77fef5 Remove dead code.
PiperOrigin-RevId: 253314416
2019-06-19 23:03:00 -07:00
Alex Zinenko ebea5767fb Start moving conversions to {lib,include/mlir}/Conversion
Conversions from dialect A to dialect B depend on both A and B.  Therefore, it
is reasonable for them to live in a separate library that depends on both
DialectA and DialectB library, and does not forces dependees of DialectA or
DialectB to also link in the conversion.  Create the directory layout for the
conversions and move the Standard to LLVM dialect conversion as the first
example.

PiperOrigin-RevId: 253312252
2019-06-19 23:02:50 -07:00
River Riddle eb28b30940 NFC: Cleanup the naming scheme for registering legalization actions to be consistent, and move a file functions to the source file.
PiperOrigin-RevId: 252639629
2019-06-11 10:14:35 -07:00
River Riddle 0cadec8ae6 Remove the ability to directly construct a DenseElementsAttr with a raw character buffer. This made assumptions about how DenseElementsAttr structured its internal storage, which may change in the future. To replace the existing use cases, a few utility methods have been added:
* 'get' methods that allow constructing from an ArrayRef of integer or floating point values.
* A 'reshape' method to allow for changing the shape without changing the underlying data.

PiperOrigin-RevId: 252067898
2019-06-09 16:23:34 -07:00
River Riddle e25796ef6e Add support for matchAndRewrite to the DialectConversion patterns. This also drops the default "always succeed" match override to better align with RewritePattern.
PiperOrigin-RevId: 251941625
2019-06-09 16:21:20 -07:00
River Riddle 08d407f243 Add a few utility overloads for OpAsmParser methods:
* Add a getCurrentLocation that returns the location directly.
* Add parseOperandList/parseTrailingOperandList overloads without the required operand count.

PiperOrigin-RevId: 251585488
2019-06-09 16:18:21 -07:00
River Riddle f1b848e470 NFC: Rename FuncBuilder to OpBuilder and refactor to take a top level region instead of a function.
PiperOrigin-RevId: 251563898
2019-06-09 16:17:59 -07:00
River Riddle f59f64e838 Add support to AffineApplyOp::fold for folding dim and symbol expression results.
PiperOrigin-RevId: 251512700
2019-06-09 16:17:46 -07:00
River Riddle 95eaca3e0f Refactor the dialect conversion framework to support multi-level conversions. Multi-level conversions are those that require multiple patterns to be applied before an operation is completely legalized. This essentially means that conversion patterns do not have to directly generate legal operations, and may be chained together to produce legal code.
To accomplish this, moving forward users will need to provide a legalization target that defines what operations are legal for the conversion. A target can mark an operation as legal by providing a specific legalization action. The initial actions are:
* Legal
  - This action signals that every instance of the given operation is legal,
    i.e. any combination of attributes, operands, types, etc. is valid.
* Dynamic
  - This action signals that only some instances of a given operation are legal. This
    allows for defining fine-tune constraints, like say std.add is only legal when
    operating on 32-bit integers.

An example target is shown below:
struct MyTarget : public ConversionTarget {
  MyTarget(MLIRContext &ctx) : ConversionTarget(ctx) {
    // All operations in the LLVM dialect are legal.
    addLegalDialect<LLVMDialect>();

    // std.constant op is always legal on this target.
    addLegalOp<ConstantOp>();

    // std.return op has dynamic legality constraints.
    addDynamicallyLegalOp<ReturnOp>();
  }

  /// Implement the custom legalization handler to handle
  /// std.return.
  bool isLegal(Operation *op) override {
    // Process the dynamic handling for a std.return op (and any others that were
    // marked "dynamic").
    ...
  }
};

PiperOrigin-RevId: 251289374
2019-06-03 19:27:02 -07:00
Geoffrey Martin-Noble c912981bbd Static cast size_t -> int64_t instead of vice versa for equals comparisons
These were just introduced by a previous CL moving MemRef getRank to return int64_t. size_t could be smaller than 64 bits and in equals comparisons, signed vs unsigned doesn't matter. In these cases, we know right now that the particular int64_t is not larger than max size_t (because it currently comes directly from a size() call), the alternative cast plus equals comparison is always safe, so we might as well do it that way and no longer require reasoning deeper into the callstack.

    We are already assuming that size() calls fit into int64_t in a number of other cases like the aforementioned getRank() (since exabytes of RAM are rare). If we want to avoid this assumption we will have to come up with a principled way to do it throughout.

--

PiperOrigin-RevId: 250980297
2019-06-01 20:13:49 -07:00
Geoffrey Martin-Noble 65eae3f75f Get rid of separate getRank() on MemRef now that it subclasses ShapedType
We are moving towards int64_t for these shape/dimension -related values to avoid buginess with unsigned arithmetic

--

PiperOrigin-RevId: 250945322
2019-06-01 20:13:00 -07:00
River Riddle 4fd012cda2 Replace a usage of std::vector with SmallVector to allow constructing with non-constant iterators on MSVC.
--

PiperOrigin-RevId: 250769027
2019-06-01 20:11:22 -07:00
Jacques Pienaar c59538977e Add keywords in target_link_libraries post add_llvm_executable.
--

PiperOrigin-RevId: 250704528
2019-06-01 20:10:42 -07:00
River Riddle 11e485ca19 Replace usages of 'add_executable' with 'add_llvm_executable'.
--

PiperOrigin-RevId: 250691487
2019-06-01 20:10:32 -07:00
Jacques Pienaar 4a697a91de Fix 5 ClangTidy - Readability findings.
* the 'empty' method should be used to check for emptiness instead of 'size'
    * using decl 'CapturableHandle' is unused
    * redundant get() call on smart pointer
    * using decl 'apply' is unused
    * using decl 'ScopeGuard' is unused

--

PiperOrigin-RevId: 250623863
2019-06-01 20:10:22 -07:00
MLIR Team 5a91b9896c Remove "size" property of affine maps.
--

PiperOrigin-RevId: 250572818
2019-06-01 20:09:02 -07:00
River Riddle b33a7232a2 Add a 'getDialectNamespace' utility to a few dialects.
--

PiperOrigin-RevId: 250049416
2019-06-01 20:03:43 -07:00
River Riddle 9e21ab8f52 Add a templated wrapper around RewritePattern that allows for defining match/rewrite methods with an instance of the source op instead of a raw Operation*.
--

PiperOrigin-RevId: 250003405
2019-06-01 20:03:22 -07:00
River Riddle c2d069323b Rename DialectConversion to TypeConverter and split out pattern construction. This simplifies building the conversion pattern list from multiple sources.
--

PiperOrigin-RevId: 249930583
2019-06-01 20:02:03 -07:00
River Riddle 06734badbc Add operand type iterators to Operation and cleanup usages of operand->getType. This also simplifies some lingering usages of result->getType.
--

PiperOrigin-RevId: 249889174
2019-06-01 20:00:43 -07:00
River Riddle ae1651368f NFC: Rename DialectConversionPattern to ConversionPattern.
--

PiperOrigin-RevId: 249857277
2019-06-01 20:00:13 -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
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 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
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
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
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 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 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 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
River Riddle 1a100849c4 Add support for saving and restoring the insertion point of a FuncBuilder. This also updates the edsc::ScopedContext to use a single builder that saves/restores insertion points. This is necessary for using edscs within RewritePatterns.
--

PiperOrigin-RevId: 248812645
2019-05-20 13:46:35 -07:00
Jacques Pienaar f471c91afd Update cmake dependencies.
--

PiperOrigin-RevId: 248650428
2019-05-20 13:45:08 -07:00
Stella Laurenzo 1a2ad06bae Fix lingering sign compare warnings in exposed by "ninja check-mlir".
--

PiperOrigin-RevId: 248050178
2019-05-20 13:41:11 -07:00
Jacques Pienaar 3427d87719 Fix -Wsign-compare in Toy LateLowering.
--

PiperOrigin-RevId: 248005642
2019-05-20 13:40:33 -07:00
River Riddle bc5c7378b2 Add a utility method to MLIRContext get a registered dialect with the derived type instead of the string name. The derived dialect type must provide a static 'getDialectNamespace' method.
This means that we can now do something like:
      ctx->getRegisteredDialect<LLVMDialect>();

    as opposed to:
      static_cast<LLVMDialect *>(ctx->getRegisteredDialect("llvm");

--

PiperOrigin-RevId: 247989896
2019-05-20 13:40:13 -07:00
River Riddle d7c467ded1 Remove the explicit "friend Operation" statement from each of the derived operations now that op casting is no longer inside of Operation.
--

PiperOrigin-RevId: 247791672
2019-05-20 13:38:02 -07:00
River Riddle d5b60ee840 Replace Operation::isa with llvm::isa.
--

PiperOrigin-RevId: 247789235
2019-05-20 13:37:52 -07:00
River Riddle adca3c2edc Replace Operation::cast with llvm::cast.
--

PiperOrigin-RevId: 247785983
2019-05-20 13:37:42 -07:00
River Riddle c5ecf9910a Add support for using llvm::dyn_cast/cast/isa for operation casts and replace usages of Operation::dyn_cast with llvm::dyn_cast.
--

PiperOrigin-RevId: 247780086
2019-05-20 13:37:31 -07:00
MLIR Team 41d90a85bd Automated rollback of changelist 247778391.
PiperOrigin-RevId: 247778691
2019-05-20 13:37:20 -07:00
River Riddle 02e03b9bf4 Add support for using llvm::dyn_cast/cast/isa for operation casts and replace usages of Operation::dyn_cast with llvm::dyn_cast.
--

PiperOrigin-RevId: 247778391
2019-05-20 13:37:10 -07:00
Mehdi Amini bd8ed0d215 Fix unused variable warning in the Toy tutorial (NFC)
--

PiperOrigin-RevId: 247672377
2019-05-10 19:29:58 -07:00
Mehdi Amini 52d0dbbd2a Make header-defined method inline instead of static (NFC)
This is fixing a clang warning when this header is included in a file
    that does not use this function.

--

PiperOrigin-RevId: 247557803
2019-05-10 19:27:16 -07:00
Mehdi Amini 6459c821bf Fix class/struct mismatch between declaration/definition (NFC)
Fix clang warnings

--

PiperOrigin-RevId: 247557395
2019-05-10 19:27:07 -07:00
River Riddle b7dc252683 NFC: Make ParseResult public and update the OpAsmParser(and thus all of the custom operation parsers) to use it instead of bool.
--

PiperOrigin-RevId: 246955523
2019-05-10 19:23:24 -07:00
River Riddle 4ea887be41 Namespaceify a few explicit template specializations to appease errors caused by a bug in gcc versions < 7.0.
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480)

--

PiperOrigin-RevId: 246664463
2019-05-06 08:29:09 -07:00
River Riddle 3b930b0d70 Add explicit friendship with Operation to each derived op class to ensure access to the inherited protected constructor of `Op`. Some compiler versions have different rules for the visibility of inherited constructors.
--

PiperOrigin-RevId: 246661686
2019-05-06 08:28:50 -07:00
Jacques Pienaar dd726ea99d Update to address missing cmake target & qualify make_pair.
--

PiperOrigin-RevId: 246355137
2019-05-06 08:24:41 -07:00
Geoffrey Martin-Noble 45c8245cca Substitute getI64IntegerAttr for the more verbose code it replaces.
--

PiperOrigin-RevId: 246227344
2019-05-06 08:24:12 -07:00
Nicolas Vasilache 56c7a957bf Parsing support for Range, View and Slice operations
This CL implements the previously unsupported parsing for Range, View and Slice operations.
    A pass is introduced to lower to the LLVM.
    Tests are moved out of C++ land and into mlir/test/Examples.
    This allows better fitting within standard developer workflows.

--

PiperOrigin-RevId: 245796600
2019-05-06 08:20:55 -07:00
River Riddle 1423acc03c Rename isa_nonnull to isa_and_nonnull to match the upstream llvm name.
--

PiperOrigin-RevId: 244928036
2019-04-23 22:03:14 -07:00
Guangda Lai 7977e62b96 Fix typo (transpose -> reshape).
--

PiperOrigin-RevId: 244270801
2019-04-23 22:00:45 -07:00
Nicolas Vasilache 8370cc7492 Start a Linalg dialect
This CL starts implementing a Linalg dialect with the objective of supporting
    optimizing compilation of loops and library calls for a subset of common linear
    algebra operations.

    This CL starts by simply adding a linalg.range type and an operation with the
    proper roundtripping test.

--

PiperOrigin-RevId: 244189468
2019-04-18 11:50:27 -07:00
Chris Lattner 09c053bfd0 Expand the pretty dialect type system to support arbitrary punctuation and
other characters within the <>'s now that we can.  This will allow quantized
    types to use the pretty syntax (among others) after a few changes.

--

PiperOrigin-RevId: 243521268
2019-04-18 11:48:09 -07:00
Lei Zhang 0836f670f1 Add missing dependencies for EDSC and linalg libraries
This solves the missing "mlir/StandardOps/Ops.h.inc" issue when building
    a fresh checkout on macOS.

--

PiperOrigin-RevId: 243120388
2019-04-11 12:35:29 -07:00
Mehdi Amini 6c6ed466a6 Expose `setupTargetTriple` as a public static method on ExecutionEngine
This allows client to be able to reuse the same logic to setup a module
    for the ExecutionEngine without instanciating one. One use case is running
    the optimization pipeline but not JIT-ing.

--

PiperOrigin-RevId: 242614380
2019-04-11 10:51:24 -07:00
Mehdi Amini c4dee61c0e Fix Toy cmake build: add missing includes
--

PiperOrigin-RevId: 242609231
2019-04-08 23:27:02 -07:00
Mehdi Amini c39592b09c Toy tutorial Chapter 5: Lowering to Linalg and LLVM
--

PiperOrigin-RevId: 242606796
2019-04-08 23:26:54 -07:00
Mehdi Amini a43f216fd5 Automated rollback of changelist 242546977.
PiperOrigin-RevId: 242604949
2019-04-08 23:26:46 -07:00
Nicolas Vasilache 1ee07e7fde De-templatize TensorContractionBase (Linalg example/tutorial)
TensorContractionBase has become too unwieldy with all the CRTP manipulation once less trivial transformations are implemented.
    This CL drops CRTP for inheritance and uses the same name comparison trick to figure out what to cast into.
    As a byproduct, all the -inl.h files disappear.
    To maintain the separation between directories, a LINALG_STEP variable is introduced

--

PiperOrigin-RevId: 242546977
2019-04-08 19:17:56 -07:00
Nicolas Vasilache 046a993967 Add CMakeLists rules for Linalg
--

PiperOrigin-RevId: 242454319
2019-04-08 19:17:56 -07:00
Nicolas Vasilache ca89e7167d Fix build for the Linalg example dialect with MacOS
--

PiperOrigin-RevId: 242443831
2019-04-08 19:17:56 -07:00
Alex Zinenko adb0ca0732 Example Linalg3: manually register the Linalg dialect
This dialect does not have a global constructor and has to be registered
    manually in `main`.  Also fix the way it is exercised in the test.

--

PiperOrigin-RevId: 242434886
2019-04-08 19:17:56 -07:00
Alex Zinenko 8e193e617c Change initialization syntax for ScopedContext in examples
For some reason, the OSS build on macOS was not happy with the initialization
    syntax and was attempting to call a copy constructor.  Hotfix it to use a
    different syntax pending further investigation.

--

PiperOrigin-RevId: 242432634
2019-04-08 19:17:56 -07:00
Mehdi Amini 89d5d36964 Fix bug in Toy tutorial where IR emission stopped after any `print`
--

PiperOrigin-RevId: 242407970
2019-04-08 18:54:25 -07:00
Mehdi Amini fea0560816 Fix Linalg3 lowering to use the floating point element type matching the view
It used to be hardcoded to f32, but Toy tutorial is using f64.

--

PiperOrigin-RevId: 242370172
2019-04-07 18:22:34 -07:00
Mehdi Amini 364b7e624e Add support for f64 type conversion for Linalg dialect to LLVM lowering
--

PiperOrigin-RevId: 242345259
2019-04-07 18:22:22 -07:00
Chris Lattner 72441fcbf2 Change the asmprinter to use pretty syntax for dialect types when it can,
making the IR dumps much nicer.

    This is part 2/3 of the path to making dialect types more nice.  Part 3/3 will
    slightly generalize the set of characters allowed in pretty types and make it
    more principled.

--

PiperOrigin-RevId: 242249955
2019-04-07 18:21:13 -07:00
Nicolas Vasilache a1b4cae30a Post commit cleanups to the Linalg dialect
--

PiperOrigin-RevId: 242181687
2019-04-07 18:20:19 -07:00
River Riddle e4628b79fb Add new utilities for RTTI Operation casting: dyn_cast_or_null and isa_nonnull
* dyn_cast_or_null
      - This will first check if the operation is null before trying to 'dyn_cast':

        Value *v = ...;
        if (auto forOp = dyn_cast_or_null<AffineForOp>(v->getDefiningOp()))
          ...
    * isa_nonnull
      - This will first check if the pointer is null before trying to 'isa':

        Value *v = ...;
        if (isa_nonnull<AffineForOp>(v->getDefiningOp());
          ...

--

PiperOrigin-RevId: 242171343
2019-04-07 18:20:07 -07:00
Alex Zinenko 6196c8a9fd Linalg3 example: implement JIT-compilation and execution
Use MLIR's ExecutionEngine to demonstrate how one can implement a simple
    JIT-compiler and executor after fully lowering the Linalg dialect to the LLVM
    IR dialect, using the direct conversion (not going through standard
    loads/stores).

--

PiperOrigin-RevId: 242127690
2019-04-07 18:19:35 -07:00
Mehdi Amini 01e8ec94c3 Fix CMake build: account for renamed files and add missing include on MacOS
--

PiperOrigin-RevId: 242101364
2019-04-05 07:43:23 -07:00
Nicolas Vasilache 92df395068 Linalg portion of the tutorial - part 4
This CL adds declarative tiling support in the linalg dialect by providing:
    1. loop tiling on linalg ops by simply calling into mlir::tile
    2. view tiling on linalg ops by:
      a. computing the subview between for each tile dimension based on the loop tile size and the mapping of loops to operand ranges.
      b. declaring that the tiled form of a tensorcontraction is the same tensorcontraction on subviews, which essentially gives us a recursive form.

    Point 2.b is potentially subject to change in the future.

--

PiperOrigin-RevId: 242058658
2019-04-05 07:43:14 -07:00
River Riddle fde21c6faf NFC: Fix a few typos in the tutorials and one in the comment of FunctionAttr::dropFunctionReference.
--

PiperOrigin-RevId: 242050934
2019-04-05 07:43:05 -07:00
Mehdi Amini d33a9dcc73 Add Chapter 4 for the Toy tutorial: shape inference, function specialization, and basic combines
--

PiperOrigin-RevId: 242050514
2019-04-05 07:42:56 -07:00
Nicolas Vasilache 623e4b9711 Linalg portion of the tutorial - part 3-3
This CL adds the last bit to convert from linalg.LoadOp and linalg.StoreOp to the affine dialect, as well as a unit test to exercise the conversion.

--

PiperOrigin-RevId: 242045826
2019-04-05 07:42:38 -07:00
River Riddle a83181cd20 NFC: Fix erroneous use of 'OpaqueType' with 'Type' when setting the ToyTypeKind, as well as a few mistakes in Chapter 2 of the Toy tutorial.
--

PiperOrigin-RevId: 242021477
2019-04-05 07:42:10 -07:00
River Riddle 6fa3181329 Remove the non-postorder walk functions from Function/Block/Instruction and rename walkPostOrder to walk.
--

PiperOrigin-RevId: 241965239
2019-04-05 07:41:23 -07:00
Alex Zinenko 8b790434e5 Example Linalg3: support Load/Store conversion from Linalg to LLVM IR dialect
Load and Store Linalg operations are converter to their LLVM IR counterparts
    preceded by a sequence of operations that recover the effective address of the
    accessed element.  The address is computed given the subscripts and the view
    descriptor as

        base_pointer + base_offset + SUM_i subscript_i * stride_i.

    Manual testing shows that the resulting LLVM IR for the matrix multiplication
    example can be compiled and executed, producing correct results.

--

PiperOrigin-RevId: 241889003
2019-04-05 07:40:21 -07:00
Mehdi Amini f0a328b6d5 Chapter 3 for Toy tutorial: introduction of a dialect
--

PiperOrigin-RevId: 241849162
2019-04-03 19:22:32 -07:00
Mehdi Amini 3a2955fa1f Rename UnknownType to OpaqueType (NFC)
This came up in a review of the tutorial, it was suggested that "opaque" is more
    descriptive than "unknown" here.

--

PiperOrigin-RevId: 241832927
2019-04-03 19:21:47 -07:00
Mehdi Amini a261ce5b40 Move the top-level `tutorial` as `Linalg` nested in the examples folder
--

PiperOrigin-RevId: 241831176
2019-04-03 19:21:38 -07:00
Mehdi Amini 5854fb9b94 Fix Toy tutorial gcc 7 build (NFC)
--

PiperOrigin-RevId: 241613710
2019-04-02 15:16:30 -07:00
Mehdi Amini 213dda687b Chapter 2 of the Toy tutorial
This introduces a basic MLIRGen through straight AST traversal,
    without dialect registration at this point.

--

PiperOrigin-RevId: 241588354
2019-04-02 13:41:00 -07:00
Mehdi Amini 38b71d6b84 Initial version for chapter 1 of the Toy tutorial
--

PiperOrigin-RevId: 241549247
2019-04-02 13:40:06 -07:00