This is an archive of the discontinued LLVM Phabricator instance.

[NFC] factor out unrolling decision logic
ClosedPublic

Authored by Ali-Sed on Jul 14 2021, 10:12 AM.

Details

Summary

Decoupling the unrolling logic into three different functions. The shouldPragmaUnroll() covers the 1st and 2nd priorities of the previous code, the shouldFullUnroll() covers the 3rd, and the shouldPartialUnroll() covers the 5th. The output of each function, Optional<unsigned>, could be a value for UP.Count, which means unrolling factor has been set, or None, which means decision hasn't been made yet and should try the next priority.

Diff Detail

Event Timeline

Ali-Sed created this revision.Jul 14 2021, 10:12 AM
Ali-Sed requested review of this revision.Jul 14 2021, 10:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2021, 10:12 AM
Ali-Sed updated this revision to Diff 358662.Jul 14 2021, 10:35 AM

[WIP][NFC] factor out unrolling decision logic

mtrofin added a comment.EditedJul 15 2021, 7:58 AM

Thanks for fixing the commits! Please don't forget to add a commit message, both in git (i.e. git --amend and add a message), and then copy it in the summary here.

Like discussed offline, I think we should explore next splitting the logic of shouldUnroll into its constituent sub-pieces, i.e. shouldFullyUnroll, shouldPartiallyUnroll, etc; that will simplify their interface - the output of one of these can be an Optional<unsigned>, where the unsigned is the decided trip count (and None means 'no' such unrolling)

But maybe we can do that in a next patch - @jdoerfert , WDYT?

llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
1076

remove the commented line altogether, also the free space.

Ali-Sed updated this revision to Diff 360477.EditedJul 21 2021, 8:45 AM

[WIP][NFC]Seperating setting UP.count from other side parameters

jdoerfert added inline comments.Jul 21 2021, 9:05 AM
llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
896

Use a struct with a name, not a pair of bools. It is much harder to determine what the bools mean this way, if you return an object of type struct SomeGoodName { bool InfoA; bool InfoB; } it is clear what the bools mean.
Same in other places.

1013

We have duplication here. Can you query this once and put everything into a "info struct" and then pass that to all the functions here.

Make the functions static if you can.

Ali-Sed updated this revision to Diff 360552.EditedJul 21 2021, 12:19 PM

[WIP][NFC] Cleaning the params of functions --draft

Ali-Sed updated this revision to Diff 362088.Jul 27 2021, 10:33 AM

[WIP][NFC] Changing bool, as the return arg of unrolling logics, to optional<unsigned>

mtrofin accepted this revision.Jul 27 2021, 10:40 AM

Some nits, but lgtm assuming nits are fixed, tests pass, and also the message of this review is updated (e.g. remove WIP, and add a description for the change)

Wait for @jdoerfert if he has more feedback, too.

llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
811

return None; (same below)

935

Up.Count = *UnrollFactor. The check above ensures the dereference succeeds.

986

same as above - *UnrollFactor

1018

same as above - *UnrollFactor

This revision is now accepted and ready to land.Jul 27 2021, 10:40 AM
Ali-Sed updated this revision to Diff 362120.Jul 27 2021, 11:39 AM
Ali-Sed marked 2 inline comments as done.

[NFC] Decoupling the unrolling logic into three different functions. The shouldPragmaUnroll() covers the 1st and 2nd priorities of the previous code, the shouldFullUnroll() covers the 3rd, and the shouldPartialUnroll() covers the 5th. The output of each function, Optional<unsigned>, could be a value for UP.Count, which means unrolling factor has been set, or None, which means decision hasn't been made yet and should try the next priority.

Ali-Sed updated this revision to Diff 366778.Aug 16 2021, 6:01 PM
Ali-Sed marked 4 inline comments as done.

[NFC] Decoupling the unrolling logic
Decoupling the unrolling logic into three different functions. The shouldPragmaUnroll() covers the 1st and 2nd priorities of the previous code, the shouldFullUnroll() covers the 3rd, and the shouldPartialUnroll() covers the 5th. The output of each function, Optional<unsigned>, could be a value for UP.Count, which means unrolling factor has been set, or None, which means decision hasn't been made yet and should try the next priority.

mtrofin added inline comments.Aug 17 2021, 8:16 AM
llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
324

Nit: bool and unsigned don't get initialized, so to avoid nasty nondeterministic bugs, easiest to assign them on declaration, here, i.e. bool UserUnrollCount = false; unsigned PragmaCount = 0; etc. This improves also maintainability, because it's *much* easier for folks working with the code to follow the same pattern if they add more fields, and also figure out where the object is initialized (less reading required, basically)

767

do static_cast<uint64_t>(same stuff)

same below

895

delete this line, it's spurious

904

One thing to consider: if PragmaInfo are just carriers of those fields, and (currently) they are meant to be set once, I'd make the code even more maintainable if:

  • the fields were const
  • the struct had a ctor where you pass them and set them

that way, it's very clear that a PragmaInfo object has intentionally initialized fields, and also that they can't ever be changed.

938

why binary or? i.e. did you mean || ?

965

remove spurious line

1000

remove spurious line

1038–1039

line

1041

line

Ali-Sed retitled this revision from [WIP][NFC] factor out unrolling decision logic to [NFC] factor out unrolling decision logic.Aug 17 2021, 2:37 PM
Ali-Sed edited the summary of this revision. (Show Details)
jdoerfert accepted this revision.Aug 17 2021, 2:52 PM

LG for the high level change, @mtrofin mentioned changes then it's good to go.

Ali-Sed updated this revision to Diff 367093.Aug 17 2021, 7:16 PM
Ali-Sed marked 9 inline comments as done.

[NFC] fixing NITs

Ali-Sed updated this revision to Diff 367097.Aug 17 2021, 7:48 PM
Ali-Sed marked an inline comment as done.

[NFC] mergin temp branch and main

Ali-Sed updated this revision to Diff 367122.Aug 17 2021, 11:24 PM

[NFC] Fixing conflict issue

Ali-Sed updated this revision to Diff 367262.Aug 18 2021, 11:08 AM

[NFC] fixing merge conflicts

This revision was landed with ongoing or failed builds.Aug 18 2021, 11:22 AM
This revision was automatically updated to reflect the committed changes.

By including <optional> this makes LLVM require C++17, which it shouldn't: https://llvm.org/docs/CodingStandards.html#c-standard-versions

Ali-Sed reopened this revision.Aug 18 2021, 11:56 AM
This revision is now accepted and ready to land.Aug 18 2021, 11:56 AM
Ali-Sed updated this revision to Diff 367290.Aug 18 2021, 11:57 AM

[NFC] Fixing dependency to C++17

This revision was landed with ongoing or failed builds.Aug 18 2021, 12:05 PM
This revision was automatically updated to reflect the committed changes.