简体   繁体   English

GCC优化标志的顺序

[英]Order of GCC optimization flags

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. 我想为输入C程序定义一组优化序列,以研究我应用的序列对代码性能的影响。

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 就像-02(包括大约20个选项)一样,我想定义自己的标志

  • Does the order of these options affect the effectiveness of the produced code? 这些选项的顺序是否会影响生成代码的有效性?

    • No , the order of these options passed as command line arguments to the compiler does not affect the effectiveness of the produced code. ,这些选项作为命令行参数传递给编译器的顺序不会影响生成的代码的有效性。
  • Is there a better way to test thousands of optimization sequences? 有没有更好的方法来测试数千个优化序列?

    • Since we don't have a optimization sequence wrt the optimization flags being passed to the compiler, we don't have a way to test. 由于我们没有将优化标志传递给编译器的优化序列,因此我们没有办法进行测试。 But, as you are aware, we have optimization levels which you can experiment with. 但是,正如您所知,我们有优化级别,您可以尝试。
  • 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 请参阅GCC的优化级别

  • I would like to define my own flags 我想定义自己的旗帜

  • Currently, gcc supports many flags which you can refer in Optimize Options . 目前,gcc支持许多标志,您可以在优化选项中参考这些标志。 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. 如果你想定义一个标志,那么编译器需要理解它,你可能需要修改gcc的编译器代码,以便它可以理解一个新的标志。 Please refer to code on github, opts.c , opts.c deals with optimization flags and levels. 请参阅github上的代码, opts.c ,opts.c处理优化标志和级别。

  • As well, applying an optimization option twice does have an impact? 同样,两次应用优化选项会产生影响吗?

    • No, applying same optimization option twice will not have impact. 不,两次应用相同的优化选项不会产生影响。 For example: Executing gcc -fauto-inc-dec -fauto-inc-dec test.c would have the same impact as Executing gcc -fauto-inc-dec test.c . 例如:执行gcc -fauto-inc-dec -fauto-inc-dec test.c与执行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.) 添加有关其他优化过程的注释 - 您可以编写一个gcc优化插件来进行额外的传递。请参阅这篇文章: 创建GCC插件的介绍 。本文有助于创建插件以执行其他优化传递,转换代码或分析信息。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM