Highlights of Keil Compiler AC6 Compared to AC5

Follow+Star Public Number, don’t miss the wonderful content
Highlights of Keil Compiler AC6 Compared to AC5
Author | strongerHuang
WeChat Public Account | Embedded Column
The latest version of Keil MDK no longer includes the AC5 compiler by default (but AC5 can be installed manually), yet AC5 is still the compiler used by most engineers.
Readers who have used Keil MDK (Arm Compiler 6) version V6 should have noticed that the compilation speed of V6 is much faster than that of V5.
(Note: This refers to the AC compiler of version V6, not the MDK of version V6)
So, have you noticed the differences between Arm Compiler V6 and V5? What are the differences in optimization options integrated into MDK?

About Arm Compiler 6

Arm Compiler 6 (abbreviated as AC6) is a compilation toolchain for Arm processors, with the latest version as of December 2020: Arm Compiler V6.15.
There are many compilers available for compiling Cortex-M processors, Arm Compiler is one of them, commonly used in Keil MDK and Arm Development Studio (DS-5), and can also be installed as a standalone toolchain.
Highlights of Keil Compiler AC6 Compared to AC5
Of course, besides Arm Compiler, there are many compilers for Cortex-M, such as: GNU Compiler, IAR Compiler, CCS Compiler, etc.
The Arm Compiler 6 toolchain includes:
armclang: A compiler and integrated assembler based on LLVM and Clang technology.
armasm: The old assembler for armasm syntax assembly code. It integrates the armclang assembler for all new assembly files.
armar: Allows ELF object files to be collected together.
armlink: A linker that combines objects and libraries to generate executable files.
fromelf: An image converter and disassembler.
Arm C libraries: Runtime support libraries for embedded systems.
Arm C++ libraries: Libraries based on the LLVM libc++ project.
Highlights of Keil Compiler AC6 Compared to AC5
ARM Compiler 5 (and earlier versions) use the armcc compiler, while ARM Compiler 6 replaces armcc with armclang, which is based on LLVM and has different command line parameters, instructions, etc., thus it is considered a new compiler.
More related content:
What are the differences between GCC and Clang compilers?
http://www2.keil.com/mdk5/compiler/6/
https://developer.arm.com/tools-and-software/embedded/arm-compiler/downloads/version-6
(The public account does not support external links, please copy the link to the browser to open)

AC5 and AC6

Arm Compiler 5 (AC5) is a widely used generation of compilers, used in Keil MDK V4 versions and early V5 versions.
If readers want to change the compiler in Keil MDK, they can refer to my shared article: How to Install and Change AC Compiler in Keil MDK?
In 2015, AC6 was released and subsequently integrated into new versions of MDK, and the latest version of MDK now integrates AC6.21 (version can be modified):

Highlights of Keil Compiler AC6 Compared to AC5

Advantages of AC6 Compared to AC5
AC6 has made many changes compared to previous versions of the compiler, the most intuitive feeling is the significant improvement in compilation speed and code size.
Of course, besides speed and size, there are many other advantages, such as: support for C++ 14 standard, creating secure and non-secure code for devices using TrustZone for Armv8-M, and compatibility with source code based on GCC, meaning that source code compilable by GCC can also be compiled.
This is the official code size comparison:
Highlights of Keil Compiler AC6 Compared to AC5
Upgrading from AC5 to AC6
AC5 and AC6 are different compilers, there are compatibility differences that require migration. The official documentation for this migration process is provided:
https://developer.arm.com/docs/100068/0614/migrating-from-arm-compiler-5-to-arm-compiler-6
Of course, you can also refer to my previously shared article:
What Needs to be Done to Upgrade MDK-ARM Compiler from V5 to V6?
Related videos:

Keil MDK Optimization Options

In Keil MDK, compared to AC5, using AC6 adds several optimization options: code size, speed, balance, etc.
Highlights of Keil Compiler AC6 Compared to AC5
Optimization options include:
Highlights of Keil Compiler AC6 Compared to AC5
Optimization Level -O0
<span>-O0</span> Disables all optimizations. This optimization level is the default setting. Using<span>-O0</span> results in faster compilation and build times, but the generated code is slower than that produced by other optimization levels. Compared to<span>-O0</span> other optimization levels, the code size and stack usage are significantly higher. The generated code is closely related to the source code, but the amount of generated code is larger, including useless code.

