Quads and their Components

The program representation that we will be using is this class is a control flow graph, where basic blocks consist of simple operations known as Quads. Quads consist of an Operator and up to four Operands.


Operator types

All operators are inherited from the Operator class. Operators have the following methods:

All the operations are hierarchically ordered. For example, there are different operations to write to a field in a class, depending on the type of the field. For example, the PUTFIELD_{I,F,L,D,A,B,C,S,Z} Operators represent array load instructions for the types integer, floating-point, long, double, reference, byte, character, short, and boolean. PUTFIELD_{I,F,L,D,A,B,C,S,Z}_DYNLINK are similar to PUTFIELD_{I,F,L,D,A,B,C,S,Z}, except that the invoked function may need to be loaded dynamically. We use the % symbol to stand for DYNLINK when printing the quads . All the various PUTFIELD variants inherit from the Putfield class, which inherits from Operator. Associated with each class is a set of methods, allowing the compiler writer to refer to the operands of a quad by more meaningful names than getOp1, getOp2 etc. For example, the first operand for Binary operations can be retrieved by invoking getDest on the quad containing the operator.

Operator

Short Description

Subclasses

Methods

Move

Move between pseudo registers

MOVE_{I,F,L,D,A}

getMoveOp
getDest
getSrc

Binary

Binary operation, with two sources and one destination

ADD_{I,L,F,D}, SUB_{I,L,F,D},
MUL_{I,L,F,D}, DIV_{I,L,F,D},
REM_{I,L,F,D},
AND_{I,L}, OR_{I,L}, XOR_{I,L},
SHL_{I,L}, SHR_{I,L}, USHR_{I,L},
CMP_{L,F,D}

getDest
getSrc1
getSrc2

Unary

Unary operation, with one source and one destination

NEG_{I,F,L,D},
INT_2LONG, INT_2FLOAT, INT_2DOUBLE,
LONG_2INT, LONG_2FLOAT, LONG_2DOUBLE,
FLOAT_2INT, DOUBLE_2LONG, DOUBLE_2FLOAT,
INT_2BYTE, INT_2CHAR, INT_2SHORT,
OBJECT_2INT, INT_2OBJECT,
FLOAT_2INTBITS, INTBITS_2FLOAT,
DOUBLE_2FLOAT,
DOUBLE_2LONGBITS, LONGBITS_2DOUBLE

getDest
getSrc

Goto

unconditional branch

GOTO

getTarget

IntIfCmp

conditional branch

IFCMP_{I,A}

getSrc1
getSrc2
getCond
getTarget

TableSwitch

table switch instruction

TABLESWITCH

setTarget
getSrc
getDefault
getLow
getTarget
getTargetTable

LookupSwitch

lookup switch instruction

LOOKUPSWITCH

setMatch
setTarget
getSrc
getMatch
getTarget
getValueTable
getTargetTable

Getstatic

load from a static field

GETSTATIC_{I,F,L,D,A},
GETSTATIC_{I,F,L,D,A}_DYNLINK

getDest
getField

Putstatic

store to a static field

PUTSTATIC_{I,F,L,D,A},
PUTSTATIC_{I,F,L,D,A}_DYNLINK

getSrc
getField

Getfield

load from an object field

GETFIELD_{I,F,L,D,A,B,C,S,Z},
GETFIELD_{I,F,L,D,A,B,C,S,Z}_DYNLINK

getDest
getBase
getField
getGuard

Putfield

store to an object field

PUTFIELD_{I,F,L,D,A,B,C,S,Z},
PUTFIELD_{I,F,L,D,A,B,C,S,Z}_DYNLINK

getBase
getSrc
getField
getGuard

ALoad

array load

ALOAD_{I,L,F,D,A,B,C,S}

getDest
getIndex
getGuard

AStore

array store

ASTORE_{I,L,F,D,A,B,C,S}

getValue
getBase
getIndex
getGuard

ALength

array length

ARRAYLENGTH

getDest
getSrc

BoundsCheck

array bounds check

BOUNDS_CHECK

getRef
getIndex
getGuard

NullCheck

null pointer check

NULL_CHECK

getDest
getSrc

ZeroCheck

null pointer check

ZERO_CHECK

getDest
getSrc

StoreCheck

array object type store check

ASTORE_CHECK

getRef
getElement
getGuard

New

allocate a new object

NEW

getDest
getType

NewArray

allocate a new array

NEWARRAY

getDest
getSize
getType

CheckCast

run time type check

CHECK_CAST

getDest
getSrc
getType

InstanceOf

run time type check

INSTANCEOF

getDest
getSrc
getType

Invoke

call another method

INVOKEVIRTUAL_{V,I,F,L,D,A},
INVOKESTATIC_{V,I,F,L,D,A},
INVOKEVIRTUAL_{V,I,F,L,D,A}_DYNLINK,
INVOKESTATIC_{V,I,F,L,D,A}_DYNLINK,
INVOKESPECIAL_{V,I,F,L,D,A}_DYNLINK,
INVOKEINTERFACE_{V,I,F,L,D,A}

setParam
getDest
getMethod
getParam
getParamList

Jsr

call an internal subroutine

JSR

getDest
getTarget

Ret

return from an internal subroutine

RET

getTarget

Return

return from the current method

RETURN_{V,I,F,L,D,A},THROW_A

getSrc

Monitor

access atomic lock for an object

MONITORENTER,MONITOREXIT

getSrc


Operand types

The following provides a short description of all the different kinds of operands.

RegisterOperand

specifies an abstract location

IConstOperand

integer constant (32 bit)

FConstOperand

floating point constant operand (32 bit)

LConstOperand

long integer constant operand (64 bit)

DConstOperand

double-precision floating point constant operand (64 bit)

AConstOperand

object reference constant

MethodOperand

specifies the target method of a method call instruction

ParamListOperand

specifies the parameter list for a method call instruction

FieldOperand

specifies an object field associated with a get/put field instruction

TypeOperand

specifies a type for use in type check instructions

ConditionOperand

Specifies a condition code associated with a conditional branch instruction

TargetOperand

specifies the target of a branch instruction

BasicBlockTableOperand

specifies a table of targets, for use in switch instructions


Basic blocks and the control flow graph

Quads are organized into BasicBlocks. BasicBlocks are single-entry, meaning that control flow can only enter at the start of a basic block. Barring exceptions and method calls, they are also single-exit, meaning that control flow can only leave at the end of a basic block. This is an important difference between the basic blocks that were covered in lecture. Exceptions can cause basic blocks to exit early.

Each BasicBlock contains a list of Quads. They also include a set of predecessor and successor basic blocks. Basic blocks are numbered with unique integer identifiers. There are two special basic blocks, the entry basic block and the exit basic block. These basic blocks always have identifiers 0 and 1, respectively. These blocks mark the method entry point and exit point. They never contain instructions. Obviously, the entry basic block has no predecessors, and the exit basic block has no successors.

Basic blocks also have exception handlers. When an exception occurs within a basic block, control flow jumps to the handler for that basic block that matches the type of the exception that occurred.

BasicBlocks are contained in a ControlFlowGraph. The ControlFlowGraph contains references to the start and end nodes and a list of all exception handlers.

<-- previous home next -->