Commit Graph

7516 Commits

Author SHA1 Message Date
Kazu Hirata 47d7e922d8 [mlir] Ensure a newline at the end of a file (NFC) 2022-01-23 13:59:59 -08:00
Groverkss ad36f37ce2 [MLIR][Presburger] Clean PresburgerSet identifier interface to match IntegerPolyhedron's interface
This patch changes names of identifiers and their corresponding getters in
PresburgerSet to match those of IntegerPolyhedron.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D117998
2022-01-24 01:09:07 +05:30
Prashant Kumar b6098c07cb [MLIR] Fix negative gcd in `normalizeDivisionByGCD` function.
When the coefficients of dividend are negative, the gcd may be negative
which will change the sign of dividend and overflow denominator.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D117911
2022-01-22 13:09:28 +05:30
not-jenni 08574ce4d6 [mlir][tosa] Add clamp + clamp as single clamp canonicalization
When 2 clamp ops are in a row, they can be canonicalized into a single clamp
that uses the most constrained range

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D117934
2022-01-21 16:24:43 -08:00
Aart Bik efa15f4178 [mlir][sparse] add ability for sparse tensor output
Rationale:
Although file I/O is a bit alien to MLIR itself, we provide two convenient ways
for sparse tensor I/O. The input part was already there (behind the swiss army
knife sparse_tensor.new). Now we have a sparse_tensor.out to write out data. As
before, the ops are kept vague and may change in the future. For now this
allows us to compare TACO vs MLIR very easily.

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D117850
2022-01-21 15:43:29 -08:00
Rob Suderman 2f9f9afa4e [mlir] Add polynomial approximation for atan and atan2
Implement a taylor series approximation for atan and add an atan2 lowering
that uses atan's appromation. This includes tests for edge cases and tests
for each quadrant.

Reviewed By: NatashaKnk

Differential Revision: https://reviews.llvm.org/D115682
2022-01-21 12:22:58 -08:00
wren romano 4d0a18d06e [mlir][sparse] Adding assertions for overhead storage types
Fixes https://bugs.llvm.org/show_bug.cgi?id=52314 aka https://github.com/llvm/llvm-project/issues/51656

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D117597
2022-01-21 11:56:52 -08:00
Alexander Belyaev fd0c6f5391 [mlir] Move linalg::PadTensorOp to tensor::PadOp.
RFC: https://llvm.discourse.group/t/rfc-move-linalg-padtensorop-to-tensor-padop/5785

Differential Revision: https://reviews.llvm.org/D117892
2022-01-21 20:02:39 +01:00
Lei Zhang 4710750854 [mlir][spirv] Support size-1 vector inserts during conversion
Differential Revision: https://reviews.llvm.org/D115517
2022-01-21 13:56:26 -05:00
serge-sans-paille 75e164f61d [llvm] Cleanup header dependencies in ADT and Support
The cleanup was manual, but assisted by "include-what-you-use". It consists in

1. Removing unused forward declaration. No impact expected.
2. Removing unused headers in .cpp files. No impact expected.
3. Removing unused headers in .h files. This removes implicit dependencies and
   is generally considered a good thing, but this may break downstream builds.
   I've updated llvm, clang, lld, lldb and mlir deps, and included a list of the
   modification in the second part of the commit.
4. Replacing header inclusion by forward declaration. This has the same impact
   as 3.

Notable changes:

- llvm/Support/TargetParser.h no longer includes llvm/Support/AArch64TargetParser.h nor llvm/Support/ARMTargetParser.h
- llvm/Support/TypeSize.h no longer includes llvm/Support/WithColor.h
- llvm/Support/YAMLTraits.h no longer includes llvm/Support/Regex.h
- llvm/ADT/SmallVector.h no longer includes llvm/Support/MemAlloc.h nor llvm/Support/ErrorHandling.h

You may need to add some of these headers in your compilation units, if needs be.

As an hint to the impact of the cleanup, running

clang++ -E  -Iinclude -I../llvm/include ../llvm/lib/Support/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l

before: 8000919 lines
after:  7917500 lines

Reduced dependencies also helps incremental rebuilds and is more ccache
friendly, something not shown by the above metric :-)

Discourse thread on the topic: https://llvm.discourse.group/t/include-what-you-use-include-cleanup/5831
2022-01-21 13:54:49 +01:00
MaheshRavishankar a99e06aa86 [mlir][Linalg] Avoid generating illegal operations during elementwise fusion.
In some cases, fusion can produce illegal operations if after fusion
the range of some of the loops cannot be computed from shapes of its
operands. Check for this case and abort the fusion if this happens.

Differential Revision: https://reviews.llvm.org/D117602
2022-01-20 23:43:50 -08:00
Mehdi Amini 9006bf4248 Remove obsolete `getAsmResultNames` from OpAsmDialectInterface
This is superseded by the same method on OpAsmOpInterface, which is
available on the Dialect through the Fallback mechanism,

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117750
2022-01-21 05:58:32 +00:00
Rahul Kayaith 308d8b8c66 [mlir][python] 8b/16b DenseIntElements access
This extends dense attribute element access to support 8b and 16b ints.
Also extends the corresponding parts of the C api.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D117731
2022-01-21 05:21:09 +00:00
Mehdi Amini 26167cae45 Print the `// ----` separator between modules when using -split-input-file with mlir-opt
This allows to pipe sequences of `mlir-opt -split-input-file | mlir-opt -split-input-file`.

Depends On D117750

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117756
2022-01-21 05:16:02 +00:00
Rob Suderman cd2d736963 [mlir][tosa] Limit right-shift to 31 bits
Right shift can occur that is a 32-bit right shift. This is undefined behavior.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D117732
2022-01-20 14:39:57 -08:00
River Riddle 5ef7abbc6f [mlir:TiingInterface] Remove unnecessary include of Tensor.h
Interfaces in Interfaces/ should not depend on any dialects, and this include
is unnecessary anyways.
2022-01-20 13:10:44 -08:00
Krzysztof Drewniak 40aef79db0 [MLIR][GPU] Add debug output to enable dumping GPU assembly
- Set the DEBUG_TYPE of SerializeToBlob to serialize-to-blob
- Add debug output to print the assembly or PTX for GPU modules before
  they are assembled and linked

Note that, as SerializeToBlob is a superclass of SerializeToCubin and
SerializeToHsaco, --debug-only=serialize-to-blom will dump the
intermediate compiler result for both of these passes.

In addition, if LLVM options such as --stop-after are used to control
the GPU kernel compilation process, the debug output will contain the
appropriate intermediate IR.

Reviewed By: herhut

