Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005917OCamlOCaml backend (code generation)public2013-02-11 10:412014-08-15 18:22
Reporterchambart 
Assigned To 
PrioritynormalSeverityfeatureReproducibilityhave not tried
StatusacknowledgedResolutionopen 
PlatformOSOS Version
Product Version 
Target Versionafter-4.02.0Fixed 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
code.
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
inlining.


This patch may be used to improve the patch submited for issue 0005894.
Tagspatch
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

-  Notes
There are no notes attached to this issue.

- 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 => after-4.02.0


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker