scale.score.trans
Class Inlining

java.lang.Object
  extended by scale.score.trans.Inlining

public final class Inlining
extends java.lang.Object

This class performs inlining.

$Id: Inlining.java,v 1.84 2007-10-04 19:58:36 burrill Exp $

Copyright 2008 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.

Inlining replaces routine calls by the code of the routine called. It ranks all routine calls across all routines and replaces the calls with inlined code in the order of that ranking.

The ranking depends on the nested loop depth of the call and the "cost" of the inlined code. The deeper the call is in a loop nest the more likely the call will be replaced by inlined code. The smaller the routine is the more likely it will be inlined. These metrics can be over-ridden by using profile-guided inlining.

Not all calls are replaced that satisfy the above criteria. No routine is inlined if the resultant module code size will exceed the bloat factor. No routine is inlined if a heuristic determines that the call is a poor choice to be replaced by an inlined routine.

Code Bloat: A floating point value, called the bloat factor, is used. This value is multiplied by the current module size prior to inlining to give the maximum size to which that the resultant module is allowed to grow. No routine call is replaced with an inlined routine if the result will cause the module to exceed the maximum size. Values for the bloat factor can be greater than or equal to 1.0. (If the value specified is less than 1.0, the value of 1.0 is used. Note - this may still allow some inlining if the inlined routine is smaller than the call overhead.)

Heuristics: The following heuristics are used to inhibit the replacement of a call by an inlined routine:


Field Summary
static int callOverhead
          Assumed cost, in instructions, of a subroutine call.
static boolean classTrace
           
static boolean ignoreComplexityHeuristic
          True if "complexity" heuristic for inhibiting the inlining of a routine should be ignored.
static int simpleFtnLimit
          Maximum size in instructions of a "simple" function.
 
Constructor Summary
Inlining(Suite suite, boolean allowCrossModuleInlining)
          Prepare for an inlining batch.
 
Method Summary
 void displayStatus(java.io.PrintWriter cout)
           
protected  VariableDecl genTemp(Type t, Scribble scribble)
          Create a new temporary variable for use by the optimized code.
static int inlined()
          Return the number of times inlining was performed.
static int newCFGNodes()
          Return the number of new nodes created.
 void optimize(double bloatFactor)
          This is the main function for this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

callOverhead

public static int callOverhead
Assumed cost, in instructions, of a subroutine call.


simpleFtnLimit

public static int simpleFtnLimit
Maximum size in instructions of a "simple" function.


ignoreComplexityHeuristic

public static boolean ignoreComplexityHeuristic
True if "complexity" heuristic for inhibiting the inlining of a routine should be ignored.


classTrace

public static boolean classTrace
Constructor Detail

Inlining

public Inlining(Suite suite,
                boolean allowCrossModuleInlining)
Prepare for an inlining batch.

Parameters:
suite - the suite containing the procedures that will be inlined and the list of globals that might be modified
Method Detail

inlined

public static int inlined()
Return the number of times inlining was performed.


newCFGNodes

public static int newCFGNodes()
Return the number of new nodes created.


optimize

public void optimize(double bloatFactor)
This is the main function for this class. It makes a list of all the candidate calls, and gives each call a priority for inlining, based on an estimate of how many times each one is called dynamically, and how large the function being inlined is.

In order of decreasing priority, each call that can be inlined within the given code-bloat maximum is, until we run out of candidates or reach our minimum priority bound.

Parameters:
bloatFactor - the level of inlining to be performed -- higher levels allow for more code bloat

displayStatus

public void displayStatus(java.io.PrintWriter cout)

genTemp

protected VariableDecl genTemp(Type t,
                               Scribble scribble)
Create a new temporary variable for use by the optimized code. The variable definition is added to the set of variables for this CFG.