⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 optimize-options.html

📁 gcc手册
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<html lang="en">

<head>

<title>Using the GNU Compiler Collection (GCC)</title>

<meta http-equiv="Content-Type" content="text/html">

<meta name="description" content="Using the GNU Compiler Collection (GCC)">

<meta name="generator" content="makeinfo 4.3">

<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">

<!--

Copyright &copy; 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,

1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.



   <p>Permission is granted to copy, distribute and/or modify this document

under the terms of the GNU Free Documentation License, Version 1.2 or

any later version published by the Free Software Foundation; with the

Invariant Sections being "GNU General Public License" and "Funding

Free Software", the Front-Cover texts being (a) (see below), and with

the Back-Cover Texts being (b) (see below).  A copy of the license is

included in the section entitled "GNU Free Documentation License".



   <p>(a) The FSF's Front-Cover Text is:



   <p>A GNU Manual



   <p>(b) The FSF's Back-Cover Text is:



   <p>You have freedom to copy and modify this GNU Manual, like GNU

     software.  Copies published by the Free Software Foundation raise

     funds for GNU development.-->

</head>

<body>

<div class="node">

<p>

Node:<a name="Optimize%20Options">Optimize Options</a>,

Next:<a rel="next" accesskey="n" href="Preprocessor-Options.html#Preprocessor%20Options">Preprocessor Options</a>,

Previous:<a rel="previous" accesskey="p" href="Debugging-Options.html#Debugging%20Options">Debugging Options</a>,

Up:<a rel="up" accesskey="u" href="Invoking-GCC.html#Invoking%20GCC">Invoking GCC</a>

<hr><br>

</div>



<h3 class="section">Options That Control Optimization</h3>



   <p>These options control various sorts of optimizations.



   <p>Without any optimization option, the compiler's goal is to reduce the

cost of compilation and to make debugging produce the expected

results.  Statements are independent: if you stop the program with a

breakpoint between statements, you can then assign a new value to any

variable or change the program counter to any other statement in the

function and get exactly the results you would expect from the source

code.



   <p>Turning on optimization flags makes the compiler attempt to improve

the performance and/or code size at the expense of compilation time

and possibly the ability to debug the program.



   <p>Not all optimizations are controlled directly by a flag.  Only

optimizations that have a flag are listed.



     <dl>

<dt><code>-O</code>

     <dd><dt><code>-O1</code>

     <dd>Optimize.  Optimizing compilation takes somewhat more time, and a lot

more memory for a large function.



     <p>With <code>-O</code>, the compiler tries to reduce code size and execution

time, without performing any optimizations that take a great deal of

compilation time.



     <p><code>-O</code> turns on the following optimization flags:

     <pre class="smallexample">          -fdefer-pop 

          -fmerge-constants 

          -fthread-jumps 

          -floop-optimize 

          -fcrossjumping 

          -fif-conversion 

          -fif-conversion2 

          -fdelayed-branch 

          -fguess-branch-probability 

          -fcprop-registers

          </pre>



     <p><code>-O</code> also turns on <code>-fomit-frame-pointer</code> on machines

where doing so does not interfere with debugging.



     <br><dt><code>-O2</code>

     <dd>Optimize even more.  GCC performs nearly all supported optimizations

that do not involve a space-speed tradeoff.  The compiler does not

perform loop unrolling or function inlining when you specify <code>-O2</code>. 

As compared to <code>-O</code>, this option increases both compilation time

and the performance of the generated code.



     <p><code>-O2</code> turns on all optimization flags specified by <code>-O</code>.  It

also turns on the following optimization flags:

     <pre class="smallexample">          -fforce-mem 

          -foptimize-sibling-calls 

          -fstrength-reduce 

          -fcse-follow-jumps  -fcse-skip-blocks 

          -frerun-cse-after-loop  -frerun-loop-opt 

          -fgcse   -fgcse-lm   -fgcse-sm 

          -fdelete-null-pointer-checks 

          -fexpensive-optimizations 

          -fregmove 

          -fschedule-insns  -fschedule-insns2 

          -fsched-interblock -fsched-spec 

          -fcaller-saves 

          -fpeephole2 

          -freorder-blocks  -freorder-functions 

          -fstrict-aliasing 

          -falign-functions  -falign-jumps 

          -falign-loops  -falign-labels

          </pre>



     <p>Please note the warning under <code>-fgcse</code> about

invoking <code>-O2</code> on programs that use computed gotos.



     <br><dt><code>-O3</code>

     <dd>Optimize yet more.  <code>-O3</code> turns on all optimizations specified by

<code>-O2</code> and also turns on the <code>-finline-functions</code> and

<code>-frename-registers</code> options.



     <br><dt><code>-O0</code>

     <dd>Do not optimize.  This is the default.



     <br><dt><code>-Os</code>

     <dd>Optimize for size.  <code>-Os</code> enables all <code>-O2</code> optimizations that

do not typically increase code size.  It also performs further

optimizations designed to reduce code size.



     <p><code>-Os</code> disables the following optimization flags:

     <pre class="smallexample">          -falign-functions  -falign-jumps  -falign-loops 

          -falign-labels  -freorder-blocks -fprefetch-loop-arrays

          </pre>



     <p>If you use multiple <code>-O</code> options, with or without level numbers,

the last such option is the one that is effective. 

</dl>



   <p>Options of the form <code>-f</code><var>flag</var><code></code> specify machine-independent

flags.  Most flags have both positive and negative forms; the negative

form of <code>-ffoo</code> would be <code>-fno-foo</code>.  In the table

