PROJECT STAGE3

 Introduction:

For Stage III, my goal is to further validate and demonstrate that my project can accurately process multiple cloned functions in a single program and make individual PRUNE/NOPRUNE recommendations for each one. In fact, my project has already supported this functionality since Stage II. To identify cloned functions, I extract the base function name from fun->decl, then iterate over all functions in the program using FOR_EACH_FUNCTION(node) while ensuring each has a valid name. I check if a function’s name starts with the base name and includes a dot (.) afterward, which typically signifies a clone. I also skip any functions containing .resolver in their name. Functions that meet these criteria are printed as cloned functions. This approach allows the detection of multiple clones, assuming they follow GCC’s naming conventions. To enable this analysis, DUMP_ALL must be set to 1 to activate all GCC dumps. For this stage, I will create test cases with at least two cloned functions per program and verify PRUNE/NOPRUNE decisions on both x86_64 and aarch64.


Create one test case that contains two cloned functions

In order to contain a minimum of two cloned functions,I added a new clone of the scale_samples function, named scale_samples_v2, in the clone-test-core.c file. Both functions are identical in operation, and I applied the CLONE_ATTRIBUTE macro to them. In the main function, I called both scale_samples and scale_samples_v2 with the same input and output buffers, enabling the test binary to detect both clones. This update supports testing the compiler's clone detection and pruning capabilities without modifying the Makefile.

Updated clone-test-core.c:Click here



Output:

Problem at this point:
The GIMPLE dump was showing strange output like '8' and '10' instead of the actual function logic. So, I decided to switch to -O0 and added -fno-inline to force the compiler to keep both functions intact. This allowed me to test whether my customized pass can find all clone functions with the same code and operand types.

Updated makefile:Click here
After running make clean followed by make, the output now correctly shows the expected GIMPLE codes instead of the strange 8 10 values:

Output:


Problem at this point:
When I disable all optimizations with -O0 and add those specific flags, I am essentially preventing GCC from making any meaningful transformations to the code, which results in identical GIMPLE representations even for functions that should be different in the "noprune" case.However, this also confirms that my function is correctly identifying all cloned functions that have identical GIMPLE code and operand types.


Problem fixed:
I wrote my own test case, and it works.
Updated Test Case:click here

For noprune result:

For prune result:


I have created a GitHub folder containing all the necessary and changed files to test my function,and my function works correctly on both architectures (x86_64 and aarch64)  Github Repo: https://github.com/ZiyangWangGit/SPO-PROJECT/tree/main/Stage3Final

Reflection:

In this stage, I focused on ensuring that my program could properly handle PRUNE/NOPRUNE decisions for cloned functions. I created test cases with cloned functions to test how well the program could detect and process them. I faced a challenge with compiler optimizations, which caused strange outputs in the GIMPLE dump. To fix this, I turned off optimizations and added flags to stop the compiler from changing the code. This allowed me to check if the program could correctly detect cloned functions. After making these changes, I confirmed that the function detection worked well, even with optimizations turned off. The PRUNE/NOPRUNE decisions were also accurate in my tests. The GitHub repository contains all the necessary files to test my approach. This part of the project showed me how important it is to account for compiler optimizations when testing functions and how to deal with issues that arise during testing. 


Comments

Popular posts from this blog

PROJECT STAGE2

PROJECT STAGE1

LAB 4