Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
48 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Tablegen helpers for declarative rewrite (DRR) patterns | ||
load("@llvm-project//mlir:tblgen.bzl", "td_library") | ||
|
||
package( | ||
default_applicable_licenses = ["@heir//:license"], | ||
default_visibility = ["//visibility:public"], | ||
) | ||
|
||
td_library( | ||
name = "DRR", | ||
srcs = [ | ||
"Utils.td", | ||
], | ||
# include from the heir-root to enable fully-qualified include-paths | ||
includes = ["../../.."], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
include "mlir/Dialect/Arith/IR/ArithOps.td" | ||
include "mlir/IR/EnumAttr.td" | ||
include "mlir/IR/PatternBase.td" | ||
|
||
// When using DRR to define new artih ops, one must include an attribute | ||
// describing the overflow semantics. When the new arith op is built from an | ||
// existing op, one should match the overflow attribute and propagate it, but | ||
// when the op is built from scratch, one needs to pass an overflow choice, and | ||
// if there is no reason to pick a particular overflow type, use this helper as | ||
// a default. | ||
defvar DefOverflow = ConstantEnumCase<Arith_IntegerOverflowAttr, "none">; | ||
|
||
// When constructing a new variadic op, and you want to pass it a single argument | ||
// as its variadic input, use this helper. To understand why this is needed, see | ||
// https://discourse.llvm.org/t/compilation-failure-with-drr-generated-pattern/77385 | ||
def MakeSingleResultVariadic: NativeCodeCall<"{ $0 }">; | ||
|
||
// Determine if an input integer attr is zero | ||
def IsZeroIntAttr : | ||
Constraint< | ||
CPred<"llvm::cast<mlir::IntegerAttr>($0).getValue().isZero()">>; | ||
|
||
// Construct an index.cast op, which is necessary here because the default | ||
// builder is not compatible with DRR as of 2024-03-11. | ||
def CreateIndexCastOp : NativeCodeCall< | ||
"$_builder.create<arith::IndexCastOp>($0.getLoc(), $1.getType(), $0)">; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters