# `Beaver.MLIR.Rewrite`

This module defines functions working with MLIR rewrite patterns and pattern sets.

# `apply_result`

```elixir
@type apply_result() :: {Beaver.MLIR.LogicalResult.t(), diagnostics()}
```

# `config_callback`

```elixir
@type config_callback() :: (config_handle() -&gt; any())
```

Callback used to customize a greedy rewrite config before application.

# `config_handle`

```elixir
@type config_handle() :: term()
```

Opaque greedy rewrite driver config handle passed to configuration callbacks.

# `config_input`

```elixir
@type config_input() :: config_opts() | config_callback() | nil
```

# `config_option`

```elixir
@type config_option() ::
  {:max_iterations, integer()}
  | {:max_num_rewrites, integer()}
  | {:use_top_down_traversal, boolean()}
  | {:enable_folding, boolean()}
  | {:enable_constant_cse, boolean()}
```

Supported high-level rewrite config options.

# `config_opts`

```elixir
@type config_opts() :: [config_option()]
```

# `diagnostic`

```elixir
@type diagnostic() ::
  {severity :: atom(), location :: String.t(), message :: String.t(),
   nested :: [diagnostic()]}
```

Processed MLIR diagnostic tree emitted during rewrite application.

# `diagnostics`

```elixir
@type diagnostics() :: [diagnostic()]
```

# `match_and_rewrite`

```elixir
@type match_and_rewrite() :: (Beaver.MLIR.RewritePattern.t(),
                        Beaver.MLIR.Operation.t(),
                        Beaver.MLIR.PatternRewriter.t(),
                        any() -&gt;
                          {:ok, any()} | {:error, any()})
```

Pattern callback entries accepted by the list-based rewrite surface.

# `pattern_entry`

```elixir
@type pattern_entry() ::
  Beaver.Pattern.Native.Descriptor.t()
  | {root_name :: term(),
     match_and_rewrite() | Beaver.Pattern.Native.Descriptor.t()}
```

# `pattern_list`

```elixir
@type pattern_list() :: [pattern_entry()]
```

# `rewrite_ir`

```elixir
@type rewrite_ir() :: Beaver.MLIR.Module.t() | Beaver.MLIR.Operation.t()
```

IR surfaces accepted by the rewrite driver.

# `apply_patterns`

```elixir
@spec apply_patterns(rewrite_ir(), Beaver.MLIR.FrozenRewritePatternSet.t()) ::
  apply_result()
@spec apply_patterns(rewrite_ir(), Beaver.MLIR.RewritePatternSet.t()) ::
  apply_result()
@spec apply_patterns(rewrite_ir(), pattern_list()) :: apply_result()
```

# `apply_patterns`

```elixir
@spec apply_patterns(
  rewrite_ir(),
  Beaver.MLIR.FrozenRewritePatternSet.t(),
  config_input()
) :: apply_result()
@spec apply_patterns(
  rewrite_ir(),
  Beaver.MLIR.RewritePatternSet.t(),
  config_input()
) :: apply_result()
@spec apply_patterns(rewrite_ir(), pattern_list(), config_input()) :: apply_result()
```

# `apply_patterns!`

```elixir
@spec apply_patterns!(rewrite_ir(), Beaver.MLIR.FrozenRewritePatternSet.t()) ::
  rewrite_ir()
@spec apply_patterns!(rewrite_ir(), Beaver.MLIR.RewritePatternSet.t()) :: rewrite_ir()
@spec apply_patterns!(rewrite_ir(), pattern_list()) :: rewrite_ir()
```

# `apply_patterns!`

```elixir
@spec apply_patterns!(
  rewrite_ir(),
  Beaver.MLIR.FrozenRewritePatternSet.t(),
  config_input()
) :: rewrite_ir()
@spec apply_patterns!(
  rewrite_ir(),
  Beaver.MLIR.RewritePatternSet.t(),
  config_input()
) :: rewrite_ir()
@spec apply_patterns!(rewrite_ir(), pattern_list(), config_input()) :: rewrite_ir()
```

# `stop_thread_pool`

```elixir
@spec stop_thread_pool() :: :ok
```

# `to_config_callback`

```elixir
@spec to_config_callback(config_input()) :: config_callback()
```

# `with_default_config`

```elixir
@spec with_default_config((config_handle() -&gt; result)) :: result when result: var
```

# `with_default_config`

```elixir
@spec with_default_config(config_input(), (config_handle() -&gt; result)) :: result
when result: var
```

