[Mlir-commits] [mlir] [mlir][spirv] Support function argument decorations for ptr in the PhysicalStorageBuffer (PR #76353)

Kohei Yamaguchi llvmlistbot at llvm.org
Thu Jan 4 22:30:00 PST 2024


================
@@ -177,6 +177,31 @@ LogicalResult Serializer::processUndefOp(spirv::UndefOp op) {
   return success();
 }
 
+LogicalResult Serializer::processFuncParameter(spirv::FuncOp op) {
+  for (auto [idx, arg] : llvm::enumerate(op.getArguments())) {
+    uint32_t argTypeID = 0;
+    if (failed(processType(op.getLoc(), arg.getType(), argTypeID))) {
+      return failure();
+    }
+    auto argValueID = getNextID();
+
+    // Process decoration attributes of arguments.
+    auto funcOp = cast<FunctionOpInterface>(*op);
+    for (auto argAttr : funcOp.getArgAttrs(idx)) {
+      if (auto decAttr = dyn_cast<DecorationAttr>(argAttr.getValue())) {
----------------
sott0n wrote:

I checked this case in my local:

```bash
> cat test.mlir
spirv.module PhysicalStorageBuffer64 GLSL450 requires #spirv.vce<v1.0,
    [Shader, PhysicalStorageBufferAddresses], [SPV_KHR_physical_storage_buffer]> {
  spirv.func @func_arg_decoration_aliased(
      %arg0 : !spirv.ptr<i32, PhysicalStorageBuffer> { spirv.decoration = #spirv.decoration<Restrict>, random_attr = #spirv.decoration<Aliased> }
  ) "None" {
    spirv.Return
  }
}
```

This cases an error below:
```bash
> mlir-translate -no-implicit-module -test-spirv-roundtrip test.mlir
test.mlir:3:3: error: 'spirv.func' op arguments may only have dialect attributes
  spirv.func @func_arg_decoration_aliased(
  ^
test.mlir:3:3: note: see current operation:
"spirv.func"() <{arg_attrs = [{random_attr = #spirv.decoration<Aliased>, spirv.decoration = #spirv.decoration<Restrict>}], function_control = #spirv.function_control<None>, function_type = (!spirv.ptr<i32, PhysicalStorageBuffer>) -> (), sym_name = "func_arg_decoration_aliased"}> ({
^bb0(%arg0: !spirv.ptr<i32, PhysicalStorageBuffer>):
  "spirv.Return"() : () -> ()
}) : () -> ()

```

It seems to be not allowed the random attributes, but I agree with your comment. So I add checking a name of `spirv.decoration` before checking `DecorationAttr` and a test for random attribute case.

https://github.com/llvm/llvm-project/pull/76353


More information about the Mlir-commits mailing list