This is an archive of the discontinued LLVM Phabricator instance.

[Codegen] Have the generic debug skip functions return true on empty.
AbandonedPublic

Authored by iteratee on Dec 19 2016, 5:28 PM.

Details

Reviewers
MatzeB
fhahn
Summary

Overall this leads to simpler code even though a few cases are slightly longer.
NFC.

Diff Detail

Event Timeline

iteratee updated this revision to Diff 82043.Dec 19 2016, 5:28 PM
iteratee retitled this revision from to [Codegen] Have the generic debug skip functions return true on empty..
iteratee updated this object.
iteratee added a reviewer: fhahn.
iteratee set the repository for this revision to rL LLVM.
iteratee added a subscriber: llvm-commits.
fhahn edited edge metadata.Dec 20 2016, 3:02 AM

skipDebugInstructionsForward/Backward take the iterator by value and return the advanced iterator again, because it seemed more in line with C++'s iterator functions (like next and prev), @MatzeB suggested that in https://reviews.llvm.org/D27782#623009 .

In my opinion, it's obvious what the current implementation does by just looking at the call and having the end/beginning checks are in the caller's code, whereas the version proposed in this review is a little bit less obvious and the savings in code size seem quite small.

skipDebugInstructionsForward/Backward take the iterator by value and return the advanced iterator again, because it seemed more in line with C++'s iterator functions (like next and prev), @MatzeB suggested that in https://reviews.llvm.org/D27782#623009 .

Note that the standard also has ::advance(it, n) which works via side-effect, so the std can't decide one way or the other.

In my opinion, it's obvious what the current implementation does by just looking at the call and having the end/beginning checks are in the caller's code, whereas the version proposed in this review is a little bit less obvious and the savings in code size seem quite small.

Even without returning empty, I prefer the side effect version. It makes nearly all the call sites simpler.

probinson added inline comments.
lib/CodeGen/BranchFolding.cpp
1814

Seems like this ought to become

if (skipDebugInstructionsForward(TIB, TIE) ||
    skipDebugInstructionsForward(FIB, FIE))
  break;
lib/CodeGen/IfConversion.cpp
624

These two 'if's can be combined. Or if you prefer to leave them as they are, that's fine too. But put a space between 'if' and paren.

666

As above these could be combined if you like.

fhahn added a comment.Dec 20 2016, 2:09 PM

skipDebugInstructionsForward/Backward take the iterator by value and return the advanced iterator again, because it seemed more in line with C++'s iterator functions (like next and prev), @MatzeB suggested that in https://reviews.llvm.org/D27782#623009 .

Note that the standard also has ::advance(it, n) which works via side-effect, so the std can't decide one way or the other.

Oh yes of course! I guess it comes down to personal preference and that's not a call for me to make.

MatzeB requested changes to this revision.Jan 5 2017, 12:02 PM
MatzeB added a reviewer: MatzeB.

I'm not in favor of this. Reference parameters (that actually change a variable) are non obvious and should mostly be avoided in C++.
At least to me it is also not obvious what that return value is when seeing the name skipDebugInstructionsForward.

This revision now requires changes to proceed.Jan 5 2017, 12:02 PM
iteratee abandoned this revision.Jan 5 2017, 6:27 PM