about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2012-08-07 18:39:41 -0700
committerGraydon Hoare <graydon@mozilla.com>2012-08-07 18:40:02 -0700
commit8c95feda3961efaffe4461d775b029f92a1744c4 (patch)
tree58f30249839c20bb64217d046af6211a4c9f8f3b /src
parent438765da59075339c99499e201384e835187f0ae (diff)
downloadrust-8c95feda3961efaffe4461d775b029f92a1744c4.tar.gz
rust-8c95feda3961efaffe4461d775b029f92a1744c4.zip
Add minor debug mode for measuring type sizes, helper for #3025.
Diffstat (limited to 'src')
-rw-r--r--src/rustc/driver/session.rs6
-rw-r--r--src/rustc/middle/trans/base.rs8
2 files changed, 13 insertions, 1 deletions
diff --git a/src/rustc/driver/session.rs b/src/rustc/driver/session.rs
index df9370afaea..712c7d2cc41 100644
--- a/src/rustc/driver/session.rs
+++ b/src/rustc/driver/session.rs
@@ -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 \
@@ -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)
     ]
 }
 
@@ -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) }
diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs
index c4ea48e3d41..2c7885a3f0c 100644
--- a/src/rustc/middle/trans/base.rs
+++ b/src/rustc/middle/trans/base.rs
@@ -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
@@ -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) }