Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions clang/lib/CodeGen/CodeGenPGO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ enum PGOHashVersion : unsigned {
PGO_HASH_V1,
PGO_HASH_V2,
PGO_HASH_V3,
PGO_HASH_V4,

// Keep this set to the latest hash version.
PGO_HASH_LATEST = PGO_HASH_V3
PGO_HASH_LATEST = PGO_HASH_V4
};

namespace {
Expand Down Expand Up @@ -152,7 +153,9 @@ static PGOHashVersion getPGOHashVersion(llvm::IndexedInstrProfReader *PGOReader,
return PGO_HASH_V1;
if (PGOReader->getVersion() <= 5)
return PGO_HASH_V2;
return PGO_HASH_V3;
if (PGOReader->getVersion() <= 12)
return PGO_HASH_V3;
return PGO_HASH_V4;
}

/// A RecursiveASTVisitor that fills a map of statements to PGO counters.
Expand Down Expand Up @@ -1099,6 +1102,8 @@ void CodeGenPGO::mapRegionCounters(const Decl *D) {
assert(Walker.NextCounter > 0 && "no entry counter mapped for decl");
NumRegionCounters = Walker.NextCounter;
FunctionHash = Walker.Hash.finalize();
if (HashVersion >= PGO_HASH_V4)
FunctionHash &= llvm::NamedInstrProfRecord::FUNC_HASH_MASK;
}

bool CodeGenPGO::skipRegionMappingForDecl(const Decl *D) {
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Profile/Inputs/c-counter-overflows.proftext
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main
7779561829442898616
862032801801816760
8
1
68719476720
Expand Down
Binary file added clang/test/Profile/Inputs/c-general.profdata.v12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to avoid checking in a binary file. I'm guessing that we can't have this be a .proftext file because there is no way to set the version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. There are also c-general.profdata.v{1,3,5} already existing in the folder :-)

Binary file not shown.
12 changes: 6 additions & 6 deletions clang/test/Profile/Inputs/c-general.proftext
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ simple_loops
75

conditionals
4904767535850050386
293081517422662482
13
1
100
Expand All @@ -24,7 +24,7 @@ conditionals
1

early_exits
2880354649761471549
574511640547777597
9
1
0
Expand All @@ -37,7 +37,7 @@ early_exits
0

jumps
15051420506203462683
63440946314451995
22
1
1
Expand Down Expand Up @@ -86,7 +86,7 @@ switches
0

big_switch
13144136522122330070
461999971447013334
17
1
32
Expand Down Expand Up @@ -125,7 +125,7 @@ boolean_operators
33

boolop_loops
12402604614320574815
873389568252105055
13
1
50
Expand All @@ -149,7 +149,7 @@ conditional_operator
1

do_fallthrough
8714614136504380050
644163604256451218
4
1
10
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Profile/Inputs/c-unprofiled-blocks.proftext
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
never_called
6820425066224770721
1055817543190535841
9
0
0
Expand All @@ -17,7 +17,7 @@ main
1

dead_code
5254464978620792806
642778960193404902
10
1
0
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Profile/Inputs/cxx-rangefor.proftext
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
_Z9range_forv
8789831523895825398
719380991647896566
5
1
4
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Profile/Inputs/cxx-throws.proftext
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
_Z6throwsv
18172607911962830854
878785342860126214
9
1
100
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
main
# Func Hash:
8734802134600123338
664351602352194506
# Num Counters:
9
# Counter Values:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
main
# Func Hash:
3721743393642630379
262978879822089451
# Num Counters:
10
# Counter Values:
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Profile/c-collision.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// RUN: %clang_cc1 -UEXTRA -triple x86_64-unknown-linux-gnu -main-file-name c-collision.c %s -o - -emit-llvm -fprofile-instrument=clang | FileCheck %s --check-prefix=CHECK-NOEXTRA
// RUN: %clang_cc1 -DEXTRA -triple x86_64-unknown-linux-gnu -main-file-name c-collision.c %s -o - -emit-llvm -fprofile-instrument=clang | FileCheck %s --check-prefix=CHECK-EXTRA

// CHECK-NOEXTRA: @__profd_foo = private global { {{.*}} } { i64 6699318081062747564, i64 7156072912471487002,
// CHECK-EXTRA: @__profd_foo = private global { {{.*}} } { i64 6699318081062747564, i64 -4383447408116050035,
// CHECK-NOEXTRA: @__profd_foo = private global { {{.*}} } { i64 6699318081062747564, i64 238543884830405146,
// CHECK-EXTRA: @__profd_foo = private global { {{.*}} } { i64 6699318081062747564, i64 228238610311337869,

extern int bar;
void foo(void) {
Expand Down
1 change: 1 addition & 0 deletions clang/test/Profile/c-general.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// RUN: llvm-profdata merge %S/Inputs/c-general.proftext -o %t.profdata
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use=clang -fprofile-instrument-use-path=%t.profdata | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOUSE %s
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use=clang -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v12 | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOUSE %s
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use=clang -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v5 | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOUSE %s
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use=clang -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v3 | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOUSE %s
// Also check compatibility with older profiles.
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/include/profile/InstrProfData.inc
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
/* Raw profile format version (start from 1). */
#define INSTR_PROF_RAW_VERSION 10
/* Indexed profile format version (start from 1). */
#define INSTR_PROF_INDEX_VERSION 12
#define INSTR_PROF_INDEX_VERSION 13
/* Coverage mapping format version (start from 0). */
#define INSTR_PROF_COVMAP_VERSION 6

Expand Down
10 changes: 7 additions & 3 deletions llvm/include/llvm/ProfileData/InstrProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -1058,8 +1058,10 @@ struct NamedInstrProfRecord : InstrProfRecord {
StringRef Name;
uint64_t Hash;

// We reserve this bit as the flag for context sensitive profile record.
static const int CS_FLAG_IN_FUNC_HASH = 60;
// We reserve the highest 4 bits as flags.
static constexpr uint64_t FUNC_HASH_MASK = 0x0FFF'FFFF'FFFF'FFFF;
// The 60th bit is for context sensitive profile record.
static constexpr unsigned CS_FLAG_IN_FUNC_HASH = 60;

NamedInstrProfRecord() = default;
NamedInstrProfRecord(StringRef Name, uint64_t Hash,
Expand Down Expand Up @@ -1174,7 +1176,9 @@ enum ProfVersion {
Version11 = 11,
// VTable profiling, decision record and bitmap are modified for mcdc.
Version12 = 12,
// The current version is 12.
// In this version, the frontend PGO stable hash algorithm defaults to V4.
Version13 = 13,
// The current version is 13.
CurrentVersion = INSTR_PROF_INDEX_VERSION
};
const uint64_t Version = ProfVersion::CurrentVersion;
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/ProfileData/InstrProfData.inc
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
/* Raw profile format version (start from 1). */
#define INSTR_PROF_RAW_VERSION 10
/* Indexed profile format version (start from 1). */
#define INSTR_PROF_INDEX_VERSION 12
#define INSTR_PROF_INDEX_VERSION 13
/* Coverage mapping format version (start from 0). */
#define INSTR_PROF_COVMAP_VERSION 6

Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/ProfileData/InstrProf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,7 @@ Expected<Header> Header::readFromBuffer(const unsigned char *Buffer) {
IndexedInstrProf::ProfVersion::CurrentVersion)
return make_error<InstrProfError>(instrprof_error::unsupported_version);

static_assert(IndexedInstrProf::ProfVersion::CurrentVersion == Version12,
static_assert(IndexedInstrProf::ProfVersion::CurrentVersion == Version13,
"Please update the reader as needed when a new field is added "
"or when indexed profile version gets bumped.");

Expand Down Expand Up @@ -1723,10 +1723,11 @@ size_t Header::size() const {
// of the header, and byte offset of existing fields shouldn't change when
// indexed profile version gets incremented.
static_assert(
IndexedInstrProf::ProfVersion::CurrentVersion == Version12,
IndexedInstrProf::ProfVersion::CurrentVersion == Version13,
"Please update the size computation below if a new field has "
"been added to the header; for a version bump without new "
"fields, add a case statement to fall through to the latest version.");
case 13ull:
case 12ull:
return 72;
case 11ull:
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ProfileData/InstrProfWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
// The WritePrevVersion handling will either need to be removed or updated
// if the version is advanced beyond 12.
static_assert(IndexedInstrProf::ProfVersion::CurrentVersion ==
IndexedInstrProf::ProfVersion::Version12);
IndexedInstrProf::ProfVersion::Version13);
if (static_cast<bool>(ProfileKind & InstrProfKind::IRInstrumentation))
Header.Version |= VARIANT_MASK_IR_PROF;
if (static_cast<bool>(ProfileKind & InstrProfKind::ContextSensitive))
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ void FuncPGOInstrumentation<Edge, BBInfo>::computeCFGHash() {
FunctionHash = (((uint64_t)JCH.getCRC()) << 28) + JC.getCRC();

// Reserve bit 60-63 for other information purpose.
FunctionHash &= 0x0FFFFFFFFFFFFFFF;
FunctionHash &= NamedInstrProfRecord::FUNC_HASH_MASK;
if (IsCS)
NamedInstrProfRecord::setCSFlagInHash(FunctionHash);
LLVM_DEBUG(dbgs() << "Function Hash Computation for " << F.getName() << ":\n"
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-profdata/profile-version.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Test the profile version.

RUN: llvm-profdata merge -o %t.profdata %p/Inputs/basic.proftext
RUN: llvm-profdata show --profile-version %t.profdata | FileCheck %s
CHECK: Profile version: 12
CHECK: Profile version: 13

RUN: llvm-profdata merge -o %t.prev.profdata %p/Inputs/basic.proftext --write-prev-version
RUN: llvm-profdata show --profile-version %t.prev.profdata | FileCheck %s --check-prefix=PREV
Expand Down