19 Commits

Author SHA1 Message Date
Kazu Hirata
cac806bcc5
[mlir] Remove unused includes (NFC) (#148535) 2025-07-13 13:13:01 -07:00
Ramkumar Ramachandra
db791b278a
mlir/LogicalResult: move into llvm (#97309)
This patch is part of a project to move the Presburger library into
LLVM.
2024-07-02 10:42:33 +01:00
Théo Degioanni
b86a9c5bf2
[mlir][irdl] Lookup symbols near dialects instead of locally (#92819)
Because symbols cannot refer to operations outside of their symbol
tables, it was impossible to refer to operations outside of the dialect
currently being defined. This PR modifies the lookup logic to happen
relative to the symbol table containing the dialect-defining operations.
This is a bit of hack but should unblock the situation here.
2024-05-31 09:15:50 +01:00
Oleksandr "Alex" Zinenko
105c992c83
[mlir] use irdl as matcher description in transform (#89779)
Introduce a new Transform dialect extension that uses IRDL op
definitions as matcher descriptors. IRDL allows one to essentially
define additional op constraits to be verified and, unlike PDL, does not
assume rewriting will happen. Leverage IRDL verification capability to
filter out ops that match an IRDL definition without actually
registering the corresponding operation with the system.
2024-05-02 15:03:30 +02:00
Christian Sigg
a5757c5b65
Switch member calls to isa/dyn_cast/cast/... to free function calls. (#89356)
This change cleans up call sites. Next step is to mark the member
functions deprecated.

See https://mlir.llvm.org/deprecation and
https://discourse.llvm.org/t/preferred-casting-style-going-forward.
2024-04-19 15:58:27 +02:00
Mehdi Amini
04e2a5d983 Apply clang-tidy fixes for readability-identifier-naming in IRDLLoading.cpp (NFC) 2024-01-17 08:51:41 -08:00
Daniil Dudkin
d4bde6968e [mlir][irdl] Introduce a way to define regions
This patch introduces new operations:
`irdl.region` and `irdl.regions`.
The former lets us to specify characteristics of a region,
such as the arguments for the entry block and the number of blocks.
The latter accepts all results of the former operations
to define the set of the regions for the operation.

Example:

```
    irdl.dialect @example {
      irdl.operation @op_with_regions {
          %r0 = irdl.region
          %r1 = irdl.region()
          %v0 = irdl.is i32
          %v1 = irdl.is i64
          %r2 = irdl.region(%v0, %v1)
          %r3 = irdl.region with size 3

          irdl.regions(%r0, %r1, %r2, %r3)
      }
    }
```

The above snippet demonstrates an operation named `@op_with_regions`,
which is constrained to have four regions.

* Region `%r0` doesn't have any constraints on the arguments or the number of blocks.
* Region `%r1` should have an empty set of arguments.
* Region `%r2` should have two arguments of types `i32` and `i64`.
* Region `%r3` should contain exactly three blocks.

In the future the block count constraint may be expanded to support range of possible number of blocks.

Reviewed By: math-fehr, Mogball

Differential Revision: https://reviews.llvm.org/D155112
2023-08-23 17:55:10 +03:00
Mathieu Fehr
1295a351bd [mlir][irdl] Support variadicity check in operations
This patch adds support for loading IRDL operations that are
using optional or variadics operands and results.

If an operation declares more than one optional/variadic operand
or result, then it requires the segment sizes in the attribute
dictionary, and otherwise it is computed using the number of
operands or results.

Currently, a variadic operand or result definiton expects all
operands and results in that definition to have the same type.
This restriction will be removed in a following patch.

Depends on D153983

Reviewed By: Mogball, unterumarmung

Differential Revision: https://reviews.llvm.org/D154073
2023-08-20 17:21:59 +01:00
Mathieu Fehr
00aa1a8c3d Revert "[mlir][irdl] Support variadicity check in operations"
This reverts commit 62b2b399924cc98c349979a84f1e375b97ee924c.

This is the error reported by the buildbot:
 /home/buildbots/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/mlir/lib/Dialect/IRDL/IRDLLoading.cpp:97:22: error: no member named 'reduce' in namespace 'std'
  int32_t sum = std::reduce(denseSegmentSizes.asArrayRef().begin(),

Full details are available at:
    https://lab.llvm.org/buildbot#builders/21/builds/78689
2023-08-20 16:57:40 +01:00
Mathieu Fehr
62b2b39992 [mlir][irdl] Support variadicity check in operations
This patch adds support for loading IRDL operations that are
using optional or variadics operands and results.

If an operation declares more than one optional/variadic operand
or result, then it requires the segment sizes in the attribute
dictionary, and otherwise it is computed using the number of
operands or results.

Currently, a variadic operand or result definiton expects all
operands and results in that definition to have the same type.
This restriction will be removed in a following patch.

Depends on D153983

Reviewed By: Mogball, unterumarmung

Differential Revision: https://reviews.llvm.org/D154073
2023-08-20 16:39:30 +01:00
Daniil Dudkin
f1a0402983 [mlir][irdl] Add irdl.attributes operation for defining named attributes
This commit introduces the `irdl.attributes` operation, which allows defining named attributes for the parent operation. Each attribute is defined with a name and a type constraint.

Example usage:
```
irdl.dialect @example {
  irdl.operation @attr_op {
    %0 = irdl.any
    %1 = irdl.is i64
    irdl.attributes {
      "attr1" = %0,
      "attr2" = %1
    }
  }
}
```
In this example the operation will expect an arbitrary attribute "attr1"
and an attribute "attr2" with value `i64`.

Reviewed By: math-fehr, Mogball

Differential Revision: https://reviews.llvm.org/D152618
2023-06-20 22:30:09 +03:00
Mathieu Fehr
4b52665780 [mlir][irdl] NFC: Ensure ops ends with Op suffix
IRDL operations were inconsistent in their naming. They now
all end with the `Op` suffix.

Reviewed By: rriddle, jpienaar

Differential Revision: https://reviews.llvm.org/D152354
2023-06-08 13:11:43 +01:00
Mathieu Fehr
42987dfa3a [mlir][irdl] Add irdl.any_of operation
The `irdl.any_of` operation represent a constraint that is satisfied
if any of its subconstraint is satisfied.

For instance, in the following example:
```
%0 = irdl.is f32
%1 = irdl.is f64
%2 = irdl.any_of(f32, f64)
```

`%2` can only be satisfied by `f32` or `f64`.

Note that the verification algorithm required by `irdl.any_of` is
non-trivial, since we want that the order of arguments of
`irdl.any_of` to not matter. For this reason, our registration
algorithm fails if two constraints used by `any_of` might be
satisfied by the same `Attribute`. This is approximated by checking
the possible `Attribute` bases of each constraints.

Depends on D145734

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D145735
2023-05-17 21:57:16 +01:00
Mathieu Fehr
c8a581c331 [mlir][irdl] Add verification of IRDL ops
This patch adds verification on registered IRDL operations, types,
and attributes.

This is done through an interface implemented by operations from the
`irdl` dialect, which translate the operations into `Constraint`.
This interface is then use in the `registerDialect` function to
generate verifiers for the entire operation/type/attribute.

Depends on D145733

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D145734
2023-05-17 13:34:00 +01:00
Mathieu Fehr
648d192040 Revert "[mlir][irdl] Add verification of IRDL ops"
This reverts commit 52761cb99164acd4ea76f91fc16a3e40ec94b898.
2023-05-12 19:48:00 +01:00
Mathieu Fehr
52761cb991 [mlir][irdl] Add verification of IRDL ops
This patch adds verification on registered IRDL operations, types,
and attributes.

This is done through an interface implemented by operations from the
`irdl` dialect, which translate the operations into `Constraint`.
This interface is then use in the `registerDialect` function to
generate verifiers for the entire operation/type/attribute.

Depends on D145733

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D145734
2023-05-12 19:39:13 +01:00
Mathieu Fehr
8ac8c922fb [mlir][irdl] Add IRDL registration
This patch add support for loading IRDL dialects at runtime
with `mlir-opt`.

Given the following `dialect.irdl` file:
```mlir
module {
  irdl.dialect @cmath {
    irdl.type @complex {
      %0 = irdl.is f32
      %1 = irdl.is f64
      %2 = irdl.any_of(%0, %1)
      irdl.parameters(%2)
    }

    irdl.operation @norm {
      %0 = irdl.any
      %1 = irdl.parametric @complex<%0>
      irdl.operands(%1)
      irdl.results(%0)
    }
}
```

the IRDL file can be loaded with the `mlir-opt --irdl-file=dialect.irdl`
command, and the following file can then be parsed:

```mlir
func.func @conorm(%p: !cmath.complex<f32>, %q: !cmath.complex<f32>) -> f32 {
  %norm_p = "cmath.norm"(%p) : (!cmath.complex<f32>) -> f32
  %norm_q = "cmath.norm"(%q) : (!cmath.complex<f32>) -> f32
  %pq = arith.mulf %norm_p, %norm_q : f32
  return %pq : f32
}
```

To minimize the size of this patch, the operation, attribute, and type verifier are all always returning `success()`.

Depends on D144692

Reviewed By: rriddle, Mogball, mehdi_amini

Differential Revision: https://reviews.llvm.org/D144693
2023-04-23 17:28:44 +01:00
Arjun P
5115ede632 Revert "[mlir][irdl] Add IRDL registration"
This reverts commit e0d884de360b5c3fe79c6a53f8f88b57f0e42275.

Reverting due to buildbot failure.
2023-04-20 15:55:57 +01:00
Mathieu Fehr
e0d884de36 [mlir][irdl] Add IRDL registration
This patch add support for loading IRDL dialects at runtime
with `mlir-opt`.

Given the following `dialect.irdl` file:
```mlir
module {
  irdl.dialect @cmath {
    irdl.type @complex {
      %0 = irdl.is f32
      %1 = irdl.is f64
      %2 = irdl.any_of(%0, %1)
      irdl.parameters(%2)
    }

    irdl.operation @norm {
      %0 = irdl.any
      %1 = irdl.parametric @complex<%0>
      irdl.operands(%1)
      irdl.results(%0)
    }
}
```

the IRDL file can be loaded with the `mlir-opt --irdl-file=dialect.irdl`
command, and the following file can then be parsed:

```mlir
func.func @conorm(%p: !cmath.complex<f32>, %q: !cmath.complex<f32>) -> f32 {
  %norm_p = "cmath.norm"(%p) : (!cmath.complex<f32>) -> f32
  %norm_q = "cmath.norm"(%q) : (!cmath.complex<f32>) -> f32
  %pq = arith.mulf %norm_p, %norm_q : f32
  return %pq : f32
}
```

To minimize the size of this patch, the operation, attribute, and type verifier are all always returning `success()`.

Depends on D144692

Reviewed By: rriddle, Mogball, mehdi_amini

Differential Revision: https://reviews.llvm.org/D144693
2023-04-20 15:35:41 +01:00