scale.common
Class Machine

java.lang.Object
  extended by scale.common.Machine
Direct Known Subclasses:
AlphaMachine, MipsMachine, PPCMachine, SparcMachine, Trips2Machine, X86Machine, XyzMachine

public abstract class Machine
extends java.lang.Object

This is the base class for all machine specific information.

$Id: Machine.java,v 1.61 2007-11-01 16:52:31 burrill Exp $

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


Field Summary
static int ALL_CONDITIONAL_MOVES
          Capability: All the conditional move possibilities.
protected  int cacheLineSize
          The size in addressable units of an L1 cache line.
static Machine currentMachine
          The current machine specification.
protected  FloatType doubleType
          The type used for the C double type.
protected  FloatType floatCalcType
          The real type best used for floating point calculations.
protected  FloatType floatType
          The type used for the C float type.
static int HAS_EXPENSIVE_SUBROUTINE_CALLS
          Capability: bad to flatten/unroll loops that contain a function call.
static int HAS_FF_CONDITIONAL_MOVE
          Capability: Has a conditional move using a floating point test and floating point values.
static int HAS_FI_CONDITIONAL_MOVE
          Capability: Has a conditional move using a floating point test and integer values.
static int HAS_IF_CONDITIONAL_MOVE
          Capability: Has a conditional move using an integer test and floating point values.
static int HAS_II_CONDITIONAL_MOVE
          Capability: Has a conditional move using an integer test and integer values.
static int HAS_INT_FROM_FP_CMP
          Capability: Has a floating point compare that returns an integer value.
static int HAS_NO_FP_DIVIDE
          Capability: Floating point divides are not performed by an instruction but by a subroutine call.
static int HAS_NO_INT_DIVIDE
          Capability: Integer divides are not performed by an instruction but by a subroutine call.
static int HAS_NON_VOLATILE_FP_REGS
          Capability: Has a floating point registers that are saved over function calls.
static int HAS_PREDICATION
          Capability: Has predicated instructions.
static int HAS_SIMPLE_FLOOR
          Capability: Has a simple inline floor capability.
static int HAS_WHILE_LOOP_UNROLL_BENEFIT
          Capability: Has benefit from unrolling loops with no induction variable.
protected  IntegerType intCalcType
          The integer type best used for integer calculations.
protected  FloatType longDoubleType
          The type used for the C long double type.
protected  IntegerType ptrdifftType
          The type used for the C ptrdiff_t type.
protected  IntegerType signedCharType
          The type used for the C signed char type.
protected  IntegerType signedIntType
          The type used for the C signed int type.
protected  IntegerType signedLongLongType
          The type used for the C signed long long type.
protected  IntegerType signedLongType
          The type used for the C signed long type.
protected  IntegerType signedShortType
          The type used for the C signed short type.
protected  IntegerType sizetType
          The type used for the C size_t type.
protected  IntegerType smallestAddressableUnitType
          The type for the smallest addressable unit (e.g., char).
protected  IntegerType unsignedCharType
          The type used for the C unsigned char type.
protected  IntegerType unsignedIntType
          The type used for the C unsigned int type.
protected  IntegerType unsignedLongLongType
          The type used for the C unsigned long long type.
protected  IntegerType unsignedLongType
          The type used for the C unsigned long type.
protected  IntegerType unsignedShortType
          The type used for the C unsigned short type.
protected  Type vaListType
          The type to be used for va_list.
protected  PointerType voidStarType
          The type used for the C void* type.
protected  IntegerType wchartType
          The type used for the C char_t type.
 
Constructor Summary
Machine(int capabilities)
          Create a Machine instance.
 
Method Summary
abstract  void addCPPFlags(Vector<java.lang.String> v)
          Add the flags necessary for the C preprocessor.
abstract  int addressableMemoryUnits(int bitSize)
          Return the number of addressable units required
abstract  int alignData(int dataSize)
          Return the integer value alignmentthat satisfies (0 == address % alignment) for the data size specified.
static long alignTo(long value, int to)
          Round up a value so that it is evenly divisible by the second value.
abstract  java.lang.String determineArchitecture(java.lang.String architecture, java.lang.String extension)
          Determine the architecture sub-type.
abstract  int executionCostEstimate(double value)
          Return an estimate of the execution cost to provide this value.
abstract  int executionCostEstimate(long value)
          Return an estimate of the execution cost to provide this value.
abstract  int generalAlignment()
          Return the most general purpose alignment in memory units.
abstract  java.lang.String getArchitectureName()
          Return the name of the specific target architecture.
 java.lang.String getAsmFileExtension()
          Return the file extension to use for an assembler source file.
 java.lang.String getAssemblerCommand(int backendFeatures)
          Return the assembler command appropriate to the architecture.
static java.lang.String getAssemblerCommand(java.lang.String user, int backendFeatures)
          Return the assembler command to use.
 int getCacheSize(int typeSize)
          Return the number of elements of the specified size in a cache line.
static Generator getCodeGenerator(CallGraph cg, int backendFeatures)
          Return a backend code generator instance for the specified target architecture.
 FloatType getDoubleType()
          Return the type used for the C double type.
 FloatType getFloatType()
          Return the type used for the C float type.
 byte[] getFunctionalUnitDescriptions()
          Return the functional unit information.
abstract  java.lang.String getGenericArchitectureName()
          Return the name of the generic target architecture.
 ICEstimator getInstructionCountEstimator()
          Return the proper instruction count estimator for the target architecture.
 IntegerType getIntegerCalcType()
          Return the type best used for integer calculations.
 FloatType getLongDoubleType()
          Return the type used for the C long double type.
 int getMaxBlockSize()
          For architectures that block instructions, this is the maximum number of instructions that can be in a block.
 IntegerType getPtrdifftType()
          Return the type used for the C ptrdiff_t type.
 FloatType getRealCalcType()
          Return the type best used for floating point calculations.
 IntegerType getSignedCharType()
          Return the type used for the C signed char type.
 IntegerType getSignedIntType()
          Return the type used for the C signed int type.
 IntegerType getSignedLongLongType()
          Return the type used for the C signed long long type.
 IntegerType getSignedLongType()
          Return the type used for the C signed long type.
 IntegerType getSignedShortType()
          Return the type used for the C signed short type.
 IntegerType getSizetType()
          Return the type used for the C size_t type.
 IntegerType getSmallestAddressableUnitType()
          Return the type of the smallest addressable unit for this machine.
 IntegerType getUnsignedCharType()
          Return the type used for the C unsigned char type.
 IntegerType getUnsignedIntType()
          Return the type used for the C unsigned int type.
 IntegerType getUnsignedLongLongType()
          Return the type used for the C unsigned long long type.
 IntegerType getUnsignedLongType()
          Return the type used for the C unsigned long type.
 IntegerType getUnsignedShortType()
          Return the type used for the C unsigned short type.
 Type getVaListType()
          Return the type to be used for va_list.
 PointerType getVoidStarType()
          Return the type used for the C void* type.
 IntegerType getWchartType()
          Return the type used for the C wchar_t type.
 boolean hasCapabilities(int capabilities)
          Return true if this architecture has all of the specified capabilities.
 boolean hasCapability(int capability)
          Return true if this architecture has one of the specified capabilities.
 boolean keepTypeInRegister(Type type, boolean temporary)
          Return true if a value of the type should be allocated to a register.
abstract  boolean littleEndian()
          Return true if the machine is little-endian.
 int maxBitFieldSize()
          Return the maximum bit field size in bits.
protected  void setup()
          Setup this instance of the machine.
static java.lang.String setup(java.lang.String architecture)
          Setup for the specified machine.
static ICEstimator sGetInstructionCountEstimator()
          Return the proper instruction count estimator for the target architecture.
abstract  int stackAlignment(Type type)
          Return the alignment of things stored on the stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HAS_II_CONDITIONAL_MOVE

public static final int HAS_II_CONDITIONAL_MOVE
Capability: Has a conditional move using an integer test and integer values.

See Also:
Constant Field Values

HAS_IF_CONDITIONAL_MOVE

public static final int HAS_IF_CONDITIONAL_MOVE
Capability: Has a conditional move using an integer test and floating point values.

See Also:
Constant Field Values

HAS_FI_CONDITIONAL_MOVE

public static final int HAS_FI_CONDITIONAL_MOVE
Capability: Has a conditional move using a floating point test and integer values.

See Also:
Constant Field Values

HAS_FF_CONDITIONAL_MOVE

public static final int HAS_FF_CONDITIONAL_MOVE
Capability: Has a conditional move using a floating point test and floating point values.

See Also:
Constant Field Values

HAS_INT_FROM_FP_CMP

public static final int HAS_INT_FROM_FP_CMP
Capability: Has a floating point compare that returns an integer value.

See Also:
Constant Field Values

HAS_SIMPLE_FLOOR

public static final int HAS_SIMPLE_FLOOR
Capability: Has a simple inline floor capability.

See Also:
Constant Field Values

HAS_NON_VOLATILE_FP_REGS

public static final int HAS_NON_VOLATILE_FP_REGS
Capability: Has a floating point registers that are saved over function calls.

See Also:
Constant Field Values

HAS_PREDICATION

public static final int HAS_PREDICATION
Capability: Has predicated instructions.

See Also:
Constant Field Values

HAS_WHILE_LOOP_UNROLL_BENEFIT

public static final int HAS_WHILE_LOOP_UNROLL_BENEFIT
Capability: Has benefit from unrolling loops with no induction variable.

See Also:
Constant Field Values

HAS_EXPENSIVE_SUBROUTINE_CALLS

public static final int HAS_EXPENSIVE_SUBROUTINE_CALLS
Capability: bad to flatten/unroll loops that contain a function call.

See Also:
Constant Field Values

HAS_NO_INT_DIVIDE

public static final int HAS_NO_INT_DIVIDE
Capability: Integer divides are not performed by an instruction but by a subroutine call.

See Also:
Constant Field Values

HAS_NO_FP_DIVIDE

public static final int HAS_NO_FP_DIVIDE
Capability: Floating point divides are not performed by an instruction but by a subroutine call.

See Also:
Constant Field Values

ALL_CONDITIONAL_MOVES

public static final int ALL_CONDITIONAL_MOVES
Capability: All the conditional move possibilities.

See Also:
Constant Field Values

currentMachine

public static Machine currentMachine
The current machine specification.


cacheLineSize

protected int cacheLineSize
The size in addressable units of an L1 cache line.


smallestAddressableUnitType

protected IntegerType smallestAddressableUnitType
The type for the smallest addressable unit (e.g., char).


intCalcType

protected IntegerType intCalcType
The integer type best used for integer calculations.


floatCalcType

protected FloatType floatCalcType
The real type best used for floating point calculations.


vaListType

protected Type vaListType
The type to be used for va_list.


signedCharType

protected IntegerType signedCharType
The type used for the C signed char type.


unsignedCharType

protected IntegerType unsignedCharType
The type used for the C unsigned char type.


signedShortType

protected IntegerType signedShortType
The type used for the C signed short type.


unsignedShortType

protected IntegerType unsignedShortType
The type used for the C unsigned short type.


signedIntType

protected IntegerType signedIntType
The type used for the C signed int type.


unsignedIntType

protected IntegerType unsignedIntType
The type used for the C unsigned int type.


signedLongType

protected IntegerType signedLongType
The type used for the C signed long type.


unsignedLongType

protected IntegerType unsignedLongType
The type used for the C unsigned long type.


signedLongLongType

protected IntegerType signedLongLongType
The type used for the C signed long long type.


unsignedLongLongType

protected IntegerType unsignedLongLongType
The type used for the C unsigned long long type.


sizetType

protected IntegerType sizetType
The type used for the C size_t type.


ptrdifftType

protected IntegerType ptrdifftType
The type used for the C ptrdiff_t type.


wchartType

protected IntegerType wchartType
The type used for the C char_t type.


