[spirv] Fix function entry block erase after moving to spv.selection
authorLei Zhang <antiagainst@google.com>
Mon, 7 Oct 2019 19:36:39 +0000 (12:36 -0700)
committerA. Unique TensorFlower <gardener@tensorflow.org>
Mon, 7 Oct 2019 19:37:13 +0000 (12:37 -0700)
commitebf584b8134e6e0530e5848be55a330d185c688d
tree7575d864a5dab346901a23d7124be1e50d5b23ee
parent89e7a76a1cc77f9b67adb866e3a9e09ec5470790
[spirv] Fix function entry block erase after moving to spv.selection

The structured selection/loop's entry block does not have arguments.
If the function's header block is also part of the structured control
flow, we cannot just simply erase it because it may contain arguments
matching the function signature and used by the cloned blocks. Instead,
turn it into a block only containing a spv.Branch op.

Also, we can directly emit instructions for the spv.selection header
block to the block containing the spv.selection op. This eliminates
unnecessary branches in the SPIR-V blob.

Added a test for nested spv.loop.

PiperOrigin-RevId: 273351424
mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp
mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
mlir/test/Dialect/SPIRV/Serialization/loop.mlir
mlir/test/Dialect/SPIRV/Serialization/selection.mlir