• Keine Ergebnisse gefunden

c++ OptionslVirtual Tables

Im Dokument or an (Seite 83-90)

The -Vn option controls the C++ virtual tables. It has five variations:

-v

Smart generates common C++ virtual tables and out-of-line inline functions across modules within your application. Asa result, only one instance of a given virtual table or out-of-line inline function is included in the program.

This produces the smallest and most efficient executables, but uses .OBJ and .ASM extensions only available with TLINK or T ASM.

-Vs Local generates local virtual tables and out-of-line inline functions. As a result, each module gets its own private copy of each virtual table or out-of-line inline function it uses; this setting produces larger executables than the Smart setting.

-va

External creates external references to virtual tables. If you don't want to use the Smart or Local options, you can use External and Public to produce and reference global virtual tables.

70 Borland C++ Users Guide

OptionsIProjectIC++ OptionslVirtual I abies

-V1 Public produces public definitions for virtual tables. When using External or Public options, at least one of the modules in the program must be compiled with the Public option to supply the definitions for the virtual tables. All other modules should be compiled with the

-va

option to refer to that Public copy of the virtual tables.

c++ OptionslTemplates

For more information about templates, see Chapter 3 in the Programmer's Guide.

-Jg Smart generates public definitions of all template instances. If more than one module generates the same template instance, the linker merges them to produce a single copy of the instance. To generate the instances~

however, the compiler must have available the function body (in the case of a template function) or the bodies of member functions and definitions for static data members (in the case of a template class).

-Jgd Global generates public definitions for all template instances encountered.

Duplicate instances are not merged, causing the linker to report public symbol redefinition errors if more than one module defines the same template instance.

-Jgx External generates external references to template instances. Make sure instances are publicly defined in some other module (using the -Jgd option), so that external references are properly resolved.

c++ OptionslException handling/RTTI

-x Enable exceptions enables C++ exception handling. If you use C++

exception handling constructs in your code and compile with this option disabled (by unchecking the option in the IDE or using the -x- command-line option), you'll get an error.

-xp Enable exception location information makes available run-time identification of exceptions by providing the line numbers in the source code where the exception occurred. This lets the program query the file and line number from where a C++ exception occurred.

-xd Enable destructor cleanup destructors are called for all automatically declared objects between the scope of the catch and throw statements when an exception is thrown. Note that destructors aren't automatically called for dynamic objects and dynamic objects aren't automatically freed.

optionsIProjectlC++ OptionslException handling/Rnl

-RT Enable runtime type information generates code that allows run-time type identification.

Optimizations

The Borland compiler contains an optimizer for improving your

application's speed or reducing its size. Compiling takes only 50% longer for full speed optimizations and 20% longer for size optimizations. You can compile with optimizations any time during your project cycle. When debugging, compiling with optimizations on can sometimes help reveal bugs in your code (the integrated debugger works with optimized code).

-Od Disable all optimizations turns off all optimizations. You can override this using named options sets in the project manager.

OptimizationslSpecific

-02 -Ot -Ox -G Executable speed creates the fastest code. The compiler determines whether it can safely generate code to perform a rep movsw instruction instead of calling a helper function to do the copy. This produces faster structure copies for structures and unions over eight bytes long than does the helper function call. The command-line option -Ox is provided for

• compatibility with the Microsoft compiler.

-01 -Os -G- Executable size creates the smallest code by scanning the generated code for duplicate sequences. When such sequences warrant, the optimizer replaces one sequence of code with a jump to the other and eliminates the first piece of code. This occurs most often with switch statements.

