From 6a489b28371a38235a6f94e32610897f7334d68b Mon Sep 17 00:00:00 2001 From: Mathieu Fehr Date: Thu, 11 Jan 2024 13:49:56 +0000 Subject: [PATCH] Use all operations so replace with itself is properly tested --- xdsl_pdl/analysis/mlir_analysis.py | 2 +- xdsl_pdl/fuzzing/generate_pdl_matches.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/xdsl_pdl/analysis/mlir_analysis.py b/xdsl_pdl/analysis/mlir_analysis.py index 777af81..c415dbe 100644 --- a/xdsl_pdl/analysis/mlir_analysis.py +++ b/xdsl_pdl/analysis/mlir_analysis.py @@ -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]) diff --git a/xdsl_pdl/fuzzing/generate_pdl_matches.py b/xdsl_pdl/fuzzing/generate_pdl_matches.py index 082d990..32cf044 100644 --- a/xdsl_pdl/fuzzing/generate_pdl_matches.py +++ b/xdsl_pdl/fuzzing/generate_pdl_matches.py @@ -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 @@ -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:]): @@ -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()