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

    <tr>
        <th>Summary</th>
        <td>
            [HLSL] Fix global resource initialization
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            HLSL
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          llvm-beanz
      </td>
    </tr>
</table>

<pre>
    Currently we connect global resource initialization in `GenerateCXXGlobalInitFunc` (https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGDeclCXX.cpp#L1087), but this is really not the right place. This function can be called multiple times throughout compilation to generate different initializer functions.

Clang has a mechanism for collecting global initializer functions and including them in the final module initializer, we should instead use that mechanism by adding our initializer to CodeGenModule's CXXGlobalInits list.

We could either generate an initializer function per-resource (which I think is preferred), or we could generate a single initializer late, but either way we should not have a hook in the place it is today.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUU81u4zYQfhrqMohBUZZsH3RIHShdID21QHOlqLE4XYoUyGFS79MX1DqbBFig2BMBYv6-P50SzR6xF-1von2odGYbYu_cy3I3ovbfqjFM1_6cY0TP7gqvCCZ4j4ZhdmHUDiKmkKNBIE9M2tE3zRQ8kAfRyUf0GDXj-fn5cav_4omH7I3oJAh1tMxrEs29UINQw0xs87gzYRFqKEfcnrs1hn_QsFDD6MIo1LBo8kINxmk_lyIqn-cw4SOW__PjAxp3fn7emXUVqnmq5fEg1EmoM4yZgS0loAQRtXNX8KF8IUSaLcPqtMEd_FVqLtmbDY7RHkYEo53DCZbsmFaHwLRgArYx5NmGzGDCspL7TgEHmG_4YaLLBQuJ7zxh_DE-7YS8F_L-XPCA1Qk0LGis9pQWuIQIJjiHhsnPb8T_dA5oPwF54_JUStniUpQo4C7ktYMlTNnhx-bCyStCsiG70psY9QQ5IbDV_OGM8Qp62saGHD-t5wA37v_Yxgt1SPBJ8gSOEt9Q_l1MVJYhscX4TpL2P0UFK8a7Hz4T6vhqyVj4UmT0X4uOa8QLxojTTeMQvzu1LHmfDon8_Bk8OM345orbOa_6-oGQ4g2rX0q7DeHrG5ubSYC4bOcw6euumvpmOjUnXWFfH5p9t1eyVZXtT-OxOZru1DajORzkoRvbtj6ibPayOdQtVtQrqfa1qk-qlrJVu7qeal3L8XQ6qkvddWIvcdHkdiUMuxDnilLK2NdKdk1XOT2iS1uGlfr96c8noVRJ81uQ85zEXhYB0vsEJnZb7reG9gEG-vd_Ml3l6PpfTux2ahJquF370qv_AgAA___MlYlN">