Assignment on RTL IR Manipulation

Problem Statement

  1. Traverse the RTL level CFG

  2. Print a more understandable RTL code by using "=" for set operations, converting prefix expressions into infix, and using familiar symbols for operations. Ignore non-instruction organisational rtx's like NOTE insns.
  3. Example:

    For the following two rtl instructions :

    (insn 5 4 6 3 1.c:15 (set (reg:SI 59)
    (mem/c/i:SI (plus:SI (reg/f:SI 54 virtual-stack-vars)
    (const_int -8 [0xfffffff8])) [0 b+0 S4 A32])) -1 (nil))

    (insn 6 5 7 3 1.c:15 (set (reg:SI 61)
    (mem/c/i:SI (plus:SI (reg/f:SI 54 virtual-stack-vars)
    (const_int -4 [0xfffffffc])) [0 a+0 S4 A32])) -1 (nil))

    (insn 7 6 8 3 1.c:15 (parallel [
    (set (reg:SI 60)
    (plus:SI (reg:SI 61)
    (reg:SI 59)))
    (clobber (reg:CC 17 flags))
    ]) -1 (nil))

    Generate the following:

    r59 = *(r54 - 8)
    r61 = *(r54 - 4)
    r60 = r61 + r59 || clobber r17

Hints:

A. Possible approach:

  1. Take a very simple program, eg.
    main()
    {
    int a,b,c;
    c = a + b;
    }
  2. Generate the rtl dump by executing gcc. Inspect the rtl dump of pass_expand.
  3. Extend the base code to handle rtl objects appearing in the rtl dump of the above program.
  4. Handle other rtl objects.

B. Solution hint:

Use recursion. Trying modifying the base code.

Debugging AID: use GET_RTX_NAME(int rxt_code) to print the ascii string describing the rtl object you are currently processing.

Anticipated Problems:

  1. The most important macros needed are:
    GET_CODE
    GET_RTX_NAME
    Accessor functions, XINT, XEXP,XSTR,XVEC

  2. What are The CODES of the RTL objects? Handle these cases first:
    PLUS, MINUS, MUL, DIV
    GE,LE,GT...
    NEG, NOT
    SET
    MEM, REG
    CONST_INT
    SYMBOL_REF, LABEL_REF, CODE_LABEL
    PC,COMPARE,IF_THEN_ELSE
    USE,CC0