Returns a function if it already exists, or declares a header if it doesn't.
(&self, instance: Instance<'tcx>)
| 37 | impl<'tcx> CodegenCx<'tcx> { |
| 38 | /// Returns a function if it already exists, or declares a header if it doesn't. |
| 39 | pub fn get_fn_ext(&self, instance: Instance<'tcx>) -> SpirvValue { |
| 40 | assert!(!instance.substs.has_infer()); |
| 41 | assert!(!instance.substs.has_escaping_bound_vars()); |
| 42 | |
| 43 | if let Some(&func) = self.instances.borrow().get(&instance) { |
| 44 | return func; |
| 45 | } |
| 46 | |
| 47 | // Because we've already declared everything with predefine_fn, if we hit this branch, we're guaranteed to be |
| 48 | // importing this function from elsewhere. So, slap an extern on it. |
| 49 | let linkage = Some(LinkageType::Import); |
| 50 | let llfn = self.declare_fn_ext(instance, linkage); |
| 51 | |
| 52 | self.instances.borrow_mut().insert(instance, llfn); |
| 53 | |
| 54 | llfn |
| 55 | } |
| 56 | |
| 57 | // The call graph of how this is reachable is a little tangled, so: |
| 58 | // MiscMethods::get_fn -> get_fn_ext -> declare_fn_ext |
no test coverage detected