Abstract:Modern compilers typically come equipped with hundreds of program optimization strategies. These strategies are controlled by optimization options and can be enabled or disabled during the compilation process, in order to enhance the performance of the generated binary code. However, not all optimization options can produce positive effects in specific programs. Instead, interactions between different optimization options may lead to unpredictable outcomes. Given the complexity of optimization options and the difficulty of manual selection in modern compilers, this study focuses on the selection problem of compiler optimization. We conduct an in-depth analysis of classic compiler autotuning algorithms, including genetic algorithms, Bayesian optimization, and reinforcement learning. Based on this analysis, we propose an compiler autotuning system specifically designed for the RISC-V architecture. The system takes the popular GCC compiler and typical benchmark programs Coremark and Dhrystone as the experimental platform. On the K230 development board equipped with a RISC-V processor, it obtains the correspondence between optimization options and program performance by actually running the program, and then automatically searches for the best optimization combination by using supervised or unsupervised learning methods. Experimental results show that the proposed compiler autotuning technology achieves significant performance improvements on the RISC-V architecture. Compared to the compiler"s default O2 or O3 optimization combinations, this technology delivers a 10.7% to 16.2% improvement in program execution performance on Coremark and a 200% improvement on Dhrystone.