Anonymous | Login | Signup for a new account 2017-10-19 07:31 CEST
 Main | My View | View Issues | Change Log | Roadmap

View Issue Details  Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005894OCamlback end (clambda to assembly)public2013-01-17 21:072017-09-07 01:23
Reporterchambart
Assigned To
PrioritynormalSeverityfeatureReproducibilityhave not tried
StatusacknowledgedResolutionopen
PlatformOSOS Version
Product Version
Target VersionlaterFixed in Version
Summary0005894: [patch] Avoid boxing float/int32/int64 when doing direct call
DescriptionFunctions taking floating points parameters always receive them boxed.
When a direct call is done, it is possible to specialise the call to
pass those parameters in registers. This also applies to boxed integers.
The return value can also be unboxed.

This allow avoiding all allocations in a function like

let (-) = Nativeint.sub
let rec fib n =
if n < 2n then 0n + 1n else fib(n-1n) + fib(n-2n)
Additional InformationThis patch take care of not unboxing parameters when it is possible that this
could increase the number of allocation.

For instance a function like this

ignore [x] (* force boxing of x *)

bad will not be specialised because its parameter is used boxed inside its body.

In a case like:

let rec f x y =
let _ = x +. 1. in
let _ = y +. 1. in
h 1. x

and g a b =
let _ = a+.1. in
let _ = b+.1. in
f b 1.

and h c d =
let _ = c +. 1. in
let _ = d +. 1. in
let _ = g 1. c in
let _ = g 1. d in

only the y parameter of f and a of g will be unboxed.

The return value will be unboxed if every possible returned value is unboxed.

For instance

x +. y is considered unboxed

but

if b
then x +. y
else List.hd l

is considered boxed because List.hd return an already boxed value.

Current problems:

- Constants are considered boxed because they are already boxed at
compile time, but this may not be the right default choice. It can still be
circumvented by things like 0n + 1n in the fibonacci example.

- Specialised functions code is duplicated:
* It is possible to know that some functions will never be used in direct call:
those can be compiled only one time
* specialisation could be forbidden over a certain size
* the generic version of function specialised only for parameters (not return
value) could be compiled by adding a stub before the specialised version.
Tagspatch
Attached Files 0001-Preparing-for-specialisation-patches-1.patch [^] (23,207 bytes) 2013-01-17 21:07
0002-Preparing-for-specialisation-patches-2.patch [^] (7,497 bytes) 2013-01-17 21:08
0003-Propagate-simple-type-informations-about-parameters-.patch [^] (7,392 bytes) 2013-01-17 21:08
0004-Propagate-type-information-to-clambda.patch [^] (43,180 bytes) 2013-01-17 21:08
0005-Use-type-information-in-cmm.patch [^] (8,296 bytes) 2013-01-17 21:08

Relationships
 related to 0005917 closed chambart [patch] Generate direct call inside inlined function