Last week we saw how, I was able to make my own pass in a version of gcc and was able to get a dump of this file.
In that version, I was able to generate a hash for all functions where the cloned function have same hash. I was also able to print this hash in the dump if the dump flag was passed. However I was not able to able to compare these hashes with each other, I tried a bunch of things but nothing work. In this blog I will talk about the things I did to fix this, and see if I was able to solve this problem or not.
Note: you can find my changes I made in my fork of gcc here.
Comparing the hashes
Branch prune-hash contains my previous changes where the output file printed the hashes of the functions. I was unable to get the pass to compare the hash functions to determine weather this hash is copy of another hash or not. In other words, I was not able to share calculated hashes to all of the runs.
When we run this with the dump flag, we would see something like this.
For a noprune version - See how the hashes of the functions are different.
For a prune version - See how the highlighted hashes are the same indicated duplicate functions.
I made a new branch called prune-compare-hash where I experimented further to get the compare working. However, I was not able to get it to work, I ended up pushing all of my code to this branch. NOTE: the pass in this branch is not complete and the gcc build on this branch will result in errors. My idea was to create a static hash map that stores all the hashes and can be accesses in difference runs because of its static property.
Problem
- There is not enough/proper documentation for us to refer and make conclusive decisions.
- If someone is not familiar with the build process, they can end up spending a lot of time just trying to build the file. Also, Some errors are very cryptic, and I ended up restarting my build from scratch (2~ hours). So save this time, make sure you are not making any manual changes in the build folder and only using the make utility to interact with the build.
- Dont forget to use threads when building the compiler.
Next steps
All of the above work was done on x84, Perhaps the result could be different I were to use arch64. I would like to test this theory after this course and make sure I understand the underlying problem. With my current understanding, I am unable to pinpoint the main cause of the errors I am facing. Nor am I able to implement other solutions outside of the scope of my knowledge.
I would also like to go back maybe rethink my hashing algorithm which could be a root to my problem.
I did not get time to look in use dynamic memory allocation, This might very well be a dead end but I would still like to give this a try in the future.
Reflection
I started with making lines and patterns on a small 6502 emulator. Then I ended up making a whole game on this small chip. I made a small version of assembly to print numbers from 1 to 30 (this task is more challenging than you think!). I ended up with making an actual change/contribution to my personal version of gcc!!! This is one the hardest course I did in my school yet somehow most rewarding. I now have a deeper knowledge of our code at lower level and optimization techniques that can be incorporated for best results. These techniques could be different based on what environment we are in. Even though my pass was not completely working, it was a great learning experience for me and expanded my perspective on how the compilers works.
Top comments (0)