Project Stage 3
Introduction
My experiences working on the final assignment for my Software Portability and Optimization course are detailed in this post. Adding diagnostic output functionality to the Gnu Compiler Collection (GCC) was the project's main objective. Implementing a diagnostic output capability that could be enabled with particular command-line parameters was my given task. This post describes the difficulties I encountered, how I worked with the current codebase to merge my improvements, and my thoughts on the project.
Relevant Links
Integration
I explained how I implemented the diagnostic output feature in the previous post. In order to integrate this feature, it was essential to create a new test dump pass for diagnostic output and update the relevant GCC files.
To achieve this, I made the following changes:
Created
test-dump-pass.cc
:#include "config.h" #include "system.h" #include "coretypes.h" #include "tm.h" #include "tree.h" #include "tree-pass.h" #include "diagnostic-core.h" #include "context.h" #include "gimple-expr.h" #include "gimple-pretty-print.h" #include "function.h" #include "opts.h" #include "plugin.h" #include "cp/cp-tree.h" // Define a global array and counter for AFMV targets #define AFMV_MAX_ARRAY_SIZE 100 unsigned int afmv_cnt = 0; char* afmv_targets[AFMV_MAX_ARRAY_SIZE]; // Test dump pass implementation static unsigned int test_dump_execute(void) { if (afmv_cnt > 0) { for (unsigned int i = 0; i < afmv_cnt; i++) { inform(UNKNOWN_LOCATION, "AFMV target: %s", afmv_targets[i]); } } else { inform(UNKNOWN_LOCATION, "No AFMV targets specified."); } return 0; } namespace { const pass_data test_dump_pass_data = { GIMPLE_PASS, /* type */ "test_dump", /* name */ OPTGROUP_NONE, /* optinfo_flags */ TV_NONE, /* tv_id */ PROP_gimple_any, /* properties_required */ 0, /* properties_provided */ 0, /* properties_destroyed */ 0, /* todo_flags_start */ 0, /* todo_flags_finish */ }; struct pass_test_dump : gimple_opt_pass { pass_test_dump(gcc::context *ctxt) : gimple_opt_pass(test_dump_pass_data, ctxt) {} unsigned int execute(function *fun) override { return test_dump_execute(); } }; } gimple_opt_pass * make_pass_test_dump(gcc::context *ctxt) { return new pass_test_dump(ctxt); }
Updated
passes.def
to register the new test dump pass:NEXT_PASS(pass_test_dump);
Updated
Makefile.in
to include the new test dump pass:OBJS = test-dump-pass.o $(OBJS)
Error Investigation
I ran across a few problems during the integration process, most of which have to do with accessing the variables between various compilation units. My professor and I conducted some research and found that the linker was having problems finding the correct variables, which was the cause of the problem. I had to use a workaround to fix this, which entailed changing the condition to use the other branch's command-line macro instead of the variable that was creating the problem, but I was unable to fix every error that was appearing in gcc.
Limitations
There are a few limitations with the current implementation:
- Hard-coded Values: The code uses a limited set of hard-coded strings as acceptable targets instead of utilizing the existing target validation code.
- Workaround: The implementation relies on a workaround due to the issues encountered with accessing variables across compilation units.
../../gcc/gcc/analyzer/region-model.cc: In member function ‘std::unique_ptr<text_art::widget> ana::region_model::make_dump_widget(const text_art::dump_widget_info&) const’:
../../gcc/gcc/analyzer/region-model.cc:559:20: warning: redundant move in return statement [-Wredundant-move]
559 | return std::move (model_widget);
| ~~~~~~~~~~^~~~~~~~~~~~~~
../../gcc/gcc/analyzer/region-model.cc:559:20: note: remove ‘std::move’ call
make[2]: Leaving directory '/home/ahryhorzhevskyi/gcc-build-001/gcc'
make[1]: *** [Makefile:4704: all-gcc] Error 2
make[1]: Leaving directory '/home/ahryhorzhevskyi/gcc-build-001'
make: *** [Makefile:1065: all] Error 2
What Has Not Been Tested?
The code has not been tested with the actual function cloning and pruning features of GCC. It has only been tested using simple test programs to validate the diagnostic output functionality.
Reflections
Project Work
This project was rewarding and tough to work on. It was intimidating at first to navigate the GCC codebase and add a new feature, but as I got the hang of things, it was easier. I gained a lot of knowledge about the complexities of GCC's compilation process during the integration step, which required careful tweaks to assure compatibility with the current code.
The Course
The actual route was challenging, especially considering its shortened schedule. The professor was outstanding, and the material was interesting despite the difficulties. The chance to contribute to a major project like GCC was thrilling, and the experience has been beneficial in offering insights on software portability and optimization.
All things considered, I am pleased with the work I completed and the knowledge I learned from this course. Although the path was difficult, it was a worthwhile experience that has well-prepared me for my future aspirations in optimization and software development.
Комментарии
Отправить комментарий