Partial support for integer divisions in access vectors
[suif.git] / html / suif1_16.html
bloba5c109eee2cd24c53c87226c6eafe488ae94bb57
1 <HTML>
2 <HEAD>
3 <!-- This HTML file has been created by texi2html 1.54
4 from suif1.texi on 28 April 1999 -->
6 <TITLE>The SUIF Version 1 Library - Loop Nodes</TITLE>
7 <link href="suif1_17.html" rel=Next>
8 <link href="suif1_15.html" rel=Previous>
9 <link href="suif1_toc.html" rel=ToC>
11 </HEAD>
12 <BODY>
13 <p>Go to the <A HREF="suif1_1.html">first</A>, <A HREF="suif1_15.html">previous</A>, <A HREF="suif1_17.html">next</A>, <A HREF="suif1_113.html">last</A> section, <A HREF="suif1_toc.html">table of contents</A>.
14 <P><HR><P>
17 <H3><A NAME="SEC16" HREF="suif1_toc.html#TOC16">Loop Nodes</A></H3>
18 <P>
19 <A NAME="IDX64"></A>
20 <A NAME="IDX65"></A>
22 </P>
23 <P>
24 <A NAME="IDX66"></A>
25 <A NAME="IDX67"></A>
26 <A NAME="IDX68"></A>
27 <A NAME="IDX69"></A>
28 <A NAME="IDX70"></A>
29 A <CODE>tree_loop</CODE> node represents a "do-while" loop. It contains two
30 tree node lists: the <CODE>body</CODE> and the <CODE>test</CODE>. The <CODE>body</CODE>
31 list comes first and holds the loop body. The <CODE>test</CODE> list contains
32 code to evaluate the "while" expression and conditionally branch back
33 to the beginning of the body.
35 </P>
36 <P>
37 <A NAME="IDX71"></A>
38 <A NAME="IDX72"></A>
39 <A NAME="IDX73"></A>
40 <A NAME="IDX74"></A>
41 <A NAME="IDX75"></A>
42 <A NAME="IDX76"></A>
43 There are three labels associated with a <CODE>tree_loop</CODE> node:
44 <CODE>toplab</CODE>, <CODE>contlab</CODE>, and <CODE>brklab</CODE>. The <CODE>toplab</CODE>
45 label marks the beginning of the loop <CODE>body</CODE>; the <CODE>test</CODE> list
46 typically contains a conditional branch back to <CODE>toplab</CODE>. A
47 "continue" statement in the loop body requires a jump over the rest of
48 the body to the beginning of the test code. The <CODE>contlab</CODE> label is
49 positioned at the beginning of the <CODE>test</CODE> list for this purpose.
50 Similarly, a "break" statement in the loop is translated to a jump to
51 the <CODE>brklab</CODE> label which is located immediately after the loop.
52 These <CODE>tree_loop</CODE> labels must be defined in the scope of the loop
53 node, but the label positions are implicit rather than being marked by
54 label instructions. When the <CODE>tree_loop</CODE> is expanded to low-SUIF
55 form, the label instructions are inserted into the tree node lists.
57 </P>
58 <P>
59 Because the loop nodes are only intended for use with structured control
60 flow, certain restrictions on the contents of the <CODE>tree_loop</CODE>
61 lists are required. The <CODE>test</CODE> part has exactly the same
62 restrictions as the <CODE>header</CODE> of a <CODE>tree_if</CODE> except that it
63 is the <CODE>toplab</CODE> label instead of the <CODE>jumpto</CODE> label to which
64 jumps and branches are allowed and expected. See section <A HREF="suif1_15.html#SEC15">If Nodes</A>. Note
65 in particular that use of the <CODE>brklab</CODE> and <CODE>contlab</CODE> labels
66 is not allowed in the <CODE>test</CODE> list.
68 </P>
69 <P>
70 The <CODE>body</CODE> list has restrictions analogous to the restriction on
71 <CODE>then_part</CODE> and <CODE>else_part</CODE> lists of a <CODE>tree_if</CODE>:
72 arbitrary nesting of other <CODE>tree_node</CODE>s is allowed, but control
73 flow into or out of the <CODE>body</CODE> is not allowed. The <CODE>body</CODE>
74 list is allowed slightly more leeway, though: jumps or branches are
75 allowed from anywhere in the <CODE>body</CODE> to the <CODE>brklab</CODE> or the
76 <CODE>contlab</CODE> labels. This is the only place where the <CODE>brklab</CODE>
77 or <CODE>contlab</CODE> labels can be used--they cannot be used outside the
78 <CODE>tree_loop</CODE> or in the <CODE>test</CODE> list.
80 </P>
81 <P>
82 Note that either or both of the <CODE>test</CODE> and <CODE>body</CODE> parts may
83 be empty lists, but if the <CODE>test</CODE> part is empty, the loop is
84 degenerate--it will always execute exactly once.
86 </P>
87 <P>
88 For example, the following C code could be translated into the SUIF code
89 shown in a simplified form below. Note that because the <CODE>test</CODE>
90 code is at the <EM>bottom</EM> of the loop, the "while" loop must be
91 converted to a "do-while" loop guarded by an "if" node. See section <A HREF="suif1_15.html#SEC15">If Nodes</A>.
93 </P>
95 <PRE>
96 while (k &#62; 0) {
97 if (k = 1) break;
98 k = k - 1;
99 if (k &#60; 10) continue;
100 k = k - 10;
102 </PRE>
105 <PRE>
106 IF (Jumpto=L:__L1)
107 IF HEADER
108 bfalse e1, L:__L1
109 e1: sl e2, k
110 e2: ldc 0
111 IF THEN
112 LOOP (Top=L:__L2 Cont=L:__L3 Brk=L:__L4)
113 LOOP BODY
114 btrue e1, L:__L4
115 e1: seq k, e2
116 e2: ldc 1
117 sub k = k, e1
118 e1: ldc 1
119 btrue e1, L:__L3
120 e1: sl k, e2
121 e2: ldc 10
122 sub k = k, e1
123 e1: ldc 10
124 LOOP TEST
125 btrue e1, L:__L2
126 e1: sl e2, k
127 e2: ldc 0
128 LOOP END
129 IF ELSE
130 IF END
131 </PRE>
133 <P><HR><P>
134 <p>Go to the <A HREF="suif1_1.html">first</A>, <A HREF="suif1_15.html">previous</A>, <A HREF="suif1_17.html">next</A>, <A HREF="suif1_113.html">last</A> section, <A HREF="suif1_toc.html">table of contents</A>.
135 </BODY>
136 </HTML>