Skip to content

Commit d83effd

Browse files
committed
---
yaml --- r: 757 b: refs/heads/master c: ef5a64e h: refs/heads/master i: 755: 5a7cdc5 v: v3
1 parent 0ec17f1 commit d83effd

File tree

4 files changed

+82
-10
lines changed

4 files changed

+82
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 71c266f9377c4aa29bd7b69e6ed221ce407bc030
2+
refs/heads/master: ef5a64e2cf8e4ee5b31c9e040867fd107692c835

trunk/src/boot/driver/main.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ let (sess:Session.sess) =
6161
Session.sess_failed = false;
6262
Session.sess_spans = Hashtbl.create 0;
6363
Session.sess_report_timing = false;
64+
Session.sess_report_quads = false;
6465
Session.sess_report_gc = false;
6566
Session.sess_report_deps = false;
6667
Session.sess_next_crate_id = 0;
6768
Session.sess_fuzz_item_count = 5;
6869
Session.sess_timings = Hashtbl.create 0;
70+
Session.sess_quad_counts = Hashtbl.create 0;
6971
Session.sess_lib_dirs = Queue.create ();
7072
Session.sess_crate_meta = Hashtbl.create 0;
7173
Session.sess_node_id_counter = ref (Node 0);
@@ -221,6 +223,8 @@ let argspecs =
221223

222224
(flag (fun _ -> sess.Session.sess_report_timing <- true)
223225
"-rtime" "report timing of compiler phases");
226+
(flag (fun _ -> sess.Session.sess_report_quads <- true)
227+
"-rquads" "report categories of quad emitted");
224228
(flag (fun _ -> sess.Session.sess_report_gc <- true)
225229
"-rgc" "report gc behavior of compiler");
226230
("-rsig", Arg.String dump_sig,

trunk/src/boot/driver/session.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ type sess =
4646
mutable sess_trace_gc: bool;
4747
mutable sess_failed: bool;
4848
mutable sess_report_timing: bool;
49+
mutable sess_report_quads: bool;
4950
mutable sess_report_gc: bool;
5051
mutable sess_report_deps: bool;
5152
mutable sess_next_crate_id: int;
5253
mutable sess_fuzz_item_count: int;
5354

5455
sess_timings: (string, float) Hashtbl.t;
56+
sess_quad_counts: (string, int ref) Hashtbl.t;
5557
sess_spans: (node_id,span) Hashtbl.t;
5658
sess_lib_dirs: filename Queue.t;
5759
sess_crate_meta: (meta, crate_id) Hashtbl.t;

trunk/src/boot/me/trans.ml

Lines changed: 75 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ let trans_visitor
163163
let emitters = Stack.create () in
164164
let push_new_emitter (vregs_ok:bool) (fnid:node_id option) =
165165
let e = Il.new_emitter
166-
abi.Abi.abi_emit_target_specific
167-
vregs_ok fnid
166+
abi.Abi.abi_emit_target_specific
167+
vregs_ok fnid
168168
in
169169
Stack.push e emitters;
170170
in
@@ -179,13 +179,54 @@ let trans_visitor
179179
Hashtbl.clear (emitter_size_cache())
180180
in
181181

182+
let quad_categories = Hashtbl.create 0 in
183+
let quad_category_stack = Stack.create () in
184+
let in_quad_category name thunk =
185+
if cx.ctxt_sess.Session.sess_report_quads
186+
then Stack.push name quad_category_stack;
187+
let x = thunk() in
188+
if cx.ctxt_sess.Session.sess_report_quads
189+
then ignore (Stack.pop quad_category_stack);
190+
x
191+
in
192+
193+
let credit name i =
194+
let c =
195+
htab_search_or_add quad_categories name
196+
(fun _ -> ref 0)
197+
in
198+
c := (!c) + i
199+
in
200+
201+
let in_native_quad_category name thunk =
202+
if cx.ctxt_sess.Session.sess_report_quads
203+
then
204+
let i = (emitter()).Il.emit_pc in
205+
let x = thunk() in
206+
let j = (emitter()).Il.emit_pc in
207+
credit name (j-i);
208+
x
209+
else
210+
thunk()
211+
in
212+
182213
let emit q =
183214
begin
184215
match q with
185216
Il.Jmp _ -> flush_emitter_size_cache();
186217
| _ -> ()
187218
end;
188-
Il.emit (emitter()) q
219+
Il.emit (emitter()) q;
220+
if cx.ctxt_sess.Session.sess_report_quads
221+
then
222+
begin
223+
let name =
224+
if Stack.is_empty quad_category_stack
225+
then "other"
226+
else Stack.top quad_category_stack
227+
in
228+
credit name 1
229+
end
189230
in
190231

191232
let next_vreg _ = Il.next_vreg (emitter()) in
@@ -2517,15 +2558,19 @@ let trans_visitor
25172558
(ret:Il.cell)
25182559
(args:Il.operand array)
25192560
: unit =
2520-
abi.Abi.abi_emit_native_call (emitter())
2521-
ret nabi_rust (upcall_fixup name) args;
2561+
in_native_quad_category "upcall"
2562+
(fun _ ->
2563+
abi.Abi.abi_emit_native_call (emitter())
2564+
ret nabi_rust (upcall_fixup name) args)
25222565

25232566
and trans_void_upcall
25242567
(name:string)
25252568
(args:Il.operand array)
25262569
: unit =
2527-
abi.Abi.abi_emit_native_void_call (emitter())
2528-
nabi_rust (upcall_fixup name) args;
2570+
in_native_quad_category "upcall"
2571+
(fun _ ->
2572+
abi.Abi.abi_emit_native_void_call (emitter())
2573+
nabi_rust (upcall_fixup name) args);
25292574

25302575
and trans_log_int (a:Ast.atom) : unit =
25312576
trans_void_upcall "upcall_log_int" [| (trans_atom a) |]
@@ -4705,7 +4750,8 @@ let trans_visitor
47054750
annotate s;
47064751
end;
47074752
Stack.push stmt.id curr_stmt;
4708-
trans_stmt_full stmt;
4753+
(in_quad_category "stmt"
4754+
(fun _ -> trans_stmt_full stmt));
47094755
begin
47104756
match stmt.node with
47114757
Ast.STMT_be _
@@ -5834,6 +5880,24 @@ let trans_visitor
58345880
inner.Walk.visit_crate_pre crate
58355881
in
58365882

5883+
let report_quads _ =
5884+
if cx.ctxt_sess.Session.sess_report_quads
5885+
then
5886+
begin
5887+
let cumulative = ref 0 in
5888+
Printf.fprintf stdout "quads:\n\n";
5889+
Array.iter
5890+
begin
5891+
fun name ->
5892+
let t = Hashtbl.find quad_categories name in
5893+
Printf.fprintf stdout "%20s: %d\n" name (!t);
5894+
cumulative := (!cumulative) + (!t)
5895+
end
5896+
(sorted_htab_keys quad_categories);
5897+
Printf.fprintf stdout "\n%20s: %d\n" "cumulative" (!cumulative)
5898+
end
5899+
in
5900+
58375901
let visit_crate_post crate =
58385902

58395903
inner.Walk.visit_crate_post crate;
@@ -5921,7 +5985,9 @@ let trans_visitor
59215985

59225986
provide_existing_native cx SEG_data "rust_crate" cx.ctxt_crate_fixup;
59235987

5924-
leave_file_for crate.id
5988+
leave_file_for crate.id;
5989+
5990+
report_quads()
59255991
in
59265992

59275993
{ inner with

0 commit comments

Comments
 (0)