Procedure Inline

From emmtrix Wiki
Jump to navigation Jump to search

Procedure inlining is an optimization technique that replaces function calls with the actual body of the function. By eliminating function calls, this transformation reduces call overhead and enables further compiler optimizations. Inlining can improve execution speed by avoiding context switching and function call latency, making it particularly beneficial for performance-critical applications. Additionally, it increases opportunities for other transformations, such as loop optimizations and instruction reordering, while preserving the original program logic.

Procedure Inline Transformation in emmtrix Studio

emmtrix Studio can implement procedure inline using #pragma directives or via the GUI. Procedure inline is a transformation that inlines function body. It replaces function calls with their implementation.

Typical Usage and Benefits

The transformation is used to reduce the overhead caused by function calls and to increase the potential for optimizations. The latter is expressed through reduced parallelization difficulties and higher possibility for other transformations to be applied.

Example

/* The following code tests procedure inline transformation applied to a compound statement.
 * In the given example, function call func() is replaced with its lambda expression. 
 * The definition of the function is hence removed.
 */   

#include <stdio.h>

void func() {
    printf(Hello World\ n);
}
int main() {
    #pragma EMX_TRANSFORMATION ProcedureInlineTransform {
        /*
         * We have to use braces so we can use the pragma above
         * Otherwise the block will not be found
         */
        func();
    }
    return 0;
}
/* The following code is the generated code after the transformation has been applied.
 */

#include <stdio.h>

int main(void) {
    {
        printf(Hello World\ n);
    }
    return 0;
}