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

📄 optimize-options.html

📁 自己收集的linux入门到学懂高级编程书集 包括linux程序设计第三版
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<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.6"><!--Copyright &copy; 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.   <p>Permission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.2 orany later version published by the Free Software Foundation; with theInvariant Sections being "GNU General Public License" and "FundingFree Software", the Front-Cover texts being (a) (see below), and withthe Back-Cover Texts being (b) (see below).  A copy of the license isincluded 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.--><meta http-equiv="Content-Style-Type" content="text/css"><style type="text/css"><!--  pre.display { font-family:inherit }  pre.format  { font-family:inherit }  pre.smalldisplay { font-family:inherit; font-size:smaller }  pre.smallformat  { font-family:inherit; font-size:smaller }  pre.smallexample { font-size:smaller }  pre.smalllisp    { font-size:smaller }--></style></head><body><div class="node"><p>Node:&nbsp;<a name="Optimize%20Options">Optimize Options</a>,Next:&nbsp;<a rel="next" accesskey="n" href="Preprocessor-Options.html#Preprocessor%20Options">Preprocessor Options</a>,Previous:&nbsp;<a rel="previous" accesskey="p" href="Debugging-Options.html#Debugging%20Options">Debugging Options</a>,Up:&nbsp;<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 thecost of compilation and to make debugging produce the expectedresults.  Statements are independent: if you stop the program with abreakpoint between statements, you can then assign a new value to anyvariable or change the program counter to any other statement in thefunction and get exactly the results you would expect from the sourcecode.   <p>Turning on optimization flags makes the compiler attempt to improvethe performance and/or code size at the expense of compilation timeand possibly the ability to debug the program.   <p>The compiler performs optimization based on the knowledge it has ofthe program.  Optimization levels <code>-O2</code> and above, inparticular, enable <em>unit-at-a-time</em> mode, which allows thecompiler to consider information gained from later functions inthe file when compiling a function.  Compiling multiple files atonce to a single output file in <em>unit-at-a-time</em> mode allowsthe compiler to use information gained from all of the files whencompiling each of them.   <p>Not all optimizations are controlled directly by a flag.  Onlyoptimizations 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 lotmore memory for a large function.     <p>With <code>-O</code>, the compiler tries to reduce code size and executiontime, without performing any optimizations that take a great deal ofcompilation time.     <p><code>-O</code> turns on the following optimization flags:     <pre class="smallexample">          -fdefer-pop           -fmerge-constants           -fthread-jumps           -floop-optimize           -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 machineswhere doing so does not interfere with debugging.     <br><dt><code>-O2</code>     <dd>Optimize even more.  GCC performs nearly all supported optimizationsthat do not involve a space-speed tradeoff.  The compiler does notperform loop unrolling or function inlining when you specify <code>-O2</code>. As compared to <code>-O</code>, this option increases both compilation timeand the performance of the generated code.     <p><code>-O2</code> turns on all optimization flags specified by <code>-O</code>.  Italso 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  -fgcse-las           -fdelete-null-pointer-checks           -fexpensive-optimizations           -fregmove           -fschedule-insns  -fschedule-insns2           -fsched-interblock  -fsched-spec           -fcaller-saves           -fpeephole2           -freorder-blocks  -freorder-functions           -fstrict-aliasing           -funit-at-a-time           -falign-functions  -falign-jumps           -falign-loops  -falign-labels           -fcrossjumping          </pre>     <p>Please note the warning under <code>-fgcse</code> aboutinvoking <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>,<code>-fweb</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 thatdo not typically increase code size.  It also performs furtheroptimizations 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  -freorder-blocks-and-partition -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-independentflags.  Most flags have both positive and negative forms; the negativeform of <code>-ffoo</code> would be <code>-fno-foo</code>.  In the tablebelow, only one of the forms is listed--the one you typically willuse.  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 eitheractivated by <code>-O</code> options or are related to ones that are.  Youcan use the following flags in the rare cases when "fine-tuning" ofoptimizations to be performed is desired.     <dl><dt><code>-fno-default-inline</code>     <dd>Do not make member functions inline by default merely because they aredefined inside the class scope (C++ only).  Otherwise, when you specify<code>-O</code>, member functions defined inside class scope are compiledinline by default; i.e., you don't need to add <code>inline</code> in front ofthe member function name.     <br><dt><code>-fno-defer-pop</code>     <dd>Always pop the arguments to each function call as soon as that functionreturns.  For machines which must pop arguments after a function call,the compiler normally lets arguments accumulate on the stack for severalfunction 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 doingarithmetic on them.  This produces better code by making all memoryreferences potential common subexpressions.  When they are not commonsubexpressions, instruction combination should eliminate the separateregister-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 beforedoing 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 thatdon't need one.  This avoids the instructions to save, set up andrestore frame pointers; it also makes an extra register availablein many functions.  <strong>It also makes debugging impossible onsome machines.</strong>     <p>On some machines, such as the VAX, this flag has no effect, becausethe standard calling sequence automatically handles the frame pointerand nothing is saved by pretending it doesn't exist.  Themachine-description macro <code>FRAME_POINTER_REQUIRED</code> controlswhether 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 optionis 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 compilerheuristically decides which functions are simple enough to be worthintegrating in this way.     <p>If all calls to a given function are integrated, and the function isdeclared <code>static</code>, then the function is normally not output asassembler 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 flagallows the control of this limit for functions that are explicitly marked asinline (i.e., marked with the inline keyword or defined within the classdefinition in c++).  <var>n</var> is the size of functions that can be inlined innumber of pseudo instructions (not counting parameter handling).  The defaultvalue of <var>n</var> is 600. Increasing this value can result in more inlined code atthe cost of compilation time and memory consumption.  Decreasing usually makesthe compilation faster and less code will be inlined (which presumablymeans slower programs).  This option is particularly useful for programs thatuse inlining heavily such as those based on recursive templates with C++.     <p>Inlining is actually controlled by a number of parameters, which may bespecified 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 parametersas follows:          <dl> <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>See below for a documentation of the individualparameters controlling inlining.     <p><em>Note:</em> pseudo instruction represents, in this particular context, an

⌨️ 快捷键说明

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