Content deleted Content added
better lede, templatize ref (and call it a ref), see also Strahler number |
Adding short description: "Algorithm for minimising register usage" |
||
(28 intermediate revisions by 25 users not shown) | |||
Line 1:
{{Short description|Algorithm for minimising register usage}}
In [[computer science]], the '''Sethi–Ullman algorithm''' is an [[algorithm]] named after [[Ravi Sethi]] and [[Jeffrey D. Ullman]], its inventors, for translating [[abstract syntax tree]]s into [[machine code]] that uses as few
==Overview==
When [[
==Simple Sethi–Ullman algorithm==
The '''simple Sethi–Ullman algorithm''' works as follows (for a [[
# Traverse the [[abstract syntax tree]] in pre- or postorder
## For every leaf node, if it is a non-constant
## For every non-leaf node
# To emit code, if the subtrees need different numbers of registers, evaluate the subtree needing the most registers first (since the register needed to save the result of one subtree may make the other one [[Register spilling|spill]]), otherwise the order is irrelevant.
===Example===
For an arithmetic expression <math>a = (b + c + f * g)
=
Line 49:
/ \ / \
b<sub>'''1'''</sub> c<sub>'''0'''</sub>f<sub>'''1'''</sub> g<sub>'''0'''</sub>
From this tree it can be seen that we need 2 registers to compute the left subtree of the '*', but only 1 register to compute the right subtree.
==Advanced Sethi–Ullman algorithm==
Line 56:
==See also==
*[[Strahler number]], the minimum number of registers needed to evaluate an expression without any external storage
*[[Ershov Number]], basically the same concept as Strahler number
==References==
*{{citation|title=The Generation of Optimal Code for Arithmetic Expressions|first1=Ravi|last1=Sethi|author1-link=Ravi Sethi|first2=Jeffrey D.|last2=Ullman|author2-link=Jeffrey D. Ullman|journal=[[Journal of the Association for Computing Machinery]]|volume=17|issue=4|year=1970|pages=715–728|doi=10.1145/321607.321620|hdl=10338.dmlcz/101207|hdl-access=free}}.
==External links==
*[
{{DEFAULTSORT:Sethi-Ullman algorithm}}
[[Category:Compiler
[[Category:Graph algorithms]]
|