Add minor debug mode for measuring type sizes, helper for #3025.

This commit is contained in:
Graydon Hoare 2012-08-07 18:39:41 -07:00
parent 438765da59
commit 8c95feda39
2 changed files with 13 additions and 1 deletions

View file

@ -41,6 +41,7 @@ const borrowck_note_pure: uint = 2048;
const borrowck_note_loan: uint = 4096; const borrowck_note_loan: uint = 4096;
const no_landing_pads: uint = 8192; const no_landing_pads: uint = 8192;
const debug_llvm: uint = 16384; const debug_llvm: uint = 16384;
const count_type_sizes: uint = 32768;
fn debugging_opts_map() -> ~[(~str, ~str, uint)] { fn debugging_opts_map() -> ~[(~str, ~str, uint)] {
~[(~"ppregions", ~"prettyprint regions with \ ~[(~"ppregions", ~"prettyprint regions with \
@ -63,7 +64,9 @@ fn debugging_opts_map() -> ~[(~str, ~str, uint)] {
borrowck_note_loan), borrowck_note_loan),
(~"no-landing-pads", ~"omit landing pads for unwinding", (~"no-landing-pads", ~"omit landing pads for unwinding",
no_landing_pads), no_landing_pads),
(~"debug-llvm", ~"enable debug output from LLVM", debug_llvm) (~"debug-llvm", ~"enable debug output from LLVM", debug_llvm),
(~"count-type-sizes", ~"count the sizes of aggregate types",
count_type_sizes)
] ]
} }
@ -179,6 +182,7 @@ impl session for session {
fn ppregions() -> bool { self.debugging_opt(ppregions) } fn ppregions() -> bool { self.debugging_opt(ppregions) }
fn time_passes() -> bool { self.debugging_opt(time_passes) } fn time_passes() -> bool { self.debugging_opt(time_passes) }
fn count_llvm_insns() -> bool { self.debugging_opt(count_llvm_insns) } fn count_llvm_insns() -> bool { self.debugging_opt(count_llvm_insns) }
fn count_type_sizes() -> bool { self.debugging_opt(count_type_sizes) }
fn time_llvm_passes() -> bool { self.debugging_opt(time_llvm_passes) } fn time_llvm_passes() -> bool { self.debugging_opt(time_llvm_passes) }
fn trans_stats() -> bool { self.debugging_opt(trans_stats) } fn trans_stats() -> bool { self.debugging_opt(trans_stats) }
fn no_asm_comments() -> bool { self.debugging_opt(no_asm_comments) } fn no_asm_comments() -> bool { self.debugging_opt(no_asm_comments) }

View file

@ -490,6 +490,13 @@ fn note_unique_llvm_symbol(ccx: @crate_ctxt, sym: ~str) {
fn declare_tydesc(ccx: @crate_ctxt, t: ty::t) -> @tydesc_info { fn declare_tydesc(ccx: @crate_ctxt, t: ty::t) -> @tydesc_info {
let _icx = ccx.insn_ctxt(~"declare_tydesc"); let _icx = ccx.insn_ctxt(~"declare_tydesc");
let llty = type_of(ccx, t); let llty = type_of(ccx, t);
if ccx.sess.count_type_sizes() {
io::println(fmt!("%u\t%s",
llsize_of_real(ccx, llty),
ty_to_str(ccx.tcx, t)));
}
let llsize = llsize_of(ccx, llty); let llsize = llsize_of(ccx, llty);
let llalign = llalign_of(ccx, llty); let llalign = llalign_of(ccx, llty);
//XXX this triggers duplicate LLVM symbols //XXX this triggers duplicate LLVM symbols
@ -576,6 +583,7 @@ fn emit_tydescs(ccx: @crate_ctxt) {
for ccx.tydescs.each |key, val| { for ccx.tydescs.each |key, val| {
let glue_fn_ty = T_ptr(T_glue_fn(ccx)); let glue_fn_ty = T_ptr(T_glue_fn(ccx));
let ti = val; let ti = val;
let take_glue = let take_glue =
match copy ti.take_glue { match copy ti.take_glue {
none => { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) } none => { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) }