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
Constant
handles have been used during lowering. Even if I reserve the next range ofMachLabel
s after the number of blocks for constants, we still need to keep track of a map ofConstant
toMachLabel
so I can see if we've used a constant previously.Additionally, some structure needs to map those
MachLabel
s back to their constant data so they can actually be emitted once we have aMachBuffer
available duringVCode::emit
. So we need another map ofMachLabel
toConstantData
so that we can then callMachBuffer::defer_constant
after all instructions have been emitted. This map must be separate from theConstant
toMachLabel
map because during lowering we can generate new constants that will not have aConstant
handle (since we can't modify theConstantPool
inself.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 23 2024 at 12:05 UTC