digitalmars.D - Detailed inline behavior of dmd?
- SteveGuo (6/6) Aug 06 2013 D supports inline functions, But I want to know the details.
- Peter Alexander (6/6) Aug 06 2013 1. You have to add -inline
- SteveGuo (3/9) Aug 06 2013 Thanks for replying:)
- SteveGuo (1/3) Aug 06 2013 Or maybe I should ask are there levels for the switch -inline?
- Iain Buclaw (6/18) Aug 06 2013 I wonder what other compiler you are referring to that has a
- David (6/13) Aug 06 2013 My experience with -inline.
- SteveGuo (1/7) Aug 06 2013 Thanks for replying:) I will try LDC or GDC.
- bearophile (7/10) Aug 06 2013 Recently the dmd inlining situation has improved, now the small
- qznc (10/14) Aug 06 2013 As far as I know, no compiler specifies anything for this.
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
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
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
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
On 6 August 2013 12:18, SteveGuo <steveguo outlook.com> wrote:On Tuesday, 6 August 2013 at 11:07:54 UTC, Peter Alexander wrote: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';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
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
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 segfaultsThanks for replying:) I will try LDC or GDC.
Aug 06 2013
David:My experience with -inline. Without: runs fine With: segfaultsRecently 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
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