[Mlir-commits] [mlir] 8c05c7c - [MLIR][SPIRV] Support different function control in (de)serialization

George Mitenkov llvmlistbot at llvm.org
Wed Sep 30 02:26:47 PDT 2020


Author: George Mitenkov
Date: 2020-09-30T12:25:36+03:00
New Revision: 8c05c7c8d87c7ab02fca2a789dfcca4976c6601b

URL: https://github.com/llvm/llvm-project/commit/8c05c7c8d87c7ab02fca2a789dfcca4976c6601b
DIFF: https://github.com/llvm/llvm-project/commit/8c05c7c8d87c7ab02fca2a789dfcca4976c6601b.diff

LOG: [MLIR][SPIRV] Support different function control in (de)serialization

Added support for different function control
in serialization and deserialization.

Reviewed By: mravishankar

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp b/mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp
index eaa8f4d94833..b5eea4333824 100644
--- a/mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp
+++ b/mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp
@@ -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 
diff erent 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");

diff  --git a/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp b/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
index 887def35f791..1eda166a0325 100644
--- a/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
+++ b/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
@@ -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);
 

diff  --git a/mlir/test/Dialect/SPIRV/Serialization/module.mlir b/mlir/test/Dialect/SPIRV/Serialization/module.mlir
index 29973e9e4d77..2e8f635d7d3c 100644
--- a/mlir/test/Dialect/SPIRV/Serialization/module.mlir
+++ b/mlir/test/Dialect/SPIRV/Serialization/module.mlir
@@ -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
   }
 }


        


More information about the Mlir-commits mailing list