Table of Contents

SPO600 2025 Winter Project

Before Starting

Before starting this project, please perform Lab 4.

Project Stage I: Create a Basic GCC Pass

Create a pass for the current development version of the GCC compiler which:

  1. Iterates through the code being compiled;
  2. Prints the name of every function being compiled;
  3. Prints a count of the number of basic blocks in each function; and
  4. Prints a count of the number of gimple statements in each function.

Your code must build on both of the SPO600 Servers.

It is recommended that you proceed in steps:

It is recommended that you position your compiler pass late in the compilation/optimization process.

Resources

Recommendations for Building GCC

A reminder that the make utility will rebuild a codebase in as few steps as possible. It does this by comparing the timestamps of the dependencies (inputs) for each target (output) to determine which source (or other input files) have changed since the related targets were built, and then rebuilding only those targets.

This can effectively cut the build time for a complex project like GCC from hours to minutes. On my development system (a Ryzen 7735HS with 32 GB RAM), a null rebuild (no source changes - make is checking that everything is up-to-date) takes about 8.3 seconds, and a rebuild with edits to one pass source file take 23-30 seconds. On the SPO600 Servers the rebuild times are similar.

To take advantage of this capability, do an initial full build of GCC in a separate build directory as usual, then make whatever required edits to the source code in the source directory. Run make with appropriate options (including -j job values) in the build directory.

Remember to use screen (or a similar program such as tmux) when building on remote systems in case your network connection gets interrupted, and it's a good idea to time every build (prepend time to your make command) and redirect both stdout and stderr to a log file: time make … |& tee build.log if you also want to see the output on the terminal or time make … &> build.log if you don't want to see the output.

You can do your development work on either architecture, but remember to test your work on both architectures.

Submitting your Project Stage I

Blog about your process and results:

Due Date

Project Stage II: Clone-Pruning Analysis Pass

Create a pass for the GCC compiler which analyzes the program being compiled and:

  1. Identifies one or more functions which have been cloned. These functions will have the name function.variant where the function portion is the same, and there will be a corresponding resolver named function.resolver.
  2. Examines the cloned functions to determine if they are substantially the same or different. “Substantially the same” means that they are identical, with the possible exception of identifiers such as temporary and single static assignment (SSA) variable names, labels, and basic block numbers. For example, two cloned functions may have two different names for the first declared integer variable, but the corresponding variables will appear at exactly the same points in the two functions and are therefore equivalent.
  3. Emit a message in the GCC diagnostic dump for the pass that indicates if the functions should be pruned (in the case that they're substantially the same) or not pruned (if they are different). The diagnostic dump may contain other information.

It is recommended that you proceed in steps:

To limit complexity, you may make these assumptions:

However, if you choose to handle multiple cloned functions, or more than two clones, that would be a welcome enhancement!

It is important that you position your compiler pass late in the compilation/optimization process so that any significant optimizations, such as vectorization, are performed before your analysis. Ideally, it should be one of the last “tree” (gimple) passes performed.

Two possible approaches to this problem are (1) to iterate through the statements in each function, comparing them statement-by-statement; or (2) generating some type of hash or signature that uniquely identifies the implementation of the function and which can be compared to the hash/signature of a clone to see if they are different. In either case, you need to accomodate the variation in variable, label, and basic block names.

You must output one of these specific strings in your dump file per function, each on its own line, conditional on whether the cloned functions are the same (PRUNE) or different (NOPRUNE):

Where function is the original name of the function that should (or should not) be pruned, without the variant portion.

Your solution should build and execute successfully on both x86_64 and aarch64 systems, and should take into account the differences between the FMV implementations on those two architectures (for example, the munging algorithm used to create the suffixes for the cloned functions is different).

Test Cases for Pruning/No-Pruning

Each of the SPO600 Servers has a file /public/spo600-test-clone.tgz which is a tar archive containing code to build test cases on x86_64 or aarch64 systems. On each architecture, two binaries will be built, each containing one cloned function. Building these binaries with a copy of GCC that contains your analysis pass should result in a decision to prune (for the binary test-clone-arch-prune) or not to prune (for the binary test-clone-arch-noprune), where arch is either x86 or aarch64.

Refer to the README.txt file within the tgz file for more detail.

Your code must be able to correctly output PRUNE or NOPRUNE messages for the test programs on each platform.

Submitting your Project Stage II

Blog your results:

Due Date

Project Stage III: Tidy & Wrap

What was planned for Stage III

My original intention for Stage III was to provide a GCC codebase that included AFMV cloning – that is to say, every function would be cloned, without having to add the target_clones attribute to each function – that you could test against.

Here's the background: there are at least two ways that AFMV cloning can be implemented…

I attempted to use the first approach, incorporating some work started by a student in the summer of 2024. However, subsequent issues with this approach arose from the assumption built into the code code that information about the architectural variants should be available in the tree representation of the code (Gimple). This is not the case, leading to a segmentation fault (segfault) in the later portions of the AFMV processing, in the case where the compiler has determined that a function cannot be cloned due to a (pretty rare!) situation where there is a non-local goto statement. This exact situation occurs within the GCC code itself, which causes the normal bootstrap compilation to fail.

I spent a considerable effort to rectify this issue but was not able to do so in time to incorporate AFMV cloning into the codebase for Stage III of this semester's project; my current perspective is that the second approach outlined above is probably the cleaner way to tackle this issue.

Therefore, we're going to use Stage III to wrap up our project work with enhanced testing, without AFMV automatic cloning.

Requirements for Stage III

Submitting your Project Stage III

Blog your results:

Due Date