|
49 | 49 | //! expand_params: Option<Vec<usize>>,
|
50 | 50 | //! ```
|
51 | 51 |
|
| 52 | +use crate::linker::ipo::CallGraph; |
52 | 53 | use crate::spirv_type_constraints::{self, InstSig, StorageClassPat, TyListPat, TyPat};
|
53 |
| -use indexmap::{IndexMap, IndexSet}; |
| 54 | +use indexmap::IndexMap; |
54 | 55 | use rspirv::dr::{Builder, Function, Instruction, Module, Operand};
|
55 | 56 | use rspirv::spirv::{Op, StorageClass, Word};
|
56 | 57 | use rustc_data_structures::captures::Captures;
|
@@ -186,88 +187,6 @@ pub fn specialize(module: Module, specialization: impl Specialization) -> Module
|
186 | 187 | expander.expand_module()
|
187 | 188 | }
|
188 | 189 |
|
189 |
| -// FIXME(eddyb) use newtyped indices and `IndexVec`. |
190 |
| -type FuncIdx = usize; |
191 |
| - |
192 |
| -struct CallGraph { |
193 |
| - entry_points: IndexSet<FuncIdx>, |
194 |
| - |
195 |
| - /// `callees[i].contains(j)` implies `functions[i]` calls `functions[j]`. |
196 |
| - callees: Vec<IndexSet<FuncIdx>>, |
197 |
| -} |
198 |
| - |
199 |
| -impl CallGraph { |
200 |
| - fn collect(module: &Module) -> Self { |
201 |
| - let func_id_to_idx: FxHashMap<_, _> = module |
202 |
| - .functions |
203 |
| - .iter() |
204 |
| - .enumerate() |
205 |
| - .map(|(i, func)| (func.def_id().unwrap(), i)) |
206 |
| - .collect(); |
207 |
| - let entry_points = module |
208 |
| - .entry_points |
209 |
| - .iter() |
210 |
| - .map(|entry| { |
211 |
| - assert_eq!(entry.class.opcode, Op::EntryPoint); |
212 |
| - func_id_to_idx[&entry.operands[1].unwrap_id_ref()] |
213 |
| - }) |
214 |
| - .collect(); |
215 |
| - let callees = module |
216 |
| - .functions |
217 |
| - .iter() |
218 |
| - .map(|func| { |
219 |
| - func.all_inst_iter() |
220 |
| - .filter(|inst| inst.class.opcode == Op::FunctionCall) |
221 |
| - .map(|inst| func_id_to_idx[&inst.operands[0].unwrap_id_ref()]) |
222 |
| - .collect() |
223 |
| - }) |
224 |
| - .collect(); |
225 |
| - Self { |
226 |
| - entry_points, |
227 |
| - callees, |
228 |
| - } |
229 |
| - } |
230 |
| - |
231 |
| - /// Order functions using a post-order traversal, i.e. callees before callers. |
232 |
| - // FIXME(eddyb) replace this with `rustc_data_structures::graph::iterate` |
233 |
| - // (or similar). |
234 |
| - fn post_order(&self) -> Vec<FuncIdx> { |
235 |
| - let num_funcs = self.callees.len(); |
236 |
| - |
237 |
| - // FIXME(eddyb) use a proper bitset. |
238 |
| - let mut visited = vec![false; num_funcs]; |
239 |
| - let mut post_order = Vec::with_capacity(num_funcs); |
240 |
| - |
241 |
| - // Visit the call graph with entry points as roots. |
242 |
| - for &entry in &self.entry_points { |
243 |
| - self.post_order_step(entry, &mut visited, &mut post_order); |
244 |
| - } |
245 |
| - |
246 |
| - // Also visit any functions that were not reached from entry points |
247 |
| - // (they might be dead but they should be processed nonetheless). |
248 |
| - for func in 0..num_funcs { |
249 |
| - if !visited[func] { |
250 |
| - self.post_order_step(func, &mut visited, &mut post_order); |
251 |
| - } |
252 |
| - } |
253 |
| - |
254 |
| - post_order |
255 |
| - } |
256 |
| - |
257 |
| - fn post_order_step(&self, func: FuncIdx, visited: &mut [bool], post_order: &mut Vec<FuncIdx>) { |
258 |
| - if visited[func] { |
259 |
| - return; |
260 |
| - } |
261 |
| - visited[func] = true; |
262 |
| - |
263 |
| - for &callee in &self.callees[func] { |
264 |
| - self.post_order_step(callee, visited, post_order); |
265 |
| - } |
266 |
| - |
267 |
| - post_order.push(func); |
268 |
| - } |
269 |
| -} |
270 |
| - |
271 | 190 | // HACK(eddyb) `Copy` version of `Operand` that only includes the cases that
|
272 | 191 | // are relevant to the inference algorithm (and is also smaller).
|
273 | 192 | #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
0 commit comments