<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58422>58422</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Profile Guided Optimization improved workflow
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ujos
      </td>
    </tr>
</table>

<pre>
    A few month ago I reported an idea to Microsoft about [improved PGO workflow](https://developercommunity.visualstudio.com/t/Profile-Guided-Optimization-experience/1654825). While on my project our target compiler is MSVC , from time to time we compile our code with LLVM and GNU C++ to find the best compiler that produces the fastest code. Because our code compiles on both MSVC and Clang compilers I wonder if you could also implement that idea so we can compare which binary is faster.

Following is a copy-paste from the [Microsoft Developer Community website](https://developercommunity.visualstudio.com/t/Profile-Guided-Optimization-experience/1654825)

I’d like to improve the workflow of how Profiler Guided Optimization (PGO) is used.

The current workflow
--------------------

The current workflow involves a lot of people and a lot of moving parts:

1.  Developer: Builds the instrumented binary
2.  Developer: Deploys the instrumented binary to User and asks User to run the instrumented binary
3.  User: Returns PGD file to developer after some time
4.  Developer: Builds the optimized version of the binary
5.  Developer: Deploys the optimized version of the binary to User

### The disadvantages of this approach are:

1.  User must contact the Developer after binary is profiled. Developer can be busy and is not able to rebuild the optimized binary quickly.
2.  User must contact the Develop again in case if conditions are changed and PGD file does not reflect the production behaviour.
3.  The developer must ensure that the PGD file applies to the code he is trying to rebuild (relink). E.g. it is undefined if PGD is applied to another version of the source code (some functions could be renamed/removed/modified)
4.  The developer must restore the entire environment to build the optimized binary for the given PGD file.

The optimized workflow
----------------------

The optimized workflow solves all issues of the current workflow by moving the responsibility to generate the final optimized binary from Developer to User. It is like what Java/.NET Runtime does. At first CLR interprets the byte code. After some time, when CLR got enough of statistics information it can compile the byte code into native assembly.

The improved workflow requires:

1.  The compiler to generate:  
    a. Instrumented binary file (dll or exe). It is already there, there is nothing to do here.  
    b. An intermediate byte code, which will be deployed to User as an archive (single file, no source code)
2.  The tool to generate an optimized binary. As an input to this tool following is provided:  
    a. An intermediate byte code created at step 1b. (archive)  
    b. PGD file

The sequence of actions is as following:

1.  Developer: Builds the instrumented binary and an intermediate byte code
2.  Developer: Deploys the instrumented binary and an intermediate byte code to User
3.  User: Runs the application on production
4.  User: When the production test is completed, User generates the final optimized binary and replaces the instrumented binary.
5.  Whenever the conditions are changed, the User runs the instrumented binary again and rebuilds the optimized binary.

I may be wrong, but theoretically it is possible to achieve the improved workflow by merging all lib and obj files into one lib file and running the MSVC++ linker on the User side. I afraid that may require full Visual Studio setup on the User side (linker, Windows SDK)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9V9ty4jgQ_Rp4UcUFhiTwwEMuM1PZnVvN9Vm2ZayJLHl1gWG_fk9LBhPCZKp2qzZFgmNJfTndfbpVmGq3umG12LLWaN8wvjbsgVnRGetFxbhmshKcecPeydIaZ2rPeGGCZ6PLW9l21myw7eObD2xr7GOtzHZ0eT_KF433nRvNbkb5a3wqsRHKdMKWpm2Dln6XbaQLXDkfKmkyvMYuj9-P1tRSiYs3AXqriw-dl638m3tp9IX4CQlS6FJg4_Tqcr7IL0f5MmPfGxxhRrN2x2DRD1F6ZoJlntu18AzSO2ywTDr27vO3OzbK71htTcsgXJBv8Xsr9jvj4dJUeCeBydu3394BiYq9ef-V3Y3yW3zoVC3xzjeCFcIdafEN92RGFUrh4nrNnU9bKpGxW1Hy4I6U9CcdeVAYKIxGksI7xfX6INkhMlujK_KkZjsTsBIUgqScYYiFEq3QPumPUcNrcgpBJBHcwp9Glg0rpOZ2R3BEy2w2mtyPJjfp72ujEEUJvVjnONntLjra1kMGfxD6IRvu97Fld_vgQmvhpBf_eyoc-_EwepWPFpPRclkxJR9jnPuEjU7s85WZmjX46tVZlvSxY33ImAVyHBoIFASvegLZF4grg7WE_qEM4srFmZ_fnWRSb4zaCEJfGU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