-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[CIR] Implement NRVO variable cleanup #170774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,7 +106,7 @@ CIRGenFunction::emitAutoVarAlloca(const VarDecl &d, | |
| cir::ConstantOp falseNVRO = builder.getFalse(loc); | ||
| Address nrvoFlag = createTempAlloca(falseNVRO.getType(), | ||
| CharUnits::One(), loc, "nrvo", | ||
| /*arraySize=*/nullptr, &address); | ||
| /*arraySize=*/nullptr); | ||
| assert(builder.getInsertionBlock()); | ||
| builder.createStore(loc, falseNVRO, nrvoFlag); | ||
|
|
||
|
|
@@ -835,7 +835,24 @@ template <class Derived> struct DestroyNRVOVariable : EHScopeStack::Cleanup { | |
| QualType ty; | ||
|
|
||
| void emit(CIRGenFunction &cgf, Flags flags) override { | ||
| assert(!cir::MissingFeatures::cleanupDestroyNRVOVariable()); | ||
| // Along the exceptions path we always execute the dtor. | ||
| bool nrvo = flags.isForNormalCleanup() && nrvoFlag; | ||
|
|
||
| CIRGenBuilderTy &builder = cgf.getBuilder(); | ||
| mlir::OpBuilder::InsertionGuard guard(builder); | ||
| mlir::Location loc = addr.getPointer().getLoc(); | ||
|
||
| if (nrvo) { | ||
| // If we exited via NRVO, we skip the destructor call. | ||
| mlir::Value didNRVO = builder.createFlagLoad(loc, nrvoFlag); | ||
| mlir::Value notNRVO = builder.createNot(didNRVO); | ||
| cir::IfOp::create(builder, loc, notNRVO, /*withElseRegion=*/false, | ||
| [&](mlir::OpBuilder &b, mlir::Location) { | ||
| static_cast<Derived *>(this)->emitDestructorCall(cgf); | ||
| builder.createYield(loc); | ||
| }); | ||
| } else { | ||
| static_cast<Derived *>(this)->emitDestructorCall(cgf); | ||
| } | ||
| } | ||
|
|
||
| virtual ~DestroyNRVOVariable() = default; | ||
|
|
@@ -851,7 +868,9 @@ struct DestroyNRVOVariableCXX final | |
| const CXXDestructorDecl *dtor; | ||
|
|
||
| void emitDestructorCall(CIRGenFunction &cgf) { | ||
| assert(!cir::MissingFeatures::cleanupDestroyNRVOVariable()); | ||
| cgf.emitCXXDestructorCall(dtor, Dtor_Complete, | ||
| /*forVirtualBase=*/false, | ||
| /*delegating=*/false, addr, ty); | ||
| } | ||
| }; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was wrong. It was overwriting the
Addressin this function that is tracking the variable we're emitting. The incubator passes a separateallocaAddrargument here, which is also wrong but that variable isn't used in the incubator so it doesn't cause problems. Classic codegen has anAllocaAddrvariable, but it doesn't pass it toCreateTempAllocain this part of the code.