MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / run

Method run

cranelift/filetests/src/test_inline.rs:69–117  ·  view source on GitHub ↗
(&self, func: Cow<ir::Function>, context: &Context)

Source from the content-addressed store, hash-verified

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
120struct Inliner<'a>(Ref<'a, HashMap<ir::UserFuncName, ir::Function>>);

Callers

nothing calls this directly

Calls 15

pretty_anyhow_errorFunction · 0.85
msgFunction · 0.85
pretty_verifier_errorFunction · 0.85
check_precise_outputFunction · 0.85
run_filecheckFunction · 0.85
into_ownedMethod · 0.80
legalizeMethod · 0.80
flags_or_isaMethod · 0.80
optimizeMethod · 0.80
collectMethod · 0.80
InlinerClass · 0.70
unwrapMethod · 0.45

Tested by

no test coverage detected