Commit Graph

99 Commits

Author SHA1 Message Date
natashaknk d4d50e4710 [mlir][tosa] Add lowering for tosa.clz using scf::whileOp
Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D109540
2021-09-09 15:57:35 -07:00
Alex Zinenko 8b58ab8ccd [mlir] Factor type reconciliation out of Standard-to-LLVM conversion
Conversion to the LLVM dialect is being refactored to be more progressive and
is now performed as a series of independent passes converting different
dialects. These passes may produce `unrealized_conversion_cast` operations that
represent pending conversions between built-in and LLVM dialect types.
Historically, a more monolithic Standard-to-LLVM conversion pass did not need
these casts as all operations were converted in one shot. Previous refactorings
have led to the requirement of running the Standard-to-LLVM conversion pass to
clean up `unrealized_conversion_cast`s even though the IR had no standard
operations in it. The pass must have been also run the last among all to-LLVM
passes, in contradiction with the partial conversion logic. Additionally, the
way it was set up could produce invalid operations by removing casts between
LLVM and built-in types even when the consumer did not accept the uncasted
type, or could lead to cryptic conversion errors (recursive application of the
rewrite pattern on `unrealized_conversion_cast` as a means to indicate failure
to eliminate casts).

In fact, the need to eliminate A->B->A `unrealized_conversion_cast`s is not
specific to to-LLVM conversions and can be factored out into a separate type
reconciliation pass, which is achieved in this commit. While the cast operation
itself has a folder pattern, it is insufficient in most conversion passes as
the folder only applies to the second cast. Without complex legality setup in
the conversion target, the conversion infra will either consider the cast
operations valid and not fold them (a separate canonicalization would be
necessary to trigger the folding), or consider the first cast invalid upon
generation and stop with error. The pattern provided by the reconciliation pass
applies to the first cast operation instead. Furthermore, having a separate
pass makes it clear when `unrealized_conversion_cast`s could not have been
eliminated since it is the only reason why this pass can fail.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D109507
2021-09-09 16:51:24 +02:00
Alex Zinenko 1ce752b741 [mlir] support reductions in SCF to OpenMP conversion
OpenMP reductions need a neutral element, so we match some known reduction
kinds (integer add/mul/or/and/xor, float add/mul, integer and float min/max) to
define the neutral element and the atomic version when possible to express
using atomicrmw (everything except float mul). The SCF-to-OpenMP pass becomes a
module pass because it now needs to introduce new symbols for reduction
declarations in the module.

Reviewed By: chelini

Differential Revision: https://reviews.llvm.org/D107549
2021-09-09 13:04:27 +02:00
Benjamin Kramer 1a88bd68c1 [Bazel] Add missing dependency after 650bbc5620 2021-09-05 21:14:05 +02:00
Geoffrey Martin-Noble dcd590a8bf [Bazel] Add explicit dependency on llvm:Support to reflect layering
Differential Revision: https://reviews.llvm.org/D109173
2021-09-02 10:34:30 -07:00
Geoffrey Martin-Noble 43d9cc1e20 [Bazel] Update for Cpp emitter (2f0750dd2e)
Update the Bazel build for
https://github.com/llvm/llvm-project/commit/2f0750dd2e.

Differential Revision: https://reviews.llvm.org/D109171
2021-09-02 10:09:19 -07:00
MaheshRavishankar ba72cfe734 [mlir] Add an interface to allow operations to specify how they can be tiled.
An interface to allow for tiling of operations is introduced. The
tiling of the linalg.pad_tensor operation is modified to use this
interface.

Differential Revision: https://reviews.llvm.org/D108611
2021-08-30 16:31:18 -07:00
Matthias Springer d18ffd61d4 [mlir][SCF] Canonicalize dim(x) where x is an iter_arg
* Add `DimOfIterArgFolder`.
* Move existing cross-dialect canonicalization patterns to `LoopCanonicalization.cpp`.
* Rename `SCFAffineOpCanonicalization` pass to `SCFForLoopCanonicalization`.
* Expand documentaton of scf.for: The type of loop-carried variables may not change with iterations. (Not even the dynamic type.)

