Skip to content

[CIR][CIRGen] Convert trivial copy constructor and assignment operator calls to memcpy #1677

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 13 commits into from
Jun 26, 2025

Conversation

Arthur-Chang016
Copy link
Contributor

No description provided.

 - Modified the `forceCopy` function to demonstrate that the original member-by-member copy will be optimized out, resulting in a direct `cir.copy` operation.
 - Modified the expected output in derived-to-base.cpp to replace the copy constructor call with a direct cir.copy operation
 - Replace call operations with cir.copy for buffy and A class instances in vcall function
 - Replaced the expected copy constructor call with a direct cir.copy operation in the test for exception handling.
 - Updated the LLVM output to reflect the new memcpy operation for trivial copy constructs, aligning with recent optimizations in CIR code generation.
 - Update test1 to replace copy assignment with cir.copy operation
- Replaced expected copy constructor calls with direct cir.copy operations in the tests for both A and C structs.
- Updated LLVM output to reflect the new memcpy operation, aligning with recent optimizations in CIR code generation for trivial copy constructs.
 - Remove commented debug output from runOnOp function in LoweringPreparePass
@Arthur-Chang016
Copy link
Contributor Author

Reimplement the replacement of trivial copy constructor / assignment to cir.copy in the LoweringPrepare phase.

Key Features:

  • Find the FuncOp for the trivial copy and check if it's trivial by checking the AST info
  • Replaces them with direct cir.copy operations
  • Aggressive safety checks: Validates that constructor calls have no return values and exactly 2 operands (dst and src)
  • Leave the placeholder for future std::move (not sure if it will be handled here but looks suitable)

@Arthur-Chang016
Copy link
Contributor Author

Note that clang/test/CIR/CodeGen/eh.cpp is marked Expectedly Failed since it looks like there's CIR parsing issue.

tmp/test.cir:54:14: error: expected '{' to begin a region
    } catch [#cir.unwind {

@Arthur-Chang016
Copy link
Contributor Author

link issues / pr
#1616
#1202

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo few nits

@Arthur-Chang016
Copy link
Contributor Author

Thanks for the review!

@bcardosolopes bcardosolopes merged commit f87bee5 into llvm:main Jun 26, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants