[llvm-dev] PGO — opt -instrprof pass programatically?

Xinliang David Li via llvm-dev llvm-dev at lists.llvm.org
Tue Oct 31 22:38:12 PDT 2017


On Tue, Oct 31, 2017 at 11:43 AM, Connor Gray via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hi,
>
> I’m working to add PGO to the IR I’m producing. Currently I’m using opt
> -instrprof to expand the llvm.instrprof_increment calls into runtime calls.


The intrinsic call won't be lowered into calls, but into counter update
inline sequence.


> I’d like to be able to do this programmatically instead, and avoid calling
> an external process.
>

Looks like you want to implement the instrumentation lowering.  Why do you
want to do that? Can you just invoke the InstrProfiling (lowering) pass?



>
> I gather from what I’ve read online that this is implemented inside of opt
> and clang using the InstrProf pass, but, frustratingly, I haven’t been able
> to track down how or where it’s invoked, or even defined. I’m aware of a
> large amount of the logic in InstrProf.cpp, but that doesn’t have a clear
> entry point. What I’ve read online always makes use of opt or clang, but
> does not show how to run this pass programatically.
>
> Is this even possible to do cleanly, or are the implementations closely
> tied to opt/clang?
>
> If somebody knows of any tutorials or examples of this they could share,
> that would be very helpful. Otherwise, direction towards the important
> locations in source would be useful.
>

You should look at Transforms/Instrumentation/InstrProfiling.cpp.  The file
named InstrProf.cpp under ProfileData dir defines common APIs for
instr-gen, lowering, and profile reading/writing.

David

>
>
> Thanks in advance,
> Connor
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171031/833e25b7/attachment.html>


More information about the llvm-dev mailing list