Add spirv::GlobalVariableOp that allows module level definition of variables
authorMahesh Ravishankar <ravishankarm@google.com>
Sat, 17 Aug 2019 17:19:48 +0000 (10:19 -0700)
committerA. Unique TensorFlower <gardener@tensorflow.org>
Sat, 17 Aug 2019 17:20:13 +0000 (10:20 -0700)
commitd745101339f3e56f202311a0243d1ba7ef04f56a
tree300dbddf775a9f1a366f5c544298f4651b55906a
parentc268666f15ee5ad36ed39b0a38ec5bf9d58216d4
Add spirv::GlobalVariableOp that allows module level definition of variables

FuncOps in MLIR use explicit capture. So global variables defined in
module scope need to have a symbol name and this should be used to
refer to the variable within the function. This deviates from SPIR-V
spec, which assigns an SSA value to variables at all scopes that can
be used to refer to the variable, which requires SPIR-V functions to
allow implicit capture. To handle this add a new op,
spirv::GlobalVariableOp that can be used to define module scope
variables.
Since instructions need an SSA value, an new spirv::AddressOfOp is
added to convert a symbol reference to an SSA value for use with other
instructions.
This also means the spirv::EntryPointOp instruction needs to change to
allow initializers to be specified using symbol reference instead of
SSA value
The current spirv::VariableOp which returns an SSA value (as defined
by SPIR-V spec) can still be used to define function-scope variables.
PiperOrigin-RevId: 263951109
12 files changed:
mlir/include/mlir/Dialect/SPIRV/SPIRVOps.td
mlir/include/mlir/Dialect/SPIRV/SPIRVStructureOps.td
mlir/include/mlir/IR/OpBase.td
mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp
mlir/lib/Dialect/SPIRV/SPIRVOps.cpp
mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp
mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
mlir/test/Conversion/GPUToSPIRV/simple.mlir
mlir/test/Dialect/SPIRV/Serialization/entry_interface.mlir
mlir/test/Dialect/SPIRV/Serialization/variables.mlir
mlir/test/Dialect/SPIRV/Serialization/variables_init.mlir
mlir/test/Dialect/SPIRV/ops.mlir