Changeset View
Changeset View
Standalone View
Standalone View
mlir/test/Rewrite/pdl-bytecode.mlir
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | module @patterns { | ||||
^end: | ^end: | ||||
pdl_interp.finalize | pdl_interp.finalize | ||||
} | } | ||||
module @rewriters { | module @rewriters { | ||||
func @success(%root : !pdl.operation) { | func @success(%root : !pdl.operation) { | ||||
%operand = pdl_interp.get_operand 0 of %root | %operand = pdl_interp.get_operand 0 of %root | ||||
pdl_interp.apply_rewrite "rewriter"[42](%operand : !pdl.value) on %root | pdl_interp.apply_rewrite "rewriter"[42](%root, %operand : !pdl.operation, !pdl.value) | ||||
pdl_interp.finalize | pdl_interp.finalize | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// CHECK-LABEL: test.apply_rewrite_1 | // CHECK-LABEL: test.apply_rewrite_1 | ||||
// CHECK: %[[INPUT:.*]] = "test.op_input" | // CHECK: %[[INPUT:.*]] = "test.op_input" | ||||
// CHECK-NOT: "test.op" | // CHECK-NOT: "test.op" | ||||
// CHECK: "test.success"(%[[INPUT]]) {constantParams = [42]} | // CHECK: "test.success"(%[[INPUT]]) {constantParams = [42]} | ||||
module @ir attributes { test.apply_rewrite_1 } { | module @ir attributes { test.apply_rewrite_1 } { | ||||
%input = "test.op_input"() : () -> i32 | %input = "test.op_input"() : () -> i32 | ||||
"test.op"(%input) : (i32) -> () | "test.op"(%input) : (i32) -> () | ||||
} | } | ||||
// ----- | |||||
module @patterns { | |||||
func @matcher(%root : !pdl.operation) { | |||||
pdl_interp.check_operation_name of %root is "test.op" -> ^pat, ^end | |||||
^pat: | |||||
pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end | |||||
^end: | |||||
pdl_interp.finalize | |||||
} | |||||
module @rewriters { | |||||
func @success(%root : !pdl.operation) { | |||||
%op = pdl_interp.apply_rewrite "creator"(%root : !pdl.operation) : !pdl.operation | |||||
pdl_interp.erase %root | |||||
pdl_interp.finalize | |||||
} | |||||
} | |||||
} | |||||
// CHECK-LABEL: test.apply_rewrite_2 | |||||
// CHECK: "test.success" | |||||
module @ir attributes { test.apply_rewrite_2 } { | |||||
"test.op"() : () -> () | |||||
} | |||||
// ----- | // ----- | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// pdl_interp::AreEqualOp | // pdl_interp::AreEqualOp | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
module @patterns { | module @patterns { | ||||
func @matcher(%root : !pdl.operation) { | func @matcher(%root : !pdl.operation) { | ||||
▲ Show 20 Lines • Show All 230 Lines • ▼ Show 20 Lines | |||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// pdl_interp::CreateAttributeOp | // pdl_interp::CreateAttributeOp | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// Fully tested within the tests for other operations. | // Fully tested within the tests for other operations. | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// pdl_interp::CreateNativeOp | |||||
//===----------------------------------------------------------------------===// | |||||
// ----- | |||||
module @patterns { | |||||
func @matcher(%root : !pdl.operation) { | |||||
pdl_interp.check_operation_name of %root is "test.op" -> ^pat, ^end | |||||
^pat: | |||||
pdl_interp.record_match @rewriters::@success(%root : !pdl.operation) : benefit(1), loc([%root]) -> ^end | |||||
^end: | |||||
pdl_interp.finalize | |||||
} | |||||
module @rewriters { | |||||
func @success(%root : !pdl.operation) { | |||||
%op = pdl_interp.create_native "creator"(%root : !pdl.operation) : !pdl.operation | |||||
pdl_interp.erase %root | |||||
pdl_interp.finalize | |||||
} | |||||
} | |||||
} | |||||
// CHECK-LABEL: test.create_native_1 | |||||
// CHECK: "test.success" | |||||
module @ir attributes { test.create_native_1 } { | |||||
"test.op"() : () -> () | |||||
} | |||||
//===----------------------------------------------------------------------===// | |||||
// pdl_interp::CreateOperationOp | // pdl_interp::CreateOperationOp | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// ----- | // ----- | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// pdl_interp::CreateTypeOp | // pdl_interp::CreateTypeOp | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
▲ Show 20 Lines • Show All 425 Lines • Show Last 20 Lines |