Rollup merge of #124178 - GuillaumeGomez:llvm-backend, r=oli-obk

[cleanup] [llvm backend] Prevent creating the same `Instance::mono` multiple times

Just a little thing I came across while going through the code.

r? ```@oli-obk```
This commit is contained in:
Guillaume Gomez 2024-04-22 20:25:58 +02:00 committed by GitHub
commit 1a12ec41e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -260,7 +260,8 @@ pub(crate) fn get_static(&self, def_id: DefId) -> &'ll Value {
#[instrument(level = "debug", skip(self, llty))]
pub(crate) fn get_static_inner(&self, def_id: DefId, llty: &'ll Type) -> &'ll Value {
if let Some(&g) = self.instances.borrow().get(&Instance::mono(self.tcx, def_id)) {
let instance = Instance::mono(self.tcx, def_id);
if let Some(&g) = self.instances.borrow().get(&instance) {
trace!("used cached value");
return g;
}
@ -273,7 +274,7 @@ pub(crate) fn get_static_inner(&self, def_id: DefId, llty: &'ll Type) -> &'ll Va
statics defined in the same CGU, but did not for `{def_id:?}`"
);
let sym = self.tcx.symbol_name(Instance::mono(self.tcx, def_id)).name;
let sym = self.tcx.symbol_name(instance).name;
let fn_attrs = self.tcx.codegen_fn_attrs(def_id);
debug!(?sym, ?fn_attrs);
@ -363,7 +364,7 @@ pub(crate) fn get_static_inner(&self, def_id: DefId, llty: &'ll Type) -> &'ll Va
}
}
self.instances.borrow_mut().insert(Instance::mono(self.tcx, def_id), g);
self.instances.borrow_mut().insert(instance, g);
g
}