Commit Graph

1232 Commits

Author SHA1 Message Date
Mehdi Amini 3518122e86 Simplify API uses of `getContext()` (NFC)
The Pass base class is providing a convenience getContext() accessor.

PiperOrigin-RevId: 240634961
2019-03-29 17:47:11 -07:00
Mehdi Amini 7641900d2f Allow to mutate the type of MLIR Value in-place
This avoid trashing memory by cloning and replaceAllUseswith when
performing type inference.

PiperOrigin-RevId: 240631137
2019-03-29 17:46:56 -07:00
Jacques Pienaar b0244b66a5 Fix include path in test pass.
PiperOrigin-RevId: 240628260
2019-03-29 17:46:41 -07:00
Jacques Pienaar b15ac2d999 Initialize std::atomic directly.
Avoids error in OSS build:
error: copying variable of type 'std::atomic<unsigned int>' invokes deleted constructor
PiperOrigin-RevId: 240618765
2019-03-29 17:46:26 -07:00
Mehdi Amini a5f253a335 Add a method to swap the type of a function in-place
This is motivated by the need to translate function across dialect which
requires morphing their type, as well as the Toy tutorial part on interprocedural
shape inference.

The alternative is cloning the function, but it is heavy and it seems like an
arbitrary restriction to forbid morphing the function type.

PiperOrigin-RevId: 240615755
2019-03-29 17:46:11 -07:00
Jacques Pienaar 810e95b861 Use dereference instead of implicit conversion for IndexedValue to Value*.
Avoids ambiguous constructor error on some compilers.

PiperOrigin-RevId: 240606838
2019-03-29 17:45:56 -07:00
Jacques Pienaar ed4fa52b4a Add missing numeric header for std::accumulate.
PiperOrigin-RevId: 240593135
2019-03-29 17:45:42 -07:00
Alex Zinenko e2f9079a71 LLVM IR Conversion: support zero-dimensional memrefs
The spec allows zero-dimensional memrefs to exist and treats them essentially
as single-element buffers.  Unlike single-dimensional memrefs of static shape
<1xTy>, zero-dimensional memrefs do not require indices to access the only
element they store.  Add support of zero-dimensional memrefs to the LLVM IR
conversion.  In particular, such memrefs are converted into bare pointers, and
accesses to them are converted to bare loads and stores, without the overhead
of `getelementptr %buffer, 0`.

PiperOrigin-RevId: 240579456
2019-03-29 17:45:26 -07:00
Alex Zinenko 5c285f228c LLVM IR Conversion: keep LLVM dialect types as is during conversion
When converting to the LLVM IR Dialect, it is possible for the input IR to
contain LLVM IR Dialect operation and/or types, for example, some functions may
have been coverted to the LLVM IR Dialect already, or may have been created
using this dialect directly.  Make sure that type conversion keeps LLVM IR
Dialect types unmodified and does not error out.  Operations are already kept
as is.

PiperOrigin-RevId: 240574972
2019-03-29 17:45:11 -07:00
River Riddle 9c08540690 Replace usages of Instruction with Operation in the /Analysis directory.
PiperOrigin-RevId: 240569775
2019-03-29 17:44:56 -07:00
Nicolas Vasilache 04b925f1b8 Port api-test::tile_2d to the edsc::Builder API
The AST-based EDSCs implementation will be retired soon, this test was missing from the builders API.

PiperOrigin-RevId: 240547453
2019-03-29 17:44:40 -07:00
Alex Zinenko 5a5bba0279 Introduce affine terminator
Due to legacy reasons (ML/CFG function separation), regions in affine control
flow operations require contained blocks not to have terminators.  This is
inconsistent with the notion of the block and may complicate code motion
between regions of affine control operations and other regions.

