@@ -764,9 +764,6 @@ class MLIRGenImpl
764764 genContextPartial.dummyRun = true;
765765 genContextPartial.rootContext = &genContextPartial;
766766 genContextPartial.postponedMessages = &postponedMessages;
767- // TODO: no need to clean up here as whole module will be removed
768- //genContextPartial.cleanUps = new mlir::SmallVector<mlir::Block *>();
769- //genContextPartial.cleanUpOps = new mlir::SmallVector<mlir::Operation *>();
770767
771768 for (auto includeFile : includeFiles)
772769 {
@@ -781,8 +778,6 @@ class MLIRGenImpl
781778
782779 auto notResolved = processStatements(module->statements, genContextPartial);
783780
784- genContextPartial.clean();
785-
786781 // clean up: erase only the ops this discovery pass added, preserving any content that
787782 // was already generated before a nested discovery (see preExistingOps above).
788783 clearTempModule();
@@ -5557,16 +5552,22 @@ class MLIRGenImpl
55575552 llvm::ScopedHashTableScope<StringRef, VariableDeclarationDOM::TypePtr>
55585553 fullNameGlobalsMapScope(fullNameGlobalsMap);
55595554
5555+ // owned here; GenContext borrows pointers to them (see GenContext::clean)
5556+ SmallVector<mlir::Block *> cleanUpsList;
5557+ SmallVector<mlir::Operation *> cleanUpOpsList;
5558+ PassResult passResultData;
5559+ int discoverState = 1;
5560+
55605561 GenContext genContextWithPassResult{};
55615562 genContextWithPassResult.funcOp = dummyFuncOp;
55625563 genContextWithPassResult.thisType = genContext.thisType;
55635564 genContextWithPassResult.thisClassType = genContext.thisClassType;
55645565 genContextWithPassResult.allowPartialResolve = true;
55655566 genContextWithPassResult.dummyRun = true;
5566- genContextWithPassResult.cleanUps = new SmallVector<mlir::Block *>() ;
5567- genContextWithPassResult.cleanUpOps = new SmallVector<mlir::Operation *>() ;
5568- genContextWithPassResult.passResult = new PassResult() ;
5569- genContextWithPassResult.state = new int(1) ;
5567+ genContextWithPassResult.cleanUps = &cleanUpsList ;
5568+ genContextWithPassResult.cleanUpOps = &cleanUpOpsList ;
5569+ genContextWithPassResult.passResult = &passResultData ;
5570+ genContextWithPassResult.state = &discoverState ;
55705571 genContextWithPassResult.allocateVarsInContextThis =
55715572 (functionLikeDeclarationBaseAST->internalFlags & InternalFlags::VarsInObjectContext) ==
55725573 InternalFlags::VarsInObjectContext;
@@ -6091,7 +6092,8 @@ class MLIRGenImpl
60916092 auto funcGenContext = GenContext(funcDeclGenContext);
60926093 funcGenContext.clearScopeVars();
60936094 funcGenContext.funcOp = funcOp;
6094- funcGenContext.state = new int(1);
6095+ int funcState = 1;
6096+ funcGenContext.state = &funcState;
60956097 // if funcGenContext.passResult is null and allocateVarsInContextThis is true, this type should contain fully
60966098 // defined object with local variables as fields
60976099 funcGenContext.allocateVarsInContextThis =
@@ -6124,8 +6126,6 @@ class MLIRGenImpl
61246126 functionLikeDeclarationBaseAST, funcProto->getNameWithoutNamespace(), funcOp, funcProto, funcGenContext);
61256127 }
61266128
6127- funcGenContext.cleanState();
6128-
61296129 if (mlir::failed(resultFromBody))
61306130 {
61316131 return {mlir::failure(), funcOp, "", false};
0 commit comments