Skip to content

Commit 205cfa1

Browse files
committed
Create a separate deduplication cache for static items
1 parent d57bd90 commit 205cfa1

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl<'ll> CodegenCx<'ll, '_> {
227227

228228
pub(crate) fn get_static(&self, def_id: DefId) -> &'ll Value {
229229
let instance = Instance::mono(self.tcx, def_id);
230-
if let Some(&g) = self.instances.borrow().get(&instance) {
230+
if let Some(&g) = self.statics.borrow().get(&def_id) {
231231
return g;
232232
}
233233

@@ -331,7 +331,7 @@ impl<'ll> CodegenCx<'ll, '_> {
331331
}
332332
}
333333

334-
self.instances.borrow_mut().insert(instance, g);
334+
self.statics.borrow_mut().insert(def_id, g);
335335
g
336336
}
337337
}

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ pub struct CodegenCx<'ll, 'tcx> {
5454

5555
/// Cache instances of monomorphic and polymorphic items
5656
pub instances: RefCell<FxHashMap<Instance<'tcx>, &'ll Value>>,
57+
58+
/// Cache static's allocations
59+
pub statics: RefCell<FxHashMap<DefId, &'ll Value>>,
5760
/// Cache generated vtables
5861
pub vtables:
5962
RefCell<FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), &'ll Value>>,
@@ -467,6 +470,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
467470
llcx,
468471
codegen_unit,
469472
instances: Default::default(),
473+
statics: Default::default(),
470474
vtables: Default::default(),
471475
const_str_cache: Default::default(),
472476
const_globals: Default::default(),

compiler/rustc_codegen_llvm/src/mono_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<'tcx> PreDefineMethods<'tcx> for CodegenCx<'_, 'tcx> {
3838
}
3939
}
4040

41-
self.instances.borrow_mut().insert(instance, g);
41+
self.statics.borrow_mut().insert(def_id, g);
4242
}
4343

4444
fn predefine_fn(

0 commit comments

Comments
 (0)