This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][LLVMDialect] SelectionOp conversion pattern
ClosedPublic

Authored by georgemitenkov on Jul 15 2020, 2:21 AM.

Details

Summary

This patch introduces conversion pattern for spv.selection op. The conversion can only be applied to selection with all blocks being reachable. Moreover, selection with control attributes "Flatten" and "DontFlatten" is not supported.

Since the PatternRewriter hook for block merging has not been implemented for ConversionPatternRewriter, merge and continue blocks are kept separately.

Also, straight lowering to LLVM was chosen over going via SCF dialect.

Diff Detail

Event Timeline

georgemitenkov created this revision.Jul 15 2020, 2:21 AM
georgemitenkov edited the summary of this revision. (Show Details)Jul 15 2020, 2:22 AM

Since the PatternRewriter hook for block merging has not been implemented for ConversionPatternRewriter, merge and continue blocks are kept separately.

A common workaround is to clone operations from one block into the other with a value replacement map that updates block arguments.

This LGTM, but please get approval from @antiagainst or @mravishankar for the SPIR-V parts.

antiagainst accepted this revision.Jul 20 2020, 6:29 AM
mlir/test/Conversion/SPIRVToLLVM/control-flow-ops-to-llvm.mlir
112

Remove the trailing // pred: part from all the tests.

126

selection_with_both_true_and_false_block?

150

selection_with_early_return?

This revision is now accepted and ready to land.Jul 20 2020, 6:29 AM
georgemitenkov marked 3 inline comments as done.

Addressed comments on tests naming and style.

georgemitenkov updated this revision to Diff 279459.EditedJul 21 2020, 2:40 AM

Separated invalid test case from others in control-flow-to-llvm.mlir

Put selection tests in one module.

Harbormaster completed remote builds in B65055: Diff 279473.
This revision was automatically updated to reflect the committed changes.