Project Stage 2 - (Preparation part)

Introduction

Today, I am going to delve into the GCC codebase to understand its behavior better. The objective is to create a proof-of-concept for automatic function multi-versioning (AFMV) as an optional tool via command-line arguments when compiling with GCC. This will involve isolating and building on specific parts of the codebase to implement a given subtask.

How GCC Compiles Code

First, let’s explore how GCC operates when compiling source code. A "pass" refers to a stage in the compilation process where the compiler processes the source code to understand and transform it for subsequent stages. Early passes typically involve parsing command-line options, while later passes check for syntactic correctness, perform optimizations, generate machine code for the target architecture, and finally, assemble and link the code.

Detailed Plan for Implementation

Reviewing Cloned Functions

Create an analysis pass that scans the program's symbol table to find functions that have been cloned multiple times. Maintain records of the original function and its clones.

Analyze & Comparison

For each cloned function, compare it to the original function from which it was cloned. Compare both the generated code and optimization metadata such as flags and attributes.

Pruning

If a cloned function lacks optimizations and its code is identical to the original, mark it for deletion. Remove these functions from the symbol table and eliminate their corresponding code.

Integration with Pass Manager

Incorporate this pass into the pass manager, specifying the order in which this pass should be executed.

Execution

Ensure that this pass is run during compilation when the appropriate flag is set, either through command-line options or an indicator that all functions have been marked for cloning.

Testing

Thoroughly test the newly created pass to verify that it accurately identifies and prunes cloned functions that have not been optimized.

Key Files in the GCC Codebase

To implement the above tasks, the following files in the GCC codebase are particularly important:

  • gcc/gcc.cc: The main function for GCC's execution.
  • gcc/pass_manager.h: Manages the optimization passes during compilation and retrieves input/output from each pass.
  • gcc/tree_pass.h: Ensures that passes are executed in the correct order.
  • gcc/passes.cc: Implements the coordination and execution of optimization passes during compilation.
  • gcc/passes.def: Contains information related to a pass, including its name, description, and category.
  • gcc/symtab.h and gcc/symtab.cc: Define and implement the symbol table that manages symbols, particularly useful for function symbols in our context.
  • ipa-fnsummary.cc: An IPA pass that collects information about functions. One significant product of this pass is the determination of function body size, which can indicate whether a function has been altered.

댓글

이 블로그의 인기 게시물

Project stage-3 (testing & reflection)

Understanding SIMD and SVE: Harnessing Parallelism for Enhanced Performance

Lab3 - AArch64