Content deleted Content added
Niceguyedc (talk | contribs) m WPCleaner v1.34 - Repaired 1 link to disambiguation page - (You can help) - Registers |
→Simple Sethi–Ullman algorithm: Just to avoid a potential 1/l typographical confusion. |
||
Line 9:
# Traverse the [[abstract syntax tree]] in pre- or postorder
## For every non-constant leaf node, assign a 1 (i.e. 1 register is needed to hold the variable/field/etc.). For every constant leaf node (RHS of an operation – literals, values), assign a 0.
## For every non-leaf node ''n'', assign the number of registers needed to evaluate the respective subtrees of ''n''. If the number of registers needed in the left subtree (''l'') are not equal to the number of registers needed in the right subtree (''r''), the number of registers needed for the current node ''n'' is max(l, r). If ''l == r'', then the number of registers needed for the current node is
# Code emission
## If the number of registers needed to compute the left subtree of node ''n'' is bigger than the number of registers for the right subtree, then the left subtree is evaluated first (since it may be possible that the one more register needed by the right subtree to save the result makes the left subtree [[Register spilling|spill]]). If the right subtree needs more registers than the left subtree, the right subtree is evaluated first accordingly. If both subtrees need equal as much registers, then the order of evaluation is irrelevant.
|