CodeWarrior Compiler Settings
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Tutorial Introduction
PURPOSE:
-To describe the process of selecting compiler settings for a Build Target
in CodeWarrior
OBJECTIVES:
-Describe the build process and how a compiler is selected.
-Describe how to use the settings panels to select compiler settings for
language-specific features, code generation, and optimization..
CONTENT:
-11 pages
-2 questions
LEARNING TIME:
-5-10 minutes
Welcome to this tutorial on compiler settings. In this tutorial, you’ll learn how to select the target hardware and operating system on which the program code executes. You’ll also learn how to adjust the compiler and processor-specific controls to generate machine code that is precisely tuned for your target device.
Overview of the Build Process
•The build process issues commands that generate code.
•.The Project Manager handles all dependencies.
–The process is automatic.
–If one file is changed, all dependent files are marked for update.
•The object code is generated in accordance with --
–Language settings
–Global (IR) optimizations
–Back-end settings
•“Object code” is placed in the project data folder.
–Users should not change the contents of the data folder manually
Let’s begin this tutorial with an overview of the build process.A Build command can be issued in three different ways: (1) from the Project Window toolbar, (2) from the Project menu, or (3) from a keyboard sequence. The first thing the IDE does is to check dependencies, for files that have changed. Such files need to be updated or recompiled as part of the build.
Note that CodeWarrior automatically handles file dependencies. If you change any file, a header file for example, all other files that use that header are automatically marked for update.
The object code is generated according to your Build Target settings. There are no traditional .o files. Rather, CodeWarrior places the object code in a single flat file. This file is located inside the data folder. The data folder is in your project directory. You should never change the contents of the data folder manually. CodeWarrior manages access to the object code transparently.
Selecting a Compiler
•Front-end compiler --
–Save files with the correct name extension.
–Use the File Mappings panel to see or modify options.
–Select Edit ==> Target Name Settings ==> File Mappings
•Back-end compiler --
–Specify a linker, the Platform target.
–Select Edit ==> Target Name Settings ==> Target Settings panel
–Appropriate language panels will appear.
–Other target-specific panels will appear.
You control which compiler is used to compile your code based on the file properties in the File Mappings panel. Each file has an associated compiler. For example, a source file with a .cpp extension uses the MW C/C++ compiler.
The back-end compiler is chosen in the Target Settings panel. Choosing the Platform target, that is, the linker-setting item in this panel, causes the appropriate language panel and target-specific panel to appear.
Controlling Language Features
•Use the language settings panel for
your programming language.
–Select Edit ==> Target Name
Settings ==> C/C++ Language panel.
•Modify the settings to fit your work.
• Same for all CodeWarrior compilers.
•For additional details see
–C Compilers Reference
Language-specific settings are controlled by the appropriate language panel. You should modify the settings in this panel to match your program’s requirements. Some language-specific settings you can control include: (1) function in-lining actions, (2) language support (ex. bool, wchar_t) and (3) how strict the source code should conform to the language standard.
Using the Target Panel
•Use the Target Settings panel
–Select Edit ==> Target Name
Settings ==> Target Settings.
•The panel varies per target, but
typical options are listed below:
–output file name
–type of code being built (e.g.,
executable, library)
–basic options for the build
•See Targeting manuals for details.
The "Target" panel is specific to the chip you are targeting. The panel shown here is the EPPC Target panel. While there are differences between platform targets, the common options include: (1) the file name for the binary you create; (2) the ability to choose what kind of code you build, such as library, executable, etc.; and (3) related options.
Using the Processor Panel
•Use the Processor settings panel.
–Select Edit ==> Target Name
Settings ==> Chip Name Processor.
•The panel varies per target, but
typical options are as follows:
–processor selection
–data alignment
–some target-specific optimizations
•See Targeting manuals for details.
The “Processor” panel is another chip-specific panel. Again, the options in this panel vary depending on the target platform. The panel shown is the EPPC Processor Panel. Typical options include: (1) the processor type you want to target, (2) data alignment options, and (3) some chip-specific optimizations.
Note that some platforms include additional panels. For example, the EPPC platform includes a EPPC Exceptions panel in the Debugger group.
Global Optimizations
•Optimize for size or speed.
•Choose the desired level of
optimization.
–Levels 1,2 typically debug-friendly.
–Levels 3,4 aren’t debug-friendly.
•You can select individual optimizations
outside of this panel.
–Pragmas can be used to control fine detail.
• Same for all CodeWarrior compilers.
Now let’s discuss optimization, beginning with global optimization. Specific optimizations can be performed on your code, regardless of the platform target. The type of optimization performed depends on the optimization level you choose.
There are two types of optimization commands available. Optimize for Faster Execution Speed or for Smaller Code Size, which tells the compiler to favor one type of optimization over the other, since the compiler actually performs both optimizations all of the time. For example, if you choose Optimize For: Faster Execution Speed, the compiler performs both speed and size optimizations, but in some cases will favor speed and thus may produce code slightly larger than optimal size. The same is true for the Optimize For: Smaller Code Size option. One option is always favored.
There are four levels of optimization available. Each setting is compounded. Level 2
performs all the optimizations of Level 1, plus some extras. Unlike the Optimize For: Faster Execution Speed and Optimize For: Smaller Code Size options, the optimization level
command can be disabled. While optimization Levels 1 and 2 are generally debug-friendly, it is advisable to disable all optimizations when debugging your code. That is recommended because the compiler might be able to “optimize out” an entire function making you unable debug the non-optimized code. For fine tuning optimizations, pragmas must be used in your code. See the C Compiler Reference for more information.
Highlight 1 (E07)Highlight 2
(E07A)Highlight 3
(E07B)
Processor-Specific Optimizations
•These optimizations are found in the Chip Name Processor panel
•These optimizations vary with the type of platform target.
•Some typical optimizations include:
–Instruction scheduling
–Peephole optimizations
–Data alignment
This page summarizes the optimizations controlled by the processor-specific settings panel. This panel lets you control how the back-end generates and applies optimizations to the machine code generated for the target processor. Generally, such settings determine the following: (1) how the back-end schedules instructions, (2) how certain instruction sequences are optimized, and (3) how data is aligned in memory.
Instruction scheduling arranges the instruction stream for a selected processor; it’s precisely tuned to the processor’s micro-architecture for maximum execution speed. Please note that scheduling code for one processor may hinder the code’s performance on another.
The peephole optimizer examines the generated machine code and replaces certain sequences of instructions with more efficient ones. The instructions do not have to be adjacent for the CodeWarrior peephole optimizer to perform an instruction substitution.
The data alignment optimizer organizes data structures so that they fit within the processor’s preferred memory access patterns. Note that aligned data can triple the processor’s data fetch rate.
Question
Which of the following mechanisms selects the front-end language compiler?
Click on your choice.
A) The file extension
B) The Target Settings panel
C) The Chip Name Processor panel
D) The Global Optimizations panel
Let’s complete this tutorial with a couple of questions.
Which of the following mechanisms selects the front-end language compiler?
Answer:
The file extension determines which front-end language compiler CodeWarrior uses.
Question
Which of the following mechanisms selects the back-end compiler? Click on your
choice.
A) The file extension
B) The Target Settings panel
C) The Chip Name Processor panel
D) The Global Optimizations panel
Which of the following mechanisms selects the back-end compiler?
Answer:
The Target Settings panel is where you choose the linker, which in turn specifies the back-end compiler.
Tutorial Completion
•CodeWarrior supports a variety of high-level languages and processor targets.
–The file extension determines the front-end language parser used.
–The Target Settings panel determines the back-end processor-specific code generator used.
•The front-end language panel controls language-specific optimizations, support, and
conformance to a language standard.
•The Global Optimizations panel controls how well internal representations of the
program are optimized.
•The back-end Chip Name panel controls processor-specific optimizations.
Let’s review what we discussed in this tutorial.
CodeWarrior has an extensive group of settings panels that enable you to precisely control
machine code generation. Using these panels, you can adjust the resulting machine code so
that it runs on an entire family of processors or on just one specific member of that processor
family. This wide range of settings enables you to migrate code quickly among products that
contain related members of a processor family, or fine-tune the code for a specific embedded
processor for maximum performance.
11。