-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathHandshakeCanonicalization.td
More file actions
63 lines (51 loc) · 2.46 KB
/
HandshakeCanonicalization.td
File metadata and controls
63 lines (51 loc) · 2.46 KB
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
//===- HandshakeCanonicalize.td - Dialect patterns ---------*- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Declarative canonicalization patterns for Handhsake operations.
//
//===----------------------------------------------------------------------===//
#ifndef DYNAMATIC_DIALECT_HANDSHAKE_HANDSHAKE_CANONICALIZATION_TD
#define DYNAMATIC_DIALECT_HANDSHAKE_HANDSHAKE_CANONICALIZATION_TD
include "mlir/IR/PatternBase.td"
include "dynamatic/Dialect/Handshake/HandshakeArithOps.td"
//===----------------------------------------------------------------------===//
// ExtSIOp
//===----------------------------------------------------------------------===//
// extsi(extui(x iN : iM) : iL) -> extui(x : iL)
def ExtSIOfExtUI : Pat<
(Handshake_ExtSIOp (Handshake_ExtUIOp $x)), (Handshake_ExtUIOp $x)
>;
def ExtUIOfConst : Pat<
(Handshake_ExtUIOp:$ext (Handshake_ConstantOp $attr, $ctrl)),
(Handshake_ConstantOp (NativeCodeCall<"constantFoldExt($0.getOwner(), $1)"> $ext, $attr), $ctrl)
>;
def ExtSIOfConst : Pat<
(Handshake_ExtSIOp:$ext (Handshake_ConstantOp $attr, $ctrl)),
(Handshake_ConstantOp (NativeCodeCall<"constantFoldExt($0.getOwner(), $1)"> $ext, $attr), $ctrl)
>;
//===----------------------------------------------------------------------===//
// TruncIOp
//===----------------------------------------------------------------------===//
def ValueWiderThan :
Constraint<CPred<"getDataBitWidth($0) > getDataBitWidth($1)">>;
def TruncationMatchesShiftAmount :
Constraint<And<[
CPred<"succeeded(getIntOrSplatIntValue($2))">,
CPred<"(getScalarOrElementWidth($0) - getScalarOrElementWidth($1)) == "
"*getIntOrSplatIntValue($2)">]>>;
// trunci(extsi(x)) -> extsi(x), when only the sign-extension bits are truncated
def TruncIExtSIToExtSI : Pat<
(Handshake_TruncIOp:$tr (Handshake_ExtSIOp:$ext $x)), (Handshake_ExtSIOp $x),
[(ValueWiderThan $ext, $tr), (ValueWiderThan $tr, $x)]
>;
// trunci(extui(x)) -> extui(x), when only the zero-extension bits are truncated
def TruncIExtUIToExtUI : Pat<
(Handshake_TruncIOp:$tr (Handshake_ExtUIOp:$ext $x)), (Handshake_ExtUIOp $x),
[(ValueWiderThan $ext, $tr), (ValueWiderThan $tr, $x)]
>;
#endif // DYNAMATIC_DIALECT_HANDSHAKE_HANDSHAKE_CANONICALIZATION_TD