Introduce `affine.terminator`, a special terminator operation that must be used
to terminate blocks inside affine operations and transfers the control back to
he region enclosing the affine operation.  For brevity and readability reasons,
allow `affine.for` and `affine.if` to omit the `affine.terminator` in their
regions when using custom printing and parsing format.  The custom parser
injects the `affine.terminator` if it is missing so as to always have it
present in constructed operations.

Update transformations to account for the presence of terminator.  In
particular, most code motion transformation between loops should leave the
terminator in place, and code motion between loops and non-affine blocks should
drop the terminator.

PiperOrigin-RevId: 240536998
2019-03-29 17:44:24 -07:00
River Riddle af45236c70 Add experimental support for multi-threading the pass manager. This adds support for running function pipelines on functions across multiple threads, and is guarded by an off-by-default flag 'experimental-mt-pm'. There are still quite a few things that need to be done before multi-threading is ready for general use(e.g. pass-timing), but this allows for those things to be tested in a multi-threaded environment.
PiperOrigin-RevId: 240489002
2019-03-29 17:44:08 -07:00
Jacques Pienaar c6b294ac7b Include numeric header for std::accumulate.
PiperOrigin-RevId: 240462910
2019-03-29 17:43:52 -07:00
River Riddle f9d91531df Replace usages of Instruction with Operation in the /IR directory.
This is step 2/N to renaming Instruction to Operation.

PiperOrigin-RevId: 240459216
2019-03-29 17:43:37 -07:00
Jacques Pienaar d5259edefd Update header notices.
PiperOrigin-RevId: 240457737
2019-03-29 17:43:20 -07:00
Feng Liu c489f50e6f Add a trait to set the result type by attribute
Before this CL, the result type of the pattern match results need to be as same
as the first operand type, operand broadcast type or a generic tensor type.
This CL adds a new trait to set the result type by attribute. For example, the
TFL_ConstOp can use this to set the output type to its value attribute.

PiperOrigin-RevId: 240441249
2019-03-29 17:43:06 -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
Mehdi Amini e18d8ad7fa Add a getContext() utility to the Module/FunctionPass class (NFC)
This is just a convenience for reducing boilerplate when writing a pass.

PiperOrigin-RevId: 240407564
2019-03-29 17:42:35 -07:00
River Riddle 97db10d413 Add a utility Instruction::getDialect method to return the dialect an operation is associated with, or nullptr if the associated dialect has not been registered.
PiperOrigin-RevId: 240402300
2019-03-29 17:42:19 -07:00
River Riddle bee7b53031 Update the canonicalization patterns for AffineApply and AffineForOp to use matchAndRewrite.
PiperOrigin-RevId: 240398220
2019-03-29 17:42:03 -07:00
Nicolas Vasilache 56d5afdddf Fix createAffineComputationSlice comments
PiperOrigin-RevId: 240384796
2019-03-29 17:41:48 -07:00
Rob Suderman c7ada0b376 Tablegen changes to add support for tuples.
PiperOrigin-RevId: 240380512
2019-03-29 17:41:32 -07:00
Nicolas Vasilache 8811e284e8 Add an IndexedValue::operator Value*
This avoids the need to explicitly convert to a ValueHandle when using an Indexed where a Value* is expected.

PiperOrigin-RevId: 240371014
2019-03-29 17:41:17 -07:00
Alex Zinenko a7215a9032 Allow creating standalone Regions
Currently, regions can only be constructed by passing in a `Function` or an
`Instruction` pointer referencing the parent object, unlike `Function`s or
`Instruction`s themselves that can be created without a parent.  It leads to a
rather complex flow in operation construction where one has to create the
operation first before being able to work with its regions.  It may be
necessary to work with the regions before the operation is created.  In
particular, in `build` and `parse` functions that are executed _before_ the
operation is created in cases where boilerplate region manipulation is required
(for example, inserting the hypothetical default terminator in affine regions).
Allow creating standalone regions.  Such regions are meant to own a list of
blocks and transfer them to other regions on demand.

