cgccssagimple

Meaning of a variable in GCC SSA format


I want to look at the SSA format GCC uses, so I tried the following simple test program:

    #include <stdio.h>

    int main(int argc, char **argv) {
      int n = 0;
      int i;
      for (i = 0; i < 13; i++)
        n += argc;
      printf("%d\n", n);
      return 0;
    }

Compiled with gcc -fdump-tree-all a.c and got, among other things, a.c.016t.ssa with the following contents:

;; Function main (main, funcdef_no=0, decl_uid=2178, cgraph_uid=0)

main (int argc, char * * argv)
{
  int i;
  int n;
  int D.2186;
  int _8;

  <bb 2>:
  n_3 = 0;
  i_4 = 0;
  goto <bb 4>;

  <bb 3>:
  n_6 = n_1 + argc_5(D);
  i_7 = i_2 + 1;

  <bb 4>:
  # n_1 = PHI <n_3(2), n_6(3)>
  # i_2 = PHI <i_4(2), i_7(3)>
  if (i_2 <= 12)
    goto <bb 3>;
  else
    goto <bb 5>;

  <bb 5>:
  printf ("%d\n", n_1);
  _8 = 0;

<L3>:
  return _8;

}

Much of this is clear, but what does argc_5(D) mean? Does it have anything to do with int D.2186?


Solution

  • The (D) is a suffix added to ssa_name nodes which are DEFAULt_DEF.

    SSA_NAME_IS_DEFAULT_DEF : Nonzero if this SSA_NAME is the default definition for the underlying symbol. A default SSA name is created for symbol S if the very first reference to S in the function is a read operation. Default definitions are always created by an empty statement and belong to no basic block.

    It is typically the case of the argument, so you will find this suffix added to the arguments.

    The D. is a prefix added when dumping the name of node which are _DECL nodes, don't have a name or have a flag to Display decl UIDsn and are neither labels nor debug expression nor constants otherwise other prefix will be used.

    If you have D.2186 in your dump, probably you compiled with O0. normally you will found that in the precedent dump it was used for the return value. in the ssa_dump _8 is used for the retuen value by The D.2186 was not deleted yet ( with O0) but it will not be expanded (to rtl). Add -fdump-rtl-all and you see that _8 will be expanded but not D.2186 for example.