Skip to content

Do not emit references to dead labels (spacetime)#9097

Merged
mshinwell merged 3 commits intoocaml:trunkfrom
gretay-js:fix_dce_spacetime_labels
Nov 26, 2019
Merged

Do not emit references to dead labels (spacetime)#9097
mshinwell merged 3 commits intoocaml:trunkfrom
gretay-js:fix_dce_spacetime_labels

Conversation

@gretay-js
Copy link
Copy Markdown
Contributor

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

type op = Eq | Neq
let [@inline always] f a = print_endline (string_of_int a)
let foo op =
  let a = true in
  match op, a with
  | Eq, true -> f 1
  | Neq, true -> f 2
  | _, _ -> f 3

fails with a linker error:

$ ocamlopt test2.ml -o test 
test2.o: In function `camlTest2__spacetime_shapes':
:(.data+0x190): undefined reference to `.L112'
:(.data+0x1a8): undefined reference to `.L111'
collect2: error: ld returned 1 exit status
File "caml_startup", line 1:
Error: Error during linking

when compiled with spacetime and without flambda.

With flambda, the match is simplified before spacetime table is computed. Without flambda, the calls are instrumented with spacetime and f is 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.mlp because 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_labels is 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.

  • statmemprof/native does not terminate
  • output-complete-obj/test fails to find libunwind.

All other tests pass. The example above compiles and works under spacetime.

@gasche
Copy link
Copy Markdown
Member

gasche commented Nov 7, 2019

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.

@mshinwell
Copy link
Copy Markdown
Contributor

@gasche We're using Spacetime to profile Flambda 2.0, so "yes" :) The existing tools work just fine.

Copy link
Copy Markdown
Contributor

@mshinwell mshinwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok for merging after comments addressed.

@gretay-js gretay-js force-pushed the fix_dce_spacetime_labels branch from 67e84d0 to 50c76ed Compare November 20, 2019 18:26
@mshinwell mshinwell merged commit 6daaf62 into ocaml:trunk Nov 26, 2019
@gretay-js
Copy link
Copy Markdown
Contributor Author

gretay-js commented Dec 10, 2019

This should probably be backported to 4.10. The issue it fixes was introduced in PR #2321 which is included in 4.10.

@gasche
Copy link
Copy Markdown
Member

gasche commented Dec 10, 2019

(Backporting sounds sensible to me, but I don't have time to do it now. Whoever should feel free to do it, please use git cherry-pick -x -m 1 <github merge commit>.)

stedolan added a commit to janestreet/ocaml that referenced this pull request Mar 17, 2020
gretay-js added a commit to gretay-js/ocaml that referenced this pull request Jun 4, 2020
gretay-js pushed a commit to gretay-js/ocaml that referenced this pull request Jun 4, 2020
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)
gretay-js pushed a commit to gretay-js/ocaml that referenced this pull request Jun 4, 2020
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
gretay-js pushed a commit to gretay-js/ocaml that referenced this pull request Jun 4, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Jul 16, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Jul 20, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Jul 20, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Jul 21, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Jul 21, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Jul 30, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Jul 30, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Aug 3, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Aug 4, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Aug 5, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Aug 7, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Aug 10, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Aug 10, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Aug 17, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Aug 18, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Aug 19, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Aug 20, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Aug 28, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Sep 2, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Sep 2, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Sep 2, 2020
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
mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Sep 7, 2020
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants