SPO600 2025 Winter Project - Stage 1: Feedback Response & Additional Evidence (part3)

 Introduction

I received feedback on my Stage 1 post and would like to provide further evidence and reflections to address the missing components.


Evidence of GIMPLE Code Iteration

After reviewing the feedback from Stage 1, I realized that my initial blog post did not clearly demonstrate that my GCC pass was successfully analyzing GIMPLE code and printing out relevant function-level information (such as function name, basic block count, and GIMPLE statement count). To address this, I made the following updates and ran tests to verify the pass behavior.


In the `execute()` function of my custom GIMPLE pass, I originally printed the analysis results only to the `dump_file`. However, this did not show up in standard output, which likely caused the evidence to appear missing.


To resolve this, I added the following lines to also print the information directly to the console using `printf()`:

const char* fname = function_name(fun);

printf("Function: %s\n", fname);

printf("Basic blocks: %d\n", bb_count);

printf("GIMPLE statements: %d\n\n", gimple_stmt_count);

This ensured that every time a function is analyzed by the pass, its name, the number of basic blocks, and the number of GIMPLE statements are clearly displayed in the terminal.


Testing The Pass

To verify that my pass works correctly, I created a simple C file (test.c) with two functions:

int foo(int a) { return a * 2; }


int main() {

    int x = foo(5);

    return x;

}


I compiled the file using the xgcc binary from my build:

cd ~/gcc-build-001/gcc

./xgcc -B. ~/test.c -O2


Output

The compilation produced the following output in the terminal:








This confirms that my pass is functioning as expected and provides the required information directly in standard output.



Dump File Output

To further address the feedback, I verified that my custom pass correctly generates a dump file using the `-fdump-tree-skim` option.


I compiled the same test file as before, this time with the `-fdump-tree-skim` flag:

./xgcc -B. ~/test.c -O2 -fdump-tree-skim


This produced a file named test.c.012t.skim in the working directory. The number prefix may vary depending on the exact pass order, but the .skim extension matches the name of my custom pass.







Even though the output shown in the dump file is nearly identical to the console output, it is written via a different mechanism. The dump file confirms that the pass was properly registered in the GCC pass manager and executed as expected.



Capabilities and Limitations of My Code

 Capabilities

- My pass successfully iterates over all functions in the source file during the GIMPLE pass stage.

- For each function, it counts:

- The number of basic blocks (BBs).

- The number of GIMPLE statements within each basic block.

- It prints this information both to standard output (console) and to the `dump_file` if enabled.

- The pass is safe and does not modify the GIMPLE IR in any way, making it suitable for analysis-only purposes.


 Limitations

- Currently, the pass does not handle inlined functions or externally defined functions that may appear during optimization.

- The GIMPLE statement count can vary depending on the optimization level (e.g., `-O0` vs. `-O2`), so results are not always directly comparable across builds.

- While the pass writes to `dump_file`, locating the generated `.skim` file in the build environment proved difficult, so I used standard output as the primary evidence.

- The pass currently provides only basic metrics (function name, BB count, GIMPLE count). It does not perform deeper analysis (e.g., control flow, data dependencies) yet.


Reflection

Working on this project has been a great opportunity to better understand how GCC plugins work, especially at the GIMPLE level. Before this, I had very limited exposure to compiler internals, so navigating through the structure of GCC and figuring out how to insert and test a custom pass was both challenging and educational.

One of the biggest challenges I faced was troubleshooting why my pass did not appear to generate any output at first. Although the pass was executing, the output was being written only to the `dump_file`, and I had overlooked the importance of printing to standard output. This led to confusion in my Stage 1 submission, and I now understand the importance of providing clear, visible evidence of a pass's functionality.

I also struggled with identifying whether my pass was correctly registered for dump file generation. In the end, I decided to focus on console output as the primary way to demonstrate the results of my analysis, which aligns with the feedback I received.


From this experience, I’ve learned:

- How to implement and register a GIMPLE pass in GCC.

- How to count basic blocks and GIMPLE statements.

- The importance of user-facing output when demonstrating technical functionality.

- That small oversights (like missing `printf`) can lead to major misunderstandings in documentation.


Overall, this stage helped me gain hands-on experience with compiler analysis and better prepared me for more complex pass development in the upcoming stages.


Comments

Popular posts from this blog

SPO600 2025 Winter Project - Stage 1: Create a Basic GCC Pass (part1)

SPO600 2025 Winter Project - Stage 2: GIMPLE Level Clone Analysis and Pruning (part4)

Lab 1 - 6502 Assembly Language