Do not emit references to dead labels (spacetime)#9097
Do not emit references to dead labels (spacetime)#9097mshinwell merged 3 commits intoocaml:trunkfrom
Conversation
248c965 to
3f4c437
Compare
|
Meta-level note: I wonder how important it is to work on fixing spacetime instrumentation in trunk. Last I heard, instrumentation tools where only available for an older version of OCaml, so people would basically use those versions to profile their programs. Are there active users of Spacetime on recent OCaml versions in the wild? If you do not presently have an active need for Spacetime, maybe it's reasonable to invest less resources into fixing it right now. |
|
@gasche We're using Spacetime to profile Flambda 2.0, so "yes" :) The existing tools work just fine. |
mshinwell
left a comment
There was a problem hiding this comment.
This is ok for merging after comments addressed.
67e84d0 to
50c76ed
Compare
|
This should probably be backported to 4.10. The issue it fixes was introduced in PR #2321 which is included in 4.10. |
|
(Backporting sounds sensible to me, but I don't have time to do it now. Whoever should feel free to do it, please use |
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26)
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
ocaml#8938 from upstream trunk (cherry-pick 4353c75) ocaml#9090 from upstream trunk (cherry-pick fe7c8ed) ocaml#9097 from upstream trunk (cherry-pick 6daaf62) ocaml#8939 from gretay-js/save-linear (cherry-pick 1200de9) ocaml#9003 from gretay-js/start-from-emit (cherry-pick 21d5d26) Add linear_format to dune file Update .depend
Dead code elimination in the backend can remove spacetime instrumentation and labels that spacetime table refers to. The table emitted at the end of a compilation unit still contains references to these now-undefined labels, causing a linker error. This PR fix it.
For example, the code
fails with a linker error:
when compiled with spacetime and without flambda.
With flambda, the
matchis simplified before spacetime table is computed. Without flambda, the calls are instrumented with spacetime andfis inlined. Then, dead code pass in the backend eliminates some of the inlined calls to f, including instrumentation, but spacetime table is not updated.This is most likely caused by PR #2321 (in 4.10) that eliminates dead handlers, which may include inlined calls, and hence instrumentation and labels. It seems that prior to it, labels have never been eliminated in the backend.
The proposed fix is to keep track of local labels that are emitted for a compilation unit, and then use this information to clean spacetime table right before it is emitted. The fix is in
amd64/emit.mlpbecause spacetime is specific to amd64 and dead code elimination pass is generic.Keeping track of emitted labels has some overhead in terms of compilation time and memory, but it is only enabled when the compiler is configured with spacetime. Note that
used_labelsis a superset of labels that spacetime can refer to, but it simplifies the code that keeps track of them.Testsuite: two tests are currently failing in my setup with spacetime enabled. The failures are unrelated to the PR: they fail without this patch.
All other tests pass. The example above compiles and works under spacetime.