Skip to content

Commit

Permalink
Add pseudo-instruction Ladjust_trap_depth (ocaml#2322)
Browse files Browse the repository at this point in the history
Ladjust_trap_depth replaces dummy Lpushtrap generated in linearize of
Iexit to notify assembler generation about updates to the
stack. Ladjust_trap_depth is used to keep the virtual stack pointer in
sync and emit dwarf information, without emitting any assembly
instructions. It therefore avoids generating dead code.

This patch is extract from PR1482 @lthls
  • Loading branch information
gretay-js committed Aug 26, 2019
1 parent 4cecf74 commit 00d1453
Show file tree
Hide file tree
Showing 10 changed files with 584 additions and 17 deletions.
5 changes: 5 additions & 0 deletions asmcomp/amd64/emit.mlp
Expand Up @@ -867,6 +867,11 @@ let emit_instr fallthrough i =
D.text ()
| Lentertrap ->
()
| Ladjust_trap_depth { delta_traps; } ->
(* each trap occupies 16 bytes on the stack *)
let delta = 16 * delta_traps in
cfi_adjust_cfa_offset delta;
stack_offset := !stack_offset + delta
| Lpushtrap { lbl_handler; } ->
let load_label_addr s arg =
if !Clflags.pic_code then
Expand Down
5 changes: 5 additions & 0 deletions asmcomp/arm/emit.mlp
Expand Up @@ -877,6 +877,11 @@ let emit_instr i =
end
| Lentertrap ->
0
| Ladjust_trap_depth { delta_traps } ->
(* each trap occupies 8 bytes on the stack *)
let delta = 8 * delta_traps in
cfi_adjust_cfa_offset delta;
stack_offset := !stack_offset + delta; 0
| Lpushtrap { lbl_handler; } ->
let s = emit_load_handler_address lbl_handler in
stack_offset := !stack_offset + 8;
Expand Down
6 changes: 6 additions & 0 deletions asmcomp/arm64/emit.mlp
Expand Up @@ -495,6 +495,7 @@ module BR = Branch_relaxation.Make (struct
+ begin match lbl2 with None -> 0 | Some _ -> 1 end
| Lswitch jumptbl -> 3 + Array.length jumptbl
| Lentertrap -> 0
| Ladjust_trap_depth _ -> 0
| Lpushtrap _ -> 4
| Lpoptrap -> 1
| Lraise k ->
Expand Down Expand Up @@ -875,6 +876,11 @@ let emit_instr i =
*)
| Lentertrap ->
()
| Ladjust_trap_depth { delta_traps } ->
(* each trap occupies 16 bytes on the stack *)
let delta = 16 * delta_traps in
cfi_adjust_cfa_offset delta;
stack_offset := !stack_offset + delta
| Lpushtrap { lbl_handler; } ->
` adr {emit_reg reg_tmp1}, {emit_label lbl_handler}\n`;
stack_offset := !stack_offset + 16;
Expand Down

0 comments on commit 00d1453

Please sign in to comment.