GCC - 仅在特定功能上启用编译器标志 [英] GCC - Enable compiler flags only on specific functions

查看:132
本文介绍了GCC - 仅在特定功能上启用编译器标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在开发的一个项目中,我正试图优化一个大文件中的四重嵌套for循环,我认为这将从编译器展开到-funroll-all-loops中受益。但是,当我将此标志添加到编译器时,它会将其他循环展开到文件的其余部分,并使整个程序运行速度更慢。有没有一种方法(可能通过#pragma)将编译器标志仅应用于文件中的某些函数而不是整个文件?

In a project I'm working on, there's a quadruple-nested for loop in a large file I'm trying to optimize I think would benefit from a compiler unroll with -funroll-all-loops. However, when I add this flag to the compiler, it unrolls the other loops the rest of the file and makes the overall program run more slowly. Is there a way (possibly via a #pragma) to apply compiler flags only to certain functions in the file instead of the entire file?

预先感谢。

推荐答案

GCC 函数属性 optimize 可用于为单个函数设置优化选项:

The GCC function attribute optimize can be used to set an optimization option for a single function:

void foo(int bar) __attribute__((optimize ("unroll-all-loops")))
{
}

这篇关于GCC - 仅在特定功能上启用编译器标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