[Mlir-commits] [mlir] 12541b5 - Use TranslateFromMLIRRegistration for SPIRV roundtrip (NFC)

Mehdi Amini llvmlistbot at llvm.org
Sat Aug 22 17:43:10 PDT 2020


Author: Mehdi Amini
Date: 2020-08-23T00:40:50Z
New Revision: 12541b5ed59d00c6a2ac90ccaf7aa8ff37d8d84b

URL: https://github.com/llvm/llvm-project/commit/12541b5ed59d00c6a2ac90ccaf7aa8ff37d8d84b
DIFF: https://github.com/llvm/llvm-project/commit/12541b5ed59d00c6a2ac90ccaf7aa8ff37d8d84b.diff

LOG: Use TranslateFromMLIRRegistration for SPIRV roundtrip (NFC)

This is aligning it with the other "translation" which operates on a MLIR input.

Added: 
    

Modified: 
    mlir/lib/Dialect/SPIRV/Serialization/TranslateRegistration.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/SPIRV/Serialization/TranslateRegistration.cpp b/mlir/lib/Dialect/SPIRV/Serialization/TranslateRegistration.cpp
index 42b458d314ca..d0aa2774a34c 100644
--- a/mlir/lib/Dialect/SPIRV/Serialization/TranslateRegistration.cpp
+++ b/mlir/lib/Dialect/SPIRV/Serialization/TranslateRegistration.cpp
@@ -115,23 +115,17 @@ void registerToSPIRVTranslation() {
 // Round-trip registration
 //===----------------------------------------------------------------------===//
 
-static LogicalResult roundTripModule(llvm::SourceMgr &sourceMgr,
-                                     bool emitDebugInfo, raw_ostream &output,
-                                     MLIRContext *context) {
-  // Parse an MLIR module from the source manager.
-  auto srcModule = OwningModuleRef(parseSourceFile(sourceMgr, context));
-  if (!srcModule)
-    return failure();
-
+static LogicalResult roundTripModule(ModuleOp srcModule, bool emitDebugInfo,
+                                     raw_ostream &output) {
   SmallVector<uint32_t, 0> binary;
-
-  auto spirvModules = srcModule->getOps<spirv::ModuleOp>();
+  MLIRContext *context = srcModule.getContext();
+  auto spirvModules = srcModule.getOps<spirv::ModuleOp>();
 
   if (spirvModules.begin() == spirvModules.end())
-    return srcModule->emitError("found no 'spv.module' op");
+    return srcModule.emitError("found no 'spv.module' op");
 
   if (std::next(spirvModules.begin()) != spirvModules.end())
-    return srcModule->emitError("found more than one 'spv.module' op");
+    return srcModule.emitError("found more than one 'spv.module' op");
 
   if (failed(spirv::serialize(*spirvModules.begin(), binary, emitDebugInfo)))
     return failure();
@@ -152,21 +146,16 @@ static LogicalResult roundTripModule(llvm::SourceMgr &sourceMgr,
 
 namespace mlir {
 void registerTestRoundtripSPIRV() {
-  TranslateRegistration roundtrip(
-      "test-spirv-roundtrip", [](llvm::SourceMgr &sourceMgr,
-                                 raw_ostream &output, MLIRContext *context) {
-        return roundTripModule(sourceMgr, /*emitDebugInfo=*/false, output,
-                               context);
+  TranslateFromMLIRRegistration roundtrip(
+      "test-spirv-roundtrip", [](ModuleOp module, raw_ostream &output) {
+        return roundTripModule(module, /*emitDebugInfo=*/false, output);
       });
 }
 
 void registerTestRoundtripDebugSPIRV() {
-  TranslateRegistration roundtrip(
-      "test-spirv-roundtrip-debug",
-      [](llvm::SourceMgr &sourceMgr, raw_ostream &output,
-         MLIRContext *context) {
-        return roundTripModule(sourceMgr, /*emitDebugInfo=*/true, output,
-                               context);
+  TranslateFromMLIRRegistration roundtrip(
+      "test-spirv-roundtrip-debug", [](ModuleOp module, raw_ostream &output) {
+        return roundTripModule(module, /*emitDebugInfo=*/true, output);
       });
 }
 } // namespace mlir


        


More information about the Mlir-commits mailing list