Posts

Showing posts with the label SPO600

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

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

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

Image
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 What is dump files? A dump file is essentially a snapshot of the internal data or transformations at a particular stage of the compiler's processing of a .c file. Let's take a look at what exactly is happing when you comiple a '.c file' 1. Input (.c file):   - You provide the .c file (your source code) to the compiler. 2. Compilation Stages:     -  The compiler goes through multiple stages, including parsing, syntax tree generation, optimizations, and code generation.     -  At each of these stages, the compiler might apply different transformations to make the code faster, smaller, or more efficient. 3. Dump Files:  - With specific flags (like -fdump-tree-all), you tell the compiler to save the output after each stage in a dump file.  - These dump files contain...

Project Stage 2 - part 1 : Navigating the GCC codebase

Image
Intro In this post, I will write about the progress of navigating the GCC codebase and what I learned from it. Progress I just started to go into folders and looked into the folders and the files. Sometimes I checked Docs . However, I had no idea of where I should look and what files are important. I hope I can get familiar with GCC and figure out where I should pay attention. The followings are what I thought are important while wondering around the gcc folders.  Executable files It looks like bin folder contains the executable files of GCC compiler. Passes I was wondering around the gcc-test-001 folder and found plugin/include folder, and The file passes.def looks like it controlls the compilation passes. C++ files  I also found a folder that contains c++ related files. It contains library files such as fstream and ostream. I checked the ostream file, and it looks like it contains the code for printing out as follows: As the post is getting too long, I will continue wr...

Project Stage 1 - Building GCC Compiler on aarch64 server

Image
Intro This series of Project Stage X is about the Project for SPO600 course at Seneca College. In this post, I will describe Process of Building GCC Compiler on aarch64 server I refered to the instruction on Wiki 1. Access the server using the following command ssh username@aarch64-003.spo600.cdot.systems #arrch64 machine ssh username@x86-001.spo600.cdot.systems #arrch64 machine 2. Clone the GCC compiler from github ## currently in ~ directory mkdir project cd project git clone git://gcc.gnu.org/git/gcc.git 3. Congiure the build mkdir ~/project/gcc-build-001 cd ~/project/gcc-build-001 ~/project/gcc/configure --prefix=$HOME/project/gcc-test-001 4. Perform the build time make -j 24 |& tee build.log This took me 93 minutes and 40 seconds. 5. Install the build * Run the following command inside the gcc-build-001 directory make install 6. Add `PATH` to use the test gcc compiler(that we just built) as default. PATH=$HOME/project/gcc-test-001/bin:$PATH 7. Check which gcc ...

Lab 04

  Description This post is about Lab 04 assignment for SPO600 course at Seneca College. This week, the students are required to write assembly code that pritns numbers from 0 ~ 30, both in aarch64 and x86_64. Tasks - Task 1: Printing numbers from 0 to 9 in aarch64 assembly language. Link to Code: [Task 1]   - Task 2: Printing numbers from 00-30 Link to Code: [ task 2 ] - Task 3: Printing numbers from 0 - 30 suppressing leading zero. Link to Code: [ task 3 ] - Task 4: Repeat the tasks above in x86_64. -Link to Code: [ Task 1 in x86_64 ]  [ Task 2 in x86_64 ]  [ Task 3 in x86_64 ]    Reflection Assembly Language is alwasy difficult and grinding. aarch64 and x86_64 were also very challenging. However, I expected that these 64bit assembly languages are much tougher than 6502 assembly language. As a matter of fact, these were much easier. It's because I have many more registers. And also, I can use system call for printing things, instead of manually put bytes o...

Lab03

Description This post is about Lab 03 assignment for SPO600 course at Seneca College. In this lab, studetns are required to build a program with assembly language that works on 6502 simulator The detailed instruction is as follows: Your program must work in the  6502 Emulator You must output to the character screen as well as the graphics (bitmapped) screen. You must accept user input from the keyboard in some form. You must use some arithmetic/math instructions (to add, subtract, do bitwise operations, or rotate/shift) Work Progress I was brainstorming to think of interesting program, probably a simple game. Then, I decided to make a game similar to  pac man  that I played when I was a kid with really old video game player that connects to TV. I haven't thought about the name of the game. Maybe, pac-woman? How to play This game interacts with AWSD key on keyboard since I couldn't get arrow key input with ascii code. A: Move Left your ball W: Move Up S: Move Down D: Move ...