diff options
author | River Riddle <riddleriver@gmail.com> | 2022-03-19 15:08:09 -0700 |
---|---|---|
committer | River Riddle <riddleriver@gmail.com> | 2022-04-06 17:41:59 -0700 |
commit | ea64828a10e304f8131e40dfef062173fe606e6a (patch) | |
tree | 90402a42bf6fa8f712970292b1b2315c59c005a1 /mlir/lib/Rewrite/ByteCode.cpp | |
parent | f5e48a2ad3a96118dc95cdf2fd45337612a3b132 (diff) | |
download | llvm-ea64828a10e304f8131e40dfef062173fe606e6a.zip llvm-ea64828a10e304f8131e40dfef062173fe606e6a.tar.gz llvm-ea64828a10e304f8131e40dfef062173fe606e6a.tar.bz2 |
[mlir:PDL] Expand how native constraint/rewrite functions can be defined
This commit refactors the expected form of native constraint and rewrite
functions, and greatly reduces the necessary user complexity required when
defining a native function. Namely, this commit adds in automatic processing
of the necessary PDLValue glue code, and allows for users to define
constraint/rewrite functions using the C++ types that they actually want to
use.
As an example, lets see a simple example rewrite defined today:
```
static void rewriteFn(PatternRewriter &rewriter, PDLResultList &results,
ArrayRef<PDLValue> args) {
ValueRange operandValues = args[0].cast<ValueRange>();
TypeRange typeValues = args[1].cast<TypeRange>();
...
// Create an operation at some point and pass it back to PDL.
Operation *op = rewriter.create<SomeOp>(...);
results.push_back(op);
}
```
After this commit, that same rewrite could be defined as:
```
static Operation *rewriteFn(PatternRewriter &rewriter ValueRange operandValues,
TypeRange typeValues) {
...
// Create an operation at some point and pass it back to PDL.
return rewriter.create<SomeOp>(...);
}
```
Differential Revision: https://reviews.llvm.org/D122086
Diffstat (limited to 'mlir/lib/Rewrite/ByteCode.cpp')
-rw-r--r-- | mlir/lib/Rewrite/ByteCode.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/mlir/lib/Rewrite/ByteCode.cpp b/mlir/lib/Rewrite/ByteCode.cpp index 367f51a..c2dc41a 100644 --- a/mlir/lib/Rewrite/ByteCode.cpp +++ b/mlir/lib/Rewrite/ByteCode.cpp @@ -1340,7 +1340,7 @@ void ByteCodeExecutor::executeApplyConstraint(PatternRewriter &rewriter) { }); // Invoke the constraint and jump to the proper destination. - selectJump(succeeded(constraintFn(args, rewriter))); + selectJump(succeeded(constraintFn(rewriter, args))); } void ByteCodeExecutor::executeApplyRewrite(PatternRewriter &rewriter) { @@ -1357,7 +1357,7 @@ void ByteCodeExecutor::executeApplyRewrite(PatternRewriter &rewriter) { // Execute the rewrite function. ByteCodeField numResults = read(); ByteCodeRewriteResultList results(numResults); - rewriteFn(args, rewriter, results); + rewriteFn(rewriter, results, args); assert(results.getResults().size() == numResults && "native PDL rewrite function returned unexpected number of results"); |