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 built GCC, I will use this to test my pass. (fdump-tree-ctyler)
The first step in implementing the demo passes was to copy and extract the sample tarball into my GCC source directory.
cp ~/spo600-gcc-pass-demo.tgz . - copies tarball into working directory
tar xvf spo600-gcc-pass-demo.tgz - extracts the archive
The make sure the files were correctly in place, I simply use vim editor to search for "ctyler" inside the files. Simply using /ctyler within vim for the following files insured that the correct changes were made.
1. passes.def
This file will determine the list of analysis and optimization passes used by GCC, ctyler is added in towards the end of the list.
2. tree-pass.h
These are header files that will declare all of the analysis and optimization passes used by GCC, this file holds the definition for all passes and functions.
3. tree-ctyler.cc
I tried my best to understand this pass and I believe that the gist of it is that for every function in the code it will count the number of blocks, and statements inside these blocks, and will print the count and information about these.
4. Makefile.in
This is located in the root of the GCC subdirectory and defines how GCC is compiled, it will list all source and object files including tree-ctyler.o
Rebuilding GCC with these new passes took some time, around 30 minutes. Unfortunately I did not use the -time to actually measure it but it was approximately 30 minutes.
Using a very simple testing program, called test.c I compiled it and used the fdump-tree-ctyler command to generate the output with the sample pass. A very simple hello world program that we built on the first day of classes was all I required to test the ctyler pass.
Running this command on my test.c file resulted in the generation of a file called test.c.263t.ctyler:
As expected of my analysis of the tree-ctyler.cc, the pass counts the basic blocks and statements within the code and outputs how many there were. It also shows how GCC can track memory through VDEF and VUSE. The MEM statements represent the memory state during the program, I believe this tracking of memory by GCC can be used so to optimize a functions memory and get rid of unused or redundant memory writes.
Next blog post I will discuss my own changes, improve and extend the functions of tree-ctyler.cc
Comments
Post a Comment