[mlir][spirv] Fix nested control flow serialization
authorLei Zhang <antiagainst@google.com>
Sat, 11 Dec 2021 19:40:24 +0000 (14:40 -0500)
committerLei Zhang <antiagainst@google.com>
Sat, 11 Dec 2021 19:47:19 +0000 (14:47 -0500)
commit731676b10dfe684d7f166cb0f85cd6ede1660119
treee2954109766e42224eceb3b92560f9eb37e52c44
parent36b8a4f9f39c9d1b9cd6cae9aebc82cbdb37815b
[mlir][spirv] Fix nested control flow serialization

If we have a `spv.mlir.selection` op nested in a `spv.mlir.loop`
op, when serializing the loop's block, we might need to jump
from the selection op's merge block, which might be different
than the immediate MLIR IR predecessor block. But we still need
to get the block argument from the MLIR IR predecessor block.

Also, if the `spv.mlir.selection` is in the `spv.mlir.loop`'s
header block, we need to make sure `OpLoopMerge` is emitted
in the current block before start processing the nested selection
op. Otherwise we'll see the LoopMerge in the wrong SPIR-V
basic block.

Reviewed By: Hardcode84

Differential Revision: https://reviews.llvm.org/D115560
mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
mlir/lib/Target/SPIRV/Deserialization/Deserializer.h
mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp
mlir/lib/Target/SPIRV/Serialization/Serializer.cpp
mlir/lib/Target/SPIRV/Serialization/Serializer.h
mlir/test/Target/SPIRV/loop.mlir