Compute a cache key, and hash it on your behalf. Since computing the `CacheKey` is a bit expensive, it should be done as least as possible.
(isa: &dyn TargetIsa, func: &Function)
| 163 | /// |
| 164 | /// Since computing the `CacheKey` is a bit expensive, it should be done as least as possible. |
| 165 | pub fn compute_cache_key(isa: &dyn TargetIsa, func: &Function) -> CacheKeyHash { |
| 166 | use core::hash::{Hash as _, Hasher}; |
| 167 | use sha2::Digest as _; |
| 168 | |
| 169 | struct Sha256Hasher(sha2::Sha256); |
| 170 | |
| 171 | impl Hasher for Sha256Hasher { |
| 172 | fn finish(&self) -> u64 { |
| 173 | panic!("Sha256Hasher doesn't support finish!"); |
| 174 | } |
| 175 | fn write(&mut self, bytes: &[u8]) { |
| 176 | self.0.update(bytes); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | let cache_key = CacheKey::new(isa, func); |
| 181 | |
| 182 | let mut hasher = Sha256Hasher(sha2::Sha256::new()); |
| 183 | cache_key.hash(&mut hasher); |
| 184 | let hash: [u8; 32] = hasher.0.finalize().into(); |
| 185 | |
| 186 | CacheKeyHash(hash) |
| 187 | } |
| 188 | |
| 189 | /// Given a function that's been successfully compiled, serialize it to a blob that the caller may |
| 190 | /// store somewhere for future use by `try_finish_recompile`. |
no test coverage detected