Posts

Project Stage 3 - Tidy up

Image
 Unfortunately I have been unable to complete this section of the project as I have wanted. During the compiling of my new code I came across so many errors and was tinkering around in files outside of the four provided in the sample  gcc/passes.def gcc/Makefile.in gcc/tree-ctyler.cc gcc/tree-pass.h I ended up getting some very wonky errors that I don't quite understand and couldn't find reliable resources on the internet to help me out. Below is an example of one: From what I could make of this bug out of many that I tried to wrestle away there was some sort of error in the gcc pass_manager.h where it is missing specific declarations for files, I was left very confused as some of these files I did not even interact with.  Below is what my final attempt at creating a somewhat resemblance of a GCC pass that prunes functions: #include "config.h" #include "system.h" #include "coretypes.h" #include "tree.h" #include "tree-pass.h" #i...

Project Stage 2: Testing

Image
 To test my custom pass I first extracted the spo600-test-clone files into my gcc-test-001 directory and simply compiled and ran the program with -fdump-tree-ctyler. I ran it on the vol1.c file, the contents of vol1.c are as following: [dpark39@aarch64-002 test-clone]$ cat vol1.c // vol1.c - fixed-point volume scaling algorithm // Chris Tyler 2017.11.29-2021.11.16 - Licensed under GPLv3. // For the Seneca College SPO600 Course #include <stdlib.h> #include <stdio.h> #include <stdint.h> #include <stdbool.h> #include "vol.h" int16_t scale_sample(int16_t sample, int volume) {         return ((((int32_t) sample) * ((int32_t) (32767 * volume / 100) <<1) ) >> 16); } int main() {         int             x;         int             ttl=0; // ---- Create in[] and out[] arrays         int16_t*    ...

Project Stage 2: Custom Implementation

For this stage of the project I had to implement my own custom GCC pass to iterate through the code in the program that was being compiled. Below is my code. #include "config.h" #include "system.h" #include "coretypes.h" #include "tree.h" #include "tree-pass.h" #include "context.h" #include "function.h" #include "basic-block.h"   #include "cfg.h"           #include "gimple.h"       #include "gimple-iterator.h" #include "gimple-pretty-print.h" namespace {     const pass_data pass_data_ctyler = {         GIMPLE_PASS,       // Type         "ctyler",          // Name         OPTGROUP_NONE,     // Option group         TV_NONE,           // TV identifier         PROP_cfg,          // Properties required   ...

Project Stage 2-1

Image
 With the successful build of GCC from my previous blog, we can now move on to the next step in this project which is to add our own custom GCC compiler pass that will analyze a program during its compilation and identify cloned functions, and determine if they are similar or different. It will also create messages determining if the clones should be pruned or retained. This is a very big portion of the AFMV feature for GCC.  In this blog post I will discuss how I extracted the demo files provided by my professor and used it to create dumps and analyze a simple testing program. First, my home directory is divided into three main directories consisting of 1.GCC     The source code for my GCC compiler. It contains the newly extracted source files from the sample tarball. 2.  GCC-build-001     This is the build directory for GCC, this is where I use my make command to build GCC after configuration. 3. GCC-test-001     Installation for the custom...

Building GCC again on aarch64-002

 Unfortunately the server I used to build gcc originally was aarch64-003 but that was shut down so I have to go through the process again on 002. The build time on the aarch64-002 server took 1 hour and 55 minutes approximately, I initially used time in my build command but I accidentally missed the information so I had to use stat build.log and find the duration of the build time by subtracting the final modification from the birth of the build.log file. Access: 2024-11-29 14:20:41.788188929 -0500 Modify: 2024-11-29 13:53:09.328736193 -0500 Change: 2024-11-29 13:53:09.328736193 -0500  Birth: 2024-11-29 11:57:40.960613010 -0500

Generating dumps with example.c

Image
 I created a quick "Example.c" program to test out gcc file dumps.  This program is very simple and takes two integers and returns the result, in this case the main function has 2 and 3 as arguments and will return 5.  In this part of the project, I worked on generating and analyzing GCC dump files for a small C program to gain insight into the different stages of code transformation and optimization within the compiler. The process involved using the -fdump-tree-all option, which produces detailed output files at various stages, each reflecting a unique part of the compilation pipeline. Starting with a simple example.c file containing an add function and a main function, I ran GCC with -fdump-tree-all. This command generated a series of dump files named with suffixes like .original, .gimple, .cfg, and .optimized. Each of these files represents a part of the program as it progresses through the compiler's internal stages, from raw code to fully optimized machine-read...

Early stages of project

 I initially set up and built the current version of GCC on the aarch64-3 server that is provided. I started the build and it took at least an hour to fully compile. I limited the enabled languages to strictly C and C++ as I am most comfortable in these languages and to reduce the complexity of the project. The two files that control compilation passes are passes.cc, and tree-pass.h /* Description of GIMPLE pass.  */ class gimple_opt_pass : public opt_pass { protected:   gimple_opt_pass (const pass_data& data, gcc::context *ctxt)     : opt_pass (data, ctxt)   {   } }; /* Description of RTL pass.  */ class rtl_opt_pass : public opt_pass { protected:   rtl_opt_pass (const pass_data& data, gcc::context *ctxt)     : opt_pass (data, ctxt)   {   } } I did some reading and research on gimple passes and learned that they help optimize code and makes transformation at a high level before going to lower representations.