llvm.org GIT mirror llvm / d079edb
[PGO] Exit early if all count values are zero If all the edge counts for a function are zero, skip count population and annotation, as nothing will happen. This can save some compile time. Differential Revision: https://reviews.llvm.org/D54212 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346370 91177308-0d34-0410-b5e6-96231b3b80d8 Rong Xu 10 months ago
3 changed file(s) with 58 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
858858 FreqAttr(FFA_Normal) {}
859859
860860 // Read counts for the instrumented BB from profile.
861 bool readCounters(IndexedInstrProfReader *PGOReader);
861 bool readCounters(IndexedInstrProfReader *PGOReader, bool &AllZeros);
862862
863863 // Populate the counts for all BBs.
864864 void populateCounters();
903903 FuncInfo.dumpInfo(Str);
904904 }
905905
906 uint64_t getProgramMaxCount() const { return ProgramMaxCount; }
906907 private:
907908 Function &F;
908909 Module *M;
10121013 // Read the profile from ProfileFileName and assign the value to the
10131014 // instrumented BB and the edges. This function also updates ProgramMaxCount.
10141015 // Return true if the profile are successfully read, and false on errors.
1015 bool PGOUseFunc::readCounters(IndexedInstrProfReader *PGOReader) {
1016 bool PGOUseFunc::readCounters(IndexedInstrProfReader *PGOReader, bool &AllZeros) {
10161017 auto &Ctx = M->getContext();
10171018 Expected Result =
10181019 PGOReader->getInstrProfRecord(FuncInfo.FuncName, FuncInfo.FunctionHash);
10521053 LLVM_DEBUG(dbgs() << " " << I << ": " << CountFromProfile[I] << "\n");
10531054 ValueSum += CountFromProfile[I];
10541055 }
1056 AllZeros = (ValueSum == 0);
10551057
10561058 LLVM_DEBUG(dbgs() << "SUM = " << ValueSum << "\n");
10571059
14761478 // later in getInstrBB() to avoid invalidating it.
14771479 SplitIndirectBrCriticalEdges(F, BPI, BFI);
14781480 PGOUseFunc Func(F, &M, ComdatMembers, BPI, BFI);
1479 if (!Func.readCounters(PGOReader.get()))
1481 bool AllZeros = false;
1482 if (!Func.readCounters(PGOReader.get(), AllZeros))
14801483 continue;
1484 if (AllZeros) {
1485 F.setEntryCount(ProfileCount(0, Function::PCT_Real));
1486 if (Func.getProgramMaxCount() != 0)
1487 ColdFunctions.push_back(&F);
1488 continue;
1489 }
14811490 Func.populateCounters();
14821491 Func.setBranchWeights();
14831492 Func.annotateValueSites();
0 # IR level Instrumentation Flag
1 :ir
2 foo
3 # Func Hash:
4 12884901887
5 # Num Counters:
6 1
7 # Counter Values:
8 9999
9
10 bar
11 # Func Hash:
12 12884901887
13 # Num Counters:
14 1
15 # Counter Values:
16 0
0 ; RUN: llvm-profdata merge %S/Inputs/func_entry.proftext -o %t.profdata
1 ; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s
2
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-unknown-linux-gnu"
5
6 @s = common dso_local local_unnamed_addr global i32 0, align 4
7
8 define void @bar() {
9 ; CHECK-LABEL: @bar
10 ; CHECK-SAME: !prof ![[FUNC_ENTRY_COUNT_ZERO:[0-9]+]]
11
12 entry:
13 store i32 1, i32* @s, align 4
14 ret void
15 }
16
17 define void @foo() {
18 ; CHECK-LABEL: @foo
19 ; CHECK-SAME: !prof ![[FUNC_ENTRY_COUNT_NON_ZERO:[0-9]+]]
20 entry:
21 %0 = load i32, i32* @s, align 4
22 %add = add nsw i32 %0, 4
23 store i32 %add, i32* @s, align 4
24 ret void
25 }
26
27 ; CHECK-DAG: ![[FUNC_ENTRY_COUNT_ZERO]] = !{!"function_entry_count", i64 0}
28 ; CHECK-DAG: ![[FUNC_ENTRY_COUNT_NON_ZERO]] = !{!"function_entry_count", i64 9999}