This is an archive of the discontinued LLVM Phabricator instance.

[mlir][CAPI] Add C API for Pattern Matching
Needs ReviewPublic

Authored by Danacus on Jul 22 2023, 3:56 AM.

Details

Reviewers
None
Group Reviewers
Restricted Project
Summary

Adds a C API for RewritePatternSet, PDLPatternModule and the Greedy Pattern Rewrite Driver, based on the implementation found in Beaver.

This would allow developers to write passes in PDLL, compile them to PDL MLIR modules and use them to write passes in C or languages with C bindings. I'm exploring the possiblity of using Rust to write MLIR passes, which has led me to create this revision.

I'm not sure if we should add a way to pass a GreedyRewriteConfig, since the proposed API in this revision does not allow you to configure the rewrite driver.

Would it be useful to extend the C API further in the future to support dialect conversion, or even custom RewritePatterns and PatternRewriters similar to the ExternalPass API?

Diff Detail

Event Timeline

Danacus created this revision.Jul 22 2023, 3:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 22 2023, 3:56 AM
Danacus requested review of this revision.Jul 22 2023, 3:56 AM
Danacus abandoned this revision.Jul 22 2023, 3:59 AM

Please ignore this, I'm trying to use Arcanist, but it does not behave as I expected.

Danacus updated this revision to Diff 543165.Jul 22 2023, 4:15 AM

Previous revision invalid

Previous revision was created as a mistake (it only included one of the commits), and arcanist refuses to create a new revision instead of updating this one. I apologize for the inconvenience.

Danacus edited the summary of this revision. (Show Details)Jul 22 2023, 4:29 AM
Danacus added a reviewer: Restricted Project.
Danacus updated this revision to Diff 543205.Jul 22 2023, 10:25 AM

Added a test

I've added a test with a simple PDL module. Please let me know if this suffices, or if I should add more tests.

Danacus updated this revision to Diff 543899.Jul 25 2023, 2:49 AM

Fix test failing in CI

Herald added a project: Restricted Project. · View Herald TranscriptJul 25 2023, 2:49 AM
Danacus updated this revision to Diff 543901.Jul 25 2023, 2:49 AM

Fix mistake in previous revision

Danacus updated this revision to Diff 543911.Jul 25 2023, 3:21 AM

Fix formatting