Apostila antiga - The Cyan Programming Language
Apostila antiga - The Cyan Programming Language
Apostila antiga - The Cyan Programming Language
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
CHAPTER 5. OTIMIZAÇÃO DE CÓDIGO 52<br />
2. Propagação de Cópia (Copy Propagation) .<br />
Sempre que houver uma atribuição<br />
b = c;<br />
a variável c poderá substituir b após esta instrução, desde que nenhuma das duas variáveis<br />
mude de valor.<br />
a = b;<br />
c = a + x;<br />
a = b;<br />
c = b + x;<br />
Com esta otimização, esta atribuição poderá tornar-se desnecessária e ser eliminada.<br />
3. Eliminação de Código Morto (Dead Code Elimination)<br />
Código Morto é o código que nunca será executado, independente do fluxo de execução do<br />
programa.<br />
int f (int n )<br />
{<br />
int i = 0;<br />
while ( i < n ) {<br />
if ( g == h ) {<br />
break;<br />
g = 1; // morto<br />
}<br />
i++;<br />
g--;<br />
}<br />
return g;<br />
g++; // morto<br />
}<br />
Esta função pode ser otimizada para<br />
int f (int n )<br />
{<br />
int i = 0;<br />
while ( i < n ) {<br />
if ( g == h )<br />
break;<br />
i++;<br />
g--;<br />
}