When eliminating an unreachable block we must remove any call site
information for calls residing in the block.
This was originally found on a downstream target, and the attached x86
test case was produced by hand-modifying some MIR.
Differential D64500
[DebugInfo] Remove call sites when eliminating unreachable blocks dstenb on Jul 10 2019, 8:12 AM. Authored by
Details When eliminating an unreachable block we must remove any call site This was originally found on a downstream target, and the attached x86
Diff Detail Event TimelineComment Actions Wdyt of addressing this problem in a more general way, e.g. in MachineInstruction::eraseFromParent itself? edit: I meant to write MachineBasicBlock::eraseFromParent, but I think the point still stands. Comment Actions @dstenb The patch looks good! LGTM! Thanks for working on this!
That would be great and we would not need to worry about validity of the CallSitesInfo. But the thing is that we have a problem with the MI range deletion from the MBB (see for example MachineOutliner::outline or version before this feature for TargetInstrInfo::ReplaceTailWithBranchTo). Such deletions cannot be generalized. For now, there are just two of such cases but in further we may stumble across more. Comment Actions Thanks for humoring me :). I haven't actively worked in this area, so I may be missing important/subtle details here. But ISTM that range deletion within MachineBasicBlock can be handled generically as well ('if any MI in the range is a call ...'). It doesn't seem too far-fetched to teach all APIs that unlink an MI from the instruction list to update call site info. Perhaps this would incur a little extra overhead if, say, an MI is unlinked and subsequently re-inserted somewhere else. In this case there might be two updates instead of one. However, I'd argue that the cost is likely justified if it makes the Machine* APIs safe to use from a debug info correctness perspective. Has this already been tried, and been shown to be too expensive in compile-time benchmarking? Comment Actions I just want to add that I was a bit hesitant about generalizing the removal as I think it can be quite hard to tell when call site information has been removed, so I thought it would be better to have asserts trigger for each individual case, so that we can detect and assess what to do there, rather than dropping the information silently at the risk of false negatives. The reason why I think it's hard to see that call site information has been removed is that, as far as I can tell there is no way to print the function attributes when doing something like -print-{before,after}-all, so it can be hard to to see where in the pass pipeline the callSites information was dropped. You could of course analyze the MIR and see where the information is likely to have been dropped, but I guess that can be difficult/annoying for larger programs. However, perhaps there are no cases where we erase a block, and at the same would want to redirect call site information for calls inside that block so that it points to (newly created?) calls in other blocks. My concerns may be unfounded, and it should be fine to silently drop the call site information when erasing the block. I'm not sure though. Comment Actions I hadn't realized there was an assert in DeleteMachineInstr. That sounds like a reasonable/systematic way to find missed updates. That addresses my main concern :).
Oh, I thought r364506 (D61061) implemented MIR printer support for call site metadata. If not, it's probably worth adding.
I think the current approach is fine. I don't yet see the need to pursue the alternative (updates in *::eraseFromParent). Comment Actions
This dumps the CallSitesInfo when we producing a ".mir" file. The CallSitesInfo describes an internal state of the MF like the fixedStack, frameInfo etc. I'm not sure how we could make it recognizable in -print-{before,after}-all. Maybe like some metadata extension of call instruction. However, it should be part of another patch. We share your concerns. We were not sure either. That's why we requested one more reconsideration after the patch was already accepted at D61062 and perhaps for the reasons you mentioned it is decided to go with assertion & addressing the missing parts. Thanks for contribution! Comment Actions Thanks for the reviews, and sorry for taking some time to land this! Yes, that was a bit of a sloppy comment by me. I think that it would be easier if the information was visible when printing using the -print* options, but you can of course -stop-{before,after} your way through the passes to pinpoint where the information is dropped. |