about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAmanieu d'Antras <amanieu@gmail.com>2017-11-03 00:23:56 +0000
committerAmanieu d'Antras <amanieu@gmail.com>2017-11-03 00:29:54 +0000
commitad1bb2e465a1b83bde937ce05b7cf84cf949f1b3 (patch)
tree17701c674e6c8b1faafc5660270a71d42fcfc6ef
parentb233a6e0968c48719c066b8ba4d247925071f680 (diff)
Cache the TLS model in the crate context
-rw-r--r--src/librustc_trans/consts.rs7
-rw-r--r--src/librustc_trans/context.rs10
2 files changed, 12 insertions, 5 deletions
diff --git a/src/librustc_trans/consts.rs b/src/librustc_trans/consts.rs
index 0f5ede91c7d..4ae289cfada 100644
--- a/src/librustc_trans/consts.rs
+++ b/src/librustc_trans/consts.rs
@@ -23,7 +23,6 @@ use monomorphize::Instance;
 use type_::Type;
 use type_of;
 use rustc::ty;
-use context::get_tls_model;
 
 use rustc::hir;
 
@@ -197,7 +196,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
 
         for attr in attrs {
             if attr.check_name("thread_local") {
-                llvm::set_thread_local_mode(g, get_tls_model(ccx.sess()));
+                llvm::set_thread_local_mode(g, ccx.tls_model());
             }
         }
 
@@ -216,7 +215,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
         // symbol and another one doesn't.
         for attr in ccx.tcx().get_attrs(def_id).iter() {
             if attr.check_name("thread_local") {
-                llvm::set_thread_local_mode(g, get_tls_model(ccx.sess()));
+                llvm::set_thread_local_mode(g, ccx.tls_model());
             }
         }
         if ccx.use_dll_storage_attrs() && !ccx.tcx().is_foreign_item(def_id) {
@@ -307,7 +306,7 @@ pub fn trans_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
         debuginfo::create_global_var_metadata(ccx, id, g);
 
         if attr::contains_name(attrs, "thread_local") {
-            llvm::set_thread_local_mode(g, get_tls_model(ccx.sess()));
+            llvm::set_thread_local_mode(g, ccx.tls_model());
         }
 
         base::set_link_section(ccx, g, attrs);
diff --git a/src/librustc_trans/context.rs b/src/librustc_trans/context.rs
index afdbc31c456..0089dd67121 100644
--- a/src/librustc_trans/context.rs
+++ b/src/librustc_trans/context.rs
@@ -52,6 +52,7 @@ pub struct SharedCrateContext<'a, 'tcx: 'a> {
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
     check_overflow: bool,
     use_dll_storage_attrs: bool,
+    tls_model: llvm::ThreadLocalMode,
 }
 
 /// The local portion of a `CrateContext`.  There is one `LocalCrateContext`
@@ -166,7 +167,7 @@ pub fn get_reloc_model(sess: &Session) -> llvm::RelocMode {
     }
 }
 
-pub fn get_tls_model(sess: &Session) -> llvm::ThreadLocalMode {
+fn get_tls_model(sess: &Session) -> llvm::ThreadLocalMode {
     let tls_model_arg = match sess.opts.cg.tls_model {
         Some(ref s) => &s[..],
         None => &sess.target.target.options.tls_model[..],
@@ -299,10 +300,13 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
 
         let check_overflow = tcx.sess.overflow_checks();
 
+        let tls_model = get_tls_model(&tcx.sess);
+
         SharedCrateContext {
             tcx,
             check_overflow,
             use_dll_storage_attrs,
+            tls_model,
         }
     }
 
@@ -544,6 +548,10 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
         self.shared.use_dll_storage_attrs()
     }
 
+    pub fn tls_model(&self) -> llvm::ThreadLocalMode {
+        self.shared.tls_model
+    }
+
     /// Generate a new symbol name with the given prefix. This symbol name must
     /// only be used for definitions with `internal` or `private` linkage.
     pub fn generate_local_symbol_name(&self, prefix: &str) -> String {