Differential Revision: https://reviews.llvm.org/D108806
2021-08-30 01:39:56 +00:00
Matthias Springer 2de2dbef2a [mlir][linalg] Replace AffineMinSCFCanonicalizationPattern with SCF reimplementation
Use the new canonicalization pattern in the SCF dialect.

Differential Revision: https://reviews.llvm.org/D107732
2021-08-25 08:52:56 +09:00
Matthias Springer 98aa694d0d [mlir][scf] Add general affine.min canonicalization pattern
This canonicalization simplifies affine.min operations inside "for loop"-like operations (e.g., scf.for and scf.parallel) based on two invariants:
* iv >= lb
* iv < lb + step * ((ub - lb - 1) floorDiv step) + 1

This commit adds a new pass `canonicalize-scf-affine-min` (instead of being a canonicalization pattern) to avoid dependencies between the Affine dialect and the SCF dialect.

Differential Revision: https://reviews.llvm.org/D107731
2021-08-25 07:32:30 +09:00
Geoffrey Martin-Noble 52acc0547d [Bazel] Fix version defines
Some of these were the wrong version and some of them were the wrong
format. Did some hunting around to figure out what exactly they're
supposed to be. Since basically everything is derived from the LLVM
version we should probably make this a bit less hardcoded, but just
fixing the values for now.

Sources:
https://github.com/llvm/llvm-project/blob/b686fc7a1bea/clang/include/clang/Basic/Version.inc.in
https://github.com/llvm/llvm-project/blob/b686fc7a1bea/clang/CMakeLists.txt#L353-L363
https://github.com/llvm/llvm-project/blob/b686fc7a1bea/llvm/CMakeLists.txt#L13-L29
https://github.com/llvm/llvm-project/blob/b686fc7a1bea/lld/CMakeLists.txt#L131-L138

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D108500
2021-08-20 17:01:01 -07:00
Geoffrey Martin-Noble 2bd7c30e5a [Bazel] Reduce quote escaping
There's a lot of unnecessary backslashes here that we can avoid to
reduce confusion.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D108495
2021-08-20 16:33:10 -07:00
Christian Sigg f2694500c2 Update bazel examples.
Use the simplified repo rules from https://github.com/llvm/llvm-project/commit/934f084.

Reviewed By: GMNGeoffrey

Differential Revision: https://reviews.llvm.org/D108237
2021-08-20 08:10:57 +02:00
Matthias Springer 76a1861816 [mlir][SparseTensor] Split scf.for loop into masked/unmasked parts
Apply the "for loop peeling" pattern from SCF dialect transforms. This pattern splits scf.for loops into full and partial iterations. In the full iteration, all masked loads/stores are canonicalized to unmasked loads/stores.

Differential Revision: https://reviews.llvm.org/D107733
2021-08-19 21:53:11 +09:00
Matthias Springer 8e8b70aa84 [mlir][scf] Simplify affine.min ops after loop peeling
Simplify affine.min ops, enabling various other canonicalizations inside the peeled loop body.

affine.min ops such as:
```
map = affine_map<(d0)[s0, s1] -> (s0, -d0 + s1)>
%r = affine.min #affine.min #map(%iv)[%step, %ub]
```
are rewritten them into (in the case the peeled loop):
```
%r = %step
```

To determine how an affine.min op should be rewritten and to prove its correctness, FlatAffineConstraints is utilized.

Differential Revision: https://reviews.llvm.org/D107222
2021-08-19 17:24:53 +09:00
Christian Sigg 81d5412439 Simplify setting up LLVM as bazel external repo
Only require one intermediate repository instead of two.
Fewer parameters in llvm_config.

Second attempt of https://reviews.llvm.org/D107714, this time also updating `third_party_build` and `deps_impl` paths.

Reviewed By: GMNGeoffrey

Differential Revision: https://reviews.llvm.org/D108274
2021-08-19 09:37:26 +02:00
Matthias Springer 9329438244 [mlir][linalg] Remove ConstraintsSet class
The same functionality can be implemented with FlatAffineValueConstraints.

