Posts

Showing posts from March, 2025

SPO600 2025 Winter Project - Stage 2: Plan and Approach (part1)

Introduction In Stage 2 of the SPO600 project, the goal is to implement a GCC compiler pass that detects cloned functions generated through Function Multi-Versioning (FMV) and determines whether they can be pruned. This process involves analyzing GIMPLE Intermediate Representation (IR) to compare the structural and semantic equivalence of these functions. This blog post provides an overview of the project scope, technical strategy, tools used, and implementation phases, based on extensive lecture notes, in-class guidance, and project documentation. Project Objective Create a GIMPLE-level analysis pass that: 1. Identifies cloned functions  by their FMV naming conventions. 2. Extracts and compares GIMPLE representations  of these functions. 3. Outputs a pruning recommendation  based on structural equivalence. High-Level Workflow The project can be broken into three major parts: A. Find Cloned Functions - Functions created by FMV often have suffixes like `.resolver`, `.defau...

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

Image
  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(...

SPO600 2025 Winter Project - Stage 1: Trouble Shooting & Reflection (part2)

 Introduction In Part 1 , I explained in detail how to create a basic GCC pass , covering the steps to define, register, and integrate a custom pass into the GCC compilation pipeline. In this post, I will focus on the troubleshooting process —the challenges I encountered while implementing my custom pass, the debugging steps I took, and how I resolved each issue. I will also include some reflections on the process , highlighting key lessons learned and things I would do differently if I were to start over. Troubleshooting GCC Pass Implementation Issues 1️⃣ undefined reference to make_tree_skim(gcc::context*) Error  Issue: While building GCC, the following undefined reference error occurred: /usr/bin/ld: passes.o: in function gcc::pass_manager::pass_manager(gcc::context*): undefined reference to make_tree_skim(gcc::context*) Root Cause: • The make_tree_skim() function was defined, but the linker failed to reference it properly. • The tree-skim.o file was added to...

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

Image
 Project Overview The goal of this project is to extend the GCC compiler by adding a custom pass that can analyze the functions being compiled. A GCC pass is a stage in the compilation process that processes intermediate representations (IR) of the source code. These passes perform various optimizations and analyses before generating the final machine code. 📌 What Will This Custom Pass Do? In Stage 1 , I am implementing a GCC pass that: • Iterates through each function in the compiled code. • Prints the function name being analyzed. • Counts the number of basic blocks in the function. • Counts the number of GIMPLE statements inside each function. • Outputs this information to the console. By completing this stage, I will gain hands-on experience with GCC’s internal structures, intermediate representations like GIMPLE , and how to modify GCC’s compilation pipeline. Step 1: Setting Up the Environment 🔹 Note: I have already completed GCC setup ...