-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathextra_debug.ml
66 lines (64 loc) · 3.56 KB
/
extra_debug.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(**********************************************************************************
* MIT License *
* *
* *
* Copyright (c) 2019-2021 Jane Street Group LLC *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy *
* of this software and associated documentation files (the "Software"), to deal *
* in the Software without restriction, including without limitation the rights *
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in all *
* copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
* SOFTWARE. *
* *
**********************************************************************************)
[@@@ocaml.warning "+a-30-40-41-42"]
module CL = Cfg_with_layout
let add cl =
(* Fabricate debug info when missing, because it is required to emit discriminators.
* Following the semantics of debug_line, remember the last-seen dbg and attach it
* to instructions that do not have any.
*
* The following Linear instructions do not need Fdo info,
* because they are emitted as assembly directives and
* not as addressible assembly instructions:
* Lend
* Lreloadretaddr
* Llabel
* Lentertrap
* Ladjust_stack_offset
* There is nothing wrong with emitting .loc directives for them,
* but its redundant.
* Only Lreloadretaddr has a corresponding Cfg instruction.
* Others are created during cfg_to_linear with [fdo] set to [none]. *)
let update_instr prev (i : _ Cfg.instruction) =
let dbg =
if (not (Debuginfo.is_none prev)) && Debuginfo.is_none i.dbg
then prev
else i.dbg
in
let fdo = Fdo_info.create ~discriminator:i.id ~dbg in
dbg, { i with fdo }
in
let cfg = CL.cfg cl in
let layout = CL.layout cl in
let update_block prev label =
let block = Cfg.get_block_exn cfg label in
let prev, new_body = List.fold_left_map update_instr prev block.body in
block.body <- new_body;
let prev, new_terminator = update_instr prev block.terminator in
block.terminator <- new_terminator;
prev
in
ignore (List.fold_left update_block cfg.fun_dbg layout : Debuginfo.t)