No optimization doesn't optimize common subexpressions. This option is on by default. The command-line compilers don't optimize common sub expressions by default, so there is no command-line equivalent option (you don't need to specify an option). .

-Oc Optimize locally eliminates common subexpressions within groups of statements unbroken by jumps (basic blocks).

-09 Optimize globally eliminates duplicate expressions within the target scope and stores the calculated value of those expressions once (instead of recalculating the expression). Although in theory this optimization could reduce code size, it optimizes for speed and rarely results in size

reductions. Use this option if you prefer to reuse expressions rather than recalculate them for each instance.

72 Borland C++ Users Guide

OptionSll-'rOJeCIIUptlmlZa1l0nSIi:lpeCITIC

-Oa Assume no pointer aliasing affects the way the optimizer performs common subexpression elimination and copy propagation by letting the optimizer maintain copy propagation information across function calls and maintain common subexpression information across some stores. Without this option the optimizer must discard information about copies and sub-expressions. Pointer aliasing might create bugs that are hard to spot, so it is applied only when you use -Oa.

-Oa controls how the optimizer treats expressions with pointers in them.

When compiling with common sub expressions and -Oa enabled, the optimizer recognizes *p * x as a common subexpression in function func1.

~ int g, y;

OptimizationslSize

int funcl(int *p)

{

int x=5;

y = *p * x;

9 = 3;

return (*p * Xli

void func2(void)

{

g=2;

funcl(&g); II This is incorrect--the assignment 9 = 3 II invalidates the expression *p * x

-0 Jump optimizations optimize jumps. When the Jump Optimization option is on, the compiler reduces the code size by eliminating redundant jumps and reorganizing loops and switch statements. When this option is on, the sequences of tracing and stepping in the debugger can be confusing, because there might be multiple lines of source code associated with a particular generated code sequence. When this option is off, you'll get the best stepping results when debugging.

-01 Loop optimization takes advantage of the string move instructions on the 80x86 processors by replacing the code for a loop with a string move instruction, making the code faster.

int v[lOO];

void t(void)

{

upuonSIt'roJeCIIUptlmlZatlOnSltilze

int i;

for (i = 0; i < 100; itt) v[iJ = 0;

Depending on the complexity of the operands, the compaCted loop code

~an also be smaller than the corresponding noncompacted loop.

-z

Suppress redundant loads, which you should always use when compiling with optimizations, optimizes for both speed and size by keeping track of the values loaded into registers. Values already in a register aren't loaded again.

-Ob Dead-code elimination reveals variables that might not be needed. Because the optimizer must determine where variables are no longer used and where their values are needed (live range analysis), you must use Global Register Allocation (-Oe) when using -Ob.

-ow

Windows prolog/epilog suppresses the inc bp / dec bp of an exported Windows far function Prolog and Epilog code. If the Debug information in OBJs (-v) option is on, this option is disabled because some debugging tools (such as WinSpector or Turbo Debugger for Windows) need the inc bp/dec bp to display stack frame information.

-Oe Global register allocation, which you should always use when optimizing code, increases the speed and decreases the size of your application. When the Global Register Allocation option is on, global register allocation and variable live range analysis are enabled.

OptimizationslSpeed

74

-Oi Inline intrinsic functions generates the code for memory functions (such as strcpy or memcmp) within your function's scope, thus eliminating the need for a function call. The resulting code executes faster, but it is larger. The following functions are inlined with this option:

• alloca .memset • strchr .strncmp

.fabs .rotl .strcmp .strncpy

.memchr .rotr • strcpy • strnset

.memcmp .stpcpy • strlen • strrchr

.memcpy • strcat • strncat

You can control the inlining of these functions with the pragma intrinsic.

For example, #pragma intrinsic strcpy generates inline code for all

subsequent calls to strcpy in your function, and #pragma intrinsic -strcpy

Borland C++ Users Guide

OptionslProjectlOptimizationslSpeed

prevents the compiler from inlining strcpy. Using these pragmas in a file overrides compiler options.

When inlining any intrinsic function, you must include a prototype for that function before you use it, because the compiler creates a macro that renames the inlined function to a function that the compiler recognizes internally. In the previous example, the compiler would create a macro

#define strcpy __ sticpy __ .

The compiler recognizes calls to functions with two leading and two trailing underscores and tries to match the prototype of that function against its own internally stored prototype. If you don't supply a prototype or if the prototype you supplied doesn't match the compiler's prototype, the compiler rejects the attempt to inline that function and generates an error.

-Om Invariant code motion moves invariant code out of loops and optimizes for speed. The optimizer uses information gathered about all the expressions in the function during common subexpression elimination to find expressions whose values don't change inside a loop. To prevent the calculation from being done many times inside the loop, the optimizer moves the code outside the loop so that it is calculated only once. The optimizer then reuses the calculated value inside the loop. You should use loop-invariant code motion whenever you are compiling for speed and you have used global common sub expressions, because moving code out of loops can result in enormous speed gains. For example, in the following code, x * y * z is evaluated in every iteration of the loop: .

int v[lO];

void f (void) {

int i,x,y,z;

for (i = 0; i < 10; itt) v[i] = x * y * z;

The optimizer rewrites the code:

int v[10];

void f (void) {

int i,x,y,z,tl;

tl '= x * y * z;

for (i ~ OJ i < 10; itt) v[i] = tlj

Optionsl ProjectiOptimizationsl Speed

Messages

76

-Op Copy propagation is primarily speed optimization, but it never increases the size of your code. Like loop-invariant code motion, copy propagation relies on the analysis performed during common sub expression

elimination. Copy propagation means that the optimizer remembers the values assigned to expressions and uses those values instead of loading the value of the assigned expressions. Copies of constants, expressions, and variables can be propagated.

-Ov Induction variables creates induction variables and performs strength reduction, which optimizes loops for speed. Use this option when you're compiling for speed and your code contains loops. The optimizer uses induction to create new variables (induction variables) from expressions used in loops. The optimizer assures that the operations performed on these new variables are computationally less expensive (reduced in strength) than those used by the original variables.

Optimizations are common if you use array indexing inside loops, because a multiplication operation is required to calculate the position in the array that is indicated by the index. For example, the optimizer creates an induction variable out of the operation v[il in the following code because the v[il operation requires multiplication, which also eliminates the need to preserve the value of i:

int v[10];

void f(void)

{

int i,x,y,z;

for (i = 0; i < 10i itt) v[i] = x * y * Zi

With Induction variables enabled, the code changes:

int v[10] ; void f (void)

{

int i,x,y,z, *p;

for (p = Vi P < &V[10]i ptt)

*p = x * y * z;

Messages on by default contain an asterisk next to the command-line option; these options are checked in the IDE.

Borland C++ Users Guide

uplIomjl t"'fUJt:::l,;lIIVIt:::::i::iayt::\)

-w All displays all warning messages.

-wxxx -w-xxx Selected enables the specific warning message typed at the command line or checked in the IDE. Using the pragma warn in your source code overrides messages options set either at the command line or in the IDE.

See Chapter 5 in the Programmer's Guide for more information on pragmas.

-w- None doesn't display warning messages. Errors are still displayed.

-gn Stop after n warnings stops compiling after n warnings occur in your project.

-jn Stop after n errors stops compiling after n errors occur in your project.

Im Dokument or an (Seite 83-90)