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

    <tr>
        <th>Summary</th>
        <td>
            Should available_externally functions be PGO instrumentable at all?
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            PGO,
            LTO,
            llvm:transforms
      </td>
    </tr>

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

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

<pre>
    There are some lit tests in the https://github.com/llvm/llvm-project/tree/main/llvm/test/Transforms/PGOProfile directory that check specific behavior for PGO Instrumentation generation for functions with the `available_externally` linkage e.g., https://github.com/llvm/llvm-project/blob/main/llvm/test/Transforms/PGOProfile/profdata_priv_alias.ll and https://github.com/llvm/llvm-project/blob/main/llvm/test/Transforms/PGOProfile/comdat_rename.ll

The [`InstrProfiling`](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp#L1114) pass  has some special handling for `available_externally` functions. Also, I've found this commit https://github.com/llvm/llvm-project/commit/9c056c9e1b65eb7d06970e9ea94ba76f622b85e1 from @vedantk with the following description:

```
Emitting the function definition into the object file at all appears to
be a violation of the langref: "Globals with 'available_externally'
linkage are never emitted into the object file corresponding to the LLVM
module."
```

But, [unfortunatelly], such functions are emitted sometimes. I saw this some times and didn't manage any system in this: definitions for `available_externally` functions may be emitted but for the same code only function declarations may be emitted under other conditions, I'm not sure. Anyway, usually such definitions are the simplest one and contains the `ret` instruction only.

And my question is the following: should such functions, with the `available_externally` linkage, be instrumented at all? If the functions were ignored, the special handling in some passes (in `InstrProfiling`, at least) would be able to be eliminated. Because the `available_externally` linkage means that there is the "master copy" of the function, this master copy must be instrumented. Also, because the emitted definitions for `available_externally` functions has the simplest possible form, I believe this makes no sense to instrument this form at all.

What do you think?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vl9v67Y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