2017-10-17 3 views
0

次の簡単な関数で考えてみましょう:クランは、すべての機能にNOINLINE属性を追加します

; 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機能である:

int foo() { return 42; } 

clang -emit-llvm -S foo.cpp経由LLVMにこれをコンパイルするには、以下のモジュールを生成noinlineと宣言しましたか?最適化レベル(-O0以外)が指定されている場合、フラグは追加されませんが、それを避けたいと思います。

別の方法/フラグはありますか? -O0で

+0

は(デバッグ可能にする必要がある)最適化されていないビルドのために、関数がインライン化されていない、と私には理にかなっています。それ以外の理由はどうしてですか? –

+0

私は外部ツールを使ってそれをさらに変更/解析したいので(最適化されないようにする必要がありますが)、変更されたモジュールを後で 'opt'に渡して最適化したいと思っています... – jfrohnhofen

答えて

0

、あなたはクランのソースコード (Frontend\CompilerInvocation.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 optimization levels
  • always_inline属性をインライン化する関数に選択的に適用します。たとえば
    int __attribute__((always_inline)) foo() { return 42; }
関連する問題