Project Stage 3 - Tidy up

 Unfortunately I have been unable to complete this section of the project as I have wanted. During the compiling of my new code I came across so many errors and was tinkering around in files outside of the four provided in the sample 

gcc/passes.def

gcc/Makefile.in

gcc/tree-ctyler.cc

gcc/tree-pass.h

I ended up getting some very wonky errors that I don't quite understand and couldn't find reliable resources on the internet to help me out. Below is an example of one:


From what I could make of this bug out of many that I tried to wrestle away there was some sort of error in the gcc pass_manager.h where it is missing specific declarations for files, I was left very confused as some of these files I did not even interact with. 

Below is what my final attempt at creating a somewhat resemblance of a GCC pass that prunes functions:

#include "config.h"

#include "system.h"

#include "coretypes.h"

#include "tree.h"

#include "tree-pass.h"

#include "context.h"

#include "function.h"

#include "basic-block.h"

#include "cfg.h"

#include "gimple.h"

#include "gimple-iterator.h"

#include "gimple-pretty-print.h"


namespace {

    const pass_data pass_data_ctyler = {

        GIMPLE_PASS,      

        "ctyler",          

        OPTGROUP_NONE,     

        TV_NONE,          

        PROP_cfg,         

        0,                 

        0,             

        0,                

        0            

    };


    class pass_ctyler : public gimple_opt_pass {

    public:

        pass_ctyler(gcc::context *ctxt) : gimple_opt_pass(pass_data_ctyler, ctxt) {}


        bool gate(function *) override { return true; }


        unsigned int execute(function *fun) override {

            if (dump_file) {

                fprintf(dump_file, "Analyzing function: %s\n", IDENTIFIER_POINTER(DECL_NAME(fun->decl)));

            }

            basic_block bb;

            FOR_EACH_BB_FN(bb, fun) {

                gimple_stmt_iterator gsi = gsi_start_bb(bb);

                while (!gsi_end_p(gsi)) {

                    gsi_remove(&gsi, true); // Remove statement

                }

            }


            if (dump_file) {

                fprintf(dump_file, "PRUNED function: %s\n", IDENTIFIER_POINTER(DECL_NAME(fun->decl)));

            }


            return 0;

        }

    };

} // End anonymous namespace


gimple_opt_pass *make_pass_ctyler(gcc::context *ctxt) {

    return new pass_ctyler(ctxt);

}

The original GCC pass that I created in stage two only: 
1. Iterated over all of the basic blocks in a function.
2. Printed all gimple statements within each basic block to a dump file.
3. Printed a diagnostic message whether the name of the function it analyzed.
4. Does not change, or prune the actual function itself.


The INTENT of my new code was to iterate over all blocks and their gimple statements, and then remove the gimple statements. I could not implement the cloning logic to compare whether they should be pruned or not so I wanted to just remove for all cases as just a simple demonstration of the pruning function. The new pass would simply remove any code that it analyzed. However, something went terribly wrong throughout my testing and I went down a rabbit hole of changes that I couldn't change.

For future implementations I would have liked to actually manage to implement the functions where I could clone and determine whether a function should be removed or not. The easiest way to do this would be to use strcmp to compare function names to find if they are redundant or not. The next thing I would do is check whether two functions being compared have identical/very similar gimple statements. We could use simple for each methods to iterate through these and compare the two gimple statements and see if they are equal. Finally, if the strcmp and gimple comparisons result in being identical we could apply the pruning method to delete it and out put a simple log. 

Due to the amount of time it takes to rebuild GCC (2 hours approximately) I was unable to complete and compile my passes due to time constraints. My intent for this was to initially check to see if  my implementations of deleting and actually pruning the functions was correct, and then incrementally add the logic and functions to compare the clones. Below is a github link to my GCC passes of both stage two and half-way complete stage 3: https://github.com/GranDog123/SPO600/tree/main

In conclusion, this was the hardest class I have taken so far here at Seneca and was a very new environment for me. Not to mention that I had to touch up on my C++ programing and understand new statements and functions to implement from various header files. Being the first professional elective (I believe is what they're called) that I have taken this was a major difference from my previous classes. 




Comments

Popular posts from this blog

Early stages of project

Building GCC again on aarch64-002

Project Stage 2: Testing