Project Stage 2: Clone-Pruning Analysis Pass
Project Stage 2
In Stage 2 of my project, the goal was to create a pass for the GCC compiler that would analyze the program and identify cloned functions. It would then compare these cloned functions to check if they are very similar, and decide whether they should be removed (pruned) or kept. The decision would be shown in the GCC diagnostic dump as either "PRUNE" or "NOPRUNE."
Step 1: Creating the Dummy Pass
I started by creating a simple dummy pass that would only output basic messages. This was to make sure everything was working properly before I added more complex logic.
Step 2: Iterating Through the Program Code
Once the dummy pass was working, I moved on to the next step. This involved writing logic to go through the functions in the program being compiled. GCC uses an intermediate representation called GIMPLE, and I used this to read through and prepare the functions for the next steps.
Step 3: Identifying Cloned Functions
In this step, I added the logic to find cloned functions. For simplicity, I assumed there was only one cloned function in the program, with two versions of it. This helped keep things manageable.
Step 4: Comparing the GIMPLE Representations
Next, I needed to compare the GIMPLE representations of the cloned functions to see if they were the same or different. This is where I faced a lot of difficulty. I spent several hours trying to compare the functions but ran into errors. The issue was that even small differences, like temporary variable names or labels, were making it hard to tell if the functions were truly the same. I tried a few different methods, but I couldn’t fix the issues in time.
Step 5: Deciding to Prune or Not
Once I could compare the functions properly, I planned to have the pass output "PRUNE" if the functions were the same or "NOPRUNE" if they were different. But since I couldn’t solve the comparison problems, I couldn’t complete this step.
Step 6: Positioning the Pass in the GCC Pipeline
It was also important to make sure that the pass ran late in the compilation process, after optimizations like vectorization. This would ensure that the program was fully optimized before my analysis started. But again, I couldn’t test this due to the errors.
Errors Encountered
I faced several issues that stopped me from moving forward:
Compilation Errors: I had problems integrating the pass with the rest of the GCC code. This was probably due to misconfigurations or conflicts with other parts of GCC.
GIMPLE Comparison Issues: The biggest challenge was comparing the GIMPLE representations of the cloned functions. Even small differences, like different temporary variable names, caused errors, and I couldn’t figure out how to handle them in time.
Because of these issues, I couldn’t finish the pass or fully test whether the functions should be pruned or not. This made it hard to progress further.
Conclusion and Next Steps
Even though I couldn’t complete this stage, I learned a lot about the process of creating a GCC pass. Moving forward, I plan to:
- Fix the problems with comparing GIMPLE representations and figure out how to ignore small differences.
- Make sure the pass works properly in the GCC build process, on both x86_64 and AArch64 systems.
- Test everything once the issues are fixed to ensure the pass works as expected.
This stage was challenging, but it gave me valuable experience in understanding how compilers work. I’m looking forward to resolving the issues and continuing with the project.
Comments
Post a Comment