www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Detailed inline behavior of dmd?

reply "SteveGuo" <steveguo outlook.com> writes:
D supports inline functions, But I want to know the details.

1. Is inline the default behavior? Or I have to add a compiler 
switch -inline?
2. The depth of inline.
3. If I add the switch -inline when compiling, it will inline 
everything no matter how complex the function is?
Aug 06 2013
next sibling parent "Peter Alexander" <peter.alexander.au gmail.com> writes:
1. You have to add -inline

2. Don't know. I'm guessing it depends on the function 
complexity, among other things.

3. No, it cannot possibly inline everything due to recursive 
functions, and indirect function calls. It would also be a 
terrible idea due to code bloat.
Aug 06 2013
prev sibling next sibling parent "SteveGuo" <steveguo outlook.com> writes:
On Tuesday, 6 August 2013 at 11:07:54 UTC, Peter Alexander wrote:
 1. You have to add -inline

 2. Don't know. I'm guessing it depends on the function 
 complexity, among other things.

 3. No, it cannot possibly inline everything due to recursive 
 functions, and indirect function calls. It would also be a 
 terrible idea due to code bloat.

Thanks for replying:) Ok, then is there a -forceinline option like other compiler?
Aug 06 2013
prev sibling next sibling parent "SteveGuo" <steveguo outlook.com> writes:
 Thanks for replying:)
 Ok, then is there a -forceinline option like other compiler?

Or maybe I should ask are there levels for the switch -inline?
Aug 06 2013
prev sibling next sibling parent David <d dav1d.de> writes:
Am 06.08.2013 13:01, schrieb SteveGuo:
 D supports inline functions, But I want to know the details.
 
 1. Is inline the default behavior? Or I have to add a compiler switch
 -inline?
 2. The depth of inline.
 3. If I add the switch -inline when compiling, it will inline everything
 no matter how complex the function is?

My experience with -inline. Without: runs fine With: segfaults Handle DMD with care, if you want performance, use LDC or GDC, both do a better job without introducing segfaults
Aug 06 2013
prev sibling next sibling parent "SteveGuo" <steveguo outlook.com> writes:
 My experience with -inline.
 Without: runs fine
 With: segfaults

 Handle DMD with care, if you want performance, use LDC or GDC, 
 both do a
 better job without introducing segfaults

Thanks for replying:) I will try LDC or GDC.
Aug 06 2013
prev sibling next sibling parent "qznc" <qznc web.de> writes:
On Tuesday, 6 August 2013 at 11:01:35 UTC, SteveGuo wrote:
 D supports inline functions, But I want to know the details.

 2. The depth of inline.
 3. If I add the switch -inline when compiling, it will inline 
 everything no matter how complex the function is?

As far as I know, no compiler specifies anything for this. Inlining is a difficult optimization, because it is hard to quantify if a specific call is worth inlining. Usually, there are handwavy heuristics and various magic numbers. Nobody should depend on exact behavior here. For specific cases, you can always inspect the assembly. Inlining everything is not possible in general. Consider recursive functions aka circles in the call graph. Dynamic binding and function pointers lead to calls of unknown functions.
Aug 06 2013
prev sibling next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
David:

 My experience with -inline.
 Without: runs fine
 With: segfaults

Recently the dmd inlining situation has improved, now the small lambdas often used with std.algorithms are inlined correctly, they have even removed one workaround in the all() function. I think the dmd patch was from Kenji. Bye, bearophile
Aug 06 2013
prev sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
On 6 August 2013 12:18, SteveGuo <steveguo outlook.com> wrote:
 On Tuesday, 6 August 2013 at 11:07:54 UTC, Peter Alexander wrote:
 1. You have to add -inline

 2. Don't know. I'm guessing it depends on the function complexity, among
 other things.

 3. No, it cannot possibly inline everything due to recursive functions,
 and indirect function calls. It would also be a terrible idea due to code
 bloat.

Thanks for replying:) Ok, then is there a -forceinline option like other compiler?

I wonder what other compiler you are referring to that has a -forceinline switch... seems odd to have one. -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0';
Aug 06 2013