dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.21k stars 1.57k forks source link

[vm/ffi] Inlining ffi leaf calls #45055

Open dcharkes opened 3 years ago

dcharkes commented 3 years ago

A follow up from the discussion with @cskau-g earlier this week. FFI leaf calls are not being inlined (CL).

out/ReleaseX64/dart --trace-inlining benchmarks/FfiCall/dart/FfiCall.dart // slightly modified
Inlining calls in doCall1Int8
  Depth 1 ----------
  Polymorphic Instance Calls (0)
  Static Calls (1)
  => function1Int8 (deopt count 0)
     Success
       with reason AlwaysInline, code size 2, call sites: 0
  Closure Calls (1)
     Bailout: non-closure operator

https://github.com/dart-lang/sdk/blob/3bcae5219b91f4b12d063779b44233ceffc4cf32/runtime/vm/compiler/backend/inliner.cc#L1476-L1493

The receiver is a static load:

Callee graph for inlining file:///usr/local/google/home/dacoharkes/dart-sdk/sdk/benchmarks/FfiCall/dart/FfiCall.dart_::_get_function1Int8 (optimized)
==== file:///usr/local/google/home/dacoharkes/dart-sdk/sdk/benchmarks/FfiCall/dart/FfiCall.dart_::_get_function1Int8 (ImplicitStaticGetter)
B0[graph]:0 {
      v23 <- Constant(#null)
      v24 <- Constant(#<optimized out>)
}
B6[function entry]:2
    v25 <- LoadStaticField:4(function1Int8) T{_Closure}
    Return:6(v25)

We should investigate whether we can make leaf ffi calls being inlined.

mraleph commented 2 years ago

When enabling inlining we will have to restore EmitMoveConst which was deleted by https://dart-review.googlesource.com/c/sdk/+/227741