Monday, October 22, 2012

GCC's new Local Register Allocator

Some messy code was cleared up the new GCC (GNU's C compiler) and apparently is used to be refered to as Satan. I thought that sounded a worth a skim. It's here for the interested: reload.c

I was about 1/3 of the way down, thinking - this isn't too bad, I've seen worse - then I reached this beauty of an if statement.

  if (out != 0 && GET_CODE (out) == SUBREG
      && (subreg_lowpart_p (out) || strict_low)
#ifdef CANNOT_CHANGE_MODE_CLASS
      && !CANNOT_CHANGE_MODE_CLASS (GET_MODE (SUBREG_REG (out)), outmode, rclass)
#endif
      && contains_reg_of_mode[(int) rclass][(int) GET_MODE (SUBREG_REG (out))]
      && (CONSTANT_P (SUBREG_REG (out))
   || strict_low
   || (((REG_P (SUBREG_REG (out))
  && REGNO (SUBREG_REG (out)) >= FIRST_PSEUDO_REGISTER)
        || MEM_P (SUBREG_REG (out)))
       && ((GET_MODE_PRECISION (outmode)
     > GET_MODE_PRECISION (GET_MODE (SUBREG_REG (out))))
#ifdef WORD_REGISTER_OPERATIONS
    || ((GET_MODE_PRECISION (outmode)
         < GET_MODE_PRECISION (GET_MODE (SUBREG_REG (out))))
        && ((GET_MODE_SIZE (outmode) - 1) / UNITS_PER_WORD ==
     ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))) - 1)
      / UNITS_PER_WORD)))
#endif
    ))
   || (REG_P (SUBREG_REG (out))
       && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
       /* The case of a word mode subreg
   is handled differently in the following statement.  */
       && ! (GET_MODE_SIZE (outmode) <= UNITS_PER_WORD
      && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
          > UNITS_PER_WORD))
       && ! HARD_REGNO_MODE_OK (subreg_regno (out), outmode))
   || (secondary_reload_class (0, rclass, outmode, out) != NO_REGS
       && (secondary_reload_class (0, rclass, GET_MODE (SUBREG_REG (out)),
       SUBREG_REG (out))
    == NO_REGS))
#ifdef CANNOT_CHANGE_MODE_CLASS
   || (REG_P (SUBREG_REG (out))
       && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
       && REG_CANNOT_CHANGE_MODE_P (REGNO (SUBREG_REG (out)),
        GET_MODE (SUBREG_REG (out)),
        outmode))
#endif
   ))
    {
#ifdef LIMIT_RELOAD_CLASS
      out_subreg_loc = outloc;
#endif

I've never even seen if-defs in a if statement before! Mind-boggling - seems like the clause itself should be it's own small domain language. I've not even tried to pick it apart, and as usual blogger has messed up some characters escaping them but I'm sure the insanity shines through!

No comments: