Difference between revisions of "DIP56"

From D Wiki
Jump to: navigation, search
(Add pragma to control function inlining)
 
(Changed last updated date)
 
(10 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
{| class="wikitable"
 
{| class="wikitable"
 
!Title:
 
!Title:
!'''Add pragmas to influence function inlining'''
+
!'''Provide pragma to control function inlining'''
 
|-
 
|-
 
|DIP:
 
|DIP:
Line 10: Line 10:
 
|-
 
|-
 
|Status:
 
|Status:
|Draft
+
|Preliminarily approved post 2.067
 
|-
 
|-
 
|Created:
 
|Created:
Line 16: Line 16:
 
|-
 
|-
 
|Last Modified:
 
|Last Modified:
|2014-02-23
+
|2015-02-04
 
|-
 
|-
 
|Author:
 
|Author:
Line 25: Line 25:
  
 
== Abstract ==
 
== Abstract ==
This proposal uses pragmas to add hints to the compiler.
+
This proposal uses pragmas to add inlining instructions to the compiler.
  
 
== Rationale ==
 
== Rationale ==
Line 32: Line 32:
  
 
== Description ==
 
== Description ==
<div style="padding: 1ex 1ex; background: #ffd;">This section has been adapted for MediaWiki.</div>
+
This adds a pragma 'inline', which is followed by an optional boolean expression, which influences the inlining of the function it appears in. An evaluation of 'true' means always inline, 'false' means never inline, and no argument means the default behavior, as indicated in the command line.
 +
 
 +
If this pragma is outside of a function, it affects the functions in the block it encloses.
 +
 
 +
Nested pragmas override the outer ones.
 +
 
 +
If there are multiple pragmas inside a function, the lexically last one that is semantically analyzed
 +
controls the behavior.
  
This adds a pragma 'inline' and two values for it: true and false, which influences the inlining of the
+
If the pragma is versioned out or in a false static if conditional, it is ignored.
function they appear in. 'true' means always inline, 'false' means never inline.
 
  
These are not attributes because they should not affect the semantics of the function. In particular, the function signature
+
If a pragma specifies always inline, and the compiler cannot inline it, a warning will be generated.
must not be affected.
+
Implementations will likely vary in their ability to inline.
 +
 
 +
These are not attributes because they should not affect the semantics of the function.
 +
In particular, the function signature must not be affected.
  
 
== Usage ==
 
== Usage ==
<div style="padding: 1ex 1ex; background: #ffd;">This section has been adapted for MediaWiki.</div>
+
With the <code>-inline</code> compiler flag:
 +
 
 +
    pragma(inline, true)    always inlines
 +
    pragma(inline, false)  never inlines
 +
    pragma(inline)          inlines at compiler's discretion
  
pragma(inline, true);
+
Without the <code>-inline</code> compiler flag:
pragma(inline, false);
 
  
 +
    pragma(inline, true)    always inlines
 +
    pragma(inline, false)  never inlines
 +
    pragma(inline)          never inlines
  
 
== Copyright ==
 
== Copyright ==

Latest revision as of 00:07, 5 February 2015

Title: Provide pragma to control function inlining
DIP: 56
Version: 0
Status: Preliminarily approved post 2.067
Created: 2014-02-23
Last Modified: 2015-02-04
Author: Walter Bright
Links:

Abstract

This proposal uses pragmas to add inlining instructions to the compiler.

Rationale

Sometimes generating better code requires runtime profile information. But being a static compiler, not a JIT, the compiler could use such hints from the programmer.

Description

This adds a pragma 'inline', which is followed by an optional boolean expression, which influences the inlining of the function it appears in. An evaluation of 'true' means always inline, 'false' means never inline, and no argument means the default behavior, as indicated in the command line.

If this pragma is outside of a function, it affects the functions in the block it encloses.

Nested pragmas override the outer ones.

If there are multiple pragmas inside a function, the lexically last one that is semantically analyzed controls the behavior.

If the pragma is versioned out or in a false static if conditional, it is ignored.

If a pragma specifies always inline, and the compiler cannot inline it, a warning will be generated. Implementations will likely vary in their ability to inline.

These are not attributes because they should not affect the semantics of the function. In particular, the function signature must not be affected.

Usage

With the -inline compiler flag:

   pragma(inline, true)    always inlines
   pragma(inline, false)   never inlines
   pragma(inline)          inlines at compiler's discretion

Without the -inline compiler flag:

   pragma(inline, true)    always inlines
   pragma(inline, false)   never inlines
   pragma(inline)          never inlines

Copyright

This document has been placed in the Public Domain.