Index: lib/CodeGen/CodeGenModule.cpp =================================================================== --- lib/CodeGen/CodeGenModule.cpp +++ lib/CodeGen/CodeGenModule.cpp @@ -396,6 +396,10 @@ AddGlobalCtor(OpenMPRegistrationFunction, 0); if (PGOReader) { getModule().setMaximumFunctionCount(PGOReader->getMaximumFunctionCount()); + auto *SummaryMD = PGOReader->getSummary().getMD(getModule().getContext()); + // Make sure returned metadata is non-null; + assert(SummaryMD); + getModule().setProfileSummary(SummaryMD); if (PGOStats.hasDiagnostics()) PGOStats.reportDiagnostics(getDiags(), getCodeGenOpts().MainFileName); } Index: test/Profile/Inputs/profile-summary.proftext =================================================================== --- /dev/null +++ test/Profile/Inputs/profile-summary.proftext @@ -0,0 +1,26 @@ +begin +# Func Hash: +2859428334838410 +# Num Counters: +10 +# Counter Values: +8000002 +3 +2 +2 +3 +72 +720 +7200 +72000 +720000 + +main +# Func Hash: +4 +# Num Counters: +2 +# Counter Values: +1 +4000001 + Index: test/Profile/profile-summary.c =================================================================== --- /dev/null +++ test/Profile/profile-summary.c @@ -0,0 +1,60 @@ +// Test that profile summary is set correctly. + +// RUN: llvm-profdata merge %S/Inputs/profile-summary.proftext -o %t.profdata +// RUN: %clang %s -o - -mllvm -disable-llvm-optzns -emit-llvm -S -fprofile-instr-use=%t.profdata | FileCheck %s +// +int begin(int i) { + if (!(i % 4000000)) + i++; + if (!(i % 3000000)) + i++; + if (!(i % 2000000)) + i++; + if (!(i % 1000000)) + i++; + if (!(i % 100000)) + i++; + if (!(i % 10000)) + i++; + if (!(i % 1000)) + i++; + if (!(i % 100)) + i++; + if (!(i % 10)) + i++; + return 0; +} + +int main(int argc, const char *argv[]) { + for (int i = 0; i <= 4000000; i++) { + begin(i); + begin(1000000 - i); + } + return 0; +} +// CHECK: {{![0-9]+}} = !{i32 1, !"ProfileSummary", {{![0-9]+}}} +// CHECK: {{![0-9]+}} = !{!"ProfileFormat", !"InstrProf"} +// CHECK: {{![0-9]+}} = !{!"TotalCount", i64 12800006} +// CHECK: {{![0-9]+}} = !{!"MaxBlockCount", i64 8000002} +// CHECK: {{![0-9]+}} = !{!"MaxInternalBlockCount", i64 4000001} +// CHECK: {{![0-9]+}} = !{!"MaxFunctionCount", i64 8000002} +// CHECK: {{![0-9]+}} = !{!"NumBlocks", i64 12} +// CHECK: {{![0-9]+}} = !{!"NumFunctions", i64 2} +// CHECK: {{![0-9]+}} = !{!"DetailedSummary", [[DETAILS:![0-9]+]]} +// CHECK: [[DETAILS]] = !{{{(![0-9]+, )+}}{{![0-9]+}}} +// CHECK: {{![0-9]+}} = !{i32 10000, i64 8000002, i32 1} +// CHECK: {{![0-9]+}} = !{i32 100000, i64 8000002, i32 1} +// CHECK: {{![0-9]+}} = !{i32 200000, i64 8000002, i32 1} +// CHECK: {{![0-9]+}} = !{i32 300000, i64 8000002, i32 1} +// CHECK: {{![0-9]+}} = !{i32 400000, i64 8000002, i32 1} +// CHECK: {{![0-9]+}} = !{i32 500000, i64 8000002, i32 1} +// CHECK: {{![0-9]+}} = !{i32 600000, i64 8000002, i32 1} +// CHECK: {{![0-9]+}} = !{i32 700000, i64 4000001, i32 2} +// CHECK: {{![0-9]+}} = !{i32 800000, i64 4000001, i32 2} +// CHECK: {{![0-9]+}} = !{i32 900000, i64 4000001, i32 2} +// CHECK: {{![0-9]+}} = !{i32 950000, i64 720000, i32 3} +// CHECK: {{![0-9]+}} = !{i32 990000, i64 720000, i32 3} +// CHECK: {{![0-9]+}} = !{i32 999000, i64 72000, i32 4} +// CHECK: {{![0-9]+}} = !{i32 999900, i64 7200, i32 5} +// CHECK: {{![0-9]+}} = !{i32 999990, i64 720, i32 6} +// CHECK: {{![0-9]+}} = !{i32 999999, i64 72, i32 7}