Project Stage 1 - `-fdump-tree-all` part 2

Intro

In this post, I will write about my experiment and examination of dump files that are generated by gcc compiler. This post is written by me wiht ChatGPT's help.


Progress

Next file we are suppoosed to start with in this post is `test.c.052t.profile_estimate`; However, this file show nothing, literally nothing. I think it may be related to some settings like bash_profile (e.g. how we want to optimize), but we didn't set anything so it doesn't show anything.

Next, `test.c.056t.release_ssa`

Released 0 names, 0.00%, removed 0 holes
int main ()
{
  int i;
  int sum;
  int D.4865;
  unsigned int i.0_1;
  unsigned int _2;
  int _11;

  <bb 2> :
  sum_7 = 0;
  i_8 = 1;
  goto <bb 7>; [INV]

  <bb 3> :
  sum_12 = sum_3 + i_4;
  i.0_1 = (unsigned int) i_4;
  _2 = i.0_1 & 1;
  if (_2 == 0)
    goto <bb 4>; [INV]
  else
    goto <bb 5>; [INV]

  <bb 4> :
  printf ("%d is even\n", i_4);
  goto <bb 6>; [INV]

  <bb 5> :
  printf ("%d is odd\n", i_4);

  <bb 6> :
  i_15 = i_4 + 1;

  <bb 7> :
  # sum_3 = PHI <sum_7(2), sum_12(6)>
  # i_4 = PHI <i_8(2), i_15(6)>
  if (i_4 <= 5)
    goto <bb 3>; [INV]
  else
    goto <bb 8>; [INV]

  <bb 8> :
  printf ("Sum of numbers from 1 to 5 is: %d\n", sum_3);
  _11 = 0;

  <bb 9> :
<L6>:
  return _11;

}

If you remember from previous Post, we had a dump file named `test.c.022t.ssa`. In that stage, it did ssa optimization. In this stage `test.c.056t.release_ssa`, it seems to optimize the ssa optimization, so optimization of optimization.


Next file is `test.c.057t.local-fnsummary2`, and other parts are the same but it contains the following extra information.

Analyzing function body size: main/0

IPA function summary for main/0
  global time:     45.000000
  self size:       19
  global size:     19
  min size:       0
  self stack:      0
  global stack:    0
    size:8.000000, time:9.000000
    size:2.000000, time:0.000000,  executed if:(not inlined)
  calls:
    printf/1 function body not available
      freq:1.00 loop depth: 0 size: 3 time: 12
    printf/1 function body not available
      freq:1.00 loop depth: 1 size: 3 time: 12
    printf/1 function body not available
      freq:1.00 loop depth: 1 size: 3 time: 12

Now, I think there is some patterns, we took a look at `test.c.031t.local-fnsummary1`, which provided information for inline optimization. In this file `test.c.057t.local-fnsummary2`, it's doing the same thing, but probably it does further since the name is `local-fnsummary2`.


Next, `test.c.098t.fixup_cfg3`

We are seeing this `cfg` file third time. Now I think it is time to what cfg file does. And I asked ChatGPT.

CFG stands for "Control Flow Graph". What it does is `Control Flow Graph (CFG) Fixup`, which is making sure that all building blocks are correct and valid.

It also does `Handling of Basic Blocks`, which does Merging or splitting blocks, Removing unreachable code, Correcting jump instructions or branches that do not conform to the current structure of the CFG.

Lastly, it does Optimization Preparation, which does By fixing the CFG, the compiler prepares for subsequent optimization passes. A well-structured CFG is crucial for performing optimizations that depend on understanding the control flow, such as Loop optimizations, Dead code elimination, and Inlining decisions.

It looks like cfg optimization is very important so that it's done three times. However, in this stage, our code hasn't changes; it looks like there is nothing to optimize as we have pretty simple code.


Next, `test.c.105t.adjust_alignment`

This stage doesn't do anything to our code; According to ChatGPT, it says that it checks if data is stored in memory addresses that adhere to specific rules or requirements dictated by the architecture of the computer.


Next, `test.c.251t.veclower`

This stage is for vectorization, which is what we learned in this course. It's SIMD(Single Instruction and Multiple Data). With one instruction, it's handling multiple data. However, in our code, there is nothing to vectorize as we have data that are accessed by diffiernt insturctions. As a result, there is no change.


Next, `test.c.252t.cplxlower0`

This stage is for Complex number optimization such as numbers like `i^2 1`. However, as our code doesn't include complex numbers, there was no change.


Next, `test.c.253t.bitintlower0`

This stage is for changing some conditional statement into bitwise coperation; I think I learned this in the fourth semester in Datastructure and Algorithm Course. For example, using `AND` or `OR` bit operation, you can make the last bit as 1 or 0, which can be used as odd number or even number; when you need to make something as odd number or even number, you can use this instead of using conditional statement. This can improve performance since the computer doesn't have to predict the next instruction (e.g. pipelinining)


Next, `test.c.255t.switchlower_O0`

The file name already implies that it's about switch statement, since we don't have switch statement, it didn't make any chagnes to our code


Next, `test.c.263t.isel`

This stage, it changes the abstract representation into simplified actual calculation, such as

int a = 10;
int b = 20
int c = a + b;

This will be:

mov eax, 10     ; 
add eax, 20     ; 
mov c, eax      ; 
However, in our code it doesn't change

Next, `test.c.266t.waccess3`

This does the same thing that the compiler did in `test.c.026t.waccess1`. It provides pointer optimization information.

Next, `test.c.267t.optimized`

I think this showes the final code representation of optimization. 
;; Function main (main, funcdef_no=0, decl_uid=4853, cgraph_uid=1, symbol_order=0)

int main ()
{
  int i;
  int sum;
  int D.4865;
  unsigned int i.0_1;
  unsigned int _2;
  int _11;

  <bb 2> :
  sum_7 = 0;
  i_8 = 1;
  goto <bb 7>; [INV]

  <bb 3> :
  sum_12 = sum_3 + i_4;
  i.0_1 = (unsigned int) i_4;
  _2 = i.0_1 & 1;
  if (_2 == 0)
    goto <bb 4>; [INV]
  else
    goto <bb 5>; [INV]

  <bb 4> :
  printf ("%d is even\n", i_4);
  goto <bb 6>; [INV]

  <bb 5> :
  printf ("%d is odd\n", i_4);

  <bb 6> :
  i_15 = i_4 + 1;

  <bb 7> :
  # sum_3 = PHI <sum_7(2), sum_12(6)>
  # i_4 = PHI <i_8(2), i_15(6)>
  if (i_4 <= 5)
    goto <bb 3>; [INV]
  else
    goto <bb 8>; [INV]

  <bb 8> :
  printf ("Sum of numbers from 1 to 5 is: %d\n", sum_3);
  _11 = 0;

  <bb 9> :
<L6>:
  return _11;

}

Finally, `test.c.364t.statistics, test.c.365t.earlydebug, and test.c.366t.debug`

I think these files show the final statistics and debug results. However, for my code, it showed nothing.


Next Post

In the next post, I will write about rtl option


Comments

popular posts in this blog

Project Stage 2 - part 2 : Clone-Pruning Analysis Pass

Project Stage 2 part 4 - Testing clone-test-core.c file with Modified GCC file and making further modification

Project Stage 2 part 3 - Compile a program with revised GCC