(&self, func: Cow<ir::Function>, context: &Context)
| 67 | } |
| 68 | |
| 69 | fn run(&self, func: Cow<ir::Function>, context: &Context) -> Result<()> { |
| 70 | // Legalize this function. |
| 71 | let isa = context.isa.unwrap(); |
| 72 | let mut comp_ctx = cranelift_codegen::Context::for_function(func.into_owned()); |
| 73 | comp_ctx |
| 74 | .legalize(isa) |
| 75 | .map_err(|e| crate::pretty_anyhow_error(&comp_ctx.func, e)) |
| 76 | .context("error while legalizing")?; |
| 77 | |
| 78 | // Insert this function in our map for inlining into subsequent |
| 79 | // functions. |
| 80 | let func_name = comp_ctx.func.name.clone(); |
| 81 | self.funcs |
| 82 | .borrow_mut() |
| 83 | .insert(func_name, comp_ctx.func.clone()); |
| 84 | |
| 85 | // Run the inliner. |
| 86 | let inlined_any = comp_ctx.inline(Inliner(self.funcs.borrow()))?; |
| 87 | |
| 88 | // Verify that the CLIF is still valid. |
| 89 | comp_ctx |
| 90 | .verify(context.flags_or_isa()) |
| 91 | .map_err(|errors| { |
| 92 | anyhow::Error::msg(pretty_verifier_error(&comp_ctx.func, None, errors)) |
| 93 | }) |
| 94 | .context("CLIF verification error after inlining")?; |
| 95 | |
| 96 | // If requested, run optimizations. |
| 97 | if self.optimize { |
| 98 | comp_ctx |
| 99 | .optimize(isa, &mut ControlPlane::default()) |
| 100 | .map_err(|e| crate::pretty_anyhow_error(&comp_ctx.func, e)) |
| 101 | .context("error while optimizing")?; |
| 102 | } |
| 103 | |
| 104 | // Check the filecheck expectations. |
| 105 | let actual = if inlined_any { |
| 106 | format!("{:?}", comp_ctx.func) |
| 107 | } else { |
| 108 | format!("(no functions inlined into {})", comp_ctx.func.name) |
| 109 | }; |
| 110 | log::debug!("filecheck input: {actual}"); |
| 111 | if self.precise_output { |
| 112 | let actual: Vec<_> = actual.lines().collect(); |
| 113 | check_precise_output(&actual, context) |
| 114 | } else { |
| 115 | run_filecheck(&actual, context) |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | struct Inliner<'a>(Ref<'a, HashMap<ir::UserFuncName, ir::Function>>); |
nothing calls this directly
no test coverage detected