Posts

Project Stage 3 - Tide & Wrap

  Intro This post will wrap up the project for SPO600 course. As a reminder; the goal of this project was to modify GCC Compiler to check if a cloned function can be pruned or not. However, I couldn't achieve the goal. Instead, I made a few small progresses. In this post, I will explain and wrap up the progresses that I made so far. Progress I made a few more changes from Stage 2. Actually this version is made by combining different versions of the pass implementations that I have made during this project. So it's not a huge progress: unsigned int pass_ctyler::execute(function *) { struct cgraph_node *node; int func_cnt = 0; int *stmt_counts = (int *)xmalloc(30 * sizeof(int)); FOR_EACH_FUNCTION(node) { int stmt_cnt = 0; if (dump_file) { if (node) { fprintf(dump_file, "Function Name === %s\n", node->name()); function *fn = node->get_fun(); if (fn) { ...

Project Stage 2 part 5 - Final

Intro  As I mentioned in the previous post, I realized that I was doing it in a wrong way. And I saw other students progress, based on that code. I made some modifications in the pass implementation. I was looking for coped functions and their gimple representations, but I already had it printed. What I actually had to do was comparing the two different verions of one function, and then compare them, and then make a decision of whether it should be pruned or not. Progress This is my modified code. unsigned int pass_ctyler::execute (function *fun) { basic_block bb; int bb_cnt = 0, stmt_cnt = 0; FOR_EACH_BB_FN (bb, fun) { bb_cnt++; if (dump_file) { fprintf (dump_file, "===== Basic block count: %d =====\n", bb_cnt); if (!fun || !fun->decl) { fprintf(dump_file, "Invalid function object.\n"); } else { // Print function name ...

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

Intro  In the previous post, we modified to make it print function names; Now, we are going to test it with given clone-test-core.c file and also we will try to make further changes to display more information such as cloned function and gimple representation. Progress First, I tested the provided code without making any modifications, and the results are as follows: ;; Function sum_sample (sum_sample, funcdef_no=6, decl_uid=3859, cgraph_uid=7, symbol_order=6) === Function 1 Name '__builtin_cpu_supports' === === Function 2 Name '__builtin_cpu_init' === === Function 3 Name 'scale_samples.resolver' === === Function 4 Name 'scale_samples' === === Function 5 Name 'scale_samples.popcnt' === === Function 6 Name 'printf' === === Function 7 Name 'vol_createsample' === === Function 8 Name 'calloc' === === Function 9 Name 'main' === === Function 10 Name 'scale_samples' === === Function 11 Name 'sum_sample' =...

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

  Intro In this post, we are going to use the GCC that we modified. Then, we will compile a code and see it generates a dump file by the pass we added. Progress 1. I will first test compiling my test program. Here is my simple C program. #include <stdio.h> int main() { int sum = 0; // For loop to add numbers from 1 to 5 for (int i = 1; i <= 5; i++) { sum += i; // Add i to sum // If statement to check if the number is even or odd if (i % 2 == 0) { printf("%d is even\n", i); } else { printf("%d is odd\n", i); } } printf("Sum of numbers from 1 to 5 is: %d\n", sum); return 0; } 2. I compiled the prgoram gcc -fdump-tree-all test.c -o test And this generated the following dump file as well as other dump files test.c.263t.ctyler 3. Check the content of the dump file. ===== Basic block count: 1 ===== ----- Statement count: 1 ----- sum_7 = 0; ----- Statement count...

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

Intro In Project Stage 2, we are going to add a Pass to gcc compiler. Then, we will compile a code and see it generates a dump file that we added a pass for. Progress Let's start with adding a Pass to GCC compiler.  1. Open passes.def file in ~/project/gcc/gcc folder vi passes.def 2. You will See the codes as followings. Then, add a pass NEXT_PASS (pass_ctyler);  in line 444 440 NEXT_PASS (pass_cleanup_eh); 441 NEXT_PASS (pass_musttail); 442 NEXT_PASS (pass_lower_resx); 443 NEXT_PASS (pass_nrv); 444 NEXT_PASS (pass_ctyler); # Add your pass here # If you change the location, the order of compilation is changed; and it might have problem. # Since `pass_ctyler` is similar to `pass_nrv` I think it's safe to put here 445 NEXT_PASS (pass_gimple_isel); 446 NEXT_PASS (pass_harden_conditional_branches); 447 NEXT_PASS (pass_harden_compares); 448 NEXT_PASS (pass_warn_access, /*early=*/false); ...

Project Stage 1 - `-fdump-tree-pass AND -fdump-rtl-pass`

Intro In this post, we will continue working on Project Stage 1. We are going to test the options `-fdump-tree-pass`and `-fdump-rtl-pass`. Progress I tried those commands in various ways; however, they didn't work. hshin41@aarch64-003:~/third_experiment$ gcc -fdump-tree-all -fdump-tree-pass test.c -o test cc1: error: unrecognized command-line option ‘-fdump-tree-pass’; did you mean ‘-fdump-tree-all’? // hshin41@aarch64-003:~/third_experiment$ gcc -fdump-tree-pass -fdump-rtl-all test.c - o test cc1: error: unrecognized command-line option ‘-fdump-tree-pass’; did you mean ‘-fdump-tree-all’? // hshin41@aarch64-003:~/third_experiment$ gcc -fdump-tree-pass -fdump-rtl-all test.c -o test cc1: error: unrecognized command-line option ‘-fdump-tree-pass’; did you mean ‘-fdump-tree-all’? // hshin41@aarch64-003:~/third_experiment$ gcc -fdump-tree-all -fdump-rtl-pass test.c -o test cc1: error: unrecognized command-line option ‘-fdump-rtl-pass’ // hshin41@aarch64-003:~/third_experiment$ gcc -fd...

Project Stage 1 - `-fdump-rtl-all`

Intro In the last post, we dicussed `-fdump-tree-all` option, and the files generated by the option. In this post, we will run a command `gcc -fdump-rtl-all test.c -o test` and will guess what's done. Progress Let's first start with `-fdump-tree-all` option. gcc -fdump-rtl-all test.c -o test The result will be: test test.c.271r.jump test.c.310r.mode_sw test.c.329r.jump2 test.c.359r.shorten test.c test.c.283r.reginfo test.c.311r.asmcons test.c.349r.zero_call_used_regs test.c.360r.nothrow test.c.268r.expand test.c.306r.outof_cfglayout test.c.318r.ira test.c.350r.alignments test.c.361r.dwarf2 test.c.269r.vregs test.c.307r.split1 test.c.319r.reload test.c.354r.barriers test.c.362r.final test.c.270r.into_cfglayout test.c.309r.dfinit test.c.326r.pro_and_epilogue test.c.356r.split5 ...