about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-08-11 07:29:07 -0700
committerbors <bors@rust-lang.org>2013-08-11 07:29:07 -0700
commitf08851e31ab95da3b5bc446744d6dc89905335d9 (patch)
tree1d5bdf20d9f69978745d8b3b8bc32376b854c6d1 /src/libsyntax
parent45da2a5f48300eff8ccfd524a0bad5c351c20298 (diff)
parent2f3fde60c316031f657e149c56ff3eaa8ae2c7fa (diff)
downloadrust-f08851e31ab95da3b5bc446744d6dc89905335d9.tar.gz
rust-f08851e31ab95da3b5bc446744d6dc89905335d9.zip
auto merge of #8421 : alexcrichton/rust/unnamed-addr, r=thestinger
This can be applied to statics and it will indicate that LLVM will attempt to
merge the constant in .data with other statics.

I have preliminarily applied this to all of the statics generated by the new
`ifmt!` syntax extension. I compiled a file with 1000 calls to `ifmt!` and a
separate file with 1000 calls to `fmt!` to compare the sizes, and the results
were:

```
fmt           310k
ifmt (before) 529k
ifmt (after)  202k
```

This now means that ifmt! is both faster and smaller than fmt!, yay!
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/ifmt.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/libsyntax/ext/ifmt.rs b/src/libsyntax/ext/ifmt.rs
index a3adb42425a..65d2f798f31 100644
--- a/src/libsyntax/ext/ifmt.rs
+++ b/src/libsyntax/ext/ifmt.rs
@@ -429,7 +429,12 @@ impl Context {
             let st = ast::item_static(ty, ast::m_imm, method);
             let static_name = self.ecx.ident_of(fmt!("__static_method_%u",
                                                      self.method_statics.len()));
-            let item = self.ecx.item(sp, static_name, ~[], st);
+            // Flag these statics as `address_insignificant` so LLVM can
+            // merge duplicate globals as much as possible (which we're
+            // generating a whole lot of).
+            let unnamed = self.ecx.meta_word(self.fmtsp, @"address_insignificant");
+            let unnamed = self.ecx.attribute(self.fmtsp, unnamed);
+            let item = self.ecx.item(sp, static_name, ~[unnamed], st);
             self.method_statics.push(item);
             self.ecx.expr_ident(sp, static_name)
         };
@@ -550,7 +555,10 @@ impl Context {
         let ty = self.ecx.ty(self.fmtsp, ty);
         let st = ast::item_static(ty, ast::m_imm, fmt);
         let static_name = self.ecx.ident_of("__static_fmtstr");
-        let item = self.ecx.item(self.fmtsp, static_name, ~[], st);
+        // see above comment for `address_insignificant` and why we do it
+        let unnamed = self.ecx.meta_word(self.fmtsp, @"address_insignificant");
+        let unnamed = self.ecx.attribute(self.fmtsp, unnamed);
+        let item = self.ecx.item(self.fmtsp, static_name, ~[unnamed], st);
         let decl = respan(self.fmtsp, ast::decl_item(item));
         lets.push(@respan(self.fmtsp, ast::stmt_decl(@decl, self.ecx.next_id())));
 
@@ -613,6 +621,7 @@ impl Context {
         if ty == Unknown {
             ty = Known(@"?");
         }
+
         let argptr = self.ecx.expr_addr_of(sp, self.ecx.expr_ident(sp, ident));
         match ty {
             Known(tyname) => {