Index: llvm/include/llvm/IR/ProfileSummary.h =================================================================== --- llvm/include/llvm/IR/ProfileSummary.h +++ llvm/include/llvm/IR/ProfileSummary.h @@ -64,11 +64,12 @@ ProfileSummary(Kind K, SummaryEntryVector DetailedSummary, uint64_t TotalCount, uint64_t MaxCount, uint64_t MaxInternalCount, uint64_t MaxFunctionCount, - uint32_t NumCounts, uint32_t NumFunctions) + uint32_t NumCounts, uint32_t NumFunctions, + bool Partial = false) : PSK(K), DetailedSummary(std::move(DetailedSummary)), TotalCount(TotalCount), MaxCount(MaxCount), MaxInternalCount(MaxInternalCount), MaxFunctionCount(MaxFunctionCount), - NumCounts(NumCounts), NumFunctions(NumFunctions) {} + NumCounts(NumCounts), NumFunctions(NumFunctions), Partial(Partial) {} Kind getKind() const { return PSK; } /// Return summary information as metadata. Index: llvm/lib/IR/ProfileSummary.cpp =================================================================== --- llvm/lib/IR/ProfileSummary.cpp +++ llvm/lib/IR/ProfileSummary.cpp @@ -68,14 +68,15 @@ Metadata *ProfileSummary::getMD(LLVMContext &Context) { const char *KindStr[3] = {"InstrProf", "CSInstrProf", "SampleProfile"}; Metadata *Components[] = { - getKeyValMD(Context, "ProfileFormat", KindStr[PSK]), - getKeyValMD(Context, "TotalCount", getTotalCount()), - getKeyValMD(Context, "MaxCount", getMaxCount()), - getKeyValMD(Context, "MaxInternalCount", getMaxInternalCount()), - getKeyValMD(Context, "MaxFunctionCount", getMaxFunctionCount()), - getKeyValMD(Context, "NumCounts", getNumCounts()), - getKeyValMD(Context, "NumFunctions", getNumFunctions()), - getDetailedSummaryMD(Context), + getKeyValMD(Context, "ProfileFormat", KindStr[PSK]), + getKeyValMD(Context, "TotalCount", getTotalCount()), + getKeyValMD(Context, "MaxCount", getMaxCount()), + getKeyValMD(Context, "MaxInternalCount", getMaxInternalCount()), + getKeyValMD(Context, "MaxFunctionCount", getMaxFunctionCount()), + getKeyValMD(Context, "NumCounts", getNumCounts()), + getKeyValMD(Context, "NumFunctions", getNumFunctions()), + getKeyValMD(Context, "IsPartialProfile", isPartialProfile()), + getDetailedSummaryMD(Context), }; return MDTuple::get(Context, Components); } @@ -159,7 +160,7 @@ return nullptr; uint64_t NumCounts, TotalCount, NumFunctions, MaxFunctionCount, MaxCount, - MaxInternalCount; + MaxInternalCount, IsPartialProfile; if (!getVal(dyn_cast(Tuple->getOperand(1)), "TotalCount", TotalCount)) return nullptr; @@ -176,11 +177,14 @@ if (!getVal(dyn_cast(Tuple->getOperand(6)), "NumFunctions", NumFunctions)) return nullptr; + if (!getVal(dyn_cast(Tuple->getOperand(6)), "IsPartialProfile", + IsPartialProfile)) + return nullptr; SummaryEntryVector Summary; if (!getSummaryFromMD(dyn_cast(Tuple->getOperand(7)), Summary)) return nullptr; return new ProfileSummary(SummaryKind, std::move(Summary), TotalCount, MaxCount, MaxInternalCount, MaxFunctionCount, - NumCounts, NumFunctions); + NumCounts, NumFunctions, IsPartialProfile); } Index: llvm/test/Transforms/SampleProfile/summary.ll =================================================================== --- llvm/test/Transforms/SampleProfile/summary.ll +++ llvm/test/Transforms/SampleProfile/summary.ll @@ -1,6 +1,10 @@ ; Test that we annotate entire program's summary to IR. ; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/summary.prof -S | FileCheck %s ; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/summary.prof -S | opt -sample-profile -sample-profile-file=%S/Inputs/summary.prof -S | FileCheck %s +; Test that we annotate partial profile flag to IR correctly. +; RUN: llvm-profdata merge --sample --extbinary --partial-profile %S/Inputs/summary.prof --output=%t.prof +; RUN: opt < %s -sample-profile -sample-profile-file=%t.prof -S | FileCheck %s -check-prefix=PARTIAL +; RUN: opt < %s -sample-profile -sample-profile-file=%t.prof -S | opt -sample-profile -sample-profile-file=%t.prof -S | FileCheck %s -check-prefix=PARTIAL define i32 @bar() #0 !dbg !1 { entry: @@ -18,6 +22,8 @@ ; CHECK-DAG: {{![0-9]+}} = !{!"NumCounts", i64 5} ; CHECK-DAG: {{![0-9]+}} = !{!"NumFunctions", i64 3} ; CHECK-DAG: {{![0-9]+}} = !{!"MaxFunctionCount", i64 3} +; CHECK-DAG: {{![0-9]+}} = !{!"IsPartialProfile", i64 0} +; PARTIAL: {{![0-9]+}} = !{!"IsPartialProfile", i64 1} !1 = distinct !DISubprogram(name: "bar") !2 = !DILocation(line: 2, scope: !2)