| AI Engine-ML Intrinsics User Guide (v2025.2)

Loading...
Searching...
No Matches
Macros
Loop transformations
Compiler optimizations » Code annotations

## Overview

These annotations are used after heading of the for or while loop.

## Macros
#define | __aie_loop_count(x)
| Set the number of iterations of a loop.
#define | __aie_loop_flatten()
| Unroll the loop completely (in case of a manifest loop count).
#define | __aie_loop_fold()
| Explicitly tell the compiler that the loop can be pipelined when the loop count is not manifest.
#define | __aie_loop_fold_no_warn()
| Disable the warning for missing opportunities to pipeline loops, or when the directive does not help.
#define | __aie_loop_fold_require(x)
| Set the required loop decrement for the loop to be pipelined.
#define | __aie_loop_fold_with_range(x, ...)
| Explicitly tell the compiler that the loop can be pipelined and provide the minimum and maximum number of iterations.
#define | __aie_loop_peel(x)
| Peel the first x iterations of a loop and insert them in the preamble.
#define | __aie_loop_range(x, ...)
| Set the minimum and maximum number of iterations of a loop.
#define | __aie_loop_unroll(...)
| Unroll the loop by a factor.
#define | __aie_loop_unroll_no_warn()
| Disable all the warnings related to loop unrolling.
#define | __aie_loop_unroll_preamble()
| Generates an additional preamble for the loop unrolling containing loop_count % N iterations.

## Macro Definition Documentation

## ◆ __aie_loop_count

#define __aie_loop_count | ( |  | x | ) |

Set the number of iterations of a loop.

Parameters

  x | loop count.

## ◆ __aie_loop_flatten

#define __aie_loop_flatten | ( |  | ) |

Unroll the loop completely (in case of a manifest loop count).

The flattening is done at scheduling phase (please see __aie_loop_unroll()).

## ◆ __aie_loop_fold

#define __aie_loop_fold | ( |  | ) |

Explicitly tell the compiler that the loop can be pipelined when the loop count is not manifest.

This is useful when the loop count is not manifest and the compiler cannot determine if the loop can be pipelined.

## ◆ __aie_loop_fold_no_warn

#define __aie_loop_fold_no_warn | ( |  | ) |

Disable the warning for missing opportunities to pipeline loops, or when the directive does not help.

## ◆ __aie_loop_fold_require

#define __aie_loop_fold_require | ( |  | x | ) |

Set the required loop decrement for the loop to be pipelined.

Parameters

  x | loop decrement value.

## ◆ __aie_loop_fold_with_range

#define __aie_loop_fold_with_range | ( |  | x,
|  |  | ... )

Explicitly tell the compiler that the loop can be pipelined and provide the minimum and maximum number of iterations.

## ◆ __aie_loop_peel

#define __aie_loop_peel | ( |  | x | ) |

Peel the first x iterations of a loop and insert them in the preamble.

Parameters

  x | number of iterations to peel.

## ◆ __aie_loop_range

#define __aie_loop_range | ( |  | x,
|  |  | ... )

Set the minimum and maximum number of iterations of a loop.

The format can be either: (n,) or (n,m), being n the minimum number of iterations and m the maximum number of iterations.

## ◆ __aie_loop_unroll

#define __aie_loop_unroll | ( |  | ... | ) |

Unroll the loop by a factor.

If used the value N, the loop will be unrolled N-1 times, and the loop count is divided by N. When the loop count is not guaranteed to be a multiple of N, you have to complement the unroll with __aie_loop_unroll_preamble().

The unrolling is done at the front-end level, providing better software pipelining of loops.

To fully unroll the loop, use __aie_loop_unroll(*). This requires the loop count to be manifest.

Parameters

  ... | loop unroll factor.

## ◆ __aie_loop_unroll_no_warn

#define __aie_loop_unroll_no_warn | ( |  | ) |

Disable all the warnings related to loop unrolling.

## ◆ __aie_loop_unroll_preamble

#define __aie_loop_unroll_preamble | ( |  | ) |

Generates an additional preamble for the loop unrolling containing loop_count % N iterations.