|
21 | 21 | //! the above three primitives to form a full incremental caching system.
|
22 | 22 |
|
23 | 23 | use core::fmt;
|
| 24 | +use core::hash::{Hash, Hasher}; |
24 | 25 |
|
25 |
| -use crate::alloc::string::String; |
26 | 26 | use crate::alloc::vec::Vec;
|
27 | 27 | use crate::ir::Function;
|
28 | 28 | use crate::ir::function::{FunctionStencil, VersionMarker};
|
29 | 29 | use crate::machinst::{CompiledCode, CompiledCodeStencil};
|
30 | 30 | use crate::result::CompileResult;
|
31 | 31 | use crate::{CompileError, Context, trace};
|
32 | 32 | use crate::{isa::TargetIsa, timing};
|
33 |
| -use alloc::borrow::{Cow, ToOwned as _}; |
34 |
| -use alloc::string::ToString as _; |
| 33 | +use alloc::borrow::Cow; |
35 | 34 | use cranelift_control::ControlPlane;
|
36 | 35 |
|
37 | 36 | impl Context {
|
@@ -133,43 +132,29 @@ struct CachedFunc {
|
133 | 132 | ///
|
134 | 133 | /// Note: the key will be invalidated across different versions of cranelift, as the
|
135 | 134 | /// `FunctionStencil` contains a `VersionMarker` itself.
|
136 |
| -#[derive(Hash)] |
137 | 135 | struct CacheKey<'a> {
|
138 | 136 | stencil: &'a FunctionStencil,
|
139 |
| - parameters: CompileParameters, |
| 137 | + isa: &'a dyn TargetIsa, |
140 | 138 | }
|
141 | 139 |
|
142 |
| -#[derive(Clone, PartialEq, Hash, serde_derive::Serialize, serde_derive::Deserialize)] |
143 |
| -struct CompileParameters { |
144 |
| - isa: String, |
145 |
| - triple: String, |
146 |
| - flags: String, |
147 |
| - isa_flags: Vec<String>, |
148 |
| -} |
149 |
| - |
150 |
| -impl CompileParameters { |
151 |
| - fn from_isa(isa: &dyn TargetIsa) -> Self { |
152 |
| - Self { |
153 |
| - isa: isa.name().to_owned(), |
154 |
| - triple: isa.triple().to_string(), |
155 |
| - flags: isa.flags().to_string(), |
156 |
| - isa_flags: isa |
157 |
| - .isa_flags() |
158 |
| - .into_iter() |
159 |
| - .map(|v| v.value_string()) |
160 |
| - .collect(), |
161 |
| - } |
| 140 | +impl<'a> Hash for CacheKey<'a> { |
| 141 | + fn hash<H: Hasher>(&self, state: &mut H) { |
| 142 | + self.stencil.hash(state); |
| 143 | + self.isa.name().hash(state); |
| 144 | + self.isa.triple().hash(state); |
| 145 | + self.isa.flags().hash(state); |
| 146 | + self.isa.isa_flags_hash_key().hash(state); |
162 | 147 | }
|
163 | 148 | }
|
164 | 149 |
|
165 | 150 | impl<'a> CacheKey<'a> {
|
166 | 151 | /// Creates a new cache store key for a function.
|
167 | 152 | ///
|
168 | 153 | /// This is a bit expensive to compute, so it should be cached and reused as much as possible.
|
169 |
| - fn new(isa: &dyn TargetIsa, f: &'a Function) -> Self { |
| 154 | + fn new(isa: &'a dyn TargetIsa, f: &'a Function) -> Self { |
170 | 155 | CacheKey {
|
171 | 156 | stencil: &f.stencil,
|
172 |
| - parameters: CompileParameters::from_isa(isa), |
| 157 | + isa, |
173 | 158 | }
|
174 | 159 | }
|
175 | 160 | }
|
|
0 commit comments