[MLIR][SPIRV] Support different function control in (de)serialization
authorGeorge Mitenkov <georgemitenk0v@gmail.com>
Wed, 30 Sep 2020 09:05:17 +0000 (12:05 +0300)
committerGeorge Mitenkov <georgemitenk0v@gmail.com>
Wed, 30 Sep 2020 09:25:36 +0000 (12:25 +0300)
Added support for different function control
in serialization and deserialization.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D88280

mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp
mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
mlir/test/Dialect/SPIRV/Serialization/module.mlir

index eaa8f4d..b5eea43 100644 (file)
@@ -805,16 +805,10 @@ LogicalResult Deserializer::processFunction(ArrayRef<uint32_t> operands) {
     return emitError(unknownLoc, "duplicate function definition/declaration");
   }
 
-  auto functionControl = spirv::symbolizeFunctionControl(operands[2]);
-  if (!functionControl) {
+  auto fnControl = spirv::symbolizeFunctionControl(operands[2]);
+  if (!fnControl) {
     return emitError(unknownLoc, "unknown Function Control: ") << operands[2];
   }
-  if (functionControl.getValue() != spirv::FunctionControl::None) {
-    /// TODO: Handle different function controls
-    return emitError(unknownLoc, "unhandled Function Control: '")
-           << spirv::stringifyFunctionControl(functionControl.getValue())
-           << "'";
-  }
 
   Type fnType = getType(operands[3]);
   if (!fnType || !fnType.isa<FunctionType>()) {
@@ -831,8 +825,8 @@ LogicalResult Deserializer::processFunction(ArrayRef<uint32_t> operands) {
   }
 
   std::string fnName = getFunctionSymbol(operands[1]);
-  auto funcOp =
-      opBuilder.create<spirv::FuncOp>(unknownLoc, fnName, functionType);
+  auto funcOp = opBuilder.create<spirv::FuncOp>(
+      unknownLoc, fnName, functionType, fnControl.getValue());
   curFunction = funcMap[operands[1]] = funcOp;
   LLVM_DEBUG(llvm::dbgs() << "-- start function " << fnName << " (type = "
                           << fnType << ", id = " << operands[1] << ") --\n");
index 887def3..1eda166 100644 (file)
@@ -775,8 +775,7 @@ LogicalResult Serializer::processFuncOp(spirv::FuncOp op) {
   operands.push_back(resTypeID);
   auto funcID = getOrCreateFunctionID(op.getName());
   operands.push_back(funcID);
-  // TODO: Support other function control options.
-  operands.push_back(static_cast<uint32_t>(spirv::FunctionControl::None));
+  operands.push_back(static_cast<uint32_t>(op.function_control()));
   operands.push_back(fnTypeID);
   encodeInstructionInto(functionHeader, spirv::Opcode::OpFunction, operands);
 
index 29973e9..2e8f635 100644 (file)
@@ -1,13 +1,13 @@
 // RUN: mlir-translate -test-spirv-roundtrip -split-input-file %s | FileCheck %s
 
 // CHECK:      spv.module Logical GLSL450 requires #spv.vce<v1.0, [Shader], []> {
-// CHECK-NEXT:   spv.func @foo() "None" {
+// CHECK-NEXT:   spv.func @foo() "Inline" {
 // CHECK-NEXT:     spv.Return
 // CHECK-NEXT:   }
 // CHECK-NEXT: }
 
 spv.module Logical GLSL450 requires #spv.vce<v1.0, [Shader], []> {
-  spv.func @foo() -> () "None" {
+  spv.func @foo() -> () "Inline" {
      spv.Return
   }
 }