Posts

Project Stage III: Multi-Clone Analysis in GCC Pass

 Introduction In Stage III, I enhanced my GCC pass to analyze programs with multiple cloned functions simultaneously, making individual PRUNE/NOPRUNE decisions for each clone. This involved refining GIMPLE code comparisons, handling compiler optimization challenges, and validating results on both x86_64 and aarch64 architectures. Implementation Core Logic (Key Code Snippets) 1. Data Structure for Clones // Stores GIMPLE statements and operand types for each function struct GimpleStmtInfo { int code; std::vector<tree> operands; }; std::map<std::string, std::vector<GimpleStmtInfo>> function_map; 2. Clone Detection // Identify cloned functions by name (e.g., "func.clone1") if (func_name.find(base_name + ".") == 0 && func_name.find(".resolver") == std::string::npos) { // Compare GIMPLE sequences bool is_same = (base_gimple == cloned_gimple); fprintf(dump_file, "Result: %s\n", is...

Project Stage 2: Clone-Prune Analysis Pass Implementation

Introduction This project implements a GCC compiler pass to analyze cloned functions created during Function Multi-Versioning (FMV). The goal is to determine if clones are "substantially identical" to enable pruning. Below is my detailed implementation journey. Phase 1: Clone Detection & Retrieval Data Structure for Tracking Clones std::map<std::string, std::vector<std::string>> clone_map; // Key: Base name (e.g., "scale_samples") // Value: Variants (e.g., {"scale_samples.avx2", "scale_samples.sse4"}) Function Retrieval Logic void locate_clones(const std::map<std::string, std::vector<std::string>>& clone_map) { for (const auto& [base, variants] : clone_map) { if (variants.size() != 2) { fprintf(dump_file, "Invalid clone count for %s: %zu\n", base.c_str(), variants.size()); continue; } function *clone1 = nullptr, *clone2 = nul...

SPO600 2025 Winter Project: Stage 1 - Creating a Basic GCC Pass

Image
Project Overview In this project, I enhanced the GNU Compiler Collection (GCC) by adding a custom compiler pass to analyze functions during compilation. The pass performs three key tasks: Prints the name of every function being compiled. Counts the number of basic blocks in each function. Counts the number of GIMPLE statements within each basic block. This pass helps developers understand code structure and optimization impacts. Below, I detail my implementation journey, including challenges and solutions. Environment Setup To avoid conflicts with the system compiler, I used three isolated directories: Source Directory : ~/git/gcc (GCC source code). Build Directory : ~/gcc-build-001 (compilation artifacts). Install Directory : ~/gcc-test-001 (custom GCC installation). Why This Matters : Separating source, build, and install directories ensures a clean workflow and simplifies debugging. Step 1: Creating the Custom Pass File : tree_tpatel103_pass.cc I created a new file in gcc/gcc to hou...

Lab 5: Exploring Assembly Language on x86_64 and AArch64 Architectures

Introduction In this blog post, I’ll share my experience working with assembly language on both x86_64 and AArch64 architectures as part of the SPO600 lab. This lab was an eye-opening journey into the low-level world of programming, where I got to write, debug, and optimize assembly code. I’ll walk you through the steps I took, the challenges I faced, and my thoughts on working with different assembly languages. 1. Getting Started with the Lab The lab began with unpacking the provided archive containing example programs in both C and assembly language. The directory structure was well-organized, with separate folders for x86_64 and AArch64 assembly code, as well as portable C versions for comparison. Using the tar command, I extracted the archive and explored the files. The first step was to build and run the C versions of the "Hello World" program on both architectures. This helped me understand the differences in the generated binaries and the underlying system calls. Using...

Lab-4: GCC Build Lab - Building the GCC Compiler from Source

Introduction In this lab, I explored the process of building a large software project—specifically, the GCC (GNU Compiler Collection) compiler—from source code. GCC is a critical toolchain used for compiling programs in various programming languages, including C, C++, and Fortran. The goal of this lab was to understand the build process, use tools like make and autotools , and compare the performance of the build process on two different architectures: x86-001 (x86_64) and aarch64-002 (ARM64). This lab is part of the SPO600 course, where we study software portability and optimization. Lab Steps and Results 1. Obtaining and Building GCC I followed these steps to build GCC on both servers: Cloned the GCC source code: git clone git://gcc.gnu.org/git/gcc.git gcc-source Created a separate build directory and configured the build: mkdir gcc-build cd gcc-build ../gcc-source/configure --prefix=$HOME/gcc-install --disable-multilib Built GCC using make: time make -j 16 |& tee build.log In...

Lab-3 Creating a Number Guessing Game in 6502 Assembly

Image
Introduction For this lab, I decided to create a simple Number Guessing Game using the 6502 Emulator. The game generates a random number between 0 and 9, and the player has 3 attempts to guess the correct number. The program outputs instructions and feedback to the character screen and displays a visual representation of the game's progress on the bitmapped screen . This project was a great way to explore 6502 assembly language, including handling user input, performing arithmetic operations, and managing both text and graphical displays. Program Overview The program meets all the lab requirements: Output to Character Screen : Displays instructions, remaining guesses, and feedback (e.g., "Too high" or "Too low"). Output to Bitmapped Screen : Shows a visual representation of the game's progress, such as a smiley face for a win or a sad face for a loss. User Input : Accepts numeric input from the keyboard (0-9). Arithmetic/Math Instructions : Uses subtractio...

Lab 2 - 6502 Math Lab

Introduction In this blog post, I will share my experience working on the second lab of the SPO (Systems Programming and Operating Systems) course. The goal of this lab was to create a subroutine in 6502 Assembly Language that draws an image on a bitmapped screen and then animate it by making it bounce around the screen. The lab involved writing code to move a graphic diagonally across the screen and then modifying it to make the graphic bounce off the edges of the screen. The Code   The initial code provided draws a 5x5 pixel image (either an "O" or an "X") on the screen and moves it diagonally from the top-left corner to the bottom-right corner. The image is cleared and redrawn in a new position to create the illusion of movement. The code uses a delay loop to slow down the animation so that it is visible to the human eye. Here is the initial code: ; ; draw-image-subroutine.6502 ; ; This is a routine that can place an arbitrary ; rectangular image on to the scree...