add one use check to lookThruCopyLike.
The root node is safe to be deleted if we are sure that every definition in the copy chain only has one use.
https://reviews.llvm.org/D92071 is a user of this modified function.
Differential D92069
[NFC] [TargetRegisterInfo] add one use check to lookThruCopyLike. shchenz on Nov 24 2020, 7:44 PM. Authored by
Details add one use check to lookThruCopyLike. The root node is safe to be deleted if we are sure that every definition in the copy chain only has one use. https://reviews.llvm.org/D92071 is a user of this modified function.
Diff Detail
Event TimelineComment Actions Sorry to point this out now, but taking a bool in/out pointer is some Thanks! -eric Comment Actions Yes, I am happy to change this to another version. Do you think returning std::pair<Register, bool> is an acceptable way? Comment Actions I'd like to avoid the bool completely if possible. Passing the register Do you have the follow on patch? -eric Comment Actions I don't have the follow on yet. Sorry, I am not very clear about the passing the register method to avoid the bool type. Could you please give me more details? Thanks. User patch of this API is in patch D92071 Comment Actions Thanks @echristo for bring up this. We are happy to change it for better code. However, can you help us to understand the reason, and any advice about how to design this API? As we are seeing quite decent similar usages in the code base, $ grep "bool \*" llvm/include/llvm -R |wc 53 332 5185 If this is general, do you think it worth mentioning in ProgrammersManual? Comment Actions I don't see an issue in providing two functions to achieve the two different goals: lookThruCopyLike() // Look through a chain of copies. lookThruSingleUseCopyChain() // Look through a chain of copies, checking that each def has a single use. Also, I am a little curious about what this change is meant to accomplish. The name of the introduced bool parameter is AllDefHaveOneUser yet we don't actually check all defs - we only check the final one that we are returning. So it is presumably possible to have something like this (all regs virtual): %1 = ... %2 = SUBREG_TO_REG %1, ... %3 = COPY %2 %4 = SUBREG_TO_REG %2 %5 = COPY %4 %6 = COPY %4 %7 = <some use of %4> %8 = <some use of %5> %9 = <some use of %6> Running lookThruCopyLike() on %9 will presumably correctly return %1 and if a bool argument is passed, it will be set to true. I would argue that this is a surprising result since I would expect AllDefHaveOneUser to mean that all the definitions traversed (%9, %6, %4, %2, %1) have a single use. But this is clearly not the case. Am I just missing something? Comment Actions LGTM now. Maybe give @echristo a bit of time to see if this adequately addresses his original concern.
|
You should document what it's doing ahead of time as well. It's not clear when and how you'd use this function.