Nios® V Processor Software Developer Handbook

ID 743810
Date 7/08/2024
Public
Document Table of Contents

7.11.1.2. Apply Different Compiler Flags within a Source File

Compilers provide ways to control the optimizer. riscv32-unknown-elf-gcc provides pragma GCC to control the compiler behavior temporarily . By using pragma GCC optimize("O0"), the optimization level is set to zero (no optimization) on a specified code section.

Using pragma GCC in Source Code

#pragma GCC push_options
#pragma GCC optimize("O0")
void example() {
    int x;
    x = 0;
    x += 1;
}
#pragma GCC pop_options

Assume hal.make.cflags_optimization is -O3, this specific function is excluded from any optimizations.