Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005917OCamlback end (clambda to assembly)public2013-02-11 10:412017-09-24 17:33
Assigned Tochambart 
PrioritynormalSeverityfeatureReproducibilityhave not tried
PlatformOSOS Version
Product Version 
Target VersionundecidedFixed in Version 
Summary0005917: [patch] Generate direct call inside inlined function
DescriptionCurrently when a function is inlined calls inside its body are not converted to direct call
when it is possible. For instance:

let f x = x + x

let g h (x,y) = h x, h y

let i (x,y) = g f (x,y)

When i is compiled, g will be inlined giving:

let i (x,y) = f x, f y

but calls to f will be generic calls (in that particular case it could even be inlined).

To do that, this pach add an environment of approximate values to the Closure.substitute
function to be able to retrieve the function definition at call site.

This also prepare for future patch using that environment: there are many possible things
that can be improved in functions when approximate environment is known. Normally this is
not really important because usually the programmer will avoid writing stupid code, but
when a function body is inlined, it can become redundant.

I also would like to open a discution: should we separate closure conversion and constant
propagation in two different passes ?

If we add other optimisations to the constant propagation phase, we would need to implement
them both inside the close (lambda to clambda) and substitute (clambda to clambda) functions.
So I think it would probably be simpler to simplify the closure conversion and do only that
in the lambda to clambda pass and do a separate optimisation pass on the produced clambda
Additional InformationSince the evaluation of function size for inlining is considered on the body without the
potential inline, it can be innacurate and lead to code size explosition in contrieved
examples like:

let f1 x = x + x
let f2 g (a,b) = g a, g b
let f3 g1 g2 (a,b) = g1 g2 (a,b), g1 g2 (a,b)
let f4 g1 g2 g3 (a,b) = g1 g2 g3 (a,b), g1 g2 g3 (a,b)

let f = f4 f3 f2 f1 (1,1)

If this bother someone, it is simple to forbid that by adding a limit to depth of allowed

This patch may be used to improve the patch submited for issue 0005894.
Attached Filespatch file icon 0001-Direct-call-can-be-generated-in-inlined-code.patch [^] (14,833 bytes) 2013-02-11 10:41 [Show Content]

- Relationships
related to 0005894acknowledged [patch] Avoid boxing float/int32/int64 when doing direct call 

-  Notes
chambart (developer)
2016-08-03 22:13

This was something that originally led to develop flambda. The feature was introduced in 4.03.

- Issue History
Date Modified Username Field Change
2013-02-11 10:41 chambart New Issue
2013-02-11 10:41 chambart File Added: 0001-Direct-call-can-be-generated-in-inlined-code.patch
2013-06-19 15:25 doligez Status new => acknowledged
2013-06-19 15:25 doligez Target Version => 4.01.0+dev
2013-07-16 16:32 frisch Target Version 4.01.0+dev => 4.02.0+dev
2013-12-16 14:16 doligez Tag Attached: patch
2014-08-15 18:22 gasche Target Version 4.02.0+dev => 4.02.1+dev
2014-09-04 00:25 doligez Target Version 4.02.1+dev => undecided
2016-01-08 18:11 frisch Relationship added related to 0005894
2016-08-03 22:13 chambart Note Added: 0016183
2016-08-03 22:14 chambart Status acknowledged => resolved
2016-08-03 22:14 chambart Resolution open => fixed
2016-08-03 22:14 chambart Assigned To => chambart
2017-02-23 16:35 doligez Category OCaml backend (code generation) => Back end (clambda to assembly)
2017-02-23 16:44 doligez Category Back end (clambda to assembly) => back end (clambda to assembly)
2017-09-24 17:33 xleroy Status resolved => closed

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker