Python Notes for mca i year students osmania university.docx
Complier
1.
2. Next-use information
Introduction:
we collect next-use information about names in
basic blocks.
if the name in a register is no longer needed,
then the register can be assigned to some other
name.
This idea of keeping a name in storage only if it
will be used subsequently can be applied in a
number of contexts.
4. Computing next uses
• The use of a name in a three-address
statement:
– Three-address statement i assigns a value to x
– Statement j has x as an operand
– Control can flow from statement i to j along a path that has
no intervening assignments to x
– Then statement j uses the value of x computed at i .
– Say that x is live at statement i .
4
5. Next-use information
If the algorithms generating intermediate
code or optimizing the code permit certain
temporaries to be used across blocks, these
too must be considered live.
it would be a good idea to mark any such
temporaries, so we do not have to consider
all temporaries live.
6. Next-Use Information
• Algorithm (for x=y+z) : Determining the
liveness and next-use information for each
statement in a basic block.
– INPUT: A basic block B of three-address statements. Assume the symbol table
initially shows all nontemporary variables in B as being live on exit.
– OUTPUT: At each statement i : x = y + z in B, attach to i the liveness and next-
use information of x, y, and z .
– METHOD: Start at the last statement in B and scan backwards to the beginning
of B. At each statement i: x = y + z in B, do the following:
1. Attach to i the information currently found in the symbol table regarding
the next use and
liveness of x , y, and z.
2. In the symbol table, set x to "not live" and "no next use."
3. In the symbol table, set y and z to "live" and the next uses of y and z to i.
6
7. Storage for Temporary Names
• Each time separate name has to be created for
using temporary.
• Space and Size increased.
• Pack two temporaries in same location.
• Stored in register than Memory
8. Six temp to two locations t1 & t2
t1:=a*a
t2:=a*b
t2=2*t2
t1=t1+t2
t2=b*b
t1=t1+t2
Editor's Notes
Knowing when the value of a variable will be used next is essential for generating
good code. If the value of a variable that is currently in a register will never be
referenced subsequently, then that register can be assigned to another variable.
Here we have used + as a symbol representing any operator. If the three-address
statement i is of the form x = + Y or x = y, the steps are the same as above,
ignoring z. Note that the order of steps (2) and (3) may not be interchanged
because x may be y or z.
第一步每当开始对一个基本块进行处理时,把块中各变量在符号表相应登记项的待用信息栏置为“无待用”,且依各变量在基本块的出口活跃与否,将相应的活跃信息栏置为“活跃”或“非活跃”。第二步从基本块的出口开始,反向扫视基本块中的各四元式,设当前正扫视的四元式为(i)A∶=B OP C, 对(i)依次作如下的处理: (1) 把符号表中当前所记录之变量A,B与C的待用信息及活跃信息附加到四元式(i)上; (2) 在符号表中,把与A相应的待用信息栏及活跃信息栏分别置为“无待用”及“非活跃”; (3) 在符号表中,把B和C的待用信息栏均置为(i),把它们的活跃信息栏置为“活跃”。