abrown commented on Issue #2328:
At a high level: I think we can actually do things with one less level of indirection
If we want to retain the de-duplication of constants from the constant pool AND avoid comparing long byte sequences, we need to keep track of what
Constanthandles have been used during lowering. Even if I reserve the next range ofMachLabels after the number of blocks for constants, we still need to keep track of a map ofConstanttoMachLabelso I can see if we've used a constant previously.Additionally, some structure needs to map those
MachLabels back to their constant data so they can actually be emitted once we have aMachBufferavailable duringVCode::emit. So we need another map ofMachLabeltoConstantDataso that we can then callMachBuffer::defer_constantafter all instructions have been emitted. This map must be separate from theConstanttoMachLabelmap because during lowering we can generate new constants that will not have aConstanthandle (since we can't modify theConstantPoolinself.f.dfg).Now, where we put these two maps is debatable (they could go in the same struct, different structs, be attached to
Lower, etc.) but I don't see how we get rid of either of them. What do you think?
cfallin commented on Issue #2328:
Hmm, yes, you're right; I hadn't been considering how deduplication would work. I agree that we need some sort of remapping in order to redirect duplicated constants to the original copy.
I do think that it would be good to find a way to make the deduplication optional; I want to keep the "only do the barebones fast code emission" path as true to that original spirit as possible. Given that many constants will be coming from the CLIF anyway, where they're deduplicated already, I would hope not to lose too much by omitting this (though we can certainly measure!). From your design here, it seems that we could do this with a hybrid data-structure of some sort; maybe an enum with
VCodeConstantTable::List { constants: Vec<ConstantData> }andVCodeConstantTable::Deduped { constants: HashMap<ConstantData, VCodeConstant> }?
Last updated: Dec 13 2025 at 19:03 UTC