Each instruction stores a fixed number of regions as trailing objects and has
ownership of them.  This decreases the size of the Instruction object for the
common case of instructions without regions.  Keep this behavior intact.  To
allow some flexibility in construction, make OperationState store an owning
vector of regions.  When the Builder creates an Instruction from
OperationState, the bodies of the regions are transferred into the
instruction-owned regions to minimize copying.  Thus, it becomes possible to
fill standalone regions with blocks and move them to an operation when it is
constructed, or move blocks from a region to an operation region, e.g., for
inlining.

PiperOrigin-RevId: 240368183
2019-03-29 17:40:59 -07:00
Chris Lattner 46ade282c8 Make FunctionPass::getFunction() return a reference to the function, instead of
a pointer.  This makes it consistent with all the other methods in
FunctionPass, as well as with ModulePass::getModule().  NFC.

PiperOrigin-RevId: 240257910
2019-03-29 17:40:44 -07:00
River Riddle 5f3b914a6e Replace remaining usages of "Op::operator->" with "." and remove it.
PiperOrigin-RevId: 240210336
2019-03-29 17:40:25 -07:00
River Riddle 96ebde9cfd Replace usages of "Op::operator->" with ".".
This is step 2/N of removing the temporary operator-> method as part of the de-const transition.

PiperOrigin-RevId: 240200792
2019-03-29 17:40:09 -07:00
Jacques Pienaar c8a311a788 Qualify string in OpDefinitionsGen. NFC.
PiperOrigin-RevId: 240188138
2019-03-29 17:39:52 -07:00
River Riddle 5de726f493 Refactor the Pattern framework to allow for combined match/rewrite patterns. This is done by adding a new 'matchAndRewrite' function to RewritePattern that performs the match and rewrite in one step. The default behavior simply calls into the existing 'match' and 'rewrite' functions. The 'PatternMatcher' class has now been specialized for RewritePatterns and has been rewritten to make use of the new matchAndRewrite functionality.
This combined match/rewrite functionality allows simplifying the majority of existing RewritePatterns, as they do not benefit from separate match and rewrite functions.

Some of the existing canonicalization patterns in StandardOps have been modified to take advantage of this functionality.

PiperOrigin-RevId: 240187856
2019-03-29 17:39:35 -07:00
River Riddle af1abcc80b Replace usages of "operator->" with "." for the AffineOps.
Note: The "operator->" method is a temporary helper for the de-const transition and is gradually being phased out.
PiperOrigin-RevId: 240179439
2019-03-29 17:39:19 -07:00
River Riddle 832567b379 NFC: Rename the 'for' operation in the AffineOps dialect to 'affine.for' and set the namespace of the AffineOps dialect to 'affine'.
PiperOrigin-RevId: 240165792
2019-03-29 17:39:03 -07:00
Lei Zhang 8f5fa56623 [TableGen] Consolidate constraint related concepts
Previously we have multiple mechanisms to specify op definition and match constraints:
TypeConstraint, AttributeConstraint, Type, Attr, mAttr, mAttrAnyOf, mPat. These variants
are not added because there are so many distinct cases we need to model; essentially,
they are all carrying a predicate. It's just an artifact of implementation.

It's quite confusing for users to grasp these variants and choose among them. Instead,
as the OpBase TableGen file, we need to strike to provide an unified mechanism. Each
dialect has the flexibility to define its own aliases if wanted.

This CL removes mAttr, mAttrAnyOf, mPat. A new base class, Constraint, is added. Now
TypeConstraint and AttrConstraint derive from Constraint. Type and Attr further derive
from TypeConstraint and AttrConstraint, respectively.

Comments are revised and examples are added to make it clear how to use constraints.