Optimization Level -O1

<span>-O1</span> Enables core optimizations in the compiler. This optimization level provides a good debugging experience and has better code quality than<span>-O0</span>, with improved stack usage.Arm recommends using this option for a good debugging experience.
<span>-O1</span> The differences when used compared to -O0 are:
  • Enables optimizations, which may reduce the completeness of debugging information.
  • Enables inlining and tail calls, which means backtraces may not provide the stack with the function activated.
  • Functions that are not used or not expected to be called will not be called, resulting in smaller code size.
  • The values of variables may be unavailable in their scope after they are not used. For example, their stack locations may have been reused.

Optimization Level -O2

<span>-O2</span> Compared to -O1, this level provides higher performance optimization. It adds some new optimizations and changes the heuristic methods for optimization. This is the first optimization level at which the compiler may generate vector instructions. It may also reduce the debugging experience.
<span>-O2</span> The differences when used compared to -O1 are:
  • The threshold for the compiler to consider inlining call sites as profitable may increase.
  • The number of loop unrollings performed may increase.
  • Vector instructions can be generated for related sequences of simple loops and independent scalar operations.
Vector instructions can be prevented from being created using armclang command line option<span>-fno-vectorize</span>.

Optimization Level -O3

<span>-O3</span> Compared to -O2, this level provides higher performance optimization. This optimization level allows for optimizations that require extensive compile-time analysis and resources, and it changes the heuristic methods for optimization compared to -O2.<span>-O3</span> instructs the compiler to optimize for the performance of the generated code, ignoring the size of the generated code, which may lead to an increase in code size.
<span>-O3</span> The differences when used compared to -O2 are:
  • The threshold for the compiler to consider inlining call sites as profitable increases.
  • The amount of loop unrolling performed increases.
  • Enables more aggressive instruction optimizations in the compiler pipeline.

Optimization Level -Os

<span>-Os</span> Aims to provide high performance without significantly increasing code size. Depending on your application, the performance provided may be similar to <span>-O2</span> or <span>-O3</span>.
<span>-Os</span> Compared to -O3, it reduces the code size. However, it reduces the debugging experience.
<span>-Os</span> The differences when used compared to -O3 are:
  • Reduces the threshold for the compiler to consider inlining call sites as profitable.
  • Significantly reduces the amount of loop unrolling performed.

Optimization Level -Oz

<span>-Oz</span> Aims to provide the smallest possible code size. Arm recommends using this option for the best code size. This optimization level will reduce the debugging experience..
<span>-Oz</span> The differences when used compared to -Os are:
  • The compiler optimizes only for code size, ignoring performance optimizations, which may slow down the code.
  • Inlining is not disabled. In some cases, inlining may overall reduce code size, for example, if a function is only called once. Inlining heuristics are adjusted to inline only when a reduction in expected code size is anticipated.
  • Disables optimizations that may increase code size, such as loop unrolling and loop vectorization.
  • Loops are generated as while loops rather than do-while loops.

Optimization Level -Ofast

<span>-Ofast</span> Executes optimizations from the level, including optimizations performed with the <span>-ffast-math</span> armclang option.
This level also performs other further optimizations that may violate strict adherence to language standards.
Compared to -O3, this level reduces the debugging experience and may increase code size.

Optimization Level -Omax

<span>-Omax</span> Is the maximum optimization level, specifically targeting performance optimization. It supports all optimizations performed from the level, as well as link-time optimization (LTO).
At this optimization level, Arm Compiler may violate strict adherence to language standards. Using this optimization level yields the fastest performance.
Compared to -Ofast, this level reduces the debugging experience and may increase code size.
If you compile using -Omax and have separate compile and link steps, you must also include -Omax in the armlink command line.

———— END ————

Highlights of Keil Compiler AC6 Compared to AC5

● Column “Embedded Tools”

● Column “Embedded Development”

● Column “Keil Tutorial”

● Selected Tutorials from Embedded Column

Follow the public account reply “Join Group” to join the technical exchange group according to the rules, reply “1024” to see more content.

Click “Read Original” to see more shares.

Leave a Comment