[llvm-dev] How to get analysis in a class which is not a LLVM pass?

Mehdi Amini via llvm-dev llvm-dev at lists.llvm.org
Wed Jul 13 13:57:07 PDT 2016


> On Jul 13, 2016, at 1:06 PM, Quentin Colombet via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> Hi,
> 
>> On Jul 13, 2016, at 1:03 AM, vivek pandya via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>> 
>> Hello,
>> 
>> I want to use ProfileSummaryInfo in a class which is not a LLVM pass like TargetFrameLowering class (lib/CodeGen/TargetFrameLoweringImpl.cpp) 
>> 
>> one way I know to get ProfileSummaryInfo is 
>> getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI(M);
>> but I can't use this.
>> 
>> Is this really possible? 
> 
> Not really. That would mean that anything that uses the method that access that information would need to depend on ProfileSummaryInfoWrapperPass, which is pretty bad from the software engineering standpoint.
> 
> Something possible is to use getAnalysisIfAvailable (or something like that, I haven’t checked the actual name), but that means you need to be able to work correctly if the pass is not available.

It is more complex than that: if the class where you need it is not a Pass itself (as Vivek mentions above), you can’t call getAnalysisIfAvailable either.

I believe the right way to do it is to extend the API to take an optional (or mandatory depending on what is done) extra object. Here it could be ProfileSummaryInfo for instance, but maybe something more targeted like a bool if all what’s needed is to answer “Am I processing a hot or cold function?”.

— 
Mehdi




> 
> Cheers,
> Q. 
> 
>> 
>> Sincerely,
>> Vivek
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
> 
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev



More information about the llvm-dev mailing list