PiperOrigin-RevId: 240125076
2019-03-29 17:38:46 -07:00
Mehdi Amini bb621a5596 Using getContext() instead of getInstruction()->getContext() on Operation (NFC)
PiperOrigin-RevId: 240088209
2019-03-29 17:38:29 -07:00
River Riddle 63e8725bc2 Update some of the derived type classes to use getImpl instead of a static_cast.
PiperOrigin-RevId: 240084937
2019-03-29 17:38:14 -07:00
Chris Lattner e510de0305 Various small cleanups to the code, mostly removing const_cast's.
PiperOrigin-RevId: 240083489
2019-03-29 17:37:58 -07:00
Mehdi Amini 3c747601d2 Add a `getImpl()` utility method to the `TypeBase` class as a convenience for derived class to access their associated TypeStorage (NFC)
PiperOrigin-RevId: 240077874
2019-03-29 17:37:41 -07:00
Mehdi Amini 903342c02c Change TypeStorage from a struct into a class (NFC)
By coding standard, we try to keep struct as pure storage without method or other logic attached to it.

PiperOrigin-RevId: 240076419
2019-03-29 17:37:23 -07:00
Mehdi Amini 6754968255 Move TypeStorage out of the detail namespace
Dialect implementer are expected to inherit from this class when implementing their types. It does not seems right when using MLIR "from the outside" to use directly something from `mlir::detail::`.

PiperOrigin-RevId: 240075769
2019-03-29 17:37:08 -07:00
River Riddle 9c6e92360c NFC: Rename the 'if' operation in the AffineOps dialect to 'affine.if'.
PiperOrigin-RevId: 240071154
2019-03-29 17:36:53 -07:00
Mehdi Amini 5c8113ef80 Remove `alignas(8) from TypeStorage class
This is here from history at a time where it was bit-packed and storage was dependent on this.

PiperOrigin-RevId: 240071093
2019-03-29 17:36:36 -07:00
Chris Lattner d9b5bc8f55 Remove OpPointer, cleaning up a ton of code. This also moves Ops to using
inherited constructors, which is cleaner and means you can now use DimOp()
to get a null op, instead of having to use Instruction::getNull<DimOp>().

This removes another 200 lines of code.

PiperOrigin-RevId: 240068113
2019-03-29 17:36:21 -07:00
Jacques Pienaar 7ab37aaf02 Fix missing parenthesis around negation.
This should probably be changed to instead use the negated form (e.g., get predicate + negate it + get resulting template), but this fixes it locally.

PiperOrigin-RevId: 240067116
2019-03-29 17:36:06 -07:00
Mehdi Amini 286bc49aca Add a routine to allow registering a dialect without relying on global constructors.
Using global constructors should not be mandatory when possible, clients should be able to register a dialect explicitly when they want.

PiperOrigin-RevId: 240064244
2019-03-29 17:35:50 -07:00
Chris Lattner dd2b2ec542 Push a bunch of 'consts' out of the *Op structure, in prep for removing
OpPointer.

PiperOrigin-RevId: 240044712
2019-03-29 17:35:35 -07:00
Nicolas Vasilache f26c7cd792 Cleanup ValueHandleArray
We just need a way to unpack ArrayRef<ValueHandle> to ArrayRef<Value*>.
No need to expose this to the user.

This reduces the cognitive overhead for the tutorial.

PiperOrigin-RevId: 240037425
2019-03-29 17:35:20 -07:00
Chris Lattner 405aa0af9e Deconst-ify MLIRContext, and detemplatize some stuff now that const is gone.
PiperOrigin-RevId: 239976764
2019-03-29 17:35:04 -07:00
Mehdi Amini 888554c0c6 Add a convenience getContext() method in OpState to reduce boilerplate on clients.
PiperOrigin-RevId: 239972907
2019-03-29 17:34:48 -07:00
Chris Lattner 986310a68f Remove const from Value, Instruction, Argument, and the various methods on the
*Op classes.  This is a net reduction by almost 400LOC.

PiperOrigin-RevId: 239972443
2019-03-29 17:34:33 -07:00
Jacques Pienaar b236041b93 Return operand_range instead for generated variadic operands accessor.
PiperOrigin-RevId: 239959381
2019-03-29 17:34:17 -07:00