This is an archive of the discontinued LLVM Phabricator instance.

[BasicBlock] Add instructionsWithoutDebug methods to skip debug insts.
ClosedPublic

Authored by fhahn on Apr 14 2018, 2:14 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

fhahn created this revision.Apr 14 2018, 2:14 PM
mattd added inline comments.Apr 14 2018, 3:22 PM
include/llvm/IR/BasicBlock.h
185 ↗(On Diff #142527)

I realize \brief is used throughout this header, but I do not think that is necessary anymore, because the Doxygen.cfg has AutoBrief on.

include/llvm/IR/Instruction.h
703 ↗(On Diff #142527)

I like how you made this a struct instead of just a variadic function. I was exploring a similar solution, as discussed in the aforementioned thread, but had ambiguity issues with the base case. Looks like you cracked that! I like this.

I wonder if it makes more sense to push this up into Casting.h since it's as specific as isa<>.

aprantl accepted this revision.Apr 16 2018, 8:48 AM
aprantl added inline comments.
include/llvm/IR/BasicBlock.h
185 ↗(On Diff #142527)

Yes, please avoid \brief.
Bonus points for a separate NFC commit that removes \brief from the entire header :-)

This revision is now accepted and ready to land.Apr 16 2018, 8:48 AM
vsk requested changes to this revision.Apr 16 2018, 8:56 AM
vsk added subscribers: dblaikie, timshen, debug-info.

I like the direction this is going in :).

I think having an API like 'instructions_no_debug' or similar in BasicBlock would make the interface friendlier. For one, it'd signal to readers that skipping debug intrinsics is an established pattern. Also, I think it would be easier to change if, e.g we wanted update all existing users of the API to skip lifetime intrinsics too.

lib/Transforms/IPO/PartialInlining.cpp
853 ↗(On Diff #142527)

I think this changes the inline cost of debug info intrinsics from InstrCost to 0. That seems like a correct and worthwhile change, but would probably be best to tackle in a follow-up patch.

854 ↗(On Diff #142527)

Fwiw, I found the switch a little easier to read. I'm not sure it's a clear readability improvement to put these type checks into template parameters.

This revision now requires changes to proceed.Apr 16 2018, 8:56 AM
In D45657#1068834, @vsk wrote:

I like the direction this is going in :).

I think having an API like 'instructions_no_debug' or similar in BasicBlock would make the interface friendlier. For one, it'd signal to readers that skipping debug intrinsics is an established pattern. Also, I think it would be easier to change if, e.g we wanted update all existing users of the API to skip lifetime intrinsics too.

+1

include/llvm/IR/BasicBlock.h
198 ↗(On Diff #142527)

Indirection through a function pointer may not be optimized away - may be worth baking this into a functor type?

mattd added inline comments.Apr 16 2018, 4:25 PM
include/llvm/IR/BasicBlock.h
185 ↗(On Diff #142527)

Bonus points for a separate NFC commit that removes \brief from the entire header :-)

Challenge accepted.

In D45657#1068834, @vsk wrote:

I like the direction this is going in :).

I think having an API like 'instructions_no_debug' or similar in BasicBlock would make the interface friendlier. For one, it'd signal to readers that skipping debug intrinsics is an established pattern. Also, I think it would be easier to change if, e.g we wanted update all existing users of the API to skip lifetime intrinsics too.

Thanks for the feedback! I'll add a instructionsNoDebug function. I tried to make skipInsts as flexible as possible, but I am not sure if the flexibility is really needed. Should I remove it for now?

include/llvm/IR/BasicBlock.h
198 ↗(On Diff #142527)

Will do

unittests/IR/BasicBlockTest.cpp
17 ↗(On Diff #142527)

I'll remove this.

vsk added a comment.Apr 17 2018, 12:33 PM
In D45657#1068834, @vsk wrote:

I like the direction this is going in :).

I think having an API like 'instructions_no_debug' or similar in BasicBlock would make the interface friendlier. For one, it'd signal to readers that skipping debug intrinsics is an established pattern. Also, I think it would be easier to change if, e.g we wanted update all existing users of the API to skip lifetime intrinsics too.

Thanks for the feedback! I'll add a instructionsNoDebug function. I tried to make skipInsts as flexible as possible, but I am not sure if the flexibility is really needed. Should I remove it for now?

It should be possible to implement instructionsNoDebug succinctly without skipInsts, so I'd suggest removing it.

I think the is_{any,none}_of predicates could be generally useful, though. It'd make sense to add them as a follow-up.

fhahn updated this revision to Diff 142959.Apr 18 2018, 10:22 AM
fhahn retitled this revision from [Instruction,BasicBlock] Add is_none_of and skipInsts helper functions. to [BasicBlock] Add instructionsWithoutDebug methods to skip debug insts..
fhahn edited the summary of this revision. (Show Details)

Simplified things, only add methods to skip debug instructions.

The only problem with those functions is that we cannot reverse a filter_iterator at the moment, as needed for D45379. But I suppose that should be fixable too.

Thanks! This looks really nice.

vsk accepted this revision.Apr 18 2018, 7:30 PM

Thanks, lgtm as well. I sent out a patch to fix the issue with reversing filtered iterator ranges (https://reviews.llvm.org/D45792).

This revision is now accepted and ready to land.Apr 18 2018, 7:30 PM
This revision was automatically updated to reflect the committed changes.