This is an archive of the discontinued LLVM Phabricator instance.

[FunctionPropertiesAnalysis] Add `PreciseFunctionPropertiesAnalysis`
Needs ReviewPublic

Authored by uenoku on Sep 12 2021, 10:48 AM.

Details

Summary

This patch adds an another analysis pass which is similar to FunctionPropertiesAnalysis to get more function features like
numbers of instructions, basic blocks, and so on.

Diff Detail

Event Timeline

uenoku created this revision.Sep 12 2021, 10:48 AM
uenoku requested review of this revision.Sep 12 2021, 10:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 12 2021, 10:48 AM
uenoku added a comment.EditedSep 12 2021, 10:52 AM

@jdoerfert @mtrofin
Currently, I created a new pass because I'm not sure additional costs to calculates new features are affordable at MLInliner.
I'd like to put new features on FunctionPropertiesInfo if computational costs don't matter.

And if you wish to add other features not listed here, please let me know.

@jdoerfert @mtrofin
Currently, I created a new pass because I'm not sure additional costs to calculates new features are affordable at MLInliner.
I'd like to put new features on FunctionPropertiesInfo if computational costs don't matter.

We could always make it an argument for the pass, e.g., when you create it you select the precision. Or, a command line option to get higher/lower precision. I think by default it should track all features and we can have subsets defined in a command line option if necessary. So if a user wants only 10 of the 40 features they add a selector into a command line enum and use it to skip features.

Wdyt?

We could always make it an argument for the pass, e.g., when you create it you select the precision. Or, a command line option to get higher/lower precision. I think by default it should track all features and we can have subsets defined in a command line option if necessary. So if a user wants only 10 of the 40 features they add a selector into a command line enum and use it to skip features.

Creating an argument for the pass sounds good for me. IMHO, we don't need command option for the pass because I guess all use cases are from LLVM internal.

mtrofin added inline comments.Sep 13 2021, 7:34 AM
llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
85

Nit: Is it "Precise" or "Detailed"?

101

please expose these through a getter, and hide the setter. It simplifies maintenance - easier to read and reason about code when it's easy to find where state can be mutated

uenoku updated this revision to Diff 373469.Sep 19 2021, 12:10 PM

Add setters/getters and rename the class name.

uenoku added a comment.EditedSep 19 2021, 12:20 PM

We could always make it an argument for the pass, e.g., when you create it you select the precision. Or, a command line option to get higher/lower precision. I think by default it should track all features and we can have subsets defined in a command line option if necessary. So if a user wants only 10 of the 40 features they add a selector into a command line enum and use it to skip features.

On the second thought, I think it is better to separate the pass.
Currently, FunctionPropertiesInfo is specialized for MLInliner and intended to be used practically.
We might want DetailedFunctionPropertiesInfo to be very rich analayzer which do not much care about the runtime cost.
Users can use the features of DetailedFunctionPropertiesInfo in experimentally until they find the essential features for their applications.

Wdyt?

mtrofin added inline comments.Sep 27 2021, 8:13 AM
llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
92

does the visitor need to be public?

llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
143

make 500 a flag (it's arbitrary otherwise. well... it's arbitrary after that, too, but at least it's user-controllable.). same with 15 below

156

style: capitalize variables. since you have an "I", maybe s/i/OpIdx

171

unsigned LoopDepth

eopXD added a subscriber: eopXD.Apr 4 2022, 1:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2022, 1:08 AM

@uenoku I'm interested in getting this patch into upstream LLVM and addressing the other reviewer comments. Do you mind if I commandeer this revision and tag you as a co-author on the eventual commit?

I talked with @mtrofin briefly (only covering flags/separate pass), and the plan is as follows

  • address remaining inline comments
  • Refactor DetailedFunctionPropertiesAnalysis into FunctionPropertiesAnalysis and keep the additional options behind a command line flag. I would like to use actual pass options here similar to how passes like instcombine can take in arguments, but the new pass manager doesn't seem to currently have support for analysis passes with parameters like is present for traditional function passes. I'm not sure how difficult it would be to get this implemented, but it doesn't look trivial.
  • Address additional comments, land the patch.