The MLTREE Language
![]()
MLTree is a low-level typed language: all operations are typed by its width or precision. Operations on floating point, integer, and condition code are also segregated, to prevent accidental misuse. MLTree is also tree-oriented so that it is possible to write efficient MLTree transformation routines that uses SML pattern matching.
Here are a few examples of MLTree statements.
The statement
The DefinitionsMLTree is defined in the signature MLTREE and the functor MLTreeF
The functor MLTreeF is parameterized in terms of
the label expression type, the client supplied region datatype,
the instruction stream type, and the client defined MLTree extensions.
Basic TypesThe basic types in MLTree are statements (stm) integer expressions (rexp), floating point expression (fexp), and conditional expressions (ccexp). Statements are evaluated for their effects, while expressions are evaluated for their value. (Some expressions could also have trapping effects. The semantics of traps are unspecified.) These types are parameterized by an extension type, which we can use to extend the set of MLTree operators. How this is used is described in Section MLTree Extensions.
References to registers are represented internally as integers, and are denoted
as the type reg. In addition, we use the types src and dst
as abbreviations for source and destination registers.
Note that these types are low level. Higher level distinctions such as signed and unsigned integer value, are not distinguished by the type. Instead, operators are usually partitioned into signed and unsigned versions, and it is legal (and often useful!) to mix signed and unsigned operators in an expression. Currently, we don't provide a direct way to specify non-IEEE floating point together with IEEE floating point arithmetic. If this distinction is needed then it can be encoded using the extension mechanism described in Section MLTree Extensions.
We use the types ty and fty to stand for the number of
bits in integer and floating point operations.
The BasisThe signature MLTREE_BASIS defines the basic helper types used in the MLTREE signature.signature MLTREE_BASIS = sig datatype cond = LT | LTU | LE | LEU | EQ | NE | GE | GEU | GT | GTU datatype fcond = ? | !<=> | == | ?= | !<> | !?>= | < | ?< | !>= | !?> | <= | ?<= | !> | !?<= | > | ?> | !<= | !?< | >= | ?>= | !< | !?= | <> | != | !? | <=> | ?<> datatype ext = SIGN_EXTEND | ZERO_EXTEND datatype rounding_mode = TO_NEAREST | TO_NEGINF | TO_POSINF | TO_ZERO type ty = int type fty = int endThe most important of these are the types cond and fcond, which represent the set of integer and floating point comparisions. These types can be combined with the comparison constructors CMP and FCMP to form integer and floating point comparisions.
Integer ExpressionsA reference to the th integer register with an -bit value is written as REG(,). The operators LI, LI32, and LABEL, CONST are used to represent constant expressions of various forms. The sizes of these constants are inferred from context.REG : ty * reg -> rexp LI : int -> rexp LI32 : Word32.word -> rexp LABEL : LabelExp.labexp -> rexp CONST : Constant.const -> rexpThe following figure lists all the basic integer operators and their intuitive meanings. All operators except NOTB, NEG, NEGT are binary and have the type ty * rexp * rexp -> rexpThe operators NOTB, NEG, NEGT have the type ty * rexp -> rexp
Sign and Zero ExtensionSign extension and zero extension are written using the operator CVTI2I. CVTI2I(,SIGN_EXTEND,,) sign extends the -bit value to an -bit value, i.e. the th bit is of is treated as the sign bit. Similarly, CVTI2I(,ZERO_EXTEND,,) zero extends an -bit value to an -bit value. If , then CVTI2I(,SIGN_EXTEND,,) = CVTI2I(,ZERO_EXTEND,,).
Conditional MoveMost new superscalar architectures incorporate conditional move instructions in their ISAs. Modern VLIW architectures also directly support full predication. Since branching (especially with data dependent branches) can introduce extra latencies in highly pipelined architectures, condtional moves should be used in place of short branch sequences. MLTree provide a conditional move instruction COND, to make it possible to directly express conditional moves without using branches.COND : ty * ccexp * rexp * rexp -> rexpSemantically, COND(ty,cc,,) means to evaluate cc, and if cc evaluates to true then the value of the entire expression is ; otherwise the value is . Note that and are allowed to be eagerly evaluated. In fact, we are allowed to evaluate to both branches, one branch, or neither~\footnote{When possible.}.
Various idioms of the COND form are useful for expressing common
constructs in many programming languages. For example, MLTree does not
provide a primitive construct for converting an integer value x to a
boolean value (0 or 1). But using COND, this is expressible as
COND(32,CMP(32,NE,x,LI 0),LI 1,LI 0). SML/NJ represents
the boolean values true and false as machine integers 3 and 1 respectively.
To convert a boolean condition into an ML boolean value, we can use
In general, the COND form should be used in place of MLTree's branching constructs whenever possible, since the former is usually highly optimized in various MLRISC backends. Integer LoadsInteger loads are written using the constructor LOAD.LOAD : ty * rexp * Region.region -> rexpThe client is required to specify a region that serves as aliasing information for the load. Miscellaneous Integer OperatorsAn expression of the LET(,) evaluates the statement for its effect, and then return the value of expression .LET : stm * rexp -> rexpSince the order of evaluation is MLTree operators are unspecified the use of this operator should be severely restricted to only side-effect-free forms. Floating Point ExpressionsFloating registers are referenced using the term FREG. The th floating point register with type is written as FREG(,).FREG : fty * src -> fexpBuilt-in floating point operations include addition (FADD), subtraction (FSUB), multiplication (FMUL), division (FDIV), absolute value (FABS), negation (FNEG) and square root (FSQRT). FADD : fty * fexp * fexp -> fexp FSUB : fty * fexp * fexp -> fexp FMUL : fty * fexp * fexp -> fexp FDIV : fty * fexp * fexp -> fexp FABS : fty * fexp -> fexp FNEG : fty * fexp -> fexp FSQRT : fty * fexp -> fexpA special operator is provided for manipulating signs. To combine the sign of with the magnitude of , we can write FCOPYSIGN(,)\footnote{What should happen if or is nan?}. FCOPYSIGN : fty * fexp * fexp -> fexpTo convert an -bit signed integer into an -bit floating point value, we can write CVTI2F(,,)\footnote{What happen to unsigned integers?}. CVTI2F : fty * ty * rexp -> fexpSimilarly, to convert an -bit floating point value to an -bit floating point value, we can write CVTF2F(,,)\footnote{ What is the rounding semantics?}. CVTF2F : fty * fty * -> fexp datatype rounding_mode = TO_NEAREST | TO_NEGINF | TO_POSINF | TO_ZERO CVTF2I : ty * rounding_mode * fty * fexp -> rexp FLOAD : fty * rexp * Region.region -> fexp Condition ExpressionsUnlike languages like C, MLTree makes the distinction between condition expressions and integer expressions. This distinction is necessary for two purposes:
A conditional code register bit can be referenced using the constructors
CC and FCC. Note that the condition must be specified
together with the condition code register.
The comparison operators CMP and FCMP performs integer and
floating point tests. Both of these are typed by the precision
in which the test must be performed under.
StatementsStatement forms in MLTree includes assignments, parallel copies, jumps and condition branches, calls and returns, stores, sequencing, and annotation.AssignmentsAssignments are segregated among the integer, floating point and conditional code types. In addition, all assignments are typed by the precision of destination register.
Parallel CopiesSpecial forms are provided for parallel copies for integer and floating point registers. It is important to emphasize that the semantics is that all assignments are performed in parallel.
Jumps and Conditional BranchesJumps and conditional branches in MLTree take two additional set of annotations. The first represents the control flow and is denoted by the type controlflow. The second represent control-dependence and anti-control-dependence and is denoted by the type ctrl.
The primitive jumps and conditional branch forms are represented
by the constructors JMP, BCC.
Here's an example of how control dependence predicates are used.
Consider the following MLTree statement:
Note that on architectures with speculative loads, the control dependence information can be used to guide the transformation of control dependent loads into speculative loads.
Now in constrast, the LOAD in the second alternative is not
control dependent on the control dependent predicate p, and
thus it is safe and legal to hoist the load above the test, as in
Calls and ReturnsCalls and returns in MLTree are specified using the constructors CALL and RET, which have the following types.CALL : rexp * controlflow * mlrisc * mlrisc * ctrl * ctrl * Region.region -> stm RET : ctrl * controlflow -> stmThe CALL form is particularly complex, and require some explanation. Basically the seven parameters are, in order:
The matching return statement constructor RET has two arguments. These are:
StoresStores to integer and floating points are specified using the constructors STORE and FSTORE.STORE : ty * rexp * rexp * Region.region -> stm FSTORE : fty * rexp * fexp * Region.region -> stmThe general form is STORE(, , , )Stores for condition codes are not provided. Miscelleneous StatementsOther useful statement forms of MLTree are for sequencing (SEQ), defining a local label (DEFINE).SEQ : stm list -> stm DEFINE : Label.label -> stmThe constructor DEFINE L has the same meaning as executing the method defineLabel L in the stream interface. AnnotationsAnnotations are used as the generic mechanism for exchanging information between different phases of the MLRISC system, and between a compiler front end and the MLRISC back end. The following constructors can be used to annotate a MLTree term with an annotation:MARK : rexp * Annotations.annotation -> rexp FMARK : fexp * Annotations.annotation -> fexp CCMARK : ccexp * Annotations.annotation -> ccexp ANNOTATION : stm * Annotations.annotation -> stm
|