Major Tasks in Code Generation
In addition to the basic conversion from an intermediate representation into a linear sequence of machine instructions, a typical code generator tries to optimize the generated code in some way.
Tasks which are typically part of a sophisticated compiler's "code generation" phase include:
- Instruction selection: which instructions to use.
- Instruction scheduling: in which order to put those instructions. Scheduling is a speed optimization that can have a critical effect on pipelined machines.
- Register allocation: the allocation of variables to processor registers
- Debug data generation if required so the code can be debugged.
Instruction selection is typically carried out by doing a recursive postorder traversal on the abstract syntax tree, matching particular tree configurations against templates; for example, the tree W := ADD(X,MUL(Y,Z))
might be transformed into a linear sequence of instructions by recursively generating the sequences for t1 := X
and t2 := MUL(Y,Z)
, and then emitting the instruction ADD W, t1, t2
.
In a compiler that uses an intermediate language, there may be two instruction selection stages — one to convert the parse tree into intermediate code, and a second phase much later to convert the intermediate code into instructions from the instruction set of the target machine. This second phase does not require a tree traversal; it can be done linearly, and typically involves a simple replacement of intermediate-language operations with their corresponding opcodes. However, if the compiler is actually a language translator (for example, one that converts Eiffel to C), then the second code-generation phase may involve building a tree from the linear intermediate code.
Read more about this topic: Code Generation (compiler)
Famous quotes containing the words major, tasks, code and/or generation:
“A major difference between witches and psychotherapists is that witches see the mental health of women as having important political consequences.”
—Naomi R. Goldenberg (b. 1947)
“A father who will pursue infant care tasks with ease and proficiency is simply a father who has never been led to believe he couldnt.”
—Michael K. Meyerhoff (20th century)
“...I had grown up in a world that was dominated by immature age. Not by vigorous immaturity, but by immaturity that was old and tired and prudent, that loved ritual and rubric, and was utterly wanting in curiosity about the new and the strange. Its era has passed away, and the world it made has crumbled around us. Its finest creation, a code of manners, has been ridiculed and discarded.”
—Ellen Glasgow (18731945)
“Most women of [the WW II] generation have but one image of good motherhoodthe one their mothers embodied. . . . Anything done for the sake of the children justified, even ennobled the mothers role. Motherhood was tantamount to martyrdom during that unique era when children were gods. Those who appeared to put their own needs first were castigated and shunnedthe ultimate damnation for a gender trained to be wholly dependent on the acceptance and praise of others.”
—Melinda M. Marshall (20th century)