diff --git a/llvm/lib/ProfileData/SampleProf.cpp b/llvm/lib/ProfileData/SampleProf.cpp --- a/llvm/lib/ProfileData/SampleProf.cpp +++ b/llvm/lib/ProfileData/SampleProf.cpp @@ -16,6 +16,7 @@ #include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/PseudoProbe.h" #include "llvm/ProfileData/SampleProfReader.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Error.h" @@ -29,6 +30,11 @@ using namespace llvm; using namespace sampleprof; +static cl::opt ProfileSymbolListCutOff( + "profile-symbol-list-cutoff", cl::Hidden, cl::init(-1), cl::ZeroOrMore, + cl::desc("Cutoff value about how many symbols in profile symbol list " + "will be used. This is very useful for performance debugging")); + namespace llvm { namespace sampleprof { SampleProfileFormat FunctionSamples::Format; @@ -274,12 +280,14 @@ uint64_t ListSize) { const char *ListStart = reinterpret_cast(Data); uint64_t Size = 0; - while (Size < ListSize) { + uint64_t StrNum = 0; + while (Size < ListSize && StrNum < ProfileSymbolListCutOff) { StringRef Str(ListStart + Size); add(Str); Size += Str.size() + 1; + StrNum++; } - if (Size != ListSize) + if (Size != ListSize && StrNum != ProfileSymbolListCutOff) return sampleprof_error::malformed; return sampleprof_error::success; } diff --git a/llvm/test/Transforms/SampleProfile/Inputs/profile-symbol-list.text b/llvm/test/Transforms/SampleProfile/Inputs/profile-symbol-list.text --- a/llvm/test/Transforms/SampleProfile/Inputs/profile-symbol-list.text +++ b/llvm/test/Transforms/SampleProfile/Inputs/profile-symbol-list.text @@ -1,5 +1,6 @@ _Z3goov _Z3sumii +_Z3toov __libc_csu_fini __libc_csu_init _dl_relocate_static_pie diff --git a/llvm/test/Transforms/SampleProfile/profile-sample-accurate.ll b/llvm/test/Transforms/SampleProfile/profile-sample-accurate.ll --- a/llvm/test/Transforms/SampleProfile/profile-sample-accurate.ll +++ b/llvm/test/Transforms/SampleProfile/profile-sample-accurate.ll @@ -6,6 +6,8 @@ ; RUN: llvm-profdata merge -sample -extbinary -prof-sym-list=%S/Inputs/profile-symbol-list.text %S/Inputs/profsampleacc.extbinary.afdo -o %t.symlist.afdo ; RUN: opt < %s -sample-profile -sample-profile-file=%t.symlist.afdo -profile-summary-cutoff-hot=600000 -profile-accurate-for-symsinlist -enable-new-pm=0 -S | FileCheck %s --check-prefix=PROFSYMLIST ; RUN: opt < %s -passes=sample-profile -sample-profile-file=%t.symlist.afdo -profile-summary-cutoff-hot=600000 -profile-accurate-for-symsinlist -S | FileCheck %s --check-prefix=PROFSYMLIST +; RUN: opt < %s -passes=sample-profile -sample-profile-file=%t.symlist.afdo -profile-accurate-for-symsinlist -profile-symbol-list-cutoff=2 -S | FileCheck %s --check-prefix=PSLCUTOFF2 +; RUN: opt < %s -passes=sample-profile -sample-profile-file=%t.symlist.afdo -profile-accurate-for-symsinlist -profile-symbol-list-cutoff=3 -S | FileCheck %s --check-prefix=PSLCUTOFF3 ; ; If -profile-accurate-for-symsinlist and -profile-sample-accurate both present, ; -profile-sample-accurate will override -profile-accurate-for-symsinlist. @@ -60,6 +62,16 @@ ret i32 %add, !dbg !11 } +; Check -profile-symbol-list-cutoff=3 will include _Z3toov into profile +; symbol list and -profile-symbol-list-cutoff=2 will not. +; PSLCUTOFF2: define i32 @_Z3toov{{.*}}!prof ![[TOO_ID:[0-9]+]] +; PSLCUTOFF3: define i32 @_Z3toov{{.*}}!prof ![[TOO_ID:[0-9]+]] +define i32 @_Z3toov(i32 %x, i32 %y) #0 { +entry: + %add = add nsw i32 %x, %y + ret i32 %add +} + ; Function Attrs: uwtable define i32 @main() #0 !dbg !7 { entry: @@ -132,6 +144,8 @@ ; CALL_SUM_IS_HOT: ![[ZERO_ID]] = !{!"function_entry_count", i64 0} ; CALL_SUM_IS_WARM: ![[NONZERO_ID]] = !{!"function_entry_count", i64 5179} ; PROFSYMLIST: ![[UNKNOWN_ID]] = !{!"function_entry_count", i64 -1} +; PSLCUTOFF2: ![[TOO_ID]] = !{!"function_entry_count", i64 -1} +; PSLCUTOFF3: ![[TOO_ID]] = !{!"function_entry_count", i64 0} !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5 ", isOptimized: false, emissionKind: NoDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2) !1 = !DIFile(filename: "calls.cc", directory: ".") !2 = !{}