This is an archive of the discontinued LLVM Phabricator instance.

[mlir][CAPI] Add a simple MlirOpOperand API for MlirValue uses.
ClosedPublic

Authored by mikeurbach on Dec 7 2022, 5:55 PM.

Details

Summary

This allows basic IR traversal via the C API, which is useful for
analyses in languages other than C++.

This starts by defining an MlirOpOperand struct to encapsulate a pair
of an owner operation and an operand number.

A new API is added for MlirValue, to return the first use of the Value
as an MlirOpOperand, or a "null" MlirOpOperand if there are no uses.

A couple APIs are added for MlirOpOperand. The first checks if an
MlirOpOperand is "null", by checking if its owner's pointer is
null. The second supports iteration along the use-def lists by
accepting an MlirOpOperand and returning the next use of the Value as
another MlirOpOperand, or a "null" MlirOpOperand if there are no more
uses.

Diff Detail

Event Timeline

mikeurbach created this revision.Dec 7 2022, 5:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 7 2022, 5:55 PM
mikeurbach requested review of this revision.Dec 7 2022, 5:55 PM
mikeurbach updated this revision to Diff 481306.Dec 8 2022, 8:50 AM

Switch to the usual DEFINE_C_API_STRUCT for MlirOpOperand.

mikeurbach updated this revision to Diff 481313.Dec 8 2022, 8:55 AM

Update test to use the new C API.

mehdi_amini accepted this revision.Dec 8 2022, 4:44 PM
This revision is now accepted and ready to land.Dec 8 2022, 4:44 PM