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); ...
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' =...
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...
Comments
Post a Comment