This is an archive of the discontinued LLVM Phabricator instance.

[mlir][CAPI][Python] Plumb OpPrintingFlags to C and Python APIs.
ClosedPublic

Authored by stellaraccident on Oct 20 2020, 11:22 PM.

Details

Summary
  • Adds a new MlirOpPrintingFlags type and supporting accessors.
  • Changes the signature of mlirOperationPrint. I believe that we are still experimental enough that making such a breaking change is the best thing to do.
  • Adds a full featured python Operation.print method with all options and the ability to print directly to files/stdout in text or binary.
  • Adds an Operation.get_asm which delegates to print and returns a str or bytes.
  • Reworks Operation.str to be based on get_asm.

Diff Detail

Event Timeline

stellaraccident requested review of this revision.Oct 20 2020, 11:22 PM
rriddle added inline comments.Oct 20 2020, 11:24 PM
mlir/include/mlir/IR/OperationSupport.h
567

Thanks for fixing this!

Harbormaster completed remote builds in B75819: Diff 299558.
ftynse accepted this revision.Oct 21 2020, 2:53 AM
ftynse added inline comments.
mlir/include/mlir-c/IR.h
259

intptr_t for size-like argument?

268

I was going to ask if we want a bool argument that enables/disables this, but then found that C++ doesn't have such a flag either. Not sure if we want to add one.

336

How about having mlirOperationPrint that always uses the default flags and mlirOperationPrintWithOptions that additionally takes options. This would remove the need for mlirOpPrintingFlagsGetDefault that relies on implicit conversions from NULL to llvm::None to OpPrintingFlags, which is a bit too much for my taste.

mlir/lib/Bindings/Python/IRModules.cpp
74

What's the default behavior / which value disables the limit?

2085

Nit: with get_asm method

This revision is now accepted and ready to land.Oct 21 2020, 2:53 AM
stellaraccident marked 5 inline comments as done.

Comments and rebase.

This revision was landed with ongoing or failed builds.Oct 21 2020, 12:15 PM
This revision was automatically updated to reflect the committed changes.
mlir/include/mlir-c/IR.h
268

Yeah, I followed the C++ approach of just having these flip the flag on, which I think is defensible for the future.

336

Done but used the suffix "withFlags" for consistency.

mlir/lib/Bindings/Python/IRModules.cpp
74

None is the default/disabled. Added that to the doc.