Hi,
I am working on adding a new op to spv
that would require support for variadic attributes. In particular, I am adding support to OpSpecConstantComposite
which provides a way to declare a composite specialization constant in a SPIR-V module. The value of a composite specialization constant is derived (directly or indirectly) from other specialization constants with scalar values [1].
Currently, spv
only supports scalar specialization constants which are defined as module-level symbols that don’t produce SSA values and instead are materialized inside functions using spv._reference_of
.
The way we are trying to extend that support to composites is to add a new op: spv.specConstantComposite
which is defined as follows:
def SPV_SpecConstantCompositeOp : SPV_Op<"specConstantComposite", [InModuleScope, Symbol]> {
let arguments = (ins
StrAttr:$sym_name,
// The following line doesn't actually compile because variadic attributes are not supported.
Variadic<FlatSymbolRefAttr>:$constituents
);
let results = (outs);
}
So the following SPIR-V example:
OpDecorate %x SpecId 1
OpDecorate %y SpecId 2
OpDecorate %z SpecId 3
%x = OpSpecConstant %int 32
%y = OpSpecConstant %int 16
%z = OpSpecConstant %int 1
%composite = OpSpecConstant .. %x %y %z
would be represented in MLIR as:
spv.specConstant @x spec_id(1) = 32 : i32
spv.specConstant @y spec_id(2) = 16 : i32
spv.specConstant @z spec_id(3) = 1 : i32
// 1. We can omit the () around the constituents below.
// 2. specConstantComposite doesn't provide a spec_id element.
spv.specConstantComposite @composite, (@x, @y, @z) : !spv.struct<i32, i32, i32>
As far as I can learn from the docs, there is no current support for such a variadic attributes feature. Can we extend the infrastructure in such a way to support that feature? If so, I can gladly pick up that task.
cc: @antiagainst