Skip to content

Commit

Permalink
WIP instr_size calculation fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcgilchrist committed Nov 29, 2024
1 parent d342139 commit 6f5aa77
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions asmcomp/power/emit.mlp
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,7 @@ let name_for_specific = function
| _ -> Misc.fatal_error "Emit.Ispecific"

(* Relaxation of branches that exceed the span of a relative branch. *)

module BR = Branch_relaxation.Make (struct
module Size = struct
type distance = int

module Cond_branch = struct
Expand Down Expand Up @@ -508,7 +507,9 @@ module BR = Branch_relaxation.Make (struct
(* [classify_addr], above, never identifies these instructions as needing
relaxing. As such, these functions should never be called. *)
let relax_specific_op _ = assert false
end)
end

module BR = Branch_relaxation.Make (Size)

(* Assembly code for inlined allocation *)

Expand Down Expand Up @@ -958,11 +959,37 @@ let emit_instr env i =
end

(* Emit a sequence of instructions *)

let rec emit_all env i =
(* for debugging instr_size errors *)
let emit_instr_debug env i =
let lbl = new_label () in
`{emit_label lbl}:\n`;
emit_instr env i;
let sz = Size.instr_size env.f i.desc * 4 in
` .ifne (. - {emit_label lbl}) - {emit_int sz}\n`;
` .error \"Emit.instr_size: instruction length mismatch\"\n`;
` .endif\n`
let rec emit_all env lbl_start acc i =
match i.desc with
| Lend -> ()
| _ -> emit_instr env i; emit_all env i.next
| Lend ->
(* acc measures in units of 32-bit instructions *)
let sz = acc * 4 in
` .ifne (. - {emit_label lbl_start}) - {emit_int sz}\n`;
` .error \"Emit.instr_size: instruction length mismatch\"\n`;
` .endif\n`;
| _ ->
let debug = false in
if debug then emit_instr_debug env i else emit_instr env i;
emit_all env lbl_start (acc + Size.instr_size env.f i.desc) i.next
let emit_all env i =
let lbl = new_label () in
`{emit_label lbl}:\n`;
emit_all env lbl 0 i
(* let rec emit_all env i = *)
(* match i.desc with *)
(* | Lend -> () *)
(* | _ -> emit_instr env i; emit_all env i.next *)
(* On this target, the possible "out of line" code blocks are:
- a single "call GC" point, which comes immediately after the
Expand Down

0 comments on commit 6f5aa77

Please sign in to comment.