This is an archive of the discontinued LLVM Phabricator instance.

[ADT] Implement the Waymarking as an independent utility
ClosedPublic

Authored by ekatz on Feb 11 2020, 7:55 AM.

Details

Summary

This is the Waymarking algorithm implemented as an independent utility.
The utility is operating on a range of sequential elements.
First we "tag" the elements, by calling fillWaymarks.
Then we can "follow" the tags from every element inside the tagged range, and reach the "head" (the first element), by calling followWaymarks.

Diff Detail

Event Timeline

ekatz created this revision.Feb 11 2020, 7:55 AM

Hi Ehud,

Thank you for the patch, can you elaborate on why this is a good thing to do? Is there another client of this functionality that you expect?

-Chris

+River in case you're interested in this.

Hi Ehud,

Thank you for the patch, can you elaborate on why this is a good thing to do? Is there another client of this functionality that you expect?

-Chris

Hi Chris,
I use this in another project built on top of LLVM, so I thought to share it.
It may be used in other projects as well; fir example, MLIR or Swift, in the same manner as it is used in the llvm::Use class.
We may also use this utility in the llvm::Use class itself, once it is in, to remove duplications.

RVP added a subscriber: RVP.EditedFeb 29 2020, 11:35 AM

Is there a reason why MLIR doesn't do this? The representation of Use and UseList in MLIR seems a little different from how it is done in llvm::Use.

In MLIR, IROperand points back to the Operation via the owner field.

ekatz added a comment.Mar 3 2020, 1:50 AM
In D74415#1899650, @RVP wrote:

Is there a reason why MLIR doesn't do this? The representation of Use and UseList in MLIR seems a little different from how it is done in llvm::Use.

In MLIR, IROperand points back to the Operation via the owner field.

I guess this is a question for @lattner or @rriddle.

This question would be best for River. MLIR is using a simpler approach, it isn't clear to me whether Waymarking would be worth it, but it should be possible to benchmark it now.

rriddle added a comment.EditedMar 3 2020, 10:04 AM

Using waymarking would be a nice memory savings(~1 word per operand). The main complaint I've heard about waymarking is the debuggability aspect of it.

Cool. Do you have time to review this patch for Ehud? he's been very patiently pinging

rriddle added a comment.EditedMar 4 2020, 11:35 AM

Looks mostly good to me. I think the main thing is that more documentation would be nice, waymarking can be extremely hard to follow at times if you aren't familiar with it. This is why it took me a bit to review, I had to make sure that I could follow all of the different templates correctly. That being said, I'm not sure that I am comfortable enough doing the final approval here.

llvm/include/llvm/ADT/Waymarking.h
120

Can you add better documentation for this? I know this is an implementation detail, but it would help those of us that don't really know waymarking that well.

213

Why use < instead of == or !=? This seems to apply a specific iterator pattern. For example, I don't think this would work for llvm::Use which may be allocated before the User. In that case the tags are assigned in reverse, with the end of the array being assigned the full stop tag. Could you add support and a test case for this potential usage?

217

Can you please add more comments on the specific things going on here?

228

Seems like Count is assigned to the same in both branches, can we de-duplicate?

llvm/unittests/ADT/WaymarkingTest.cpp
19

nit: Can you please hoist all of these static functions into the global namespace and mark them with 'static'? LLVM style is to generally only use anonymous namespaces for classes(or in this case, TEST).

foad added a subscriber: foad.Mar 5 2020, 1:14 AM
foad added inline comments.
llvm/include/llvm/ADT/Waymarking.h
42

Is the rightmost vertical line one bit too far to the right here?

ekatz marked 6 inline comments as done.Mar 5 2020, 10:21 AM

Thanks for the review! I really appreciate it, as I know this is a complicated one.
I'll add more documentation, and try to make it simpler/clearer.

llvm/include/llvm/ADT/Waymarking.h
42

Correct. I'll fix it.

120

Sure, I will.

213

You are correct. The more general case is to use the == and != operators. I'll change that.
Regarding llvm::Use, it has an inherent solution, using a reverse iterator on the use-array.

217

Will do.

228

Right. Will do.

llvm/unittests/ADT/WaymarkingTest.cpp
19

Will do.

ekatz updated this revision to Diff 249722.Mar 11 2020, 12:17 PM

Added changes as requested.

ekatz added a comment.Mar 17 2020, 9:27 AM

@rriddle does it seem better?

rriddle accepted this revision.Mar 18 2020, 10:55 AM

The docs made it much easier for me to follow, thanks!

llvm/unittests/ADT/WaymarkingTest.cpp
2

This looks incorrect.

This revision is now accepted and ready to land.Mar 18 2020, 10:55 AM
ekatz marked an inline comment as done.Mar 19 2020, 3:57 AM
ekatz added inline comments.
llvm/unittests/ADT/WaymarkingTest.cpp
2

Right. I'll fix that.

ekatz updated this revision to Diff 251360.Mar 19 2020, 6:06 AM

Merged with trunk.
detail::ValueOfRange was removed from "STLExtras.h".

This revision was automatically updated to reflect the committed changes.