Differential Revision: https://reviews.llvm.org/D117519
2022-01-20 20:52:12 +00:00
Mogball e99835ffed [mlir][pdl] Make `pdl` the default dialect when parsing/printing
PDLDialect being a somewhat user-facing dialect and whose ops contain exclusively other PDL ops in their regions can take advantage of `OpAsmOpInterface` to provide nicer IR.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117828
2022-01-20 20:22:53 +00:00
Sergei Grechanik 5abf116322 [mlir][vector] Allow values outside of [0; dim-size] in create_mask
This commits explicitly states that negative values and values exceeding
vector dimensions are allowed in vector.create_mask (but not in
vector.constant_mask). These values are now truncated when
canonicalizing vector.create_mask to vector.constant_mask.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D116069
2022-01-20 09:34:42 -08:00
Michael Kruse 616f77172f [OpenMPIRBuilder] Detect and fix ambiguous InsertPoints for createParallel.
When a Builder methods accepts multiple InsertPoints, when both point to
the same position, inserting instructions at one position will "move" the
other after the inserted position since the InsertPoint is pegged to the
instruction following the intended InsertPoint. For instance, when
creating a parallel region at Loc and passing the same position as AllocaIP,
creating instructions at Loc will "move" the AllocIP behind the Loc
position.

To avoid this ambiguity, add an assertion checking this condition and
fix the unittests.

In case of AllocaIP, an alternative solution could be to implicitly
split BasicBlock at InsertPoint, using the first as AllocaIP, the second
for inserting the instructions themselves. However, this solution is
specific to AllocaIP since AllocaIP will always have to be first. Hence,
this is an argument to generally handling ambiguous InsertPoints as API
sage error.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D117226
2022-01-20 10:13:44 -06:00
Stephan Herhut 6d45284618 [mlir][memref] Add better support for identity layouts in memref.collapse_shape canonicalizer
When computing the new type of a collapse_shape operation, we need to at least
take into account whether the type has an identity layout, in which case we can
easily support dynamic strides. Otherwise, the canonicalizer creates invalid
IR.

Longer term, both the verifier and the canoncializer need to be extended to
support the general case.

Differential Revision: https://reviews.llvm.org/D117772
2022-01-20 15:31:43 +01:00
Prashant Kumar 770353cd94 [MLIR] The return type in the `computeSingleVarRepr` function is modified to include equality expressions.
Earlier `computeSingleVarRepr` was returning a pair of upper bound and
lower bound indices of the inequality contraints that can be expressed
as a floordiv of an affine function. The equality expression can also be
expressed as a floordiv but contains only one index and hence the `LocalRepr`
class is introduced to facilitate this.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D117430
2022-01-20 16:40:58 +05:30
Matthias Springer 7a1579ac67 [mlir][bufferization] Move one-shot bufferization to Bufferization dialect
This commit is the first step towards unifying core bufferization and One-Shot Bufferize.

This commit does not move over the implementations of BufferizableOpInterface yet. This will be done in separate commits. This change does also not move the unit tests yet. The tests will be moved together with op interface implementations and split into separate files.

Differential Revision: https://reviews.llvm.org/D117641
2022-01-20 18:21:20 +09:00
River Riddle e39dae85f1 [mlir] Fix GCC5 build broken by improper name redefinition 2022-01-19 19:24:12 -08:00
River Riddle e084679f96 [mlir] Make locations required when adding/creating block arguments
BlockArguments gained the ability to have locations attached a while ago, but they
have always been optional. This goes against the core tenant of MLIR where location
information is a requirement, so this commit updates the API to require locations.

Fixes #53279

Differential Revision: https://reviews.llvm.org/D117633
2022-01-19 17:35:35 -08:00
Dominik Grewe 1e09f0a972 Preserve function argument locations.
Previously the optional locations of function arguments were dropped in
`parseFunctionArgumentList`. This CL adds another output argument to the
function through which they are now returned. The values are then plumbed
through as an array of optional locations in the various places.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117604
2022-01-20 00:01:12 +00:00
River Riddle d75c3e8396 [mlir] Don't print `// no predecessors` on entry blocks
Entry blocks can never have predecessors, so this is unnecessary.

Fixes #53287

Differential Revision: https://reviews.llvm.org/D117713
2022-01-19 15:57:58 -08:00
Mehdi Amini 4b12f4b2b1 Fix crash in MLIR opaque attribute parser
An assertion is triggered when the dialect is malformed.

Differential Revision: https://reviews.llvm.org/D117709
2022-01-19 23:35:48 +00:00
Mehdi Amini e7ab36f191 Change elided large constant syntax to make it more explicit
When the printer is requested to elide large constant, we emit an opaque
attribute instead. This patch fills the dialect name with
"elided_large_const" instead of "_" to remove some user confusion when
they later try to consume it.

Differential Revision: https://reviews.llvm.org/D117711
2022-01-19 20:41:42 +00:00
wren romano c4017f9d0c [mlir][sparse] Simplifying assertions in fromCOO
Hoisting invariant assertions to the top

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D117408
2022-01-19 11:25:41 -08:00
natashaknk b9b10c0e61 [tosa][mlir] Lowering for dynamic shapes in the reduce_x ops in tosa-to-linalg
Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D117691
2022-01-19 11:15:14 -08:00
Thomas Raoux d9edc1a585 [mlir][spirv] Add math.fma lowering to spirv
Differential Revision: https://reviews.llvm.org/D117704
2022-01-19 10:57:05 -08:00
Nicolas Vasilache d492a7b2ca [mlir][Linalg] Add a useLinalgCopy option to Linalg bufferization.
Benchmarks show that memref::CopyOp is curently up to 200x slower than
tiled and vectorized versions of linalg::Copy.
Add a temporary flag to allow comprehensive bufferize to generate a
linalg::GenericOp that implements a copy until this performance bug is
resolved.

Differential Revision: https://reviews.llvm.org/D117696
2022-01-19 13:00:11 -05:00
Matthias Springer cd0a923b4c [mlir][linalg][bufferize][NFC] Move analysis-related code to Comprehensive Bufferize
The code in `BufferizableOpInterface`'s header/source no longer contains any analysis code. This makes it easier to run the bufferization with a different analysis or without any analysis.

Differential Revision: https://reviews.llvm.org/D117478
2022-01-19 22:25:36 +09:00
Matthias Springer 31355482e5 [mlir][linalg][bufferize][NFC] Split analysis-related code from BufferizationState/Options
This separates the analysis (and its helpers/data structures) more clearly from the rest of the bufferization.

Differential Revision: https://reviews.llvm.org/D117477
2022-01-19 21:59:23 +09:00
Denys Shabalin ed21c9276a [mlir] Introduce Python bindings for the PDL dialect
This change adds full python bindings for PDL, including types and operations
with additional mixins to make operation construction more similar to the PDL
syntax.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D117458
2022-01-19 11:19:56 +01:00
Matthias Springer be8742b6c9 [mlir][linalg][bufferize][NFC] Merge AllocationCallbacks into BufferizationOptions
Also move `createAlloc` and related helper functions out of BufferizationState. The goal is to make BufferizationState as small as possible. (Code cleanup)

