Currently, when the branch is unswitched, the newly created branch does not copy the metadata (like branch_weights) from the old branch.
Can you upload a full context diff please? It's hard to assess what you're changing with the current limited context.
The general direction seems workable.
A couple of questions:
- Are we sure the direction of the branches are the same? If not, we may need to invert the profile metadata.
- Should we passing in the original terminator? Or just information about the metadata? Once I have context, I may have suggestions in this area.
- You should white list the metadata. Not all metadata will neccessarily apply.
- White list the metadata to be copied. Currently, prof and dbg nodes are copied.
- Handle the case if True/False is swapped in the new branch
- I prefer passing "Instruction*" instead of "SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs" because 1) the latter is much longer 2) each call site needs to prepare the vector and call getAllMetadata().