[Mlir-commits] [mlir] 2da3fac - Fix memory leak in MLIR SPIRV ModuleCombiner

Mehdi Amini llvmlistbot at llvm.org
Sat Oct 2 16:55:53 PDT 2021


Author: Mehdi Amini
Date: 2021-10-02T23:55:25Z
New Revision: 2da3facd864c36739e6e7f4b90e12aeb5afa7695

URL: https://github.com/llvm/llvm-project/commit/2da3facd864c36739e6e7f4b90e12aeb5afa7695
DIFF: https://github.com/llvm/llvm-project/commit/2da3facd864c36739e6e7f4b90e12aeb5afa7695.diff

LOG: Fix memory leak in MLIR SPIRV ModuleCombiner

Added: 
    

Modified: 
    mlir/lib/Dialect/SPIRV/Linking/ModuleCombiner/ModuleCombiner.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/SPIRV/Linking/ModuleCombiner/ModuleCombiner.cpp b/mlir/lib/Dialect/SPIRV/Linking/ModuleCombiner/ModuleCombiner.cpp
index 2b4ac38d618f..69e685973a9a 100644
--- a/mlir/lib/Dialect/SPIRV/Linking/ModuleCombiner/ModuleCombiner.cpp
+++ b/mlir/lib/Dialect/SPIRV/Linking/ModuleCombiner/ModuleCombiner.cpp
@@ -126,7 +126,7 @@ OwningOpRef<spirv::ModuleOp> combine(ArrayRef<spirv::ModuleOp> inputModules,
   unsigned lastUsedID = 0;
 
   for (auto inputModule : inputModules) {
-    spirv::ModuleOp moduleClone = inputModule.clone();
+    OwningOpRef<spirv::ModuleOp> moduleClone = inputModule.clone();
 
     // In the combined module, rename all symbols that conflict with symbols
     // from the current input module. This renaming applies to all ops except
@@ -141,7 +141,7 @@ OwningOpRef<spirv::ModuleOp> combine(ArrayRef<spirv::ModuleOp> inputModules,
       StringRef oldSymName = symbolOp.getName();
 
       if (!isa<FuncOp>(op) &&
-          failed(updateSymbolAndAllUses(symbolOp, combinedModule, moduleClone,
+          failed(updateSymbolAndAllUses(symbolOp, combinedModule, *moduleClone,
                                         lastUsedID)))
         return nullptr;
 
@@ -170,14 +170,14 @@ OwningOpRef<spirv::ModuleOp> combine(ArrayRef<spirv::ModuleOp> inputModules,
 
     // In the current input module, rename all symbols that conflict with
     // symbols from the combined module. This includes renaming spv.funcs.
-    for (auto &op : *moduleClone.getBody()) {
+    for (auto &op : *moduleClone->getBody()) {
       auto symbolOp = dyn_cast<SymbolOpInterface>(op);
       if (!symbolOp)
         continue;
 
       StringRef oldSymName = symbolOp.getName();
 
-      if (failed(updateSymbolAndAllUses(symbolOp, moduleClone, combinedModule,
+      if (failed(updateSymbolAndAllUses(symbolOp, *moduleClone, combinedModule,
                                         lastUsedID)))
         return nullptr;
 
@@ -203,7 +203,7 @@ OwningOpRef<spirv::ModuleOp> combine(ArrayRef<spirv::ModuleOp> inputModules,
     }
 
     // Clone all the module's ops to the combined module.
-    for (auto &op : *moduleClone.getBody())
+    for (auto &op : *moduleClone->getBody())
       combinedModuleBuilder.insert(op.clone());
   }
 


        


More information about the Mlir-commits mailing list