This is an archive of the discontinued LLVM Phabricator instance.

[llvm] Add function feature extraction analysis
ClosedPublic

Authored by mtrofin on May 26 2020, 12:14 PM.

Details

Diff Detail

Event Timeline

mtrofin created this revision.May 26 2020, 12:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 26 2020, 12:14 PM
jdoerfert added inline comments.May 26 2020, 3:40 PM
llvm/lib/Analysis/ML/InlineFeaturesAnalysis.cpp
13

Note: We could count Uses with getNumUses instead. For inlining there is probably no difference as non-callee uses cannot be inlined anyway, though I somehow feel it might be cleaner.

30

This seems to be a very crude approximation. Do we have to be super fast here or would it make sense to improve on this? I mean, if I read ConditionallyExecutedBlocks I assume blocks not post-dominating the entry of a function, though this counts something else. Simplest example to see the difference is if (a) s(); which would result in 3 blocks, and ConditionallyExecutedBlocks would say 2, though I argue it should be 1.

Either way, we should rename *and* document the Result members. InternalCalls seems to count calls to definitions, not to internal functions.

mtrofin updated this revision to Diff 266383.May 26 2020, 5:06 PM
mtrofin marked 3 inline comments as done.

renamed & documented members

llvm/lib/Analysis/ML/InlineFeaturesAnalysis.cpp
30

Agreed it's crude. We'd want to improve the feature set subsequently in a number of ways, I left a FIXME here with your example, and also renamed / documented members.

Last high-level comment: Should we call this "FeatureAnalysis" (without the Inline)? I can see us reusing this for other (ML) purposes. Nothing in this code is really tied or specific to the inliner I guess.

That said, I think the "analysis" is reasonable given the FIXME (thx!). It is clear there is improvement potential and the results are properly named and described.

llvm/include/llvm/Analysis/ML/InlineFeaturesAnalysis.h
33

Nit: We now count Uses, not Users.
Nit: uint64_t as all are counts.

Last high-level comment: Should we call this "FeatureAnalysis" (without the Inline)? I can see us reusing this for other (ML) purposes. Nothing in this code is really tied or specific to the inliner I guess.

That said, I think the "analysis" is reasonable given the FIXME (thx!). It is clear there is improvement potential and the results are properly named and described.

I'd prefer waiting to see another usecase before renaming, or potentially refactoring (depends on what we'll learn when we get to that usecase) - wdyt?

mtrofin updated this revision to Diff 266392.May 26 2020, 6:43 PM
mtrofin marked an inline comment as done.

feedback

mtrofin marked an inline comment as done.May 26 2020, 6:45 PM
mtrofin added inline comments.
llvm/include/llvm/Analysis/ML/InlineFeaturesAnalysis.h
33

Done the rename part.

Re. signedness / unsignedness: initially, I had them as size_t, but:

  • tensorflow works with signed values, and it is the main consumer of this data
  • one other use in the (next CL) MLInlineAdvisor is to delta-update some module-wide values (like total nr of edges in a module). With uint64_t, we need to be very careful with how that update happens (subtractions can silently overflow).

With signed int, that's not a problem.

jdoerfert added inline comments.May 26 2020, 10:13 PM
llvm/include/llvm/Analysis/ML/InlineFeaturesAnalysis.h
33

Fair enough.

mtrofin marked 2 inline comments as done.May 27 2020, 10:43 AM
mtrofin added inline comments.
llvm/include/llvm/Analysis/ML/InlineFeaturesAnalysis.h
33

Is the patch good to go?

Thanks!

jdoerfert accepted this revision.May 27 2020, 1:09 PM

I don't think this will impact anyone right now so there is little risk. LGTM

This revision is now accepted and ready to land.May 27 2020, 1:09 PM
This revision was automatically updated to reflect the committed changes.
mtrofin marked an inline comment as done.
MaskRay added a subscriber: MaskRay.EditedMay 27 2020, 3:28 PM

We should use add_llvm_component_library and LLVMBuild.txt instead of LINK_LIBS (LINK_LIBS are used for system libraries like pthread). There is also a missing dependency in LLVMPasses.

I fixed it in 993bbaf6a35baed4ad3d8422a76c4311140641a8

rriddle added inline comments.
llvm/include/llvm/Analysis/ML/InlineFeaturesAnalysis.h
2

These files are missing license headers BTW. Not sure if that was intentional.

mtrofin marked 2 inline comments as done.Jun 15 2020, 4:40 PM
mtrofin added inline comments.
llvm/include/llvm/Analysis/ML/InlineFeaturesAnalysis.h
2

It wasn't - let me correct that. I'll send a patch shortly and link it here.

mtrofin marked 3 inline comments as done.Jun 15 2020, 4:50 PM
mtrofin added inline comments.
llvm/include/llvm/Analysis/ML/InlineFeaturesAnalysis.h
2