Posts

Project - Stage 3: Tidy & Wrap

Image
 Project - Stage 3: Tidy & Wrap In Stage 2, I created a Pass that determines whether the function should be pruned or not by comparing the cloned function and the original function's basic block and Gimple code in each basic block. This works fine when there is only one cloned function. In Stage 3, I am going to cloned more than one function to see if it can apply to all the functions. My Pass is below: #include "config.h" #include "system.h" #include "coretypes.h" #include "tree.h" #include "tree-pass.h" #include "cgraph.h" #include "function.h" #include "basic-block.h" #include "gimple.h" #include "gimple-iterator.h" #include "gimple-pretty-print.h" #include "cfg.h" #include <string> #include <vector> #include <map> namespace{ const pass_data pass_data_project = { GIMPLE_PASS, /* type */ "pass_project", /* na...

Project - Stage 2: Clone-Pruning Analysis Pass

Image
Project - Stage 2: Clone-Pruning Analysis Pass In Stage 1 of the project, I learned how to develop a basic pass in GCC. However, I may need to refine my methods for accurately counting the number of basic blocks and GIMPLE statements. In Stage 2 of the project, I was required to modify my pass to determine if a function had been cloned and to make decisions about whether it should be pruned. Getting the testing code files First, I got the testing code files from /public/spo600-test-clone.tgz. To get the file, I used the following command to unpack the tar archive file. cd ~ ; tar xvf /public/spo600-test-clone.tgz Then, a folder named spo600 will appear in our home directory, which will contain the code to test. Identify functions that have been cloned In the test code, the Makefile is configured to instruct the compiler to generate a cloned version of the function scale_samples() . I attempted to identify the variant version of scale_samples using the following code. objdump -d c...

Lab 5 - 64-Bit Assembly Language - Challenge

Image
64-Bit Assembly Language In this post, I'll share a challenge I took on: writing a program in AArch64 assembly to generate and display the times tables from 1×1 to 12×12 in a specific format. Code with explanation comments: .text .globl _start _start: mov x20, 1 // set right operand x20 to 1 mov x21, 10 // load divisor 10 to x21 for calculating tens digit mov x24, 100 // load divisor 100 to x24 for calculating hundreds digit reset_left: mov x19, 1 // set left operand x19 to 1 loop: adr x3, buffer // load buffer address into x3 mov x4, x19 // copy left operand to x4 bl convert_2digits2ch // go to convert number to character function for left operand bl space // store space to buffer mov x4, 120 // ASCII 120 is 'x' strb w...

Project - Stage 1: Create a Basic GCC Pass

Image
Project - Stage 1: Create a Basic GCC Pass In this project stage 1, I am creating and adding a basic GCC pass into the GCC compiler. What is a pass? Based on my understanding, a pass is a set of operations or rules that transform the source code during compilation, optimizing it for better efficiency so that the compiler can convert the code into binary files. However, before diving into more complex passes that optimize the code, we need to first understand how to create a basic pass. To start, I will create a simple pass that performs the following operations: Iterates through the code being compiled Prints the name of every function being compiled Prints a count of the number of basic blocks in each function Prints a count of the number of GIMPLE statements in each function. Before Creating a pass We must ensure that we use a custom GCC build instead of the system's GCC to avoid causing errors in the system compiler, as we are conducting experiments. If you do not have a custom ...

Lab 5 - 64-Bit Assembly Language - x86_64

Image
 64-Bit Assembly Language In this post, I will be conducting the same experiments I did in the  aarch64  platform, but I will perform them on the x86_64 platform. Get code example The first step is to retrieve the code example from the server. The example is located in  /public/spo600-assembler-lab-examples.tgz , which is a compressed file. To extract the file and store it in the desired location, navigate to that location. For me, it's the home directory: cd ~ tar xvf /public/spo600-assembler-lab-examples.tgz After running the command, the files will be extracted to your current location. You will see a folder named  spo600. x86_64 platform Same as what I did inAarch64, w e have source code below that contains a loop, but the loop does not perform any actions. Now, I'm trying to modify the source code to make it print something. .text .globl _start min = 0 /* starting value for the loop index; **note that this is a symbol (constant)...