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) { ...
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 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