blob: 12aff08ba4a3470239f4dd1fb58889207c9d63be [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1988-2015 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "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".
(a) The FSF's Front-Cover Text is:
A GNU Manual
(b) The FSF's Back-Cover Text is:
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. -->
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>GNU Compiler Collection (GCC) Internals: loop-iv</title>
<meta name="description" content="GNU Compiler Collection (GCC) Internals: loop-iv">
<meta name="keywords" content="GNU Compiler Collection (GCC) Internals: loop-iv">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Loop-Analysis-and-Representation.html#Loop-Analysis-and-Representation" rel="up" title="Loop Analysis and Representation">
<link href="Number-of-iterations.html#Number-of-iterations" rel="next" title="Number of iterations">
<link href="Scalar-evolutions.html#Scalar-evolutions" rel="prev" title="Scalar evolutions">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="loop_002div"></a>
<div class="header">
<p>
Next: <a href="Number-of-iterations.html#Number-of-iterations" accesskey="n" rel="next">Number of iterations</a>, Previous: <a href="Scalar-evolutions.html#Scalar-evolutions" accesskey="p" rel="prev">Scalar evolutions</a>, Up: <a href="Loop-Analysis-and-Representation.html#Loop-Analysis-and-Representation" accesskey="u" rel="up">Loop Analysis and Representation</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="IV-analysis-on-RTL"></a>
<h3 class="section">15.6 IV analysis on RTL</h3>
<a name="index-IV-analysis-on-RTL"></a>
<p>The induction variable on RTL is simple and only allows analysis of
affine induction variables, and only in one loop at once. The interface
is declared in <samp>cfgloop.h</samp>. Before analyzing induction variables
in a loop L, <code>iv_analysis_loop_init</code> function must be called on L.
After the analysis (possibly calling <code>iv_analysis_loop_init</code> for
several loops) is finished, <code>iv_analysis_done</code> should be called.
The following functions can be used to access the results of the
analysis:
</p>
<ul>
<li> <code>iv_analyze</code>: Analyzes a single register used in the given
insn. If no use of the register in this insn is found, the following
insns are scanned, so that this function can be called on the insn
returned by get_condition.
</li><li> <code>iv_analyze_result</code>: Analyzes result of the assignment in the
given insn.
</li><li> <code>iv_analyze_expr</code>: Analyzes a more complicated expression.
All its operands are analyzed by <code>iv_analyze</code>, and hence they must
be used in the specified insn or one of the following insns.
</li></ul>
<p>The description of the induction variable is provided in <code>struct
rtx_iv</code>. In order to handle subregs, the representation is a bit
complicated; if the value of the <code>extend</code> field is not
<code>UNKNOWN</code>, the value of the induction variable in the i-th
iteration is
</p>
<div class="smallexample">
<pre class="smallexample">delta + mult * extend_{extend_mode} (subreg_{mode} (base + i * step)),
</pre></div>
<p>with the following exception: if <code>first_special</code> is true, then the
value in the first iteration (when <code>i</code> is zero) is <code>delta +
mult * base</code>. However, if <code>extend</code> is equal to <code>UNKNOWN</code>,
then <code>first_special</code> must be false, <code>delta</code> 0, <code>mult</code> 1
and the value in the i-th iteration is
</p>
<div class="smallexample">
<pre class="smallexample">subreg_{mode} (base + i * step)
</pre></div>
<p>The function <code>get_iv_value</code> can be used to perform these
calculations.
</p>
<hr>
<div class="header">
<p>
Next: <a href="Number-of-iterations.html#Number-of-iterations" accesskey="n" rel="next">Number of iterations</a>, Previous: <a href="Scalar-evolutions.html#Scalar-evolutions" accesskey="p" rel="prev">Scalar evolutions</a>, Up: <a href="Loop-Analysis-and-Representation.html#Loop-Analysis-and-Representation" accesskey="u" rel="up">Loop Analysis and Representation</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>