Commit Graph

115 Commits

Author SHA1 Message Date
Geoffrey Martin-Noble f6e321f74d [Bazel] Update config for 3b01cf9286
Updates the Bazel config for changes from
https://github.com/llvm/llvm-project/commit/3b01cf9286
by adding configuration for the new OpenMPOpsInterfaces tablegn target.

Differential Revision: https://reviews.llvm.org/D111347
2021-10-07 12:51:27 -07:00
Mogball 8c08f21b60 [MLIR] Split arith dialect from the std dialect
Create the Arithmetic dialect that contains basic integer and floating
point arithmetic operations. Ops that did not meet this criterion were
moved to the Math dialect.

First of two atomic patches to remove integer and floating point
operations from the standard dialect. Ops will be removed from the
standard dialect in a subsequent patch.

Reviewed By: ftynse, silvas

Differential Revision: https://reviews.llvm.org/D110200
2021-10-06 19:25:51 +00:00
Nicolas Vasilache b016bd1230 [mlir][Linalg] Refactor comprehensive bufferize for external uses - NFC
This revision exposes some minimal funcitonality to allow comprehensive
bufferization to interop with external projects.

Differential Revision: https://reviews.llvm.org/D110875
2021-09-30 20:21:08 +00:00
Stella Laurenzo 267bb194f3 [mlir] Remove old "tc" linalg ods generator.
* This could have been removed some time ago as it only had one op left in it, which is redundant with the new approach.
* `matmul_i8_i8_i32` (the remaining op) can be trivially replaced by `matmul`, which natively supports mixed precision.

Differential Revision: https://reviews.llvm.org/D110792
2021-09-30 16:30:06 +00:00
Krasimir Georgiev 6cffc35746 [Bazel] fix for aa53785f23 2021-09-29 10:52:53 +02:00
Nicolas Vasilache b74493ecea [mlir][Linalg] Refactor padding hoisting - NFC
This revision extracts padding hoisting in a new file and cleans it up in prevision of future improvements and extensions.

Differential Revision: https://reviews.llvm.org/D110414
2021-09-27 09:50:31 +00:00
Krasimir Georgiev 8cb234e07d [Bazel] Fix for 6498b0e991 2021-09-27 10:44:58 +02:00
Diego Caballero 2a876a711d [mlir] Create a generic reduction detection utility
This patch introduces a generic reduction detection utility that works
across different dialecs. It is mostly a generalization of the reduction
detection algorithm in Affine. The reduction detection logic in Affine,
Linalg and SCFToOpenMP have been replaced with this new generic utility.

The utility takes some basic components of the potential reduction and
returns: 1) the reduced value, and 2) a list with the combiner operations.
The logic to match reductions involving multiple combiner operations disabled
until we can properly test it.

Reviewed By: ftynse, bondhugula, nicolasvasilache, pifon2a

Differential Revision: https://reviews.llvm.org/D110303
2021-09-24 20:45:59 +00:00
Dan F-M 33e1713a00 [Bazel] Add support for targeting macOS arm64
In attempting to build JAX on Apple Silicon, we discovered an issue with
the bazel configuration in llvm-project-overlay. This patch fixes the
logic, at least when building JAX. More context is included on the
following GitHub issue: https://github.com/google/jax/issues/5501

Differential Revision: https://reviews.llvm.org/D109839
2021-09-21 12:24:16 -07:00
River Riddle d80d3a358f [mlir] Refactor ElementsAttr into an AttrInterface
This revision refactors ElementsAttr into an Attribute Interface.
This enables a common interface with which to interact with
element attributes, without needing to modify the builtin
dialect. It also removes a majority (if not all?) of the need for
the current OpaqueElementsAttr, which was originally intended as
a way to opaquely represent data that was not representable by
the other builtin constructs.

The new ElementsAttr interface not only allows for users to
natively represent their data in the way that best suits them,
it also allows for efficient opaque access and iteration of the
underlying data. Attributes using the ElementsAttr interface
can directly expose support for interacting with the held
elements using any C++ data type they claim to support. For
example, DenseIntOrFpElementsAttr supports iteration using
various native C++ integer/float data types, as well as
APInt/APFloat, and more. ElementsAttr instances that refer to
DenseIntOrFpElementsAttr can use all of these data types for
iteration:

```c++
DenseIntOrFpElementsAttr intElementsAttr = ...;

ElementsAttr attr = intElementsAttr;
for (uint64_t value : attr.getValues<uint64_t>())
  ...;
for (APInt value : attr.getValues<APInt>())
  ...;
for (IntegerAttr value : attr.getValues<IntegerAttr>())
  ...;
```

ElementsAttr also supports failable range/iterator access,
allowing for selective code paths depending on data type
support:

```c++
ElementsAttr attr = ...;
if (auto range = attr.tryGetValues<uint64_t>()) {
  for (uint64_t value : *range)
    ...;
}
```

Differential Revision: https://reviews.llvm.org/D109190
2021-09-21 01:57:43 +00:00
MaheshRavishankar 0b33890f45 [mlir][Linalg] Add ConvolutionOpInterface.
Add an interface that allows grouping together all covolution and
pooling ops within Linalg named ops. The interface currently
- the indexing map used for input/image access is valid
- the filter and output are accessed using projected permutations
- that all loops are charecterizable as one iterating over
  - batch dimension,
  - output image dimensions,
  - filter convolved dimensions,
  - output channel dimensions,
  - input channel dimensions,
  - depth multiplier (for depthwise convolutions)

Differential Revision: https://reviews.llvm.org/D109793
2021-09-20 10:41:10 -07:00
Alexander Grund f4b5d597d8 Add use_default_shell_env = True to ctx.actions.run
When building a tool in a non-standard environment (e.g. custom
compiler path -> LD_LIBRARY_PATH set) then
`use_default_shell_env = True` is required to run that tool in the same
environment or otherwise the build will fail due to missing symbols.
See https://github.com/google/jax/issues/7842 for this issue and
https://github.com/tensorflow/tensorflow/pull/44549 for related fix in
TF.

Reviewed By: GMNGeoffrey

Differential Revision: https://reviews.llvm.org/D109873
2021-09-20 10:09:04 -07:00
William Muir 2aa8474210 [Bazel] Use posix definitions for FreeBSD
Presently, definitions default to those for Linux which are not defined for FreeBSD (HAVE_LSEEK64, HAVE_MALLINFO, etc.).  Patch sets os_defines to posix definitions under FreeBSD.

Reviewed By: GMNGeoffrey

Differential Revision: https://reviews.llvm.org/D109913
2021-09-16 13:57:49 -07:00
Geoffrey Martin-Noble 216d974a2f [Bazel] Fix Bazel config for 2c8e784915
Updates the Bazel config for OrcTargetProcess after
https://github.com/llvm/llvm-project/commit/2c8e784915

Differential Revision: https://reviews.llvm.org/D109731
2021-09-13 18:29:42 -07:00
Geoffrey Martin-Noble 095bbc3a5a [Bazel][mlir] Simplify test/BUILD.bazel with globs
This reduces the maintenance burden by using globs, which is the
tradeoff we make in the other LLVM Bazel build files as well.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D109720
2021-09-13 13:45:23 -07:00
Benjamin Kramer 2d75cfdeb7 [mlir] Update bazel build for 802bf02a73 2021-09-13 10:51:08 +02:00
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