Skip to content

Commit ad1bb2e

Browse files
committed
Cache the TLS model in the crate context
1 parent b233a6e commit ad1bb2e

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/librustc_trans/consts.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use monomorphize::Instance;
2323
use type_::Type;
2424
use type_of;
2525
use rustc::ty;
26-
use context::get_tls_model;
2726

2827
use rustc::hir;
2928

@@ -197,7 +196,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
197196

198197
for attr in attrs {
199198
if attr.check_name("thread_local") {
200-
llvm::set_thread_local_mode(g, get_tls_model(ccx.sess()));
199+
llvm::set_thread_local_mode(g, ccx.tls_model());
201200
}
202201
}
203202

@@ -216,7 +215,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
216215
// symbol and another one doesn't.
217216
for attr in ccx.tcx().get_attrs(def_id).iter() {
218217
if attr.check_name("thread_local") {
219-
llvm::set_thread_local_mode(g, get_tls_model(ccx.sess()));
218+
llvm::set_thread_local_mode(g, ccx.tls_model());
220219
}
221220
}
222221
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>,
307306
debuginfo::create_global_var_metadata(ccx, id, g);
308307

309308
if attr::contains_name(attrs, "thread_local") {
310-
llvm::set_thread_local_mode(g, get_tls_model(ccx.sess()));
309+
llvm::set_thread_local_mode(g, ccx.tls_model());
311310
}
312311

313312
base::set_link_section(ccx, g, attrs);

src/librustc_trans/context.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub struct SharedCrateContext<'a, 'tcx: 'a> {
5252
tcx: TyCtxt<'a, 'tcx, 'tcx>,
5353
check_overflow: bool,
5454
use_dll_storage_attrs: bool,
55+
tls_model: llvm::ThreadLocalMode,
5556
}
5657

5758
/// The local portion of a `CrateContext`. There is one `LocalCrateContext`
@@ -166,7 +167,7 @@ pub fn get_reloc_model(sess: &Session) -> llvm::RelocMode {
166167
}
167168
}
168169

169-
pub fn get_tls_model(sess: &Session) -> llvm::ThreadLocalMode {
170+
fn get_tls_model(sess: &Session) -> llvm::ThreadLocalMode {
170171
let tls_model_arg = match sess.opts.cg.tls_model {
171172
Some(ref s) => &s[..],
172173
None => &sess.target.target.options.tls_model[..],
@@ -299,10 +300,13 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
299300

300301
let check_overflow = tcx.sess.overflow_checks();
301302

303+
let tls_model = get_tls_model(&tcx.sess);
304+
302305
SharedCrateContext {
303306
tcx,
304307
check_overflow,
305308
use_dll_storage_attrs,
309+
tls_model,
306310
}
307311
}
308312

@@ -544,6 +548,10 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
544548
self.shared.use_dll_storage_attrs()
545549
}
546550

551+
pub fn tls_model(&self) -> llvm::ThreadLocalMode {
552+
self.shared.tls_model
553+
}
554+
547555
/// Generate a new symbol name with the given prefix. This symbol name must
548556
/// only be used for definitions with `internal` or `private` linkage.
549557
pub fn generate_local_symbol_name(&self, prefix: &str) -> String {

0 commit comments

Comments
 (0)