Skip to content

Commit

Permalink
Use all operations so replace with itself is properly tested
Browse files Browse the repository at this point in the history
  • Loading branch information
math-fehr committed Jan 11, 2024
1 parent 6930553 commit 6a489b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion xdsl_pdl/analysis/mlir_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def analyze_with_mlir(
region, ops = pdl_to_operations(pattern, ctx, randgen)
dag = all_dags[randgen.randrange(0, len(all_dags))]
create_dag_in_region(region, dag, ctx)
for populated_region in put_operations_in_region(dag, region, ops):
for populated_region in put_operations_in_region(dag, region, ops, ctx):
cloned_region = Region()
populated_region.clone_into(cloned_region)
program = TestOp.create(regions=[cloned_region])
Expand Down
8 changes: 6 additions & 2 deletions xdsl_pdl/fuzzing/generate_pdl_matches.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from itertools import chain, combinations
from dataclasses import dataclass, field
from random import Random, randrange
from random import Random
from typing import Generator, Iterable, cast

from xdsl.ir import Attribute, Block, MLContext, OpResult, Operation, Region, SSAValue
Expand Down Expand Up @@ -230,7 +230,7 @@ def create_dag_in_region(region: Region, dag: SingleEntryDAGStructure, ctx: MLCo


def put_operations_in_region(
dag: SingleEntryDAGStructure, region: Region, ops: list[Operation]
dag: SingleEntryDAGStructure, region: Region, ops: list[Operation], ctx: MLContext
) -> Generator[Region, None, None]:
block_to_idx: dict[Block, int] = {}
for i, block in enumerate(region.blocks[1:]):
Expand Down Expand Up @@ -260,6 +260,10 @@ def rec(i: int, ops: list[Operation]) -> Generator[Region, None, None]:
block = region.blocks[i + 1]
assert block.ops.last is not None
block.insert_op_before(ops[0], block.ops.last)
block.insert_op_before(
ctx.get_op("test.use_op").create(operands=ops[0].results),
block.ops.last,
)
yield from rec(i, ops[1:])
ops[0].detach()

Expand Down

0 comments on commit 6a489b2

Please sign in to comment.