-
Notifications
You must be signed in to change notification settings - Fork 100
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
[RFC] AggExprEmitter::VisitArrayInitLoopExpr implementation #1055
Comments
Ah, one thing I didn't consider is that |
CIR needs a better representation here, it's going to be hard to reconstruct the memcpy from individual initializations.
Yes, likely a higher level op for that (as mentioned above).
Note that we already have code that does that (generate CIR loops for init), see example in
I think so, you might need to tweak it a bit or even create another op, but +1 on the overall approach.
I like (a) best, but if you decide to experiment with (c), I would suggest emitting a cir.store we can later (loweringprepare) lower to memcpy if possible.
We can mark the op with a unitattr for
Nice catch, that can probably come as incremental work tho? |
If you can extend/rename it to cover more cases, sounds good to me. If after trying that it feels odd, probably a good indication for a new op. Maybe |
One extra thing to keep in mind: think about the use cases from |
I'm seeking implementation advice for the CIRGen implementation of AggExprEmitter::VisitArrayInitLoopExpr. The ArrayInitLoopExpr docs explain the context; I'm specifically concerned with the copy constructor use case (e.g. https://godbolt.org/z/66anjPxa5 shows the initialization loop emitted by CodeGen).
For starters, CodeGen has logic to convert such initializations to a memcpy where applicable. ClangIR generally avoids this though (e.g. https://godbolt.org/z/W9n11czTc), so I assume that's the case here too. We may want to flesh out ConstructorMemcpyizer to still emit memcpy for non-record fields, but that's unrelated to this particular issue.
The CodeGen implementation of VisitArrayInitLoopExpr emits a loop to initialize each element. I'd started implementing it similarly in CIRGen, and then came across the cir.array.ctor op, which serves a pretty similar purpose. My questions are:
cir.array.ctor
to implementVisitArrayInitLoopExpr
? (The rest of this issue can be ignored if the answer is no.)cir.array.ctor
currently expects each member to be initialized by calling a constructor. Should we (a) change it to allow arbitrary initialization so that we can also use it for arrays of non-record types, (b) leave the op alone and emit a loop insideVisitArrayInitLoopExpr
for non-record types, or (c) match CodeGen and emit memcpy for non-record types, so thatVisitArrayInitLoopExpr
is never entered for them? My inclination is either (a) or (c); (b) seems like a weird middle ground that's a bunch of extra work for no gain.cir.array.ctor
bails out if there's cleanups. I'm thinking the cleanups should be handled during the lowering of thecir.array.ctor
op itself instead of at the op creation site, but I haven't thought that through fully.The text was updated successfully, but these errors were encountered: