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

    <tr>
        <th>Summary</th>
        <td>
            Add Profile-Guided Optimization (PGO) support to the Flang compiler
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang
      </td>
    </tr>

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

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

<pre>
    Similar to Clang, we need to support Profile-Guided Optimization (PGO) in Flang too. Use cases for having this optimization are completely the same as we have for Clang right now - have an ability to optimize better Fortran code based on the runtime information.

I propose adding the following PGO types for Flang:

* IR PGO (`-fprofile-generate`/`-fprofile-use` options in Clang)
* CS PGO (`fcs-profile-generate` in Clang). This option would be a good addition to IR PGO 
* Sampling PGO (AutoFDO + `-fprofile-sample-use` option in Clang). Having sampling PGO support is important if we want to collect PGO profiles directly from a production environment.

I think there is no need to implement FE PGO (`-fprofile-instr-generate`/`-fprofile-instr-use` options in Clang) in Flang since IR PGO is a better option according to the [issue](https://github.com/llvm/llvm-project/issues/45668).

As a reference, the Clang PGO [docs](https://clang.llvm.org/docs/UsersManual.html#profile-guided-optimization) can be used.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVMtu6zYQ_Rp6M4ghU5YfCy2cpErvokjQ9H7AiBxZ7KU4AknFcL6-IP2Ic5EWxd0ktDiPM-ccDoZg9o6oFtW9qB5nOMWeff2OA76jW5ofs5b1sX41g7HoITI8WHR7IR_gQOCIdPoWpnFkH-HFc2cs3T1NRpOG5zGawbxjNOxAyM3L07OQWzAOmlQEIvMcvgcChYECdOyhxzeTbnoTgG_T0RMoHkZLkewRYk8QcCDAkID0-EY5P6MDb_Z9BMcHuDtdoQNsjTXxmOCeCxO0FCN5aNhHjw4Ua4IWA2lgl1v4yUUzEBjXsR8ykrkoHkWxO_39BqPnkQMBan0CnnBYy4f06-XpGeJxPM-Whxbl7raAkDv49mcOFHIjVsVdN55J3JMjj5HEqhCy-XQ1hfQ1z8EuJELPqmw_qj683lTtVLj7ou5t5hz-upDODg48WQ0tAcKeWefx8kXkK95rq1ccRnuZV8jNborcPKbjPXzCHVLgT_A_Y_j9pH-4rXhxlwlghnRCF8F0SfdDOkYGxdaSijn83CyANp5UtEfoPA-A6UJPKvck92Y8u4Fc_EnP2Bv3I8noKTV0fDW5SdhTBjS_fSmYcSH6_5LtFPDv4n28jGCcogvRJgBerHrmDJVifzIcZ8-J6t6EMJGoHoXc9DGOITlNNkI2exP7qZ0rHoRsrH27_EuO-JtUFLLJuUHIZlmtVpukxC0ruwTAU0eenKL09lPL01PLRFT3mlX4qrdKQfPUbc5-L2STA2XzPZAPf6Cb0M77OFghy6s_8_K4u339iRuFLvlxCqTnM12XeltucUb1Yl0sqlVRLpazvsZVh1KW6wXqar3ZKKT1tq3UqlqXi61eVjNTy0KWC1lIWZabcjnfdiipUJrKdrVerJVYFjSgsVfMs8xNvV7KxWpmsSUb8rKUsjvJJtPe9HVmtJ32QSwLa0IMHxWiiZbqndb_c0FeDH_W9mSJtPyMJT-bvK1_XeA8xz8BAAD__8pw-Vw">