Differential Revision: https://reviews.llvm.org/D117476
2022-01-19 18:36:34 +09:00
Matthias Springer b44defa5a5 [mlir][linalg][bufferize] Generalize destination-passing style detection
If not allow-return-memref, raise an error if a new memory allocation is returned/yielded from a block. We do not check for new allocations directly, but for ops that yield/return values that are not equivalent to values that are defined outside of the current of the block.

Note: We still need to check that scf.for yield values and bbArgs are aliasing to ensure that getAliasingOpOperand/getAliasingOpResult is correct.

Differential Revision: https://reviews.llvm.org/D116687
2022-01-19 18:21:29 +09:00
Matthias Springer b83c67d978 [mlir][linalg][bufferize] Support scf.execute_region bufferization
This op is needed for unit testing in a subsequent revision. (This is the first op that has a block that yields equivalent values via the op's results.)

Note: Bufferization of scf.execute_region ops with multiple blocks is not yet supported.

Differential Revision: https://reviews.llvm.org/D117424
2022-01-19 18:17:09 +09:00
not-jenni 41d05e29c0 [mlir][tosa] Add tosa.clamp as no-op canonicalization
When the min/max are the total range of the value, it is a no-op as the values
are already restricted to that range.

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D117625
2022-01-18 23:15:40 -08:00
Mehdi Amini 3df97bfebc Fix GCC 5 MLIR Build (NFC)
Try to fix the error:

mlir/lib/Parser/Parser.cpp:553:14: error: cannot call member function 'mlir::InFlightDiagnostic mlir::detail::Parser::emitError(llvm::SMLoc, const llvm::Twine&)' without object
              << "operation location alias was never defined";
2022-01-19 06:44:28 +00:00
River Riddle 7ceffae18c [mlir] Convert OpTrait::FunctionLike to FunctionOpInterface
This commit refactors the FunctionLike trait into an interface (FunctionOpInterface).
FunctionLike as it is today is already a pseudo-interface, with many users checking the
presence of the trait and then manually into functionality implemented in the
function_like_impl namespace. By transitioning to an interface, these accesses are much
cleaner (ideally with no direct calls to the impl namespace outside of the implementation
of the derived function operations, e.g. for parsing/printing utilities).

I've tried to maintain as much compatability with the current state as possible, while
also trying to clean up as much of the cruft as possible. The general migration plan for
current users of FunctionLike is as follows:

* function_like_impl -> function_interface_impl
Realistically most user calls should remove references to functions within this namespace
outside of a vary narrow set (e.g. parsing/printing utilities). Calls to the attribute name
accessors should be migrated to the `FunctionOpInterface::` equivalent, most everything
else should be updated to be driven through an instance of the interface.

* OpTrait::FunctionLike -> FunctionOpInterface
`hasTrait` checks will need to be moved to isa, along with the other various Trait vs
Interface API differences.

* populateFunctionLikeTypeConversionPattern -> populateFunctionOpInterfaceTypeConversionPattern

Fixes #52917

Differential Revision: https://reviews.llvm.org/D117272
2022-01-18 20:56:53 -08:00
Peixin-Qiao a56a7d99e8 [MLIR][OpenMP] Support schedule chunk size with various bit width
The chunk size in schedule clause is one integer expression, which can
be either constant integer or integer variable. Fix schedule clause in
MLIR Op Def to support integer expression with different bit width.

Reviewed By: shraiysh

Differential Revision: https://reviews.llvm.org/D116073
2022-01-19 12:36:53 +08:00
River Riddle 4157455425 [mlir][Pass] Deprecate FunctionPass in favor of OperationPass<FuncOp>
The only benefit of FunctionPass is that it filters out function
declarations. This isn't enough to justify carrying it around, as we can
simplify filter out declarations when necessary within the pass. We can
also explore with better scheduling primitives to filter out declarations
at the pipeline level in the future.

The definition of FunctionPass is left intact for now to allow time for downstream
users to migrate.

Differential Revision: https://reviews.llvm.org/D117182
2022-01-18 19:52:44 -08:00
Benjamin Kramer ff5de8a9e0 [linalg][fusion] Disallow fusion when it would create an invalid expand_shape
The input type of a linalg.generic can be less dynamic than its output
type. If this is the case moving a reshape across the generic op would
create invalid IR, as expand_shape cannot expand arbitrary dynamic
dimensions.

Check that the reshape is actually valid before creating the
expand_shape. This exposes the existing verification logic in reshape
utils and removes the incomplete custom implementation in fusion.

Differential Revision: https://reviews.llvm.org/D116600
2022-01-18 23:44:14 +01:00
Benjamin Kramer f100bedb03 [mlir][linalg] Insert a cast for identity linalg.generics when the types don't match
This can happen when the result has different dynamic dimensions than
the input.

Differential Revision: https://reviews.llvm.org/D117498
2022-01-18 23:44:14 +01:00
Mehdi Amini 58cb303777 Allows deferred location attribute in `parseOptionalLocationSpecifier`
Before this patch, deferred location in operation like `test.pretty_printed_region` would
break the parser, and so the IR round-trip.

Depends On D117088

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117413
2022-01-18 22:00:36 +00:00
Mehdi Amini a440b0404f Use Opaque location for handling deferred references to aliases internally to the parser (NFC)
This will allow to return to the client of `parseLocationInstance` a location that is resolved later.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117088
2022-01-18 20:43:36 +00:00
River Riddle 755dc07d69 [mlir:Analysis] Move the LoopAnalysis library to Dialect/Affine/Analysis
The current state of the top level Analysis/ directory is that it contains two libraries;
a generic Analysis library (free from dialect dependencies), and a LoopAnalysis library
that contains various analysis utilities that originated from Affine loop transformations.
This commit moves the LoopAnalysis to the more appropriate home of `Dialect/Affine/Analysis/`,
given the use and intention of the majority of the code within it. After the move, if there
are generic utilities that would fit better in the top-level Analysis/ directory, we can move
them.

Differential Revision: https://reviews.llvm.org/D117351
2022-01-18 10:28:22 -08:00
Mogball aae5125550 [mlir] Replace StrEnumAttr -> EnumAttr in core dialects
Removes uses of `StrEnumAttr` in core dialects

Reviewed By: mehdi_amini, rriddle

Differential Revision: https://reviews.llvm.org/D117514
2022-01-18 17:15:00 +00:00
Mogball 5c36ee8d57 [mlir] Drop the leading space when printing regions
The leading space that is always printed at the beginning of regions is not consistent with other parts of the printing API. Moreover, this leading space can lead to undesirable assembly formats:

```
attr-dict-with-keyword $region
```

Prints as:

```
// Two spaces between `}` and `{`
attributes {foo}  { ... }
```

Moreover, the leading space results in the odd generic op format:

```
"test.op"() ( {...}) : () -> ()
```

Reviewed By: rriddle, mehdi_amini

Differential Revision: https://reviews.llvm.org/D117411
2022-01-18 16:52:34 +00:00
Alex Zinenko 1ad48d6de2 [mlir] handle nested regions in llvm-legalize-for-export
The translation from the MLIR LLVM dialect to LLVM IR includes a mechanism that
ensures the successors of a block to be different blocks in case block
arguments are passed to them since the opposite cannot be expressed in LLVM IR.
This mechanism previously only worked for functions because it was written
prior to the introduction of other region-carrying operations such as the
OpenMP dialect, which also translates directly to LLVM IR. Modify this
mechanism to handle all regions in the module and not only functions.

Reviewed By: wsmoses

Differential Revision: https://reviews.llvm.org/D117548
2022-01-18 17:09:14 +01:00
Nicolas Vasilache efdd4c169d [mlir][Linalg] NFC - Drop vectorization reliance on ConvolutionOpInterface
Differential revision: https://reviews.llvm.org/D117323
2022-01-18 09:30:46 +00:00
Nicolas Vasilache cc0d208805 [mlir][Linalg] Drop deprecated convolution vectorization patterns
Differential revision: https://reviews.llvm.org/D117326
2022-01-18 09:26:50 +00:00
Mehdi Amini 78fdbdbf26 Use reference for large object passed by value at the moment in MLIR TableGen (NFC)
Also make the ODS Operator class have const iterator, and use const
references for existing API taking Operator by reference.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117516
2022-01-18 06:48:33 +00:00
Mehdi Amini 7265688e09 Use more references in MLIR Diagnostic handling (NFC)
This saves some copies of non-trivial objects, flagged by Coverity.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117525
2022-01-18 06:45:04 +00:00
Mehdi Amini c8e047f5e1 Enable useDefault{Type/Attribute}PrinterParser by default in ODS Dialect definition
The majority of dialects reimplement the same boilerplate over and over,
switching the default makes it for better discoverability and make it simpler
to implement new dialects.

Differential Revision: https://reviews.llvm.org/D117524
2022-01-18 06:36:34 +00:00
Benjamin Kramer 964dc368e7 [AsyncToLLVM] aligned_alloc requires the size to be a multiple of aignment, so round up
Fixes a crash with debug malloc.
2022-01-17 21:48:00 +01:00
Nicolas Vasilache f40a579bea Revert "[mlir][Linalg] NFC - Drop vectorization reliance on ConvolutionOpInterface"
This reverts commit c8f5735301.

The integration tests are broken.
2022-01-17 19:38:07 +00:00
Benjamin Kramer 5acd6e0522 [AsyncToLLVM] Align frames to 64 bytes
Coroutine lowering always takes the natural alignment when spilling to
the frame (issue #53148) so using AVX2 or AVX512 in a coroutine doesn't
work. Always overalign to 64 bytes to avoid this issue until we have a
better solution.

Differential Revision: https://reviews.llvm.org/D117501
2022-01-17 18:51:42 +01:00
Nicolas Vasilache 392e16c27f [mlir][Linalg] NFC - Cleanup conv1d generators
Differential Revision: https://reviews.llvm.org/D117330
2022-01-17 17:39:19 +00:00
Nicolas Vasilache 8a8f0a00b2 [mlir][Linalg] Relax PadTensor tiling constraints and expose it to strategies.
Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D117334
2022-01-17 17:13:55 +00:00
Nicolas Vasilache c8f5735301 [mlir][Linalg] NFC - Drop vectorization reliance on ConvolutionOpInterface
Differential Revision: https://reviews.llvm.org/D117323
2022-01-17 17:01:36 +00:00
Nicolas Vasilache f98025d867 [mlir][Vector] Generalize and improve folding of ExtractOp from Insert/Transpose chain.
This revision fixes a bug where the iterative algorithm would walk back def-use chains to an incorrect operand.
This exposed opportunities for a larger refactoring and behavior improvement.
The new algorithm has improved folding behavior and proceeds by tracking both the
permutation of the extraction position and the internal vector permutation.
Multiple partial intersection cases with a candidate insertOp are supported.

The refactoring of the implementation should also help it generalize to strided insert/extract op.

This also subsumes the previous `foldExtractOpFromTranspose` which is now a simple special case and can be deleted.

Differential Revision: https://reviews.llvm.org/D117322
2022-01-17 16:05:23 +00:00
Lorenzo Chelini ca2ac2bb14 [MLIR][Linalg] Handle Attribute in InitTensorOp
In some cases, the result of an initTensorOp may have an attribute.
However, the Attribute was not passed to `inferResultType`, failing the
verifier. Therefore, propagate the Attribute to `inferResultType`.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D117192
2022-01-17 11:43:19 +01:00
Dominik Grewe 5f782d25a7 Preserve argument locations when cloning a region.
Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D117403
2022-01-16 21:17:23 +00:00
Arjun P 79be1fe0d5 [MLIR] Simplex::getRationalSample: return an optional, empty if Simplex is empty 2022-01-16 22:02:27 +05:30
Mehdi Amini 772f7b87f8 Disable the MLIR ExecutionEngine library when the native target is not configured
The execution engine would not be functional anyway, we're already
disabling the tests, this also disable the rest of the code.

Anecdotally this reduces the number of static library built when the
builtin target is disabled goes from 236 to 218.

Here is the complete list of LLVM targets built when running
`ninja check-mlir`:

libLLVMAggressiveInstCombine.a
libLLVMAnalysis.a
libLLVMAsmParser.a
libLLVMBinaryFormat.a
libLLVMBitReader.a
libLLVMBitstreamReader.a
libLLVMBitWriter.a
libLLVMCore.a
libLLVMDebugInfoCodeView.a
libLLVMDebugInfoDWARF.a
libLLVMDemangle.a
libLLVMFileCheck.a
libLLVMFrontendOpenMP.a
libLLVMInstCombine.a
libLLVMIRReader.a
libLLVMMC.a
libLLVMMCParser.a
libLLVMObject.a
libLLVMProfileData.a
libLLVMRemarks.a
libLLVMScalarOpts.a
libLLVMSupport.a
libLLVMTableGen.a
libLLVMTableGenGlobalISel.a
libLLVMTextAPI.a
libLLVMTransformUtils.a

Differential Revision: https://reviews.llvm.org/D117287
2022-01-15 19:36:27 +00:00
James Y Knight 3bd1ff9a23 Fix NDEBUG unused-variable warning after 05f6e93938. 2022-01-14 21:15:33 +00:00
Eugene Zhulenev 69bc334be5 [mlir] Remove getNumberOfExecutions from RegionBranchOpInterface
`getNumRegionInvocations` was originally added for the async reference counting, but turned out to be not useful, and currently is not used anywhere (couldn't find any uses in public github repos). Removing dead code.

Reviewed By: Mogball, mehdi_amini

Differential Revision: https://reviews.llvm.org/D117347
2022-01-14 13:15:27 -08:00
Mehdi Amini fd6ba1d2c0 Apply clang-tidy fixes for readability-container-size-empty in SCF.cpp (NFC) 2022-01-14 18:08:43 +00:00
Mehdi Amini 1c173c9442 Apply clang-tidy fixes for readability-identifier-naming in MathOps.cpp (NFC) 2022-01-14 18:08:42 +00:00
Mehdi Amini 3b6943e66c Apply clang-tidy fixes for performance-for-range-copy in PadOpInterchange.cpp (NFC) 2022-01-14 18:08:42 +00:00
Rahul Joshi 8067ced144 [MLIR] Introduce generic visitors.
- Generic visitors invoke operation callbacks before/in-between/after visiting the regions
  attached to an operation and use a `WalkStage` to indicate which regions have been
  visited.
- This can be useful for cases where we need to visit the operation in between visiting
  regions attached to the operation.

Differential Revision: https://reviews.llvm.org/D116230
2022-01-14 09:15:27 -08:00
Stephan Herhut aa3cabe3cb [mlir][memref] Fix memref.copy of scalar memref
Also fix a memory leak in the test while at it.

Differential Revision: https://reviews.llvm.org/D117314
2022-01-14 16:13:12 +01:00
Uday Bondhugula 05f6e93938 [MLIR] NFC. affine data copy generate utility return value cleanup
Clean up return value on affineDataCopyGenerate utility. Return the
actual success/failure status instead of the "number of bytes" which
isn't being used in the codebase in any way. The success/failure status
wasn't being sent out earlier.

Differential Revision: https://reviews.llvm.org/D117209
2022-01-14 19:37:05 +05:30
Matthias Springer 1eeffcdb7a [mlir][linalg][bufferize] Support custom insertion point for buffer copies
By default, copies are inserted right before the tensor OpOperand use. With this change, `bufferize` implementation can change the insertion point. This is needed for some ops where it would be illegal to insert a copy right before the use.

Differential Revision: https://reviews.llvm.org/D117291
2022-01-14 22:47:20 +09:00
Matthias Springer e58e401b79 [mlir][memref] Fold self copies
Fold `memref.copy %x, %x`.

Differential Revision: https://reviews.llvm.org/D117224
2022-01-14 22:44:22 +09:00
Matthias Springer 40f5f3d62d [mlir][linalg][bufferize] Use memref.copy instead of linalg.copy
Differential Revision: https://reviews.llvm.org/D117220
2022-01-14 22:29:05 +09:00
Stephan Herhut ab95ba704d [mlir][memref] Implement fast lowering of memref.copy
In the absence of maps, we can lower memref.copy to a memcpy.

Differential Revision: https://reviews.llvm.org/D116099
2022-01-14 14:22:15 +01:00
Matthias Springer 96acdfa0de [mlir][memref] Fold copy of cast
If the source/dest is a cast that does not change shape/element type, the cast can be skipped.

Differential Revision: https://reviews.llvm.org/D117215
2022-01-14 21:51:12 +09:00
Alex Zinenko bea16e72a7 [mlir] Fix invalid assertion in ModuleTranslation.cpp
LLVM dialect supports terminators with repeated successor blocks that take
different operands. This cannot be directly expressed in LLVM IR though since
it uses the number of the predecessor block to differentiate values in its PHI
nodes. Therefore, the translation to LLVM IR inserts dummy blocks to forward
arguments in case of repeated succesors with arguments. The insertion works
correctly. However, when connecting PHI nodes to their source values, the
assertion of the insertion having worked correctly was incorrect: it would only
trigger if repeated blocks were adjacent in the successor list (not guaranteed
by anything) and would not check if the successors have operands (no need for
dummy blocks in absence of operands since no PHIs are being created). Change
the assertion to only trigger in case of duplicate successors with operands,
and don't expect them to be adjacent.

Reviewed By: wsmoses

Differential Revision: https://reviews.llvm.org/D117214
2022-01-14 12:56:33 +01:00
Alexander Belyaev 436d17a8e9 [mlir] Expose a function to get vector::CombiningKind from Operation*.
Differential Revision: https://reviews.llvm.org/D117283
2022-01-14 08:28:18 +01:00
River Riddle 11067d711b [mlir] Optimize OperationName construction and usage
When constructing an OperationName, the overwhelming majority of
cases are from registered operations. This revision adds a non-locked
lookup into the currently registered operations, which prevents locking
in the common case. This revision also optimizes several uses of
RegisteredOperationName that expect the operation to be registered,
e.g. such as in OpBuilder.

These changes provides a reasonable speedup (5-10%) in some
compilations, especially on platforms where locking is expensive.

Differential Revision: https://reviews.llvm.org/D117187
2022-01-13 21:14:36 -08:00
wren romano cf35825388 [mlir][sparse] Moving the sort from factory method to the constructor.
This guarantees the preconditions of fromCOO; whereas prior to this, one could call the constructor directly with an unsorted tensor, which would cause fromCOO to misbehave.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D117167
2022-01-13 19:44:51 -08:00
Mehdi Amini cac7aabbd8 Apply clang-tidy fixes for readability-identifier-naming to MLIR (NFC) 2022-01-14 02:26:28 +00:00
Mehdi Amini e8d073951b Apply clang-tidy fixes for performance-unnecessary-value-param to MLIR (NFC) 2022-01-14 02:26:27 +00:00
Mehdi Amini bd87241c44 Apply clang-tidy fixes for modernize-use-override to MLIR (NFC) 2022-01-14 02:26:27 +00:00
Mehdi Amini 9940dcfa4a Apply clang-tidy fixes for modernize-use-equals-default to MLIR (NFC) 2022-01-14 02:26:27 +00:00
Mehdi Amini 59d8740f2f Apply clang-tidy fixes for modernize-use-default-member-init to MLIR (NFC) 2022-01-14 02:26:26 +00:00
Mehdi Amini d19f89b5d2 Apply clang-tidy fixes for llvm-qualified-auto to MLIR (NFC) 2022-01-14 02:26:26 +00:00
Rob Suderman 173fce4205 [mlir][tosa] Update default tosa-to-linalg passes
Adding the optional decompositions have been verified to improve memory
usage on common models. Added the decomposition to the default tosa to linalg
passes.

Reviewed By: NatashaKnk

Differential Revision: https://reviews.llvm.org/D117175
2022-01-13 10:17:44 -08:00
Duncan P. N. Exon Smith b77d4d54f9 mlir: Avoid SmallVector::set_size in SerializeToHsacoPass::loadLibraries
Spotted this in a final grep of projects I don't usually build before
pushing https://reviews.llvm.org/D115380, which makes
`SmallVector::set_size()` private.

Update to `truncate()`, a new-ish variant of `resize()` that asserts the
new size is not bigger and that avoids pulling in the allocation and
initialization code for growing. Doesn't really look like the perf
impact of that would matter here, but since `dirLength` is known to be a
smaller size then we might as well.

Differential Revision: https://reviews.llvm.org/D117073
2022-01-13 10:17:00 -08:00
Benoit Jacob 499703e9c0 Enable ReassociatingReshapeOpConversion with "non-identity" layouts.
Enable ReassociatingReshapeOpConversion with "non-identity" layouts.

This removes an early-return in this function, which seems unnecessary and is
preventing some memref.collapse_shape from converting to LLVM (see included lit test).

It seems unnecessary because the return message says "only empty layout map is supported"
but there actually is code in this function to deal with non-empty layout maps. Maybe
it refers to an earlier state of implementation and is just out of date?

Though, there is another concern about this early return: the condition that it actually
checks, `{src,dst}MemrefType.getLayout().isIdentity()`, is not quite the same as what the
return message says, "only empty layout map is supported". Stepping through this
`getLayout().isIdentity()` code in GDB, I found that it evaluates to `.getAffineMap().isIdentity()`
which does (AffineMap.cpp:271):

```
  if (getNumDims() != getNumResults())
    return false;
```

This seems that it would always return false for memrefs of rank greater than 1 ?

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D114808
2022-01-13 17:46:20 +00:00
Denys Shabalin a8a2ee6331 [mlir] Introduce C API for PDL dialect types
This change introduces C API helper functions to work with PDL types.
Modification closely follow the format of the https://reviews.llvm.org/D116546.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D117221
2022-01-13 15:29:01 +01:00
Javier Setoain 7c56458616 [mlir] Fix scalable type translation in splat element attr
LLVM Dialect Constant Op translations assume that if the attribute is a
vector, it's a fixed length one, generating an invalid translation for
constant scalable vector initializations.

Differential Revision: https://reviews.llvm.org/D117125
2022-01-13 11:14:41 +00:00
Ivan Butygin b65f21a498 [mlir] Provide getMixedOffsets/sizes/strides as free functions
* This is useful when you need to build mixed array from external static/dynamic arrays (e.g. from adaptor during dialect conversion)
* Also, to reduce C++ code in td and generated files

Differential Revision: https://reviews.llvm.org/D117106
2022-01-13 13:46:31 +03:00
Adrian Kuegel 159898d568 [mlir] Add missing const to cloneWith method. 2022-01-13 09:40:29 +01:00
River Riddle 0998637e6f [mlir] Add a parsePassPipeline overload that returns a new pass manager
This overload parses a pipeline string that contains the anchor operation type, and returns an OpPassManager
corresponding to the provided pipeline. This is useful for various situations, such as dynamic pass pipelines
which are not anchored within a parent pass pipeline.

fixes #52813

Differential Revision: https://reviews.llvm.org/D116525
2022-01-12 14:54:30 -08:00
natashaknk 310e9636ca [tosa][mlir] Support dynamic batch dimension for ops where the batch dim is explicit
Dynamic batch for rescale, gather, max_pool, avg_pool, conv2D and depthwise_conv2D. Split helper functions into a separate header file.

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D117031
2022-01-12 14:16:50 -08:00
River Riddle 676bfb2a22 [mlir] Refactor ShapedType into an interface
ShapedType was created in a time before interfaces, and is one of the earliest
type base classes in the ecosystem. This commit refactors ShapedType into
an interface, which is what it would have been if interfaces had existed at that
time. The API of ShapedType and it's derived classes are essentially untouched
by this refactor, with the exception being the API surrounding kDynamicIndex
(which requires a sole home).

For now, the API of ShapedType and its name have been kept as consistent to
the current state of the world as possible (to help with potential migration churn,
among other reasons). Moving forward though, we should look into potentially
restructuring its API and possible its name as well (it should really have "Interface"
at the end like other interfaces at the very least).

One other potentially interesting note is that I've attached the ShapedType::Trait
to TensorType/BaseMemRefType to act as mixins for the ShapedType API. This
is kind of weird, but allows for sharing the same API (i.e. preventing API loss from
the transition from base class -> Interface). This inheritance doesn't affect any
of the derived classes, it is just for API mixin.

Differential Revision: https://reviews.llvm.org/D116962
2022-01-12 14:12:09 -08:00
River Riddle a60e83fe7c [mlir][Interfaces] Add a extraSharedClassDeclaration field
This field allows for defining a code block that is placed in both the interface
and trait declarations. This is very useful when defining a set of utilities to
expose on both the Interface class and the derived attribute/operation/type.

In non-static methods, `$_attr`/`$_op`/`$_type` (depending on the type of
interface) may be used to refer to an instance of the IR entity. In the interface
declaration, this is an instance of the interface class. In the trait declaration,
this is an instance of the concrete entity class (e.g. `IntegerAttr`, `FuncOp`, etc.).

Differential Revision: https://reviews.llvm.org/D116961
2022-01-12 14:12:08 -08:00
Rob Suderman aa1c533a4e [mlir][tosa] Expand tosa.apply_scale lowering for vectors
Apply scale may encounter scalar, tensor, or vector operations. Expand the
lowering so that it can lower arbitrary of container types.

Reviewed By: NatashaKnk

Differential Revision: https://reviews.llvm.org/D117080
2022-01-12 14:07:52 -08:00
River Riddle d4d016869d [mlir] Remove populateFuncOpTypeConversionPattern
This method simply forwards to populateFunctionLikeTypeConversionPattern,
which is more general. This also helps to remove special treatment of FuncOp from
DialectConversion.

Differential Revision: https://reviews.llvm.org/D116624
2022-01-12 14:05:35 -08:00
Kazu Hirata 44bb5cd80d [mlir] Fix a warning
This patch fixes:

  mlir/lib/Dialect/Arithmetic/Transforms/ExpandOps.cpp:161:52: error:
  'static_assert' with no message is a C++17 extension
  [-Werror,-Wc++17-extensions]
2022-01-12 12:31:43 -08:00
River Riddle 56f62fbf73 [mlir] Finish removing Identifier from the C++ API
There have been a few API pieces remaining to allow for a smooth transition for
downstream users, but these have been up for a few months now. After this only
the C API will have reference to "Identifier", but those will be reworked in a followup.

The main updates are:
* Identifier -> StringAttr
* StringAttr::get requires the context as the first parameter
  - i.e. `Identifier::get("...", ctx)` -> `StringAttr::get(ctx, "...")`

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D116626
2022-01-12 11:58:23 -08:00
Christian Sigg be1aeb818c Remove NaN constant from arith.minf, arith.maxf expansion
If any of the operands is NaN, return the operand instead of a new constant.

When the rhs operand is a constant, the second arith.cmpf+select ops will be folded away.

https://reviews.llvm.org/D117010 marks the two ops commutative, which will place the constant on the rhs.

Reviewed By: herhut

Differential Revision: https://reviews.llvm.org/D117011
2022-01-12 20:56:40 +01:00
Christian Sigg f6fab68c30 Fold arith.cmpf when at least one operand is known to be NaN.
Reviewed By: herhut

Differential Revision: https://reviews.llvm.org/D117101
2022-01-12 20:48:52 +01:00
Thomas Raoux b0a309dd7a [mlir][vector] Add folding for extract + extract/insert_strided
Differential Revision: https://reviews.llvm.org/D116785
2022-01-12 11:48:35 -08:00
William S. Moses 1773dddadf [MLIR][Math] Enable constant folding of ops
Enable constant folding of ops within the math dialect, and introduce constant folders for ceil and log2

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D117085
2022-01-12 12:19:29 -05:00
Matthias Springer 57e714bcc8 [mlir][linalg][bufferize] Add pass options for `createDeallocs`
This change makes it possible to use a different buffer deallocation strategy. E.g., `-buffer-deallocation` can be used, which also works for allocations that are not in destination-passing style.

Differential Revision: https://reviews.llvm.org/D117096
2022-01-12 18:55:36 +09:00
Matthias Springer 6c654b5198 [mlir][linalg][bufferize] Support std.select bufferization
This op is an example for how to deal with ops who's OpResult may aliasing with one of multiple OpOperands.

Differential Revision: https://reviews.llvm.org/D116868
2022-01-12 17:46:44 +09:00
Uday Bondhugula fc61d07dc1 Add inliner interface for GPU dialect
Add inliner interface for GPU dialect. The interface marks all GPU
dialect ops legal to inline anywhere.

Differential Revision: https://reviews.llvm.org/D116889
2022-01-12 12:55:02 +05:30
William S. Moses d2c547342c Revert "[MLIR][Math] Enable constant folding of ops"
This reverts commit 2f8b956ab6.

There is a linker error for mlir-nvidia as seen on
https://lab.llvm.org/buildbot/#/builders/61/builds/19939.

As it's late for me here, I'm oing to rever this for now to be
investigated later.
2022-01-12 02:00:53 -05:00
William S. Moses 2f8b956ab6 [MLIR][Math] Enable constant folding of ops
Enable constant folding of ops within the math dialect, and introduce constant folders for ceil and log2

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D117085
2022-01-12 01:55:48 -05:00
William S. Moses d23fa4f2f1 [MLIR][SCF] Remove unused arguments to whileop
Canonicalize away unused arguments to the before region of a whileOp

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D117059
2022-01-11 20:18:08 -05:00
William S. Moses 97567bde5b [MLIR][SCF] Canonicalize while statement whose cmp condition is recomputed in the after region
Given a while loop whose condition is given by a cmp, don't recomputed the comparison (or its inverse) in the after region, instead use a constant since  the original condition must be true if we branched to the after region.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D117047
2022-01-11 18:34:04 -05:00
MaheshRavishankar e7cb716ef9 [mlir][Linalg] Pattern to fuse pad operation with elementwise operations.
Most convolution operations need explicit padding of the input to
ensure all accesses are inbounds. In such cases, having a pad
operation can be a significant overhead. One way to reduce that
overhead is to try to fuse the pad operation with the producer of its
source.

A sequence

```
linalg.generic -> linalg.pad_tensor
```

can be replaced with

```
linalg.fill -> tensor.extract_slice -> linalg.generic ->
tensor.insert_slice.
```

if the `linalg.generic` has all parallel iterator types.

Differential Revision: https://reviews.llvm.org/D116418
2022-01-11 13:37:25 -08:00
Mehdi Amini 75b08cce47 Apply clang-tidy fixes for readability-redundant-control-flow in OpenMPDialect.cpp (NFC) 2022-01-11 19:13:58 +00:00
Kazu Hirata 0ceb332a76 [mlir] Fix a missing override warning
This patch fixes:

  mlir/lib/Dialect/Tosa/Transforms/TosaOptionalDecompositions.cpp:28:8:
  error: 'runOnFunction' overrides a member function but is not marked
  'override' [-Werror,-Wsuggest-override]
2022-01-11 11:03:22 -08:00
Aaron DeBattista dfd070820c [mlir][tosa] Allow optional TOSA decompositions to be populated separately
Moved all TOSA decomposition patterns so that they can be optionally populated
and used by external rewrites. This avoids decomposing TOSa operations when
backends may benefit from the non-decomposed version.

Reviewed By: rsuderman, mehdi_amini

Differential Revision: https://reviews.llvm.org/D116526
2022-01-11 10:26:30 -08:00
William S. Moses 5443d2ed98 [MLIR][SCF] Simplify scf.if by swapping regions if condition is a not
Given an if of the form, simplify it by eliminating the not and swapping the regions

scf.if not(c) {
  yield origTrue
} else {
  yield origFalse
}

becomes

scf.if c {
  yield origFalse
} else {
  yield origTrue
}

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D116990
2022-01-11 12:57:29 -05:00
Benjamin Kramer 7f47005dcc [mlir][linalg] Use cast instead of dyn_cast that's always dereferenced
This turns a random nullptr deref into an assertion failure in case
`tensor::registerInferTypeOpInterfaceExternalModels` isn't called.
2022-01-11 15:05:45 +01:00
Matthias Springer 2c5c5ca868 [mlir][linalg][bufferize] Fix CallOp bufferization
Previously, CallOps did not have any aliasing OpResult/OpOperand pairs. Therefore, CallOps were mostly ignored by the analysis and buffer copies were not inserted when necessary.

This commit introduces the following changes:
* Function bbArgs writable by default. A function can now be bufferized without inspecting its callers.
* Callers must introduce buffer copies of function arguments when necessary. If a function is external, the caller must conservatively assume that a function argument is modified by the callee after bufferization. If the function is not external, the caller inspects the callee to determine if a function argument is modified.

Differential Revision: https://reviews.llvm.org/D116457
2022-01-11 20:10:21 +09:00
Julian Gross 4b01968b5e [MLIR] Update allocs to memref.allocs in documentation.
Changed the remaining appearances of alloc to memref.alloc in several
documentation sections, since they lead to misunderstandings, if they
are used.

Differential Revision: https://reviews.llvm.org/D116999
2022-01-11 11:22:22 +01:00
Diego Caballero e2b658cd5d [mlir][GPU] Fix attribute name of DL specification
D115722 added a DL spec to GPU modules. It happens that the DL
default interface implementation is sensitive to the name of the
DL spec attribute. This patch is fixing the name of the attribute
to be the expected one.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D116956
2022-01-11 08:30:52 +00:00
Tyler Augustine 87a9be2a74 Don't fail if unable to promote loops during unrolling
When the unroll factor is 1, we should only fail "unrolling" when the trip count also is determined to be 1 and it is unable to be promoted.

Reviewed By: bondhugula

Differential Revision: https://reviews.llvm.org/D115365
2022-01-10 22:26:21 +00:00
William S. Moses a02af37560 [MLIR] Generalize select to arithmetic canonicalization
Given a select whose result is an i1, we can eliminate the conditional in the select completely by adding a few arithmetic operations.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D116839
2022-01-10 11:50:17 -05:00
James Y Knight 39f75ab6a7 Fix unused-variable warnings after d0ee094d6a. 2022-01-10 16:28:54 +00:00
Nicolas Vasilache d0ee094d6a [mlir][Bufferize] Fix incorrect bufferization of rank-reducing tensor ops.
This revision fixes SubviewOp, InsertSliceOp, ExtractSliceOp construction during bufferization
where not all offset/size/stride operands were properly specified.

A test that exhibited problematic behaviors related to incorrect memref casts is introduced.
Init tensor optimization is disabled in teh testing func bufferize pass.

Differential Revision: https://reviews.llvm.org/D116899
2022-01-10 10:14:55 -05:00
Matthias Springer 0696ad9563 [mlir][linalg][bufferize][NFC] Pass missing BufferizationState objs as const ref
These should have been updated as part of D116742.

Differential Revision: https://reviews.llvm.org/D116937
2022-01-10 23:38:04 +09:00
Nicolas Vasilache 1a2474b786 [mlir][Linalg] Disable init_tensor elimination by default
init_tensor elimination is arguably a pre-optimization that should be separated from comprehensive bufferization.
In any case it is still experimental and easily results in wrong IR with violated SSA def-use orderings.
Isolate the optimization behind a flag, separate the test cases and add a test case that would results in wrong IR.

Differential Revision: https://reviews.llvm.org/D116936
2022-01-10 09:19:18 -05:00
Serge Guelton d2cc6c2d0c Use a sorted array instead of a map to store AttrBuilder string attributes
Using and std::map<SmallString, SmallString> for target dependent attributes is
inefficient: it makes its constructor slightly heavier, and involves extra
allocation for each new string attribute. Storing the attribute key/value as
strings implies extra allocation/copy step.

Use a sorted vector instead. Given the low number of attributes generally
involved, this is cheaper, as showcased by

https://llvm-compile-time-tracker.com/compare.php?from=5de322295f4ade692dc4f1823ae4450ad3c48af2&to=05bc480bf641a9e3b466619af43a2d123ee3f71d&stat=instructions

Differential Revision: https://reviews.llvm.org/D116599
2022-01-10 14:49:53 +01:00
Matthias Springer cb64c541f9 [mlir][linalg][bufferize][NFC] Clean up bufferization entry point
Differential Revision: https://reviews.llvm.org/D116892
2022-01-10 21:50:36 +09:00
Alex Zinenko c44d521b30 [mlir] address post-commit review for D116759 2022-01-10 12:40:58 +01:00
Alex Zinenko 2f672e2ffa [mlir] Don't inline calls from dead SCCs
During iterative inlining of the functions in a multi-step call chain, the
inliner could add the same call operation several times to the worklist, which
led to use-after-free when this op was considered more than once.

Closes #52887.

Reviewed By: wsmoses

Differential Revision: https://reviews.llvm.org/D116820
2022-01-10 12:07:14 +01:00
Stephan Herhut 33cec20dbd [mlir][memref] Tighten verification of memref.reinterpret_cast
We allow the omission of a map in memref.reinterpret_cast under the assumption,
that the cast might cast to an identity layout. This change adds verification
that the static knowledge that is present in the reinterpret_cast supports
this assumption.

Differential Revision: https://reviews.llvm.org/D116601
2022-01-10 11:55:47 +01:00
Shraiysh Vaishay a8586b573e [mlir][OpenMP] Change the syntax of omp.atomic.read op
This patch changes the syntax of omp.atomic.read to take the address of
destination, instead of having the value in a result. This will allow
using omp.atomic.read operation within an omp.atomic.capture operation
thus making its implementation less complex.

Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D116396
2022-01-10 16:19:45 +05:30
Mehdi Amini 60d13b85ca Apply clang-tidy fixes for performance-move-const-arg in ReductionNode.cpp (NFC) 2022-01-10 01:05:14 +00:00
Mehdi Amini ba19fa5779 Apply clang-tidy fixes for performance-for-range-copy in ElementwiseOpFusion.cpp (NFC) 2022-01-10 01:05:14 +00:00
Mehdi Amini 0c9d59e56a Apply clang-tidy fixes for performance-for-range-copy in ModuleBufferization.cpp (NFC) 2022-01-10 01:05:14 +00:00
Mehdi Amini 6a38cbfb53 Apply clang-tidy fixes for modernize-use-equals-default in IRCore.cpp (NFC) 2022-01-10 01:05:13 +00:00
Nicolas Vasilache 8871d8236a [mlir][MemRef] NFC - Improve assertion error message 2022-01-09 14:17:37 -05:00
Nicolas Vasilache 9ba25ec92d [mlir][Bufferize] NFC - Introduce areCastCompatible assertions to catch misformed CastOp early
Differential Revision: https://reviews.llvm.org/D116893
2022-01-09 14:13:08 -05:00
Mehdi Amini 18eb681821 Fix clang-tidy readability-redundant-smartptr-get in MLIR ModuleTranslation.cpp (NFC) 2022-01-08 20:07:11 +00:00
Uday Bondhugula 9cf9ed94ed Multiple fixes to affine loop tiling return status and checks
Fix crash in the presence of yield values. Multiple fixes to affine loop
tiling pre-condition checks and return status. Do not signal pass
failure on a failure to tile since the IR is still valid. Detect index
set computation failure in checkIfHyperrectangular and return failure.
Replace assertions with proper status return. Move checks to an
appropriate place earlier in the utility before mutation happens.

Differential Revision: https://reviews.llvm.org/D116738
2022-01-08 16:50:44 +05:30
Groverkss 0e19186c82 [MLIR][NFC] Move PresburgerSet to Presburger/ directory
This patch moves PresburgerSet to Presburger/ directory. This patch is purely
mechincal, it only moves and renames functionality and tests.

This patch is part of a series of patches to move presburger functionality to
Presburger/ directory.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D116836
2022-01-08 15:39:40 +05:30
Mehdi Amini 3e13c4c37c Avoid creating a ThreadPool in MlirOptMain when `--mlir-disable-threading` option is set
a32300a changed it to create a ThreadPool eagerly so that it gets reused
across buffers, however it also made it so that we create a ThreadPool
early even if we're not gonna use it later because of the command line
option `--mlir-disable-threading` is provided.

Fix #53056

Reland 45adf60802 after build fixes

Differential Revision: https://reviews.llvm.org/D116848
2022-01-08 02:26:41 +00:00
Mehdi Amini 4938949310 Revert "Avoid creating a ThreadPool in MlirOptMain when `--mlir-disable-threading` option is set"
This reverts commit 45adf60802.
Build is broken
2022-01-08 02:25:18 +00:00
Mehdi Amini 45adf60802 Avoid creating a ThreadPool in MlirOptMain when `--mlir-disable-threading` option is set
a32300a changed it to create a ThreadPool eagerly so that it gets reused
across buffers, however it also made it so that we create a ThreadPool
early even if we're not gonna use it later because of the command line
option `--mlir-disable-threading` is provided.

Fix #53056

Differential Revision: https://reviews.llvm.org/D116848
2022-01-08 02:18:19 +00:00