pragma HLS inline - 2021.2 English

Vitis High-Level Synthesis User Guide (UG1399)

Document ID
Release Date
2021.2 English


Removes a function as a separate entity in the hierarchy. After inlining, the function is dissolved into the calling function and no longer appears as a separate level of hierarchy in the RTL.

Important: Inlining a child function also dissolves any pragmas or directives applied to that function. In Vitis HLS, any pragmas applied in the child context are ignored.

In some cases, inlining a function allows operations within the function to be shared and optimized more effectively with the calling function. However, an inlined function cannot be shared or reused, so if the parent function calls the inlined function multiple times, this can increase the area required for implementing the RTL.

The INLINE pragma applies differently to the scope it is defined in depending on how it is specified:

Without arguments, the pragma means that the function it is specified in should be inlined upward into any calling functions.
Specifies that the function it is specified in should not be inlined upward into any calling functions. This disables the inline of a specific function that can be automatically inlined or inlined as part of recursion.
Applies the pragma to the body of the function it is assigned in. It applies downward, recursively inlining the contents of the function.

By default, inlining is only performed on the next level of function hierarchy, not sub-functions. However, the recursive option lets you specify inlining through levels of the hierarchy.


Place the pragma in the C source within the body of the function or region of code.

#pragma HLS inline <recursive | off>


By default, only one level of function inlining is performed, and functions within the specified function are not inlined. The recursive option inlines all functions recursively within the specified function or region.
Disables function inlining to prevent specified functions from being inlined. For example, if recursive is specified in a function, this option can prevent a particular called function from being inlined when all others are.
Tip: The Vitis HLS tool automatically inlines small functions, and using the INLINE pragma with the off option can be used to prevent this automatic inlining.

Example 1

The following example inlines all functions within the body of func_top inlining recursively down through the function hierarchy, except function func_sub is not inlined. The recursive pragma is placed in function func_top. The pragma to disable inlining is placed in the function func_sub:

func_sub (p, q) {
#pragma HLS inline off
int q1 = q + 10;
func(p1,q);// foo_3
void func_top { a, b, c, d} {
  #pragma HLS inline recursive 
Tip: Notice in this example that INLINE RECURSIVE applies downward to the contents of function func_top, but INLINE OFF applies to func_sub directly.

Example 2

This example inlines the copy_output function into any functions or regions calling copy_output.

void copy_output(int *out, int out_lcl[OSize * OSize], int output) {
#pragma HLS INLINE
    // Calculate each work_item's result update location
    int stride = output * OSize * OSize;
    // Work_item updates output filter/image in DDR
    writeOut: for(int itr = 0; itr < OSize * OSize; itr++) {
    #pragma HLS PIPELINE
        out[stride + itr] = out_lcl[itr];