Clang在发出LLVM IR时向所有函数添加noinline属性
Clang adds noinline attribute to all functions when emitting LLVM IR
考虑以下简单函数:
int foo() { return 42; }
通过clang -emit-llvm -S foo.cpp
将其编译为 LLVM 会生成以下模块:
; ModuleID = 'foo.cpp'
source_filename = "foo.cpp"
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.13.0"
; Function Attrs: noinline nounwind ssp uwtable
define i32 @_Z3foov() #0 {
ret i32 42
}
attributes #0 = { noinline nounwind ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+fxsr,+mmx,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
!llvm.module.flags = !{!0}
!llvm.ident = !{!1}
!0 = !{i32 1, !"PIC Level", i32 2}
!1 = !{!"Apple LLVM version 9.0.0 (clang-900.0.37)"}
为什么foo
函数声明为 noinline
?如果指定了优化级别(-O0
除外),则不会添加该标志,但我想避免这种情况。
有没有另一种方式/标志?
使用 -O0,从 Clang 的源代码来看,您无法全局启用内联( FrontendCompilerInvocation.cpp
):
// At O0 we want to fully disable inlining outside of cases marked with
// 'alwaysinline' that are required for correctness.
Opts.setInlining((Opts.OptimizationLevel == 0)
? CodeGenOptions::OnlyAlwaysInlining
: CodeGenOptions::NormalInlining);
根据您的要求,您可以:
- 使用
-O1
,这是最接近-O0
的。
将 -O1
与禁用它启用的优化标志结合使用。有关启用-O1
的优化标志,请参阅以下答案:Clang 优化级别
有- 选择地
always_inline
应用于应内联的函数。
例如:int __attribute__((always_inline)) foo() { return 42; }
相关文章:
- 如何仅为一个函数添加延迟
- 如何将带有参数的愚蠢函数添加到愚蠢的执行器中?
- "Missing type specifier - int assumed"无法通过向主函数添加"return 0"来解决
- C++泛型包装类,它为某些函数添加了额外的处理
- 将自己的函数添加到 ifstream
- 如何调用运算符函数添加两个对象?
- 如何在保持多态性的同时,将成员函数添加到需要它的继承类中,而不会影响其他同级类?
- Clang在发出LLVM IR时向所有函数添加noinline属性
- 将构造函数添加到boost.python子类导致参数不匹配错误
- 我需要为返回容器副本的函数添加锁吗
- 是否可以执行范围添加更新,将线性函数添加到最大分段树中
- 将第一个虚拟函数添加到类中
- 如何告诉编译器向编译的每个函数添加一个函数调用
- Doxygen没有为函数添加文档
- 在C++中为纯虚拟/抽象函数添加主体
- 如何在不重写 lib 类的情况下将函数添加到它
- ATL COM将函数添加到excel中
- 向成员函数添加常量限定符
- 向简单日志记录函数添加线程安全性
- 将函数添加到单独文件的正确方式