Reputation: 1281
I would like to define a set of optimization sequences to an input C program in order to study the impact of my applied sequences to code performance.
example:
gcc -fauto-inc-dec -fbranch-count-reg -fcombine-stack-adjustments ... test.c -o out.o
Does the order of these options affect the effectiveness of the produced code?
As well, applying an optimization option twice does have an impact?
Is there a better way to test thousands of optimization sequences? Like in -02 (that includes around 20 options), I would like to define my own flags
Upvotes: 11
Views: 5147
Reputation: 5843
Does the order of these options affect the effectiveness of the produced code?
Is there a better way to test thousands of optimization sequences?
Higher optimization levels perform more global transformations on the program and apply more expensive analysis algorithms in order to generate faster and more compact code. The price in compilation time, and the resulting improvement in execution time, both depend on the particular application and the hardware environment. You should experiment to find the best level for your application. Please refer to Optimization Levels for GCC
I would like to define my own flags
Currently, gcc supports many flags which you can refer in Optimize Options. If you would like to define a flag, then the compiler needs to understand that and you might need to modify compiler code for gcc so that it can understand a new flag. Please refer to code on github, opts.c, opts.c deals with optimization flags and levels.
As well, applying an optimization option twice does have an impact?
gcc -fauto-inc-dec -fauto-inc-dec test.c
would have the same impact as Executing gcc -fauto-inc-dec test.c
.(Adding from comments regarding additional optimization passes - You can write a gcc optimization plugin to make additional passes. Please refer to this article: An introduction to creating GCC plugins. The article helps to create plugin to do additional optimization pass, transforming code, or analyzing information.)
Upvotes: 7