voidStarType

protected PointerType voidStarType
The type used for the C void* type.


floatType

protected FloatType floatType
The type used for the C float type.


doubleType

protected FloatType doubleType
The type used for the C double type.


longDoubleType

protected FloatType longDoubleType
The type used for the C long double type.

Constructor Detail

Machine

public Machine(int capabilities)
Create a Machine instance.

Parameters:
capabilities - specifies special abilities of this architecture that the compiler can use
Method Detail

hasCapability

public final boolean hasCapability(int capability)
Return true if this architecture has one of the specified capabilities.


hasCapabilities

public final boolean hasCapabilities(int capabilities)
Return true if this architecture has all of the specified capabilities.


getSmallestAddressableUnitType

public final IntegerType getSmallestAddressableUnitType()
Return the type of the smallest addressable unit for this machine. For most machines this is type char.


getSignedCharType

public final IntegerType getSignedCharType()
Return the type used for the C signed char type.


getUnsignedCharType

public final IntegerType getUnsignedCharType()
Return the type used for the C unsigned char type.


getSignedShortType

public final IntegerType getSignedShortType()
Return the type used for the C signed short type.


getUnsignedShortType

public final IntegerType getUnsignedShortType()
Return the type used for the C unsigned short type.


getSignedIntType

public final IntegerType getSignedIntType()
Return the type used for the C signed int type.


getUnsignedIntType

public final IntegerType getUnsignedIntType()
Return the type used for the C unsigned int type.


getSignedLongType

public final IntegerType getSignedLongType()
Return the type used for the C signed long type.


getUnsignedLongType

public final IntegerType getUnsignedLongType()
Return the type used for the C unsigned long type.


getSignedLongLongType

public final IntegerType getSignedLongLongType()
Return the type used for the C signed long long type.


getUnsignedLongLongType

public final IntegerType getUnsignedLongLongType()
Return the type used for the C unsigned long long type.


getSizetType

public final IntegerType getSizetType()
Return the type used for the C size_t type.


getPtrdifftType

public final IntegerType getPtrdifftType()
Return the type used for the C ptrdiff_t type.


getWchartType

public final IntegerType getWchartType()
Return the type used for the C wchar_t type.


getVoidStarType

public final PointerType getVoidStarType()
Return the type used for the C void* type.


getFloatType

public final FloatType getFloatType()
Return the type used for the C float type.


getDoubleType

public final FloatType getDoubleType()
Return the type used for the C double type.


getLongDoubleType

public final FloatType getLongDoubleType()
Return the type used for the C long double type.


getIntegerCalcType

public final IntegerType getIntegerCalcType()
Return the type best used for integer calculations. On the Alpha this is a signed 64-bit integer type while on the Sparc V8 it is a signed 32-bit integer type.


getRealCalcType

public final FloatType getRealCalcType()
Return the type best used for floating point calculations. On Trips this is a signed 64-bit real type.


getVaListType

public final Type getVaListType()
Return the type to be used for va_list.


setup

protected void setup()
Setup this instance of the machine. Each code generator should implement this method. For example
   protected void setup()
   {
     super.setup(); // Initialize type, etc that are not set here.
 
     // Specify the types that are different.
 
     PointerType.setMinBitSize(64);
     intCalcType = scale.clef.type.SignedIntegerType.create(64);
     ....
   }
 


alignData

public abstract int alignData(int dataSize)
Return the integer value alignmentthat satisfies (0 == address % alignment) for the data size specified.

Parameters:
dataSize - is the size of the data in addressable units.

addressableMemoryUnits

public abstract int addressableMemoryUnits(int bitSize)
Return the number of addressable units required

Parameters:
bitSize - is the number of bits required for the data

executionCostEstimate

public abstract int executionCostEstimate(long value)
Return an estimate of the execution cost to provide this value. The cost should be zero if the value can be represented as a hard-wired register or in the immediate field of an instruction. The cost is relative to the cost of other operations; a good metric is the number of cycles needed to generate the value or load it from memory.


executionCostEstimate

public abstract int executionCostEstimate(double value)
Return an estimate of the execution cost to provide this value. The cost should be zero if the value can be represented as a hard-wired register or in the immediate field of an instruction. The cost is relative to the cost of other operations; a good metric is the number of cycles needed to generate the value or load it from memory.


maxBitFieldSize

public int maxBitFieldSize()
Return the maximum bit field size in bits. Also, bit fields can not be split over this boundary.


alignTo

public static long alignTo(long value,
                           int to)
Round up a value so that it is evenly divisible by the second value.

Parameters:
value - - returned rounded up
to - - specifies the divisor
Returns:
value rounded up

addCPPFlags

public abstract void addCPPFlags(Vector<java.lang.String> v)
Add the flags necessary for the C preprocessor.


generalAlignment

public abstract int generalAlignment()
Return the most general purpose alignment in memory units.


stackAlignment

public abstract int stackAlignment(Type type)
Return the alignment of things stored on the stack.


littleEndian

public abstract boolean littleEndian()
Return true if the machine is little-endian.


getCacheSize

public int getCacheSize(int typeSize)
Return the number of elements of the specified size in a cache line. Using a value of 1 returns the cache line size in addressable units.

Parameters:
typeSize - is the number of addressable units per element

getGenericArchitectureName

public abstract java.lang.String getGenericArchitectureName()
Return the name of the generic target architecture.


getArchitectureName

public abstract java.lang.String getArchitectureName()
Return the name of the specific target architecture.


determineArchitecture

public abstract java.lang.String determineArchitecture(java.lang.String architecture,
                                                       java.lang.String extension)
                                                throws java.lang.Exception
Determine the architecture sub-type.

Parameters:
architecture - specifies the target architecture
extension - specifies an extension to the a target architecture
Returns:
the name of the specific target architecture generator class.
Throws:
java.lang.Exception - if the extension is not understood

getAsmFileExtension

public java.lang.String getAsmFileExtension()
Return the file extension to use for an assembler source file.


setup

public static java.lang.String setup(java.lang.String architecture)
Setup for the specified machine. The currentMachine is initialized and the assembly generator class is located.


getCodeGenerator

public static Generator getCodeGenerator(CallGraph cg,
                                         int backendFeatures)
                                  throws java.lang.Exception
Return a backend code generator instance for the specified target architecture.

Parameters:
cg - is the call graph containing the CFGs to be converted to target architecture instructions
backendFeatures - specifies certain flags set on the command line
Throws:
java.lang.Exception

getAssemblerCommand

public java.lang.String getAssemblerCommand(int backendFeatures)
Return the assembler command appropriate to the architecture.

Parameters:
backendFeatures - specifies code generation flags such as -g

getAssemblerCommand

public static java.lang.String getAssemblerCommand(java.lang.String user,
                                                   int backendFeatures)
Return the assembler command to use. If a user-specified value is available, use it. Otherwise generate one based on the architecture.

Parameters:
user - is the command specified by the user.
backendFeatures - specifies code generation flags such as -g

keepTypeInRegister

public boolean keepTypeInRegister(Type type,
                                  boolean temporary)
Return true if a value of the type should be allocated to a register. If it is volatile or not an atomic type, it probably should not be kept in a register.

Parameters:
type - is the type
temporary - is true if the duration will be short

getInstructionCountEstimator

public ICEstimator getInstructionCountEstimator()
Return the proper instruction count estimator for the target architecture.


sGetInstructionCountEstimator

public static ICEstimator sGetInstructionCountEstimator()
Return the proper instruction count estimator for the target architecture.


getMaxBlockSize

public int getMaxBlockSize()
For architectures that block instructions, this is the maximum number of instructions that can be in a block. For other architectures, the value 0 is returned.


getFunctionalUnitDescriptions

public byte[] getFunctionalUnitDescriptions()
Return the functional unit information. This information is an array where each element of the array is the number of instructions that can be issued to the corresponding functional unit. This method should be overridden in each architecture.

See Also:
Instruction.getFunctionalUnit()