Wrapping Up Project : Stage 3

With the final stage of the SPO600 project, my journey into the GCC compiler comes to a close. This stage was all about tying up loose ends from Stage 2, testing the Clone-Pruning Analysis Pass, and reflecting on what I’ve learned throughout the project.


Progress Overview

The focus of Stage 3 was to finalize the work I started in Stage 2. Building on my earlier implementation, I managed to create a pass that iterates through functions, analyzes their GIMPLE representations, and outputs information to a dump file. Here's what my custom GCC pass can now do:

  1. Print Function Names: The pass successfully identifies and prints the names of all functions.
  2. Output GIMPLE Statements: It iterates through the GIMPLE representation of each function, printing the statements to the dump file.
  3. Count Statements: The pass tracks and stores the number of GIMPLE statements for each function.

A snippet of my pass code from tree-ctyler.cc demonstrates the approach:

unsigned int pass_ctyler::execute(function *fn) {

    struct cgraph_node *node;

    int func_cnt = 0;

    int *stmt_counts = (int *)xmalloc(30 * sizeof(int));


    FOR_EACH_FUNCTION(node) {

        int stmt_cnt = 0;

        if (dump_file) {

            fprintf(dump_file, "Function Name === %s\n", node->name());

            // Additional logic for iterating through GIMPLE statements

            stmt_counts[func_cnt] = stmt_cnt;

            fprintf(dump_file, "Statement Count: %d \n", stmt_cnt);

            func_cnt++;

        }

    }

    // Output statement counts for each function

    for (int i = 0; i < func_cnt; i++) {

        fprintf(dump_file, "Function %d: %d statements\n", i + 1, stmt_counts[i]);

    }

    free(stmt_counts);

    return 0;

}


Testing the Pass

To verify my pass, I used the test programs provided in the SPO600 servers, such as clone-test-aarch64-prune. Running these tests generated multiple dump files, including detailed GIMPLE representations for each function. Here’s a sample of the output:

Function Name = scale_samples
Statement Count: 19
Function Name = scale_samples.arch_x86_64_v3
Statement Count: 19
Function Name = main
Statement Count: 10

Challenges and Reflections

Some of the key challenges I faced during this project include:

  • Debugging Massive Codebases: Navigating the enormous GCC codebase was tiring. Understanding the structures of nodes, functions, and basic blocks required patience and persistence.
  • Inconsistent Documentation: GCC’s documentation often lacked clarity, especially for pass development. This made learning about passes and debugging much harder.

Despite these challenges, I gained valuable skills and insights on:

  • Compiler Fundamentals: Before this course, I couldn’t have imagined modifying a compiler like GCC. Now, I understand the basics of its structure and how passes work.
  • Problem-Solving in Large Systems: Tackling issues in a large and complex project helped improve my debugging and critical-thinking skills.






Comments

Popular posts from this blog

Building GCC Part 2