1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
---|
2 | <html>
|
---|
3 | <!-- Copyright (C) 2022 Richard Stallman and Free Software Foundation, Inc.
|
---|
4 |
|
---|
5 | (The work of Trevis Rothwell and Nelson Beebe has been assigned or
|
---|
6 | licensed to the FSF.)
|
---|
7 |
|
---|
8 | Permission is granted to copy, distribute and/or modify this document
|
---|
9 | under the terms of the GNU Free Documentation License, Version 1.3 or
|
---|
10 | any later version published by the Free Software Foundation; with the
|
---|
11 | Invariant Sections being "GNU General Public License," with the
|
---|
12 | Front-Cover Texts being "A GNU Manual," and with the Back-Cover
|
---|
13 | Texts as in (a) below. A copy of the license is included in the
|
---|
14 | section entitled "GNU Free Documentation License."
|
---|
15 |
|
---|
16 | (a) The FSF's Back-Cover Text is: "You have the freedom to copy and
|
---|
17 | modify this GNU manual. Buying copies from the FSF supports it in
|
---|
18 | developing GNU and promoting software freedom." -->
|
---|
19 | <!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
|
---|
20 | <head>
|
---|
21 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
---|
22 | <title>Optimization Pragmas (GNU C Language Manual)</title>
|
---|
23 |
|
---|
24 | <meta name="description" content="Optimization Pragmas (GNU C Language Manual)">
|
---|
25 | <meta name="keywords" content="Optimization Pragmas (GNU C Language Manual)">
|
---|
26 | <meta name="resource-type" content="document">
|
---|
27 | <meta name="distribution" content="global">
|
---|
28 | <meta name="Generator" content="makeinfo">
|
---|
29 | <link href="index.html" rel="start" title="Top">
|
---|
30 | <link href="Symbol-Index.html" rel="index" title="Symbol Index">
|
---|
31 | <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
---|
32 | <link href="Pragmas.html" rel="up" title="Pragmas">
|
---|
33 | <link href="Static-Assertions.html" rel="next" title="Static Assertions">
|
---|
34 | <link href="Severity-Pragmas.html" rel="prev" title="Severity Pragmas">
|
---|
35 | <style type="text/css">
|
---|
36 | <!--
|
---|
37 | a.summary-letter {text-decoration: none}
|
---|
38 | blockquote.indentedblock {margin-right: 0em}
|
---|
39 | div.display {margin-left: 3.2em}
|
---|
40 | div.example {margin-left: 3.2em}
|
---|
41 | div.lisp {margin-left: 3.2em}
|
---|
42 | kbd {font-style: oblique}
|
---|
43 | pre.display {font-family: inherit}
|
---|
44 | pre.format {font-family: inherit}
|
---|
45 | pre.menu-comment {font-family: serif}
|
---|
46 | pre.menu-preformatted {font-family: serif}
|
---|
47 | span.nolinebreak {white-space: nowrap}
|
---|
48 | span.roman {font-family: initial; font-weight: normal}
|
---|
49 | span.sansserif {font-family: sans-serif; font-weight: normal}
|
---|
50 | ul.no-bullet {list-style: none}
|
---|
51 | -->
|
---|
52 | </style>
|
---|
53 |
|
---|
54 |
|
---|
55 | </head>
|
---|
56 |
|
---|
57 | <body lang="en">
|
---|
58 | <span id="Optimization-Pragmas"></span><div class="header">
|
---|
59 | <p>
|
---|
60 | Previous: <a href="Severity-Pragmas.html" accesskey="p" rel="prev">Severity Pragmas</a>, Up: <a href="Pragmas.html" accesskey="u" rel="up">Pragmas</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
|
---|
61 | </div>
|
---|
62 | <hr>
|
---|
63 | <span id="Optimization-Pragmas-1"></span><h4 class="subsection">30.1.3 Optimization Pragmas</h4>
|
---|
64 |
|
---|
65 | <p>These pragmas enable a particular optimization for specific function
|
---|
66 | definitions. The settings take effect at the end of a function
|
---|
67 | definition, so the clean place to use these pragmas is between
|
---|
68 | function definitions.
|
---|
69 | </p>
|
---|
70 | <dl compact="compact">
|
---|
71 | <dt><code>#pragma GCC optimize <var>optimization</var></code></dt>
|
---|
72 | <dt><code>_Pragma ("GCC optimize <var>optimization</var>")</code></dt>
|
---|
73 | <dd><p>These pragmas enable the optimization <var>optimization</var> for the
|
---|
74 | following functions. For example,
|
---|
75 | </p>
|
---|
76 | <div class="example">
|
---|
77 | <pre class="example">_Pragma ("GCC optimize -fforward-propagate")
|
---|
78 | </pre></div>
|
---|
79 |
|
---|
80 | <p>says to apply the ‘<samp>forward-propagate</samp>’ optimization to all
|
---|
81 | following function definitions. Specifying optimizations for
|
---|
82 | individual functions, rather than for the entire program, is rare but
|
---|
83 | can be useful for getting around a bug in the compiler.
|
---|
84 | </p>
|
---|
85 | <p>If <var>optimization</var> does not correspond to a defined optimization
|
---|
86 | option, the pragma is erroneous. To turn off an optimization, use the
|
---|
87 | corresponding ‘<samp>-fno-</samp>’ option, such as
|
---|
88 | ‘<samp>-fno-forward-propagate</samp>’.
|
---|
89 | </p>
|
---|
90 | </dd>
|
---|
91 | <dt><code>#pragma GCC target <var>optimizations</var></code></dt>
|
---|
92 | <dt><code>_Pragma ("GCC target <var>optimizations</var>")</code></dt>
|
---|
93 | <dd><p>The pragma ‘<samp>GCC target</samp>’ is similar to ‘<samp>GCC optimize</samp>’ but is
|
---|
94 | used for platform-specific optimizations. Thus,
|
---|
95 | </p>
|
---|
96 | <div class="example">
|
---|
97 | <pre class="example">_Pragma ("GCC target popcnt")
|
---|
98 | </pre></div>
|
---|
99 |
|
---|
100 | <p>activates the optimization ‘<samp>popcnt</samp>’ for all
|
---|
101 | following function definitions. This optimization is supported
|
---|
102 | on a few common targets but not on others.
|
---|
103 | </p>
|
---|
104 | </dd>
|
---|
105 | <dt><code>#pragma GCC push_options</code></dt>
|
---|
106 | <dt><code>_Pragma ("GCC push_options")</code></dt>
|
---|
107 | <dd><p>The ‘<samp>push_options</samp>’ pragma saves on a stack the current settings
|
---|
108 | specified with the ‘<samp>target</samp>’ and ‘<samp>optimize</samp>’ pragmas.
|
---|
109 | </p>
|
---|
110 | </dd>
|
---|
111 | <dt><code>#pragma GCC pop_options</code></dt>
|
---|
112 | <dt><code>_Pragma ("GCC pop_options")</code></dt>
|
---|
113 | <dd><p>The ‘<samp>pop_options</samp>’ pragma pops saved settings from that stack.
|
---|
114 | </p>
|
---|
115 | <p>Here’s an example of using this stack.
|
---|
116 | </p>
|
---|
117 | <div class="example">
|
---|
118 | <pre class="example">_Pragma ("GCC push_options")
|
---|
119 | _Pragma ("GCC optimize forward-propagate")
|
---|
120 |
|
---|
121 | /* <span class="roman">Functions to compile</span>
|
---|
122 | <span class="roman">with the <code>forward-propagate</code> optimization.</span> */
|
---|
123 |
|
---|
124 | _Pragma ("GCC pop_options")
|
---|
125 | /* <span class="roman">Ends enablement of <code>forward-propagate</code>.</span> */
|
---|
126 | </pre></div>
|
---|
127 |
|
---|
128 | </dd>
|
---|
129 | <dt><code>#pragma GCC reset_options</code></dt>
|
---|
130 | <dt><code>_Pragma ("GCC reset_options")</code></dt>
|
---|
131 | <dd><p>Clears all pragma-defined ‘<samp>target</samp>’ and ‘<samp>optimize</samp>’
|
---|
132 | optimization settings.
|
---|
133 | </p></dd>
|
---|
134 | </dl>
|
---|
135 |
|
---|
136 | <hr>
|
---|
137 | <div class="header">
|
---|
138 | <p>
|
---|
139 | Previous: <a href="Severity-Pragmas.html" accesskey="p" rel="prev">Severity Pragmas</a>, Up: <a href="Pragmas.html" accesskey="u" rel="up">Pragmas</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
|
---|
140 | </div>
|
---|
141 |
|
---|
142 |
|
---|
143 |
|
---|
144 | </body>
|
---|
145 | </html>
|
---|