📄 8.6.2.htm
字号:
<html>
<head>
<title>编译原理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link type="text/css" rel="stylesheet" href="../css/specification.css">
</head>
<BODY>
<table align=right width=300>
<tr>
<td><img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='8.6.1_2c.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='8.6.2b.htm'"></img></td>
</tr>
</table>
<br><br>
<font class="title2"><b>8.6.2 dag的应用</b></font>
<table><tr><td>    </td>
<td class="content">
<P>当我们执行算法8.2时,可以获得一些十分有用的信息。第一,我们可以自动检测出公用子表达式。第二,我们可以确定出哪些标识符的值在该基本块中被引用;它们就是那些在步骤1中的某些时刻所建立的叶结点对应的标识符。第三,我们可以确定块中哪些语句中的定值可以在基本块外被引用;它们正好是这样的语句S,即对于S所定值的标识符x和在步骤(2)中为此语句所建立的结点n而言,在dag构造的结尾仍有node(x)=n成立;即x仍然是n的一个附加标识符。
</P>
<P><B><font class="example"><img border="0" src="images/dingyi.gif" width="32" height="31">例8.7</font></B>由于在例8.6中只有两次对结点的先前值为叶的prod和i重新定义。因此,所有的内部结点的值均可在基本块外被引用。现在,我们假定有一条语句S,其语句序号譬如小于11,它将一个值赋给i。这样对语句S我们将建立某个结点m并置node(i)=m。然而我们在语句(11)要重新定义node(i),于是由语句S所计算的值就不能在基本块外被引用。这由步骤3显示出来。
</P>
<P>我们用下面的例题说明如何应用dag删除公用子表达式,并从而缩短三地址语句序列。</P>
<P><B><font class="example"><img border="0" src="images/dingyi.gif" width="32" height="31">例8.8</font></B>按照图8.10的dag结点的建立的先后顺序对结点进行排序,让我们从该图出发重新构造其相应的基本块。我们假定任何临时变量t<SPAN
class=down><sub>1</sub></SPAN>在基本块外均是无用的,我们从代表4*i的结点开始。此结点有两个附加标识符t<SPAN
class=down><sub>1</sub></SPAN>和t<SPAN class=down><sub>4</sub></SPAN>。我们取t<SPAN
class=down><sub>1</sub></SPAN>保存4*i的值,从而构造的第(1)条语句为: </P>
<P>(1)t<SPAN class=down><sub>1</sub></SPAN>:=4*i<br>
这和以前是一样的。类似地,第(2)条语句对附加t<SPAN class=down>2</SPAN>的结点求值: </P>
<P>(2)t<SPAN
class=down><sub>2</sub></SPAN>:=a-4<br>
第(3)条语句对附加t<SPAN class=down>3</SPAN>的结点求值: </P>
<P>(3)t<SPAN
class=down><sub>3</sub></SPAN>:=t<SPAN class=down><sub>2</sub></SPAN>[t<SPAN class=down><sub>1</sub></SPAN>]<br>
接下来考虑结点t<SPAN class=down><sub>5</sub></SPAN>和t<SPAN
class=down><sub>6</sub></SPAN>。要注意的是,原来语句序列中的第(4)条 语句并没有建立新的结点。因此,我们下面生成的语句是: </P>
<P>(4)t<SPAN
class=down><sub>5</sub></SPAN>:=b-4 </P>
</td></tr></table>
<br>
<table align=right width=300>
<tr>
<td><img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='8.6.1_2c.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='8.6.2b.htm'"></img></td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -