Java Reference
In-Depth Information
to another machine much more di
cult. Most compilers implemented as
instructional projects generate target code directly from the AST, without using
an IR.
More elaborate compilers such as the GNU Compiler Collection (GCC)
may first generate a high-level IR (that is source-language oriented) and then
subsequently translate it into a low-level IR (that is target-machine oriented).
This approach allows a cleaner separation of source and target dependencies.
1.5.5 Symbol Tables
A symbol table is a mechanism that allows information to be associated with
identifiers and shared among compiler phases. Each time an identifier is
declared or used, a symbol table provides access to the information collected
about it. Symbol tables are used extensively during type checking, but they
can also be used by other compiler phases to enter, share, and later retrieve
information about types, variables, procedures, and labels. Compilers may
choose to use other structures to share information between compiler phases.
For example, a program representation such as an AST may be expanded and
refined toprovide detailed informationneeded by optimizers, code generators,
linkers, loaders, and debuggers.
1.5.6 The Optimizer
The IR code generated by the translator is analyzed and transformed into
functionally equivalent but improved IR code by the optimizer . This phase
can be complex, often involving numerous subphases, some of which may
need to be applied more than once. Most compilers allow optimizations to
be turned o
so as to speed translation. Nonetheless, a carefully designed
optimizer can significantly speed program execution by simplifying, moving,
or eliminating unneeded computations.
If both a high-level and low-level IR are used, optimizations may be per-
formed in stages. For example, a simple subroutine call may be expanded into
the subroutine's body, with actual parameters substituted for formal parame-
ters. This is a high-level optimization. Alternatively, a value already loaded
from memory may be reused. This is a low-level optimization.
Optimization can also be done after code generation. An example is peep-
hole optimization . Peephole optimization examines generated code a few
instructions at a time (in e
ff
ect, through a “peephole”). Common peephole
optimizations include eliminating multiplications by 1 or additions of 0, elim-
inating a load of a value into a register when the value is already in another
register, and replacing a sequence of instructions by a single instruction with
the same e
ff
ff
ect. A peephole optimizer does not o
ff
er the payo
ff
of a full-scale
 
 
 
Search WWH ::




Custom Search