This is an archive of the discontinued LLVM Phabricator instance.

Allow inline of all pure ops from the LLVM dialect.
ClosedPublic

Authored by ingomueller-net on Dec 2 2022, 3:07 AM.

Details

Summary

This allows to inline regions containing pure LLVM ops into their call
sites. (Note that this is not related to inlining of llvm.func but to
any the inlining of any Callable.) For now, we only allow the inlining
of Pure ops to be conservative but other ops may be considered inlinable
in the future.

Testing for purity of ops requires the C++ equivalent of the Pure trait
from SideEffectInterfaces.td, which this patch also provide. Its
implementation calls the C++ equivalents of the two traits that the Pure
trait is based on and, thus, has to be kept with the tablegen trait.

Diff Detail

Event Timeline

ingomueller-net created this revision.Dec 2 2022, 3:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 2 2022, 3:07 AM
ingomueller-net requested review of this revision.Dec 2 2022, 3:07 AM

Two comments:

  1. If someone thinks that adding the isPure function should be a different patch, please let me know.
  1. The limitation to pure ops comes from a discussion I had offline with several people, in which those were deemed to be safe to inline. This is probably a very conservative restriction and it may be useful to widen it. However; I don't know enough about LLVM and other things to be able to judge what would be safe and what could cause problems. If somebody can vouch for a wider definition, I'll happily change the patch.

I have investigate a bit more on the limitation of allowing only pure ops to be inlined. I have found two that I would like to be inlinable for my use case and where I don't see any reason that they shouldn't be:

  • CallOp (though if the callee is inlined, this op will also go away, so this may not be that big a problem)
  • LoadOp

There are probably quite a few more ops that aren't pure and could still be inlined. My possibly naive intuition would assume that this is the case for the following:

  • StoreOp
  • FreezeOp
  • FenceOp + Atomic*Op
  • InlineAsmOp

Approaching the question from the opposite end, I suspect the following ops to be not inlineable or potentially more difficult to inline:

  • InvokeOp + LandingpadOp
  • MetadataOp + *MetadataOp
  • Global*Op
  • FuncOp
ftynse accepted this revision.Dec 14 2022, 1:40 AM
ftynse added inline comments.
mlir/test/Dialect/LLVMIR/inlining.mlir
29

Please add a newline.

This revision is now accepted and ready to land.Dec 14 2022, 1:40 AM

Add missing new line at end of file.

This revision was landed with ongoing or failed builds.Dec 14 2022, 7:18 AM
This revision was automatically updated to reflect the committed changes.