Introduction To RTL: GCC Resource Center
Introduction To RTL: GCC Resource Center
March 2010
March 2010 RTL: Outline 1/27
Outline
What is RTL ?
Why RTL?
Why RTL?
For tasks such as those, RTL supports many low level features, like,
• Register classes
• Memory addressing modes
• Word sizes and types
• Compare and branch instructions
• Calling Conventions
• Bitfield operations
MD Info Required
C Source Code
(define_insn
"movsi"
(set
(match_operand 0 "register_operand" "r")
(match_operand 1 "const_int_operand" "k")
)
"" /* C boolean expression, if required */
"li %0, %1"
)
(define_insn
"movsi"
(set
(match_operand 0 "register_operand" "r")
(match_operand 1 "const_int_operand" "k")
)
"" /* C boolean expression, if required */
"li %0, %1"
)
(define_insn
"movsi"
(set
(match_operand 0 "register_operand" "r")
(match_operand 1 "const_int_operand" "k")
)
"" /* C boolean expression, if required */
"li %0, %1"
)
Predicates Constraints
An Example of Translation
(define_insn
"movsi"
(set
(match_operand 0 "register_operand" "r")
(match_operand 1 "const_int_operand" "k")
)
"" /* C boolean expression, if required */
"li %0, %1"
)
An Example of Translation
(define_insn
"movsi"
Development
(set
(match_operand 0 "register_operand" "r")
(match_operand 1 "const_int_operand" "k")
)
"" /* C boolean expression, if required */
"li %0, %1"
)
(set
Use
(reg:SI 58 [D.1283])
D.1283 = 10; (const int 10: [0xa]) li $t0, 10
)
Essential Abstrations in GCC GCC Resource Center, IIT Bombay
March 2010 RTL: The Overall Perspective 10/27
Translation of a = a + 1
Dump file: test.c.131r.expand stack($fp - 4) = stack($fp - 4) + 1
|| flags=?
Translation of a = a + 1
Dump file: test.c.131r.expand stack($fp - 4) = stack($fp - 4) + 1
|| flags=?
(insn 12 11 10 (parallel[
( set (mem/c/i:SI (plus:SI
(reg/f:SI 54 virtual-stack-vars)
(const int -4 [...])) [...])
(plus:SI
(mem/c/i:SI (plus:SI
(reg/f:SI 54 virtual-stack-vars)
(const int -4 [...])) [...])
(const int 1 [...])))
(clobber (reg:CC 17 flags))
]) -1 (nil))
Translation of a = a + 1
Dump file: test.c.131r.expand stack($fp - 4) = stack($fp - 4) + 1
|| flags=?
(insn 12 11 10 (parallel [
( set (mem/c/i:SI (plus:SI
(reg/f:SI 54 virtual-stack-vars)
(const int -4 [...])) [...])
(plus:SI
(mem/c/i:SI (plus:SI
(reg/f:SI 54 virtual-stack-vars)
(const int -4 [...])) [...])
(const int 1 [...])))
(clobber (reg:CC 17 flags))
]) -1 (nil))
1 is added to variable a
Translation of a = a + 1
Dump file: test.c.131r.expand stack($fp - 4) = stack($fp - 4) + 1
|| flags=?
(insn 12 11 10 (parallel [
( set (mem/c/i:SI (plus:SI
(reg/f:SI 54 virtual-stack-vars)
(const int -4 [...])) [...])
(plus:SI
(mem/c/i:SI (plus:SI
(reg/f:SI 54 virtual-stack-vars)
(const int -4 [...])) [...])
(const int 1 [...])))
(clobber (reg:CC 17 flags))
]) -1 (nil))
Translation of a = a + 1
Dump file: test.c.131r.expand
r39=stack($fp - 4)
r40=r39+1
stack($fp - 4)=r40
(insn 7 6 8 test.c:6 (set (reg:SI 39)
(mem/c/i:SI (plus:SI (reg/f:SI 33 virtual-stack-vars)
(const_int -4 [...])) [...])) -1 (nil))
(insn 8 7 9 test.c:6 (set (reg:SI 40)
(plus:SI (reg:SI 39)
(const_int 1 [...]))) -1 (nil))
(insn 9 8 0 test.c:6 (set
(mem/c/i:SI (plus:SI (reg/f:SI 33 virtual-stack-vars)
(const_int -4 [...])) [...])
(reg:SI 40)) -1 (nil))
Translation of a = a + 1
Dump file: test.c.131r.expand
r39=stack($fp - 4)
r40=r39+1
stack($fp - 4)=r40
(insn 7 6 8 test.c:6 (set (reg:SI 39)
(mem/c/i:SI (plus:SI (reg/f:SI 33 virtual-stack-vars)
(const_int -4 [...])) [...])) -1 (nil))
(insn 8 7 9 test.c:6 (set (reg:SI 40)
(plus:SI (reg:SI 39)
(const_int 1 [...]))) -1 (nil))
(insn 9 8 0 test.c:6 (set
(mem/c/i:SI (plus:SI (reg/f:SI 33 virtual-stack-vars)
(const_int -4 [...])) [...])
(reg:SI 40)) -1 (nil))
Translation of a = a + 1
Dump file: test.c.131r.expand
r39=stack($fp - 4)
r40=r39+1
stack($fp - 4)=r40
(insn 7 6 8 test.c:6 (set (reg:SI 39)
(mem/c/i:SI (plus:SI (reg/f:SI 33 virtual-stack-vars)
(const_int -4 [...])) [...])) -1 (nil))
(insn 8 7 9 test.c:6 (set (reg:SI 40)
(plus:SI (reg:SI 39)
(const_int 1 [...]))) -1 (nil))
(insn 9 8 0 test.c:6 (set
(mem/c/i:SI (plus:SI (reg/f:SI 33 virtual-stack-vars)
(const_int -4 [...])) [...])
(reg:SI 40)) -1 (nil))
RTL Objects
◮ Integers
◮ Wide Integers
◮ Strings
◮ Vectors
RTX Codes
RTL Classes
RTX Codes
The RTX codes are defined in rtl.def using cpp macro call
DEF RTL EXPR, like :
• DEF RTL EXPR(INSN, "insn", "iuuBieie", RTX INSN)
• DEF RTL EXPR(SET, "set", "ee", RTX EXTRA)
• DEF RTL EXPR(PLUS, "plus", "ee", RTX COMM ARITH)
• DEF RTL EXPR(IF THEN ELSE, "if then else", "eee",
RTX TERNARY)
RTX Formats
• i : Integer
• u : Integer representing a pointer
• B : Pointer to basic block
• e : Expression
RTL statements
• XEXP,XINT,XWINT,XSTR
◮ Example: XINT(x,2) accesses the 2nd operand of rtx x as an
integer
◮ Example: XEXP(x,2) accesses the same operand as an expression
containing expression
• Special macros are available for Vector operands
◮ XVEC(exp,idx) : Access the vector-pointer which is operand
the vector which is in operand number idx in exp. This value is an int
◮ XVECEXP (exp, idx, eltnum ) : Access element number
RTL Insns