📄 9.1.3.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='9.1.2.htm'" ></img></td>
<td>
<img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='9.1.3_2.htm'" ></img></td>
</tr>
</table>
<br><br>
<font class="title2">9.1.3 优化编译器的组织</font><br>
<table>
<tr>
<td>    </td>
<td class="content">
<p>
本章集中讨论对中间代码进行优化,使用的优化编译器的组织如图9.3所示,它由控制流分析,数据流分析和程序变换三部分组成。第八章讨论的代码生成器从变换后的中间代码产生目标程序。
</p>
<p>
为表达上的方便,假定中间代码由三地址语句组成。用第七章的技术为图9.2的部分程序产生的中间代码显示在图9.4中。
</p>
</td>
</tr>
</table>
<br>
<center> <img src="images/9_3.gif" vspace="20"></center>
<br>
<table><tr><td>    </td>
<td class="content">
(1) i := m - 1
(16) t7 := 4 * i <br>
(2) j := n
(17) t8 := 4 * j <br>
(3) t1 := 4 * n
(18) t9 := a[t8] <br>
(4) v := a[t1]
(19) a[t7] := t9 <br>
(5) i := i + 1
(20) t10 := 4 * j <br>
(6) t2 := 4 * i
(21) a[t10] := x <br>
(7) t3 := a[t2]
(22) goto (5) <br>
(8) if t3 < v goto (5)
(23) t11 := 4 * i <br>
(9) j := j - 1
(24) x := a[t11] <br>
(10) t4 = 4 * j
(25) t12 := 4 * i <br>
(11) t5 := a[t4]
(26) t13 := 4 * n <br>
(12) if t5 > v goto (9)
(27) t14 := a[t13] <br>
(13) if i >= j goto (23)
(28) a[t12] := t14 <br>
(14) t6 := 4 * i
(29) t15 := 4 * n <br>
(15) x := a[t6]
(30) a[t15] := x <br>
<p align = "center"><b>图9.4   图9.2部分程序的三地址代码</b></p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<p><br></p>
<p>图9.3所示的对中间代码的优化有下列优点:</p>
<p>1.实现高级结构所需的操作在中间代码中是显式的,这就有可能优化它们。例如,a[i]的地址计算在图9.4中是明显的,这样,象表达式4*i的重复计算可以被删除(下一节讨论)。
</p>
<p>2.中间代码相对独立于目标机器,所以,由一种机器的代码生成器改为另一种机器的代码生成器时,优化器不必作很多修改。
</p>
<p>在代码优化器中,程序用流图表示,边表示控制流,结点表示基本块,如8.3节讨论的那样。除非有其它说明,否则这里所说的程序意味着是单个过程。
</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='9.1.2.htm'" ></img></td>
<td>
<img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='9.1.3_2.htm'" ></img></td>
</tr>
</table>
</BODY>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -