Skip to content

Commit

Permalink
Fix memory leak in MLIR SPIRV ModuleCombiner
Browse files Browse the repository at this point in the history
  • Loading branch information
joker-eph committed Oct 2, 2021
1 parent bac4529 commit 2da3fac
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions mlir/lib/Dialect/SPIRV/Linking/ModuleCombiner/ModuleCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -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());
}

Expand Down

0 comments on commit 2da3fac

Please # to comment.