-
Notifications
You must be signed in to change notification settings - Fork 103
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
Represent all assignment operator calls in the IR #1177
Comments
Not necessarily, we could look at the node children to realize a EDIT: Maybe changing the AST could be the long term solution, my point is that it shouldn't block us to make this happen since it's fairly orthogonal |
The visitor already exists here. The problem is that the AST doesn't distinguish between arrays of primitive types (which we'd still want to memcpy) and arrays of trivial structs: https://godbolt.org/z/xcMbd8qPT. We can examine the field type in that visitor, but if the visitor says the field isn't memcpyable we'll fall back to CGF.emitStmt, which will translate that AST node into a memcpy anyway. We can special case that again, but it seems kinda ugly vs. changing the AST. https://godbolt.org/z/fhbM8ajja is an example with a non-trivial assignment operator for reference, and the generated AST contains a full initialization loop. I'm also including the default copy constructor for reference, and it's interesting that it has a much higher-level representation ( |
Our previous logic here was matching CodeGen, which folds trivial assignment operator calls into memcpys, but we want to avoid that. Note that we still end up emitting memcpys for arrays of classes with trivial assignment operators; #1177 tracks fixing that.
I think it's totally reasonable if high level code for this is just a thin wrapper for starters (e.g. a new operation with all this logic happen within it's region), this way we don't have to deviate from CIRGen, and will delimit initialization code altogether, such that when we get fancy with analysis we can then play more with additional abstractions. |
ClangIR tries to represent all function calls in the IR (e.g. CodeGen omits calls to trivial constructors but CIRGen keeps them). One exception I've discovered is around calling
operator=
for an array member when generating a defaultoperator=
. https://godbolt.org/z/nEE46ff9d is an example; for the following code:The generated code for
T::operator=
does amemcpy
for thearr
field instead of emitting the individualS::operator=
calls for each array member.This stems from how CIRGen (and CodeGen) generate default assignment operators. Clang generates an AST representation of the assignment operator, which already contains a
__builtin_memcpy
call for thearr
field, and then CIRGen emits code for that AST. We'd need to change the AST itself to not generate a memcpy here.The text was updated successfully, but these errors were encountered: