next up previous
Next: The Problem Up: Project on Machine Description Previous: What is ``GCC Machine

MD Syntax

The <target>.md file has a Lisp-like syntax. To get a feel of the syntax, we take a quick look at a concrete RTL statement in $GCCHOME/gcc/config/mips/mips.md file.

(define_insn "addsi3_internal"
  [(set (match_operand:SI 0 "register_operand" "=d,d")
        (plus:SI (match_operand:SI 1 "reg_or_0_operand" "dJ,dJ")
                 (match_operand:SI 2 "arith_operand" "d,Q")))]
  "!TARGET_MIPS16"
  "@
    addu\t%0,%z1,%2
    addiu\t%0,%z1,%2"
  [(set_attr "type"     "arith")
   (set_attr "mode"     "SI")])

The basic structure of a define_insn in MD is:

(define_insn  
    KEY (also called NAME)
    RTL TEMPLATE
    C CONDITION
    ASM
    OPTIONAL ATTRIBUTES SPECIFICATION
)

Table (1) details the correspondence between the general structure and the concrete example above.

Table 1: Correspondence between the generic define_insn and the concrete MIPS example.
KEY "addsi3_internal"
RTL TEMPLATE
 
   [(set (match_operand:SI 0 "register_operand" "=d,d")
        (plus:SI (match_operand:SI 1 "reg_or_0_operand" "dJ,dJ")
                 (match_operand:SI 2 "arith_operand" "d,Q")))]
C CONDITION "!TARGET_MIPS16"
ASM
 
   "@
    addu\t%0,%z1,%2
    addiu\t%0,%z1,%2"
  
ATTRIBUTES
 
  [(set_attr "type"     "arith")
   (set_attr "mode"     "SI")]


There are constructs other than define_insn in the <target>.md file, for instance define_attributes lists target attributes that are used in a define_insn.



2006-01-08