Java Reference
In-Depth Information
of instructions within a basic block. Global optimizations require an analysis of the whole
control graph and involve what is called data-flow analysis 3 .
One can make important improvements to the code even with analysis within single
basic blocks. Moreover, the SSA form of the HIR allows us to deal with sequences of code
that cross basic block boundaries, as long as we do not deal with those values produced by
Phi functions.
Inlining
The cost of calling a routine (for invoking a method) can be considerable. In addition the
control-flow management and stack frame management, register values must be saved on
the stack. But in certain cases, the code of a callee's body can replace the call sequence in
the caller's code, saving the overhead of a routine call. We call this inlining.
Inlining usually makes sense for methods whose only purpose is to access a field as in
getters and setters.
For example, consider the following two methods, defined within a class Getter .
staticintgetA(){
returnGetter.a;
}
staticvoidfoo(){
inti;
i=getA();
}
The a in Getter.a refers to a static field declared in Getter . We can replace the getA()
with the field selection directly:
staticvoidfoo(){
inti;
i=Getter.a;
}
Inlining makes sense only when the callee's code is relatively short. Also, when modeling
a virtual method call, we must be able to determine the routine that should be called at
compile-time. One also should be on the lookout for nested recursive calls; repeated inlining
could go on indefinitely.
A simple strategy for enabling inlining is to keep track of the number of instructions
within the HIR for a method and whether or not that method makes nested calls; this
information can be computed as the HIR for a method is constructed. Inlining method in-
vocations can create further opportunities for inlining. Inlining can also create opportunities
for other optimizations.
Constant Folding and Constant Propagation
Expressions having operands that are both constants, for example,
3+4
or even variables whose values are known to be constants, for example,
inti=3;
intj=4;
...i+j...
3 We describe a detailed data-flow analysis algorithm for computing liveness intervals for variables as
part of register allocation in Section 7.4.1
 
Search WWH ::




Custom Search