From 8c05c7c8d87c7ab02fca2a789dfcca4976c6601b Mon Sep 17 00:00:00 2001 From: George Mitenkov Date: Wed, 30 Sep 2020 12:05:17 +0300 Subject: [PATCH] [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 --- mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp | 14 ++++---------- mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp | 3 +-- mlir/test/Dialect/SPIRV/Serialization/module.mlir | 4 ++-- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp b/mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp index eaa8f4d..b5eea43 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 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()) { @@ -831,8 +825,8 @@ LogicalResult Deserializer::processFunction(ArrayRef operands) { } std::string fnName = getFunctionSymbol(operands[1]); - auto funcOp = - opBuilder.create(unknownLoc, fnName, functionType); + auto funcOp = opBuilder.create( + 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 887def3..1eda166 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(spirv::FunctionControl::None)); + operands.push_back(static_cast(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 29973e9..2e8f635 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 { -// 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 { - spv.func @foo() -> () "None" { + spv.func @foo() -> () "Inline" { spv.Return } } -- 2.7.4