Differential Revision: https://reviews.llvm.org/D108179
2021-08-19 10:57:35 +09:00
Geoffrey Martin-Noble 811dbecaf5 [Bazel] Don't set HAVE_[DE]REGISTER_FRAME on Windows
This is also done based on OS in the GN build
(https://github.com/llvm/llvm-project/blob/24b0df8686/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn#L193-L203).
Of course the right way would be to set up platform detection, but that
remains TODO.

Reviewed By: csigg

Differential Revision: https://reviews.llvm.org/D107375
2021-08-18 11:20:25 -07:00
Geoffrey Martin-Noble 0bfe614bc2 Revert "Simplify setting up LLVM as bazel external repo"
This breaks the rules for creating repository dependencies when invoked
from another workspace. See comment on https://reviews.llvm.org/D107714

This reverts commit 934f084ad4.

Differential Revision: https://reviews.llvm.org/D108245
2021-08-17 14:48:40 -07:00
Christian Sigg 934f084ad4 Simplify setting up LLVM as bazel external repo
Only require one intermediate repository instead of two.
Fewer parameters in llvm_config.
Remove bazel_skylib dependency.

Reviewed By: goncharov

Differential Revision: https://reviews.llvm.org/D107714
2021-08-17 21:58:43 +02:00
Geoffrey Martin-Noble b51e71fe66 [Bazel] Update for 957334382c
Update LLVM configuration to define `HAVE_UNW_ADD_DYNAMIC_FDE` for macOS
since https://github.com/llvm/llvm-project/commit/957334382c moved that
to a define.

Differential Revision: https://reviews.llvm.org/D108157
2021-08-16 12:20:54 -07:00
Adrian Kuegel 3c6f115ffc [mlir] Remove unused header include.
Also adjust BUILD.bazel and remove an unused dependency.

Differential Revision: https://reviews.llvm.org/D108027
2021-08-13 14:23:14 +02:00
Adrian Kuegel 970129a2dd [clang] Adjust BUILD.bazel file to also generate AttrDocTable.
Differential Revision: https://reviews.llvm.org/D108017
2021-08-13 09:00:44 +02:00
Emilio Cota 7f3c3d7aa4 [mlir] BUILD.bazel: remove LLVMDialect from MathTransforms
c1ebefdf77 "[mlir] Make polynomial approximation emit
std instead of LLVM ops" removed the dependence on LLVMDialect.

Remove the dependence also from BUILD.bazel.

Reviewed By: bkramer

Differential Revision: https://reviews.llvm.org/D107908
2021-08-11 22:27:04 +02:00
Geoffrey Martin-Noble f8b6e1faa9 [Bazel] Update for 9854f2f30f (Diff library)
Updates the Bazel build for
https://github.com/llvm/llvm-project/commit/9854f2f30f by extracting a
library from llvm-diff. Note that this does not include the new
llvm-livepatch binary, for which the CMake file was added accidentally
and reverted in https://github.com/llvm/llvm-project/commit/fec8f1a008.

Differential Revision: https://reviews.llvm.org/D107586
2021-08-05 11:01:44 -07:00
Daniele Vettorel 180f4a87c5 Add llvm-stress binary to Bazel build configuration.
The `llvm-stress` binary is currently missing from the Bazel `BUILD` file for llvm. This patch adds it.

Reviewed By: GMNGeoffrey

Differential Revision: https://reviews.llvm.org/D107571
2021-08-05 12:35:46 -04:00
Geoffrey Martin-Noble 693a95a694 [Bazel] Add support for lld
This patch adds a Bazel configuration to build lld. That includes a
BUILD.bazel file to export the libunwind headers for use by lld. Since
the lld target itself requires libxml2 (through WindowsManifest) it's
currently disabled on Buildkite and marked manual, but all the libraries
build.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D107414
2021-08-04 17:59:43 -07:00
Geoffrey Martin-Noble 981ad13ac6 [Bazel] Drop deprecated tblgen includes mechanism
Includes can now be fully managed via td_library and specified locally
to the tablegen files that require them. This has been deprecated for a
while and is not used upstream. I'm not aware of any downstream users
either.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D107389
2021-08-04 13:19:08 -07:00
Geoffrey Martin-Noble b0d58ddf87 [Bazel] Update build for ee7d20e846
Updates the Bazel configuration for
https://github.com/llvm/llvm-project/commit/ee7d20e84675. We need to
drop the dependency from llvm-tblgen to avoid a dependency cycle:

```
.-> @llvm-project//llvm:llvm-tblgen
|   @llvm-project//llvm:tblgen
|   @llvm-project//llvm:MC
|   @llvm-project//llvm:ProfileData
|   @llvm-project//llvm:Core
|   @llvm-project//llvm:attributes_gen
|   @llvm-project//llvm:include/llvm/IR/Attributes.inc
|   @llvm-project//llvm:attributes_gen__gen_attrs_genrule
`-- @llvm-project//llvm:llvm-tblgen
```

It appears this dep was not strictly necessary though. TableGen uses MC
headers but it can get those through Support, which also exports MC
headers due to layering issues.

Differential Revision: https://reviews.llvm.org/D107480
2021-08-04 10:08:57 -07:00
Adrian Kuegel 8385de1184 [mlir][Bazel] Adjust BUILD.bazel file.
The dependency is needed after 1b00b94ffc

Differential Revision: https://reviews.llvm.org/D107426
2021-08-04 08:51:02 +02:00
Matthias Springer 3a41ff4883 [mlir][SCF] Peel scf.for loops for even step divison
Add ForLoopBoundSpecialization pass, which specializes scf.for loops into a "main loop" where `step` divides the iteration space evenly and into an scf.if that handles the last iteration.

This transformation is useful for vectorization and loop tiling. E.g., when vectorizing loads/stores, programs will spend most of their time in the main loop, in which only unmasked loads/stores are used. Only the in the last iteration (scf.if), slower masked loads/stores are used.

Subsequent commits will apply this transformation in the SparseDialect and in Linalg's loop tiling.

Differential Revision: https://reviews.llvm.org/D105804
2021-08-03 10:21:38 +09:00
Shivam Gupta c3f19804f3 [Bazel] Typo fix
Reviewed By: GMNGeoffrey

Differential Revision: https://reviews.llvm.org/D107142
2021-07-30 08:38:39 -07:00
Geoffrey Martin-Noble d983499543 [Bazel] Make td_library usable as data
This patch makes it possible to list a td_library as a rule's data
attribute and get its source files and all its transitive dependencies
at runtime. This is useful for, e.g. shell tests running tblgen.

Note that this is a bit different from how a "normal" (e.g. C++) library
rule would work because those have actual library outputs and the
td_library rule just bundles some source files and includes. If someone
wanted to make use of the includes, they would have to access the TdInfo
provider, but this keeps simple things simple.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D106922
2021-07-29 18:12:39 -07:00
Geoffrey Martin-Noble f3a8a7b91e [Bazel] Unconditionally define STDC LIMIT/CONSTANT/FORMAT
These are unconditionally included in the CMake build as well and
necessary for some odd platforms (even though the C++11 standard says
they shouldn't be).

Reviewed By: chandlerc

Differential Revision: https://reviews.llvm.org/D107123
2021-07-29 18:11:52 -07:00
Geoffrey Martin-Noble 6fa2d0fbf4 [Bazel] Derive targets from file presence as in CMake build
This makes the logic used to determine if targets have the given
features the same as is used in CMake. Incidentally, it enables these
features for the targets added in https://reviews.llvm.org/D106921
which were missing because this was previously a hardcoded list.

Reviewed By: chandlerc

Differential Revision: https://reviews.llvm.org/D107019
2021-07-29 18:10:46 -07:00
Lei Zhang 26be7fe27c [mlir] NFC: split MemRef to SPIR-V conversion into their own files
Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D107094
2021-07-29 16:34:10 -04:00
Lei Zhang 995c3984ef [mlir] NFC: split Math to SPIR-V conversion into their own files
Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D107093
2021-07-29 16:34:10 -04:00
Stella Laurenzo 768f562641 Update file names and extensions for MLIR Python execution engine changes. 2021-07-29 03:19:14 +00:00
Geoffrey Martin-Noble 91842bf6aa [Bazel] Fix digest for bazel-skylib 1.0.3
I apparently left in the old digest when updating the version, so for my
local build Bazel just happily used the cached version, but anyone
attempting a fresth build would get a mismatch.

Differential Revision: https://reviews.llvm.org/D107010
2021-07-28 15:36:51 -07:00
Itai Zukerman 3ff451ca6a [Bazel] Added missing targets to LLVM bazel rules.
Added the following targets to the LLVM Bazel overlay:

AVR
Mips
MPS430
SystemZ
XCore

Reviewed By: GMNGeoffrey

Differential Revision: https://reviews.llvm.org/D106921
2021-07-28 13:32:18 -07:00
Geoffrey Martin-Noble 668aa531d6 [Bazel] Update for dbed061bf1
This adds Bazel configuration for the TargetMCA targets, which currently
only includes AMDGPU.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D106996
2021-07-28 13:24:16 -07:00
Jacques Pienaar d1c7a57fe8 [mlir][bzl] Fix typo 2021-07-27 13:32:09 -07:00
Eugene Zhulenev de7a4e53a2 [mlir] Async: lower SCF operations into CFG inside coroutines
Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D106747
2021-07-24 14:36:26 -07:00
Geoffrey Martin-Noble 3f2c1e99e4 [Bazel] Swap stray td_srcs to deps
This is the last instance of td_srcs in MLIR core build files. `deps` is
generally preferred. There are still some cases where `td_srcs` is
useful where creating a td_library would just be another layer of
indirection, so not (yet) dropping it entirely.

Differential Revision: https://reviews.llvm.org/D106716
2021-07-23 15:07:17 -07:00
Geoffrey Martin-Noble be583be23b [Bazel] Rename LLVMDWP to DWP
Since Bazel has packages, we don't prefix target names with LLVM. I
forgot when translating the CMake.
2021-07-22 16:05:43 -07:00
Michael McLoughlin b4f8a000f6 [Bazel] Change external_zlib attribute to string
When using `llvm_zlib_external` rule with `external_zlib` attribute set to a
label referring to the main repository, like `@//third_party/zlib`, it will be
replaced with `//third_party/zlib` after template substitution. This will then
attempt to find `//third_party/zlib` within the local repository
`@llvm_zlib//third_party/zlib`, which does not exist, rather than the intended
reference back to the main repository. The issue appears to be that the
conversion of `Label` type to string with
`str(repository_ctx.attr.external_zlib)`, which is causing the main repository
qualifier to be lost.

This diff fixes the issue by changing the `external_zlib` attribute to
`attr.string` type rather than `attr.label`.

In future a more elegant solution may be possible that preserves use of the
`Label` type, depending on resolution of the issue
https://github.com/bazelbuild/bazel/issues/13731.

Ported from Github PR https://github.com/google/llvm-bazel/pull/236.

Reviewed By: GMNGeoffrey

Differential Revision: https://reviews.llvm.org/D106606
2021-07-22 16:02:37 -07:00
Geoffrey Martin-Noble 25c02b32a4 [Bazel] Update for f8c6515554
Update Bazel for
https://github.com/llvm/llvm-project/commit/f8c6515554 by splitting out
an LLVMDWP library target.
2021-07-22 14:53:08 -07:00
Geoffrey Martin-Noble 13e5aa8973 [Bazel] Remove deprecated td_relative_includes
This has been deprecated for a while and there are no in-tree usages.
I'm not aware of any out-of-tree usages either.
2021-07-21 08:38:15 -07:00
Geoffrey Martin-Noble 65cead410b [Bazel] Remove copypasta from linalggen.bzl 2021-07-20 17:27:40 -07:00
Geoffrey Martin-Noble cb53febe3d [Bazel] Remove explicit relative_to_caller_repository
This is the default and the argument is deprecated. The documentation
indicating it's the default is only since 4.0
(https://docs.bazel.build/versions/4.0.0/skylark/lib/Label.html#Label),
but looking at the code it has been the default since its introduction
in https://bazel.googlesource.com/bazel/+/6f15335dea with Bazel 0.2.1
(https://bazel.googlesource.com/bazel/+show/0.2.1/CHANGELOG.md)

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D106411
2021-07-20 16:42:31 -07:00