1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
// RUN: mlir-pdll %s -I %S -I %S/../../../../include -split-input-file -x mlir | FileCheck %s
//===----------------------------------------------------------------------===//
// AttributeExpr
//===----------------------------------------------------------------------===//
// CHECK: pdl.pattern @AttrExpr
// CHECK: %[[ATTR:.*]] = attribute = 10
// CHECK: operation({{.*}}) {"attr" = %[[ATTR]]}
Pattern AttrExpr => erase op<> { attr = attr<"10"> };
// -----
//===----------------------------------------------------------------------===//
// CallExpr
//===----------------------------------------------------------------------===//
// CHECK: pdl.pattern @TestCallWithArgsAndReturn
// CHECK: %[[ROOT:.*]] = operation
// CHECK: rewrite %[[ROOT]]
// CHECK: %[[REPL_OP:.*]] = operation "test.op"
// CHECK: %[[RESULTS:.*]] = results of %[[REPL_OP]]
// CHECK: replace %[[ROOT]] with(%[[RESULTS]] : !pdl.range<value>)
Rewrite TestRewrite(root: Op) -> ValueRange => root;
Pattern TestCallWithArgsAndReturn => replace root: Op with TestRewrite(op<test.op>);
// -----
// CHECK: pdl.pattern @TestExternalCall
// CHECK: %[[ROOT:.*]] = operation
// CHECK: rewrite %[[ROOT]]
// CHECK: %[[RESULTS:.*]] = apply_native_rewrite "TestRewrite"(%[[ROOT]] : !pdl.operation) : !pdl.range<value>
// CHECK: replace %[[ROOT]] with(%[[RESULTS]] : !pdl.range<value>)
Rewrite TestRewrite(op: Op) -> ValueRange;
Pattern TestExternalCall => replace root: Op with TestRewrite(root);
// -----
//===----------------------------------------------------------------------===//
// MemberAccessExpr
//===----------------------------------------------------------------------===//
// Handle implicit "all" operation results access.
// CHECK: pdl.pattern @OpAllResultMemberAccess
// CHECK: %[[OP0:.*]] = operation
// CHECK: %[[OP0_RES:.*]] = result 0 of %[[OP0]]
// CHECK: %[[OP1:.*]] = operation
// CHECK: %[[OP1_RES:.*]] = results of %[[OP1]]
// CHECK: operation(%[[OP0_RES]], %[[OP1_RES]] : !pdl.value, !pdl.range<value>)
Pattern OpAllResultMemberAccess {
let singleVar: Value = op<>;
let rangeVar: ValueRange = op<>;
erase op<>(singleVar, rangeVar);
}
// -----
// Handle result indexing on unregistered op.
// CHECK: pdl.pattern @UnregisteredOpResultIndexing
// CHECK: %[[BAR_OP:.*]] = operation "my_dialect.unregistered_bar"
// CHECK: %[[BAR_RES:.*]] = result 0 of %[[BAR_OP]]
// CHECK: operation "my_dialect.unregistered_foo"(%[[BAR_RES]] : !pdl.value)
Pattern UnregisteredOpResultIndexing {
let bar : Op<my_dialect.unregistered_bar>;
let op = op<my_dialect.unregistered_foo>(bar.0);
erase op;
}
// -----
// Handle implicit "named" operation results access.
#include "include/ops.td"
// CHECK: pdl.pattern @OpResultMemberAccess
// CHECK: %[[OP0:.*]] = operation
// CHECK: %[[RES:.*]] = results 0 of %[[OP0]] -> !pdl.value
// CHECK: %[[RES1:.*]] = results 0 of %[[OP0]] -> !pdl.value
// CHECK: %[[RES2:.*]] = results 1 of %[[OP0]] -> !pdl.range<value>
// CHECK: %[[RES3:.*]] = results 1 of %[[OP0]] -> !pdl.range<value>
// CHECK: operation(%[[RES]], %[[RES1]], %[[RES2]], %[[RES3]] : !pdl.value, !pdl.value, !pdl.range<value>, !pdl.range<value>)
Pattern OpResultMemberAccess {
let op: Op<test.with_results>;
erase op<>(op.0, op.result, op.1, op.var_result);
}
// -----
// CHECK: pdl.pattern @TupleMemberAccessNumber
// CHECK: %[[FIRST:.*]] = operation "test.first"
// CHECK: %[[SECOND:.*]] = operation "test.second"
// CHECK: rewrite %[[FIRST]] {
// CHECK: replace %[[FIRST]] with %[[SECOND]]
Pattern TupleMemberAccessNumber {
let firstOp = op<test.first>;
let secondOp = op<test.second>(firstOp);
let tuple = (firstOp, secondOp);
replace tuple.0 with tuple.1;
}
// -----
// CHECK: pdl.pattern @TupleMemberAccessName
// CHECK: %[[FIRST:.*]] = operation "test.first"
// CHECK: %[[SECOND:.*]] = operation "test.second"
// CHECK: rewrite %[[FIRST]] {
// CHECK: replace %[[FIRST]] with %[[SECOND]]
Pattern TupleMemberAccessName {
let firstOp = op<test.first>;
let secondOp = op<test.second>(firstOp);
let tuple = (first = firstOp, second = secondOp);
replace tuple.first with tuple.second;
}
// -----
//===----------------------------------------------------------------------===//
// RangeExpr
//===----------------------------------------------------------------------===//
// CHECK: pdl.pattern @RangeExpr
// CHECK: %[[ARG:.*]] = operand
// CHECK: %[[ARGS:.*]] = operands
// CHECK: %[[TYPE:.*]] = type
// CHECK: %[[TYPES:.*]] = types
// CHECK: range : !pdl.range<value>
// CHECK: range %[[ARG]], %[[ARGS]] : !pdl.value, !pdl.range<value>
// CHECK: range : !pdl.range<type>
// CHECK: range %[[TYPE]], %[[TYPES]] : !pdl.type, !pdl.range<type>
Pattern RangeExpr {
replace op<>(arg: Value, args: ValueRange) -> (type: Type, types: TypeRange)
with op<test.op>((), (arg, args)) -> ((), (type, types));
}
// -----
//===----------------------------------------------------------------------===//
// TypeExpr
//===----------------------------------------------------------------------===//
// CHECK: pdl.pattern @TypeExpr
// CHECK: %[[TYPE:.*]] = type : i32
// CHECK: operation({{.*}}) -> (%[[TYPE]] : !pdl.type)
Pattern TypeExpr => erase op<> -> (type<"i32">);
|