Skip to content

Commit

Permalink
Add minor debug mode for measuring type sizes, helper for #3025.
Browse files Browse the repository at this point in the history
  • Loading branch information
graydon committed Aug 8, 2012
1 parent 438765d commit 8c95fed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/rustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const borrowck_note_pure: uint = 2048;
const borrowck_note_loan: uint = 4096;
const no_landing_pads: uint = 8192;
const debug_llvm: uint = 16384;
const count_type_sizes: uint = 32768;

fn debugging_opts_map() -> ~[(~str, ~str, uint)] {
~[(~"ppregions", ~"prettyprint regions with \
Expand All @@ -63,7 +64,9 @@ fn debugging_opts_map() -> ~[(~str, ~str, uint)] {
borrowck_note_loan),
(~"no-landing-pads", ~"omit landing pads for unwinding",
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)
]
}

Expand Down Expand Up @@ -179,6 +182,7 @@ impl session for session {
fn ppregions() -> bool { self.debugging_opt(ppregions) }
fn time_passes() -> bool { self.debugging_opt(time_passes) }
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 trans_stats() -> bool { self.debugging_opt(trans_stats) }
fn no_asm_comments() -> bool { self.debugging_opt(no_asm_comments) }
Expand Down
8 changes: 8 additions & 0 deletions src/rustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
let _icx = ccx.insn_ctxt(~"declare_tydesc");
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 llalign = llalign_of(ccx, llty);
//XXX this triggers duplicate LLVM symbols
Expand Down Expand Up @@ -576,6 +583,7 @@ fn emit_tydescs(ccx: @crate_ctxt) {
for ccx.tydescs.each |key, val| {
let glue_fn_ty = T_ptr(T_glue_fn(ccx));
let ti = val;

let take_glue =
match copy ti.take_glue {
none => { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) }
Expand Down

0 comments on commit 8c95fed

Please sign in to comment.