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

Method inline

crates/cranelift/src/compiler.rs:986–1047  ·  view source on GitHub ↗
(
        &self,
        func_body: &mut CompiledFunctionBody,
        get_callee: &'a mut dyn FnMut(FuncKey) -> Option<&'a CompiledFunctionBody>,
    )

Source from the content-addressed store, hash-verified

984 }
985
986 fn inline<'a>(
987 &self,
988 func_body: &mut CompiledFunctionBody,
989 get_callee: &'a mut dyn FnMut(FuncKey) -> Option<&'a CompiledFunctionBody>,
990 ) -> Result<()> {
991 debug_assert!(!func_body.code.is::<CompiledFunction>());
992 debug_assert!(func_body.code.is::<Option<CompilerContext>>());
993 let code = func_body
994 .code
995 .downcast_mut::<Option<CompilerContext>>()
996 .unwrap();
997 let cx = code.as_mut().unwrap();
998
999 cx.codegen_context.inline(Inliner(get_callee))?;
1000 return Ok(());
1001
1002 struct Inliner<'a>(&'a mut dyn FnMut(FuncKey) -> Option<&'a CompiledFunctionBody>);
1003
1004 impl cranelift_codegen::inline::Inline for Inliner<'_> {
1005 fn inline(
1006 &mut self,
1007 caller: &ir::Function,
1008 _call_inst: ir::Inst,
1009 _call_opcode: ir::Opcode,
1010 callee: ir::FuncRef,
1011 _call_args: &[ir::Value],
1012 ) -> InlineCommand<'_> {
1013 let callee = &caller.dfg.ext_funcs[callee].name;
1014 let callee = match callee {
1015 ir::ExternalName::User(callee) => *callee,
1016 ir::ExternalName::TestCase(_)
1017 | ir::ExternalName::LibCall(_)
1018 | ir::ExternalName::KnownSymbol(_) => return InlineCommand::KeepCall,
1019 };
1020 let callee = &caller.params.user_named_funcs()[callee];
1021 let callee = FuncKey::from_raw_parts(callee.namespace, callee.index);
1022 match callee {
1023 FuncKey::DefinedWasmFunction(..) => {}
1024 FuncKey::UnsafeIntrinsic(..) => {}
1025 _ => return InlineCommand::KeepCall,
1026 }
1027 match (self.0)(callee) {
1028 None => InlineCommand::KeepCall,
1029 Some(func_body) => {
1030 debug_assert!(!func_body.code.is::<CompiledFunction>());
1031 debug_assert!(func_body.code.is::<Option<CompilerContext>>());
1032 let cx = func_body
1033 .code
1034 .downcast_ref::<Option<CompilerContext>>()
1035 .unwrap();
1036 InlineCommand::Inline {
1037 callee: Cow::Borrowed(&cx.as_ref().unwrap().codegen_context.func),
1038 // We've already visited the callee for inlining
1039 // due to our bottom-up approach, no need to
1040 // visit it again.
1041 visit_callee: false,
1042 }
1043 }

Callers 1

compile_with_inliningMethod · 0.45

Calls 6

OkFunction · 0.85
user_named_funcsMethod · 0.80
InlinerClass · 0.70
unwrapMethod · 0.45
as_mutMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected