diff options
author | Rong Xu <xur@google.com> | 2016-02-08 21:07:46 +0000 |
---|---|---|
committer | Rong Xu <xur@google.com> | 2016-02-08 21:07:46 +0000 |
commit | 1288a19421232137ed288e4b9ba202f3b37b2006 (patch) | |
tree | a5c81a0b9a6c6f2ff258444f914e829610b6f3ab /llvm/lib/Transforms | |
parent | 264d7e5b685a739f52e680089ba92f0129708687 (diff) | |
download | bcm5719-llvm-1288a19421232137ed288e4b9ba202f3b37b2006.tar.gz bcm5719-llvm-1288a19421232137ed288e4b9ba202f3b37b2006.zip |
[PGO] Differentiate Clang instrumentation and IR level instrumentation profiles
This patch uses one bit in profile version to differentiate Clang
instrumentation and IR level instrumentation profiles.
PGOInstrumenation generates a COMDAT variable __llvm_profile_raw_version so
that the compiler runtime can set the right profile kind.
PGOInstrumenation now checks this bit to make sure it's an IR level
instrumentation profile.
Differential Revision: http://reviews.llvm.org/D15540
llvm-svn: 260146
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index f9e421df354..99c9e3eab74 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -713,7 +713,22 @@ void PGOUseFunc::setBranchWeights() { } } // end anonymous namespace +// Create a COMDAT variable IR_LEVEL_PROF_VARNAME to make the runtime +// aware this is an ir_level profile so it can set the version flag. +static void createIRLevelProfileFlagVariable(Module &M) { + Type *IntTy64 = Type::getInt64Ty(M.getContext()); + uint64_t ProfileVersion = (INSTR_PROF_RAW_VERSION | VARIANT_MASK_IR_PROF); + auto IRLevelVersionVariable = + new GlobalVariable(M, IntTy64, true, GlobalVariable::ExternalLinkage, + Constant::getIntegerValue(IntTy64, APInt(64, ProfileVersion)), + INSTR_PROF_QUOTE(IR_LEVEL_PROF_VERSION_VAR)); + IRLevelVersionVariable->setVisibility(GlobalValue::DefaultVisibility); + IRLevelVersionVariable->setComdat( + M.getOrInsertComdat(StringRef(INSTR_PROF_QUOTE(IR_LEVEL_PROF_VERSION_VAR)))); +} + bool PGOInstrumentationGen::runOnModule(Module &M) { + createIRLevelProfileFlagVariable(M); for (auto &F : M) { if (F.isDeclaration()) continue; @@ -751,6 +766,13 @@ bool PGOInstrumentationUse::runOnModule(Module &M) { "Cannot get PGOReader")); return false; } + // TODO: might need to change the warning once the clang option is finalized. + if (!PGOReader->isIRLevelProfile()) { + Ctx.diagnose(DiagnosticInfoPGOProfile( + ProfileFileName.data(), "Not an IR level instrumentation profile")); + return false; + } + for (auto &F : M) { if (F.isDeclaration()) |