LabWindows/CVI User Group Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

LabWindows/CVI Tip: Set Compiler Optimization Levels

Contents

  1. Overview of the Clang Optimizing Compiler
  2. How to Set the Compiler Optimization Level
  3. Learn More about Compiler Optimization Levels

Overview of Clang Optimizing Compiler

The LabWindows/CVI compiler now uses the LLVM compiler infrastructure with a Clang C front end. The updated compiler generates optimized code, meaning that you no longer need to use an external optimizing compiler for this purpose.

Clang was selected as a basis for the new LabWindows/CVI compiler because it can deliver amazingly fast compiles, extremely useful error and warning messages, and up to 60% faster execution speeds than the previous LabWindows/CVI compiler. Developers performing complex computation, mathematics, or analysis will see the highest performance gains when upgrading to LabWindows/CVI 2013 as the compiler backend is particularly suited for optimizing resources used in mathematical calculations.

LLVM and Clang began as research project out of the University of Illinois, with the goal of providing a modern, SSA-based compilation strategy capable of supporting both static and dynamic compilation of arbitrary programming languages [1]. Since then, LLVM has grown to include a number of subprojects, many of which are being used in production by a wide variety of commercial software vendors such as Apple Inc., Intel, AutoESL, NVIDIA, and National Instruments. To learn more, visit www.llvm.org.

How to Set the Compiler Optimization Level

The Optimization level is set on a project basis and is available for release builds that use the Standard CVI Compiler (ie this option is disabled in debug configurations or if using an external compiler). You can select whether the LabWindows/CVI compiler builds your code so that it uses the least amount of memory by selecting Optimize for space or builds it so that your code runs as quickly as possible at run time by selecting one of the Optimize for speed options. Higher optimization levels result in more aggressive optimization and require longer compilation times. The three Optimize for Speed levels are described in more detail below.

  1. Go to Options»Build Options
  2. Select one of the Optimization Levels:
    • No optimizations
    • Optimize for space
    • Optimize for speed (level 1)
    • Optimize for speed (level 2)
    • Optimize for speed (level 3)

Compiler Optimizations.png

Note Caution  Selecting a higher optimization level can cause undefined behavior in your programs at run time if your code does not strictly conform to the C specifications.

Learn More about Compiler Optimization Levels

The Optimize for Space optmization tells the LabWindows/CVI compiler to build your code so that it uses the least amount of memory. The Optimize for Speed options use LLVM speed optimizations when compiling an application with a set of three levels of optimization aggressiveness. Level 1 optimization is least aggressive and level 3 is most aggressive. LLVM optimizations are implemented as Transform Passes that traverse some portion of a program and mutate the program in some way. Each of the three levels uses a set of transform passes to determine which optimizations are performed.

To see a list of transform passes used for each optimization level, refer to the Knowledge Base: What Do the LabWindows/CVI Compiler Optimization Levels Mean?.

Did you find this tip useful? Rate this document or add a comment below.

If you give this a try, share your experience! Add a comment below.

National Instruments
Contributors