below, only one of the forms is listed--the one you typically will

use.  You can figure out the other form by either removing <code>no-</code>

or adding it.



   <p>The following options control specific optimizations.  They are either

activated by <code>-O</code> options or are related to ones that are.  You

can use the following flags in the rare cases when "fine-tuning" of

optimizations to be performed is desired.



     <dl>

<dt><code>-fno-default-inline</code>

     <dd>Do not make member functions inline by default merely because they are

defined inside the class scope (C++ only).  Otherwise, when you specify

<code>-O</code>, member functions defined inside class scope are compiled

inline by default; i.e., you don't need to add <code>inline</code> in front of

the member function name.



     <br><dt><code>-fno-defer-pop</code>

     <dd>Always pop the arguments to each function call as soon as that function

returns.  For machines which must pop arguments after a function call,

the compiler normally lets arguments accumulate on the stack for several

function calls and pops them all at once.



     <p>Disabled at levels <code>-O</code>, <code>-O2</code>, <code>-O3</code>, <code>-Os</code>.



     <br><dt><code>-fforce-mem</code>

     <dd>Force memory operands to be copied into registers before doing

arithmetic on them.  This produces better code by making all memory

references potential common subexpressions.  When they are not common

subexpressions, instruction combination should eliminate the separate

register-load.



     <p>Enabled at levels <code>-O2</code>, <code>-O3</code>, <code>-Os</code>.



     <br><dt><code>-fforce-addr</code>

     <dd>Force memory address constants to be copied into registers before

doing arithmetic on them.  This may produce better code just as

<code>-fforce-mem</code> may.



     <br><dt><code>-fomit-frame-pointer</code>

     <dd>Don't keep the frame pointer in a register for functions that

don't need one.  This avoids the instructions to save, set up and

restore frame pointers; it also makes an extra register available

in many functions.  <strong>It also makes debugging impossible on

some machines.</strong>



     <p>On some machines, such as the VAX, this flag has no effect, because

the standard calling sequence automatically handles the frame pointer

and nothing is saved by pretending it doesn't exist.  The

machine-description macro <code>FRAME_POINTER_REQUIRED</code> controls

whether a target machine supports this flag.  See <a href="../gccint/Registers.html#Registers">Register Usage</a>.



     <p>Enabled at levels <code>-O</code>, <code>-O2</code>, <code>-O3</code>, <code>-Os</code>.



     <br><dt><code>-foptimize-sibling-calls</code>

     <dd>Optimize sibling and tail recursive calls.



     <p>Enabled at levels <code>-O2</code>, <code>-O3</code>, <code>-Os</code>.



     <br><dt><code>-fno-inline</code>

     <dd>Don't pay attention to the <code>inline</code> keyword.  Normally this option

is used to keep the compiler from expanding any functions inline. 

Note that if you are not optimizing, no functions can be expanded inline.



     <br><dt><code>-finline-functions</code>

     <dd>Integrate all simple functions into their callers.  The compiler

heuristically decides which functions are simple enough to be worth

integrating in this way.



     <p>If all calls to a given function are integrated, and the function is

declared <code>static</code>, then the function is normally not output as

assembler code in its own right.



     <p>Enabled at level <code>-O3</code>.



     <br><dt><code>-finline-limit=</code><var>n</var><code></code>

     <dd>By default, gcc limits the size of functions that can be inlined.  This flag

allows the control of this limit for functions that are explicitly marked as

inline (i.e., marked with the inline keyword or defined within the class

definition in c++).  <var>n</var> is the size of functions that can be inlined in

number of pseudo instructions (not counting parameter handling).  The default

value of <var>n</var> is 600. 

Increasing this value can result in more inlined code at

the cost of compilation time and memory consumption.  Decreasing usually makes

the compilation faster and less code will be inlined (which presumably

means slower programs).  This option is particularly useful for programs that

use inlining heavily such as those based on recursive templates with C++.



     <p>Inlining is actually controlled by a number of parameters, which may be

specified individually by using <code>--param </code><var>name</var><code>=</code><var>value</var><code></code>. 

The <code>-finline-limit=</code><var>n</var><code></code> option sets some of these parameters

as follows:



          <dl>

 <br><dt><code>max-inline-insns</code>

          <dd>  is set to <var>n</var>. 

 <br><dt><code>max-inline-insns-single</code>

          <dd>  is set to <var>n</var>/2. 

 <br><dt><code>max-inline-insns-auto</code>

          <dd>  is set to <var>n</var>/2. 

 <br><dt><code>min-inline-insns</code>

          <dd>  is set to 130 or <var>n</var>/4, whichever is smaller. 

 <br><dt><code>max-inline-insns-rtl</code>

          <dd>  is set to <var>n</var>. 

 </dl>



     <p>Using <code>-finline-limit=600</code> thus results in the default settings

for these parameters.  See below for a documentation of the individual

parameters controlling inlining.



     <p><em>Note:</em> pseudo instruction represents, in this particular context, an

abstract measurement of function's size.  In no way, it represents a count

of assembly instructions and as such its exact meaning might change from one

release to an another.



     <br><dt><code>-fkeep-inline-functions</code>

     <dd>Even if all calls to a given function are integrated, and the function

is declared <code>static</code>, nevertheless output a separate run-time

callable version of the function.  This switch does not affect

<code>extern inline</code> functions.



     <br><dt><code>-fkeep-static-consts</code>

     <dd>Emit variables declared <code>static const</code> when optimization isn't turned

on, even if the variables aren't referenced.



     <p>GCC enables this option by default.  If you want to force the compiler to

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -