r264783 - [PGO] Move the instrumentation point closer to the value site.
Author: betulb Date: Tue Mar 29 15:44:09 2016 New Revision: 264783 URL: http://llvm.org/viewvc/llvm-project?rev=264783&view=rev Log: [PGO] Move the instrumentation point closer to the value site. For terminator instructions, the value profiling instrumentation happens in a basic block other than where the value site resides. This CR moves the instrumentation point prior to the value site. Mostly NFC. Added: cfe/trunk/test/Profile/cxx-indirect-call.cpp Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp cfe/trunk/test/Profile/c-indirect-call.c Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.cpp?rev=264783&r1=264782&r2=264783&view=diff == --- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Tue Mar 29 15:44:09 2016 @@ -757,10 +757,10 @@ void CodeGenPGO::valueProfile(CGBuilderT bool InstrumentValueSites = CGM.getCodeGenOpts().hasProfileClangInstr(); if (InstrumentValueSites && RegionCounterMap) { -llvm::LLVMContext &Ctx = CGM.getLLVMContext(); -auto *I8PtrTy = llvm::Type::getInt8PtrTy(Ctx); +auto BuilderInsertPoint = Builder.saveIP(); +Builder.SetInsertPoint(ValueSite); llvm::Value *Args[5] = { -llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy), +llvm::ConstantExpr::getBitCast(FuncNameVar, Builder.getInt8PtrTy()), Builder.getInt64(FunctionHash), Builder.CreatePtrToInt(ValuePtr, Builder.getInt64Ty()), Builder.getInt32(ValueKind), @@ -768,6 +768,7 @@ void CodeGenPGO::valueProfile(CGBuilderT }; Builder.CreateCall( CGM.getIntrinsic(llvm::Intrinsic::instrprof_value_profile), Args); +Builder.restoreIP(BuilderInsertPoint); return; } Modified: cfe/trunk/test/Profile/c-indirect-call.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/c-indirect-call.c?rev=264783&r1=264782&r2=264783&view=diff == --- cfe/trunk/test/Profile/c-indirect-call.c (original) +++ cfe/trunk/test/Profile/c-indirect-call.c Tue Mar 29 15:44:09 2016 @@ -1,13 +1,14 @@ -// Check the data structures emitted by instrumentation. +// Check the value profiling instrinsics emitted by instrumentation. + // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-indirect-call.c %s -o - -emit-llvm -fprofile-instrument=clang -mllvm -enable-value-profiling | FileCheck %s void (*foo)(void); int main(void) { // CHECK: [[REG1:%[0-9]+]] = load void ()*, void ()** @foo, align 8 -// CHECK-NEXT: call void [[REG1]]() // CHECK-NEXT: [[REG2:%[0-9]+]] = ptrtoint void ()* [[REG1]] to i64 // CHECK-NEXT: call void @__llvm_profile_instrument_target(i64 [[REG2]], i8* bitcast ({{.*}}* @__profd_main to i8*), i32 0) +// CHECK-NEXT: call void [[REG1]]() foo(); return 0; } Added: cfe/trunk/test/Profile/cxx-indirect-call.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/cxx-indirect-call.cpp?rev=264783&view=auto == --- cfe/trunk/test/Profile/cxx-indirect-call.cpp (added) +++ cfe/trunk/test/Profile/cxx-indirect-call.cpp Tue Mar 29 15:44:09 2016 @@ -0,0 +1,21 @@ +// Check the value profiling instrinsics emitted by instrumentation. + +// RUN: %clangxx %s -o - -emit-llvm -S -fprofile-instr-generate -mllvm -enable-value-profiling -fexceptions -target %itanium_abi_triple | FileCheck %s + +void (*foo) (void); + +int main(int argc, const char *argv[]) { +// CHECK: [[REG1:%[0-9]+]] = load void ()*, void ()** @foo, align 4 +// CHECK-NEXT: [[REG2:%[0-9]+]] = ptrtoint void ()* [[REG1]] to i64 +// CHECK-NEXT: call void @__llvm_profile_instrument_target(i64 [[REG2]], i8* bitcast ({{.*}}* @__profd_main to i8*), i32 0) +// CHECK-NEXT: invoke void [[REG1]]() + try { +foo(); + } catch (int) {} + return 0; +} + +// CHECK: declare void @__llvm_profile_instrument_target(i64, i8*, i32) + + + ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r264795 - [PGO] Test case fix for r264783
Author: betulb Date: Tue Mar 29 17:17:52 2016 New Revision: 264795 URL: http://llvm.org/viewvc/llvm-project?rev=264795&view=rev Log: [PGO] Test case fix for r264783 Modified: cfe/trunk/test/Profile/cxx-indirect-call.cpp Modified: cfe/trunk/test/Profile/cxx-indirect-call.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/cxx-indirect-call.cpp?rev=264795&r1=264794&r2=264795&view=diff == --- cfe/trunk/test/Profile/cxx-indirect-call.cpp (original) +++ cfe/trunk/test/Profile/cxx-indirect-call.cpp Tue Mar 29 17:17:52 2016 @@ -5,7 +5,7 @@ void (*foo) (void); int main(int argc, const char *argv[]) { -// CHECK: [[REG1:%[0-9]+]] = load void ()*, void ()** @foo, align 4 +// CHECK: [[REG1:%[0-9]+]] = load void ()*, void ()** @foo // CHECK-NEXT: [[REG2:%[0-9]+]] = ptrtoint void ()* [[REG1]] to i64 // CHECK-NEXT: call void @__llvm_profile_instrument_target(i64 [[REG2]], i8* bitcast ({{.*}}* @__profd_main to i8*), i32 0) // CHECK-NEXT: invoke void [[REG1]]() ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
RE: r264783 - [PGO] Move the instrumentation point closer to the value site.
Hi Artem, I’ve uploaded a patch to remove the alignment. Thanks, -Betul From: Artem Belevich [mailto:t...@google.com] Sent: Tuesday, March 29, 2016 3:15 PM To: Betul Buyukkurt Cc: cfe-commits Subject: Re: r264783 - [PGO] Move the instrumentation point closer to the value site. Hi, FYI, cxx-indirect-call.cpp test fails on platforms with different alignment. It may help to either use specific target or change your patterns to accommodate other targets. --Artem TEST 'Clang :: Profile/cxx-indirect-call.cpp' FAILED Script: -- /usr/local/google/home/tra/work/llvm/build/gpu/release/./bin/clang --driver-mode=g++ /work/tra/llvm/tools/clang/test/Profile/cxx-indirect-call.cpp -o - -emit-llvm -S -fprofile-instr-generate -mllvm -enable-value-profiling -fexceptions -target x86_64-unknown-linux-gnu | /usr/local/google/home/tra/work/llvm/build/gpu/release/./bin/FileCheck /work/tra/llvm/tools/clang/test/Profile/cxx-indirect-call.cpp -- Exit Code: 1 Command Output (stderr): -- /work/tra/llvm/tools/clang/test/Profile/cxx-indirect-call.cpp:8:11: error: expected string not found in input // CHECK: [[REG1:%[0-9]+]] = load void ()*, void ()** @foo, align 4 ^ :1:1: note: scanning from here ; ModuleID = '/work/tra/llvm/tools/clang/test/Profile/cxx-indirect-call.cpp' ^ :27:2: note: possible intended match here %11 = load void ()*, void ()** @foo, align 8 ^ -- On Tue, Mar 29, 2016 at 1:44 PM, Betul Buyukkurt via cfe-commits mailto:cfe-commits@lists.llvm.org> > wrote: Author: betulb Date: Tue Mar 29 15:44:09 2016 New Revision: 264783 URL: http://llvm.org/viewvc/llvm-project?rev=264783 <http://llvm.org/viewvc/llvm-project?rev=264783&view=rev> &view=rev Log: [PGO] Move the instrumentation point closer to the value site. For terminator instructions, the value profiling instrumentation happens in a basic block other than where the value site resides. This CR moves the instrumentation point prior to the value site. Mostly NFC. Added: cfe/trunk/test/Profile/cxx-indirect-call.cpp Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp cfe/trunk/test/Profile/c-indirect-call.c Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.cpp?rev=264783 <http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.cpp?rev=264783&r1=264782&r2=264783&view=diff> &r1=264782&r2=264783&view=diff == --- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Tue Mar 29 15:44:09 2016 @@ -757,10 +757,10 @@ void CodeGenPGO::valueProfile(CGBuilderT bool InstrumentValueSites = CGM.getCodeGenOpts().hasProfileClangInstr(); if (InstrumentValueSites && RegionCounterMap) { -llvm::LLVMContext &Ctx = CGM.getLLVMContext(); -auto *I8PtrTy = llvm::Type::getInt8PtrTy(Ctx); +auto BuilderInsertPoint = Builder.saveIP(); +Builder.SetInsertPoint(ValueSite); llvm::Value *Args[5] = { -llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy), +llvm::ConstantExpr::getBitCast(FuncNameVar, Builder.getInt8PtrTy()), Builder.getInt64(FunctionHash), Builder.CreatePtrToInt(ValuePtr, Builder.getInt64Ty()), Builder.getInt32(ValueKind), @@ -768,6 +768,7 @@ void CodeGenPGO::valueProfile(CGBuilderT }; Builder.CreateCall( CGM.getIntrinsic(llvm::Intrinsic::instrprof_value_profile), Args); +Builder.restoreIP(BuilderInsertPoint); return; } Modified: cfe/trunk/test/Profile/c-indirect-call.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/c-indirect-call.c?rev=264783 <http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/c-indirect-call.c?rev=264783&r1=264782&r2=264783&view=diff> &r1=264782&r2=264783&view=diff == --- cfe/trunk/test/Profile/c-indirect-call.c (original) +++ cfe/trunk/test/Profile/c-indirect-call.c Tue Mar 29 15:44:09 2016 @@ -1,13 +1,14 @@ -// Check the data structures emitted by instrumentation. +// Check the value profiling instrinsics emitted by instrumentation. + // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-indirect-call.c %s -o - -emit-llvm -fprofile-instrument=clang -mllvm -enable-value-profiling | FileCheck %s void (*foo)(void); int main(void) { // CHECK: [[REG1:%[0-9]+]] = load void ()*, void ()** @foo, align 8 -// CHECK-NEXT: call void [[REG1]]() // CHECK-NEXT: [[REG2:%[0-9]+]] = ptrtoint void ()* [[REG1]] to i64 // CHECK-NEXT: call void @__llvm_profile_instrument_target(i64 [[REG2]], i8* bitcast ({{.*}}* @__profd_main to i8*), i32 0) +// CHECK-NEXT: call void [[REG1]]() foo(); return 0; } Adde
[PATCH] D18636: [PGO] Avoid instrumenting constants at value sites
betulb created this revision. betulb added reviewers: davidxl, bogner. betulb added subscribers: llvm-commits, cfe-commits. betulb set the repository for this revision to rL LLVM. betulb changed the visibility of this Differential Revision from "Public (No Login Required)" to "All Users". Value profiling should not profile constants and/or constant expressions when they appear as callees in call instructions. Constant expressions form when a direct callee has bitcasts or inttoptr(ptrtint (callee)) nests surrounding it. Value profiling should avoid instrumenting such cases. Mostly NFC. Repository: rL LLVM http://reviews.llvm.org/D18636 Files: lib/CodeGen/CodeGenPGO.cpp test/Profile/c-avoid-direct-call.c Index: test/Profile/c-avoid-direct-call.c === --- /dev/null +++ test/Profile/c-avoid-direct-call.c @@ -0,0 +1,11 @@ +// Check the value profiling instrinsics emitted by instrumentation. + +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-avoid-direct-call.c %s -o - -emit-llvm -fprofile-instrument=clang -mllvm -enable-value-profiling | FileCheck %s + +void foo(); + +int main(void) { +// CHECK-NOT: call void @__llvm_profile_instrument_target(i64 ptrtoint (void (...)* @foo to i64), i8* bitcast ({{.*}}* @__profd_main to i8*), i32 0) + foo(21); + return 0; +} Index: lib/CodeGen/CodeGenPGO.cpp === --- lib/CodeGen/CodeGenPGO.cpp +++ lib/CodeGen/CodeGenPGO.cpp @@ -755,6 +755,9 @@ if (!ValuePtr || !ValueSite || !Builder.GetInsertBlock()) return; + if (dyn_cast(ValuePtr)) +return; + bool InstrumentValueSites = CGM.getCodeGenOpts().hasProfileClangInstr(); if (InstrumentValueSites && RegionCounterMap) { auto BuilderInsertPoint = Builder.saveIP(); Index: test/Profile/c-avoid-direct-call.c === --- /dev/null +++ test/Profile/c-avoid-direct-call.c @@ -0,0 +1,11 @@ +// Check the value profiling instrinsics emitted by instrumentation. + +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-avoid-direct-call.c %s -o - -emit-llvm -fprofile-instrument=clang -mllvm -enable-value-profiling | FileCheck %s + +void foo(); + +int main(void) { +// CHECK-NOT: call void @__llvm_profile_instrument_target(i64 ptrtoint (void (...)* @foo to i64), i8* bitcast ({{.*}}* @__profd_main to i8*), i32 0) + foo(21); + return 0; +} Index: lib/CodeGen/CodeGenPGO.cpp === --- lib/CodeGen/CodeGenPGO.cpp +++ lib/CodeGen/CodeGenPGO.cpp @@ -755,6 +755,9 @@ if (!ValuePtr || !ValueSite || !Builder.GetInsertBlock()) return; + if (dyn_cast(ValuePtr)) +return; + bool InstrumentValueSites = CGM.getCodeGenOpts().hasProfileClangInstr(); if (InstrumentValueSites && RegionCounterMap) { auto BuilderInsertPoint = Builder.saveIP(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D18636: [PGO] Avoid instrumenting constants at value sites
betulb added inline comments. Comment at: lib/CodeGen/CodeGenPGO.cpp:758 @@ -757,1 +757,3 @@ + if (dyn_cast(ValuePtr)) +return; davidxl wrote: > Is it the bitcast guaranteed to be already stripped here? No. ConstantExpr is derived from the Constant class. A ConstantExpr can only have other constants i.e. all immutable values as its operands. Direct callees' that are cast to other function prototypes, show up in the Call/Invoke instructions as ConstantExpr's. Currently llvm::CallSite's getCalledFunction() fails to return the callees in such expressions as direct calls, thus they are instrumented in both clang FE and I believe in the IR based instrumentation as well . Instrumenting such calls is a waste of counters, runtime calls and dynamic memory at run time. Repository: rL LLVM http://reviews.llvm.org/D18636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D18636: [PGO] Avoid instrumenting constants at value sites
betulb removed rL LLVM as the repository for this revision. betulb updated this revision to Diff 52249. betulb added a comment. Addressed review comments. http://reviews.llvm.org/D18636 Files: lib/CodeGen/CodeGenPGO.cpp test/Profile/c-avoid-direct-call.c Index: test/Profile/c-avoid-direct-call.c === --- /dev/null +++ test/Profile/c-avoid-direct-call.c @@ -0,0 +1,11 @@ +// Check the value profiling instrinsics emitted by instrumentation. + +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-avoid-direct-call.c %s -o - -emit-llvm -fprofile-instrument=clang -mllvm -enable-value-profiling | FileCheck %s + +void foo(); + +int main(void) { +// CHECK-NOT: call void @__llvm_profile_instrument_target + foo(21); + return 0; +} Index: lib/CodeGen/CodeGenPGO.cpp === --- lib/CodeGen/CodeGenPGO.cpp +++ lib/CodeGen/CodeGenPGO.cpp @@ -755,6 +755,9 @@ if (!ValuePtr || !ValueSite || !Builder.GetInsertBlock()) return; + if (isa(ValuePtr)) +return; + bool InstrumentValueSites = CGM.getCodeGenOpts().hasProfileClangInstr(); if (InstrumentValueSites && RegionCounterMap) { auto BuilderInsertPoint = Builder.saveIP(); Index: test/Profile/c-avoid-direct-call.c === --- /dev/null +++ test/Profile/c-avoid-direct-call.c @@ -0,0 +1,11 @@ +// Check the value profiling instrinsics emitted by instrumentation. + +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-avoid-direct-call.c %s -o - -emit-llvm -fprofile-instrument=clang -mllvm -enable-value-profiling | FileCheck %s + +void foo(); + +int main(void) { +// CHECK-NOT: call void @__llvm_profile_instrument_target + foo(21); + return 0; +} Index: lib/CodeGen/CodeGenPGO.cpp === --- lib/CodeGen/CodeGenPGO.cpp +++ lib/CodeGen/CodeGenPGO.cpp @@ -755,6 +755,9 @@ if (!ValuePtr || !ValueSite || !Builder.GetInsertBlock()) return; + if (isa(ValuePtr)) +return; + bool InstrumentValueSites = CGM.getCodeGenOpts().hasProfileClangInstr(); if (InstrumentValueSites && RegionCounterMap) { auto BuilderInsertPoint = Builder.saveIP(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r265037 - [PGO] Avoid instrumenting constants at value sites
Author: betulb Date: Thu Mar 31 13:41:34 2016 New Revision: 265037 URL: http://llvm.org/viewvc/llvm-project?rev=265037&view=rev Log: [PGO] Avoid instrumenting constants at value sites Value profiling should not profile constants and/or constant expressions when they appear as callees in call instructions. Constant expressions form when a direct callee has bitcasts or inttoptr(ptrtint (callee)) nests surrounding it. Value profiling should avoid instrumenting such cases. Mostly NFC. Added: cfe/trunk/test/Profile/c-avoid-direct-call.c Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.cpp?rev=265037&r1=265036&r2=265037&view=diff == --- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Thu Mar 31 13:41:34 2016 @@ -755,6 +755,9 @@ void CodeGenPGO::valueProfile(CGBuilderT if (!ValuePtr || !ValueSite || !Builder.GetInsertBlock()) return; + if (isa(ValuePtr)) +return; + bool InstrumentValueSites = CGM.getCodeGenOpts().hasProfileClangInstr(); if (InstrumentValueSites && RegionCounterMap) { auto BuilderInsertPoint = Builder.saveIP(); Added: cfe/trunk/test/Profile/c-avoid-direct-call.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/c-avoid-direct-call.c?rev=265037&view=auto == --- cfe/trunk/test/Profile/c-avoid-direct-call.c (added) +++ cfe/trunk/test/Profile/c-avoid-direct-call.c Thu Mar 31 13:41:34 2016 @@ -0,0 +1,11 @@ +// Check the value profiling instrinsics emitted by instrumentation. + +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-avoid-direct-call.c %s -o - -emit-llvm -fprofile-instrument=clang -mllvm -enable-value-profiling | FileCheck %s + +void foo(); + +int main(void) { +// CHECK-NOT: call void @__llvm_profile_instrument_target + foo(21); + return 0; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D18636: [PGO] Avoid instrumenting constants at value sites
betulb added a comment. Committed as r265037. Repository: rL LLVM http://reviews.llvm.org/D18636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D8940: Clang changes for indirect call target profiling
betulb updated the summary for this revision. betulb edited reviewers, added: xur; removed: dsule, bob.wilson. betulb updated this revision to Diff 44386. betulb added a comment. This CL adds in the changes necessary for instrumenting and profile metadata-attaching at clang level for value profiling. http://reviews.llvm.org/D8940 Files: lib/CodeGen/CGCall.cpp lib/CodeGen/CodeGenPGO.cpp lib/CodeGen/CodeGenPGO.h test/Profile/c-indirect-call.c Index: test/Profile/c-indirect-call.c === --- /dev/null +++ test/Profile/c-indirect-call.c @@ -0,0 +1,15 @@ +// Check the data structures emitted by instrumentation. +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-indirect-call.c %s -o - -emit-llvm -fprofile-instr-generate -mllvm -enable-value-profiling | FileCheck %s + +void (*foo)(void); + +int main(void) { +// CHECK: [[REG1:%[0-9]+]] = load void ()*, void ()** @foo, align 8 +// CHECK-NEXT: call void [[REG1]]() +// CHECK-NEXT: [[REG2:%[0-9]+]] = ptrtoint void ()* [[REG1]] to i64 +// CHECK-NEXT: call void @__llvm_profile_instrument_target(i64 [[REG2]], i8* bitcast ({ i32, i32, i64, i8*, i64*, i8*, i8*, [1 x i16] }* @__profd_main to i8*), i32 0) + foo(); + return 0; +} + +// CHECK: declare void @__llvm_profile_instrument_target(i64, i8*, i32) Index: lib/CodeGen/CodeGenPGO.h === --- lib/CodeGen/CodeGenPGO.h +++ lib/CodeGen/CodeGenPGO.h @@ -19,6 +19,7 @@ #include "CodeGenTypes.h" #include "clang/Frontend/CodeGenOptions.h" #include "llvm/ADT/StringMap.h" +#include "llvm/ProfileData/InstrProfReader.h" #include "llvm/Support/MemoryBuffer.h" #include @@ -32,20 +33,22 @@ std::string FuncName; llvm::GlobalVariable *FuncNameVar; + unsigned NumValueSites[llvm::IPVK_Last + 1]; unsigned NumRegionCounters; uint64_t FunctionHash; std::unique_ptr> RegionCounterMap; std::unique_ptr> StmtCountMap; + std::unique_ptr ProfRecord; std::vector RegionCounts; uint64_t CurrentRegionCount; /// \brief A flag that is set to true when this function doesn't need /// to have coverage mapping data. bool SkipCoverageMapping; public: CodeGenPGO(CodeGenModule &CGM) - : CGM(CGM), NumRegionCounters(0), FunctionHash(0), CurrentRegionCount(0), -SkipCoverageMapping(false) {} + : CGM(CGM), NumValueSites{0}, NumRegionCounters(0), +FunctionHash(0), CurrentRegionCount(0), SkipCoverageMapping(false) {} /// Whether or not we have PGO region data for the current function. This is /// false both when we have no data at all and when our data has been @@ -87,6 +90,9 @@ /// for an unused declaration. void emitEmptyCounterMapping(const Decl *D, StringRef FuncName, llvm::GlobalValue::LinkageTypes Linkage); + // Insert instrumentation or attach profile metadata at value sites + void valueProfile(CGBuilderTy &Builder, uint32_t ValueKind, +llvm::Instruction *ValueSite, llvm::Value *ValuePtr); private: void setFuncName(llvm::Function *Fn); void setFuncName(StringRef Name, llvm::GlobalValue::LinkageTypes Linkage); Index: lib/CodeGen/CodeGenPGO.cpp === --- lib/CodeGen/CodeGenPGO.cpp +++ lib/CodeGen/CodeGenPGO.cpp @@ -18,11 +18,14 @@ #include "clang/AST/StmtVisitor.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/MDBuilder.h" -#include "llvm/ProfileData/InstrProfReader.h" #include "llvm/Support/Endian.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MD5.h" +static llvm::cl::opt EnableValueProfiling( + "enable-value-profiling", llvm::cl::ZeroOrMore, + llvm::cl::desc("Enable value profiling"), llvm::cl::init(false)); + using namespace clang; using namespace CodeGen; @@ -740,21 +743,104 @@ Builder.getInt32(Counter)}); } +static inline std::string getRawFuncName(std::string PrefixedFunctionName) { + // For local symbols, the main file name is prepended to the function name + // to distinguish them. + std::size_t SeparatorPosition = PrefixedFunctionName.find(":"); + if (SeparatorPosition == std::string::npos) +return PrefixedFunctionName; + return PrefixedFunctionName.substr(++SeparatorPosition); +} + +// This method either inserts a call to the profile run-time during +// instrumentation or puts profile data into metadata for PGO use. +void CodeGenPGO::valueProfile(CGBuilderTy &Builder, uint32_t ValueKind, +llvm::Instruction *ValueSite, llvm::Value *ValuePtr) { + + if (!EnableValueProfiling) +return; + + if (!ValuePtr || !ValueSite || !Builder.GetInsertBlock()) +return; + + bool InstrumentValueSites = CGM.getCodeGenOpts().ProfileInstrGenerate; + llvm::IndexedInstrProfReader *PGOReader = CGM.getPGOReader(); + if (!InstrumentValueSites && !PGOReader) +return; + + llvm::LLVMContext &Ctx = CGM.getLLVMContext(); + if (I
Re: [PATCH] D8940: Clang changes for indirect call target profiling
betulb updated this revision to Diff 44657. betulb added a comment. Addressed vsk's comment on CallSite API use. http://reviews.llvm.org/D8940 Files: lib/CodeGen/CGCall.cpp lib/CodeGen/CodeGenPGO.cpp lib/CodeGen/CodeGenPGO.h test/Profile/c-indirect-call.c Index: test/Profile/c-indirect-call.c === --- /dev/null +++ test/Profile/c-indirect-call.c @@ -0,0 +1,15 @@ +// Check the data structures emitted by instrumentation. +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-indirect-call.c %s -o - -emit-llvm -fprofile-instr-generate -mllvm -enable-value-profiling | FileCheck %s + +void (*foo)(void); + +int main(void) { +// CHECK: [[REG1:%[0-9]+]] = load void ()*, void ()** @foo, align 8 +// CHECK-NEXT: call void [[REG1]]() +// CHECK-NEXT: [[REG2:%[0-9]+]] = ptrtoint void ()* [[REG1]] to i64 +// CHECK-NEXT: call void @__llvm_profile_instrument_target(i64 [[REG2]], i8* bitcast ({ i32, i32, i64, i8*, i64*, i8*, i8*, [1 x i16] }* @__profd_main to i8*), i32 0) + foo(); + return 0; +} + +// CHECK: declare void @__llvm_profile_instrument_target(i64, i8*, i32) Index: lib/CodeGen/CodeGenPGO.h === --- lib/CodeGen/CodeGenPGO.h +++ lib/CodeGen/CodeGenPGO.h @@ -19,6 +19,7 @@ #include "CodeGenTypes.h" #include "clang/Frontend/CodeGenOptions.h" #include "llvm/ADT/StringMap.h" +#include "llvm/ProfileData/InstrProfReader.h" #include "llvm/Support/MemoryBuffer.h" #include @@ -32,20 +33,22 @@ std::string FuncName; llvm::GlobalVariable *FuncNameVar; + unsigned NumValueSites[llvm::IPVK_Last + 1]; unsigned NumRegionCounters; uint64_t FunctionHash; std::unique_ptr> RegionCounterMap; std::unique_ptr> StmtCountMap; + std::unique_ptr ProfRecord; std::vector RegionCounts; uint64_t CurrentRegionCount; /// \brief A flag that is set to true when this function doesn't need /// to have coverage mapping data. bool SkipCoverageMapping; public: CodeGenPGO(CodeGenModule &CGM) - : CGM(CGM), NumRegionCounters(0), FunctionHash(0), CurrentRegionCount(0), -SkipCoverageMapping(false) {} + : CGM(CGM), NumValueSites{0}, NumRegionCounters(0), +FunctionHash(0), CurrentRegionCount(0), SkipCoverageMapping(false) {} /// Whether or not we have PGO region data for the current function. This is /// false both when we have no data at all and when our data has been @@ -87,6 +90,9 @@ /// for an unused declaration. void emitEmptyCounterMapping(const Decl *D, StringRef FuncName, llvm::GlobalValue::LinkageTypes Linkage); + // Insert instrumentation or attach profile metadata at value sites + void valueProfile(CGBuilderTy &Builder, uint32_t ValueKind, +llvm::Instruction *ValueSite, llvm::Value *ValuePtr); private: void setFuncName(llvm::Function *Fn); void setFuncName(StringRef Name, llvm::GlobalValue::LinkageTypes Linkage); Index: lib/CodeGen/CodeGenPGO.cpp === --- lib/CodeGen/CodeGenPGO.cpp +++ lib/CodeGen/CodeGenPGO.cpp @@ -18,11 +18,14 @@ #include "clang/AST/StmtVisitor.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/MDBuilder.h" -#include "llvm/ProfileData/InstrProfReader.h" #include "llvm/Support/Endian.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MD5.h" +static llvm::cl::opt EnableValueProfiling( + "enable-value-profiling", llvm::cl::ZeroOrMore, + llvm::cl::desc("Enable value profiling"), llvm::cl::init(false)); + using namespace clang; using namespace CodeGen; @@ -740,21 +743,104 @@ Builder.getInt32(Counter)}); } +static inline std::string getRawFuncName(std::string PrefixedFunctionName) { + // For local symbols, the main file name is prepended to the function name + // to distinguish them. + std::size_t SeparatorPosition = PrefixedFunctionName.find(":"); + if (SeparatorPosition == std::string::npos) +return PrefixedFunctionName; + return PrefixedFunctionName.substr(++SeparatorPosition); +} + +// This method either inserts a call to the profile run-time during +// instrumentation or puts profile data into metadata for PGO use. +void CodeGenPGO::valueProfile(CGBuilderTy &Builder, uint32_t ValueKind, +llvm::Instruction *ValueSite, llvm::Value *ValuePtr) { + + if (!EnableValueProfiling) +return; + + if (!ValuePtr || !ValueSite || !Builder.GetInsertBlock()) +return; + + bool InstrumentValueSites = CGM.getCodeGenOpts().ProfileInstrGenerate; + llvm::IndexedInstrProfReader *PGOReader = CGM.getPGOReader(); + if (!InstrumentValueSites && !PGOReader) +return; + + llvm::LLVMContext &Ctx = CGM.getLLVMContext(); + if (InstrumentValueSites && RegionCounterMap) { +auto *I8PtrTy = llvm::Type::getInt8PtrTy(Ctx); +llvm::Value *Args[5] = { + llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy), +
Re: [PATCH] D8940: Clang changes for indirect call target profiling
betulb added a comment. ping? http://reviews.llvm.org/D8940 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D8940: Clang changes for indirect call target profiling
betulb updated this revision to Diff 45550. betulb added a comment. In this revision: - Clang no longer attaches function names as metadata. - Bug fixed in checking the getNumValueSites return value. - Addressed review comments. http://reviews.llvm.org/D8940 Files: lib/CodeGen/CGCall.cpp lib/CodeGen/CodeGenPGO.cpp lib/CodeGen/CodeGenPGO.h test/Profile/c-indirect-call.c Index: test/Profile/c-indirect-call.c === --- /dev/null +++ test/Profile/c-indirect-call.c @@ -0,0 +1,15 @@ +// Check the data structures emitted by instrumentation. +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-indirect-call.c %s -o - -emit-llvm -fprofile-instr-generate -mllvm -enable-value-profiling | FileCheck %s + +void (*foo)(void); + +int main(void) { +// CHECK: [[REG1:%[0-9]+]] = load void ()*, void ()** @foo, align 8 +// CHECK-NEXT: call void [[REG1]]() +// CHECK-NEXT: [[REG2:%[0-9]+]] = ptrtoint void ()* [[REG1]] to i64 +// CHECK-NEXT: call void @__llvm_profile_instrument_target(i64 [[REG2]], i8* bitcast ({ i32, i32, i64, i8*, i64*, i8*, i8*, [1 x i16] }* @__profd_main to i8*), i32 0) + foo(); + return 0; +} + +// CHECK: declare void @__llvm_profile_instrument_target(i64, i8*, i32) Index: lib/CodeGen/CodeGenPGO.h === --- lib/CodeGen/CodeGenPGO.h +++ lib/CodeGen/CodeGenPGO.h @@ -19,6 +19,7 @@ #include "CodeGenTypes.h" #include "clang/Frontend/CodeGenOptions.h" #include "llvm/ADT/StringMap.h" +#include "llvm/ProfileData/InstrProfReader.h" #include "llvm/Support/MemoryBuffer.h" #include @@ -32,20 +33,22 @@ std::string FuncName; llvm::GlobalVariable *FuncNameVar; + unsigned NumValueSites[llvm::IPVK_Last + 1]; unsigned NumRegionCounters; uint64_t FunctionHash; std::unique_ptr> RegionCounterMap; std::unique_ptr> StmtCountMap; + std::unique_ptr ProfRecord; std::vector RegionCounts; uint64_t CurrentRegionCount; /// \brief A flag that is set to true when this function doesn't need /// to have coverage mapping data. bool SkipCoverageMapping; public: CodeGenPGO(CodeGenModule &CGM) - : CGM(CGM), NumRegionCounters(0), FunctionHash(0), CurrentRegionCount(0), -SkipCoverageMapping(false) {} + : CGM(CGM), NumValueSites{0}, NumRegionCounters(0), +FunctionHash(0), CurrentRegionCount(0), SkipCoverageMapping(false) {} /// Whether or not we have PGO region data for the current function. This is /// false both when we have no data at all and when our data has been @@ -87,6 +90,9 @@ /// for an unused declaration. void emitEmptyCounterMapping(const Decl *D, StringRef FuncName, llvm::GlobalValue::LinkageTypes Linkage); + // Insert instrumentation or attach profile metadata at value sites + void valueProfile(CGBuilderTy &Builder, uint32_t ValueKind, +llvm::Instruction *ValueSite, llvm::Value *ValuePtr); private: void setFuncName(llvm::Function *Fn); void setFuncName(StringRef Name, llvm::GlobalValue::LinkageTypes Linkage); Index: lib/CodeGen/CodeGenPGO.cpp === --- lib/CodeGen/CodeGenPGO.cpp +++ lib/CodeGen/CodeGenPGO.cpp @@ -18,11 +18,14 @@ #include "clang/AST/StmtVisitor.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/MDBuilder.h" -#include "llvm/ProfileData/InstrProfReader.h" #include "llvm/Support/Endian.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MD5.h" +static llvm::cl::opt EnableValueProfiling( + "enable-value-profiling", llvm::cl::ZeroOrMore, + llvm::cl::desc("Enable value profiling"), llvm::cl::init(false)); + using namespace clang; using namespace CodeGen; @@ -740,21 +743,95 @@ Builder.getInt32(Counter)}); } +// This method either inserts a call to the profile run-time during +// instrumentation or puts profile data into metadata for PGO use. +void CodeGenPGO::valueProfile(CGBuilderTy &Builder, uint32_t ValueKind, +llvm::Instruction *ValueSite, llvm::Value *ValuePtr) { + + if (!EnableValueProfiling) +return; + + if (!ValuePtr || !ValueSite || !Builder.GetInsertBlock()) +return; + + bool InstrumentValueSites = CGM.getCodeGenOpts().ProfileInstrGenerate; + if (InstrumentValueSites && RegionCounterMap) { +llvm::LLVMContext &Ctx = CGM.getLLVMContext(); +auto *I8PtrTy = llvm::Type::getInt8PtrTy(Ctx); +llvm::Value *Args[5] = { +llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy), +Builder.getInt64(FunctionHash), +Builder.CreatePtrToInt(ValuePtr, Builder.getInt64Ty()), +Builder.getInt32(ValueKind), +Builder.getInt32(NumValueSites[ValueKind]++) +}; +Builder.CreateCall( +CGM.getIntrinsic(llvm::Intrinsic::instrprof_value_profile), Args); +return; + } + + llvm::IndexedInstrProfReader *PGOReader = CGM.getPGOReader(); + if (PGORea
Re: [PATCH] D8940: Clang changes for indirect call target profiling
betulb marked 3 inline comments as done. Comment at: lib/CodeGen/CodeGenPGO.cpp:768 @@ +767,3 @@ +}; +Builder.CreateCall( +CGM.getIntrinsic(llvm::Intrinsic::instrprof_value_profile), Args); I removed the if check instead. It was not needed since the later lines do check on the presence of the instrumentation flags and the reader. However the old check was correct as is. http://reviews.llvm.org/D8940 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r258650 - Clang changes for value profiling
Author: betulb Date: Sat Jan 23 16:50:44 2016 New Revision: 258650 URL: http://llvm.org/viewvc/llvm-project?rev=258650&view=rev Log: Clang changes for value profiling Differential Revision: http://reviews.llvm.org/D8940 Added: cfe/trunk/test/Profile/c-indirect-call.c Modified: cfe/trunk/lib/CodeGen/CGCall.cpp cfe/trunk/lib/CodeGen/CodeGenPGO.cpp cfe/trunk/lib/CodeGen/CodeGenPGO.h Modified: cfe/trunk/lib/CodeGen/CGCall.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=258650&r1=258649&r2=258650&view=diff == --- cfe/trunk/lib/CodeGen/CGCall.cpp (original) +++ cfe/trunk/lib/CodeGen/CGCall.cpp Sat Jan 23 16:50:44 2016 @@ -3539,6 +3539,11 @@ RValue CodeGenFunction::EmitCall(const C CS.setAttributes(Attrs); CS.setCallingConv(static_cast(CallingConv)); + // Insert instrumentation or attach profile metadata at indirect call sites + if (!CS.getCalledFunction()) +PGO.valueProfile(Builder, llvm::IPVK_IndirectCallTarget, + CS.getInstruction(), Callee); + // In ObjC ARC mode with no ObjC ARC exception safety, tell the ARC // optimizer it can aggressively ignore unwind edges. if (CGM.getLangOpts().ObjCAutoRefCount) Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.cpp?rev=258650&r1=258649&r2=258650&view=diff == --- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Sat Jan 23 16:50:44 2016 @@ -18,11 +18,14 @@ #include "clang/AST/StmtVisitor.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/MDBuilder.h" -#include "llvm/ProfileData/InstrProfReader.h" #include "llvm/Support/Endian.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MD5.h" +static llvm::cl::opt EnableValueProfiling( + "enable-value-profiling", llvm::cl::ZeroOrMore, + llvm::cl::desc("Enable value profiling"), llvm::cl::init(false)); + using namespace clang; using namespace CodeGen; @@ -740,12 +743,83 @@ void CodeGenPGO::emitCounterIncrement(CG Builder.getInt32(Counter)}); } +// This method either inserts a call to the profile run-time during +// instrumentation or puts profile data into metadata for PGO use. +void CodeGenPGO::valueProfile(CGBuilderTy &Builder, uint32_t ValueKind, +llvm::Instruction *ValueSite, llvm::Value *ValuePtr) { + + if (!EnableValueProfiling) +return; + + if (!ValuePtr || !ValueSite || !Builder.GetInsertBlock()) +return; + + bool InstrumentValueSites = CGM.getCodeGenOpts().ProfileInstrGenerate; + if (InstrumentValueSites && RegionCounterMap) { +llvm::LLVMContext &Ctx = CGM.getLLVMContext(); +auto *I8PtrTy = llvm::Type::getInt8PtrTy(Ctx); +llvm::Value *Args[5] = { +llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy), +Builder.getInt64(FunctionHash), +Builder.CreatePtrToInt(ValuePtr, Builder.getInt64Ty()), +Builder.getInt32(ValueKind), +Builder.getInt32(NumValueSites[ValueKind]++) +}; +Builder.CreateCall( +CGM.getIntrinsic(llvm::Intrinsic::instrprof_value_profile), Args); +return; + } + + llvm::IndexedInstrProfReader *PGOReader = CGM.getPGOReader(); + if (PGOReader && haveRegionCounts()) { +// We record the top most called three functions at each call site. +// Profile metadata contains "VP" string identifying this metadata +// as value profiling data, then a uint32_t value for the value profiling +// kind, a uint64_t value for the total number of times the call is +// executed, followed by the function hash and execution count (uint64_t) +// pairs for each function. +if (NumValueSites[ValueKind] >= ProfRecord->getNumValueSites(ValueKind)) + return; +uint32_t NV = ProfRecord->getNumValueDataForSite(ValueKind, + NumValueSites[ValueKind]); +std::unique_ptr VD = +ProfRecord->getValueForSite(ValueKind, NumValueSites[ValueKind]); + +uint64_t Sum = 0; +for (uint32_t I = 0; I < NV; ++I) + Sum += VD[I].Count; + +llvm::LLVMContext &Ctx = CGM.getLLVMContext(); +llvm::MDBuilder MDHelper(Ctx); +SmallVector Vals; +Vals.push_back(MDHelper.createString("VP")); +Vals.push_back(MDHelper.createConstant( +llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx), ValueKind))); +Vals.push_back(MDHelper.createConstant( +llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), Sum))); + +uint32_t MDCount = 3; +for (uint32_t I = 0; I < NV; ++I) { + Vals.push_back(MDHelper.createConstant( + llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), VD[I].Value))); + Vals.push_back(MDHelper.createConstant( + llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), VD[I].Count))); + if (--MDCount ==
Re: [PATCH] D8940: Clang changes for indirect call target profiling
This revision was automatically updated to reflect the committed changes. Closed by commit rL258650: Clang changes for value profiling (authored by betulb). Changed prior to commit: http://reviews.llvm.org/D8940?vs=45550&id=45813#toc Repository: rL LLVM http://reviews.llvm.org/D8940 Files: cfe/trunk/lib/CodeGen/CGCall.cpp cfe/trunk/lib/CodeGen/CodeGenPGO.cpp cfe/trunk/lib/CodeGen/CodeGenPGO.h cfe/trunk/test/Profile/c-indirect-call.c Index: cfe/trunk/lib/CodeGen/CGCall.cpp === --- cfe/trunk/lib/CodeGen/CGCall.cpp +++ cfe/trunk/lib/CodeGen/CGCall.cpp @@ -3539,6 +3539,11 @@ CS.setAttributes(Attrs); CS.setCallingConv(static_cast(CallingConv)); + // Insert instrumentation or attach profile metadata at indirect call sites + if (!CS.getCalledFunction()) +PGO.valueProfile(Builder, llvm::IPVK_IndirectCallTarget, + CS.getInstruction(), Callee); + // In ObjC ARC mode with no ObjC ARC exception safety, tell the ARC // optimizer it can aggressively ignore unwind edges. if (CGM.getLangOpts().ObjCAutoRefCount) Index: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp === --- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp +++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp @@ -18,11 +18,14 @@ #include "clang/AST/StmtVisitor.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/MDBuilder.h" -#include "llvm/ProfileData/InstrProfReader.h" #include "llvm/Support/Endian.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MD5.h" +static llvm::cl::opt EnableValueProfiling( + "enable-value-profiling", llvm::cl::ZeroOrMore, + llvm::cl::desc("Enable value profiling"), llvm::cl::init(false)); + using namespace clang; using namespace CodeGen; @@ -740,21 +743,95 @@ Builder.getInt32(Counter)}); } +// This method either inserts a call to the profile run-time during +// instrumentation or puts profile data into metadata for PGO use. +void CodeGenPGO::valueProfile(CGBuilderTy &Builder, uint32_t ValueKind, +llvm::Instruction *ValueSite, llvm::Value *ValuePtr) { + + if (!EnableValueProfiling) +return; + + if (!ValuePtr || !ValueSite || !Builder.GetInsertBlock()) +return; + + bool InstrumentValueSites = CGM.getCodeGenOpts().ProfileInstrGenerate; + if (InstrumentValueSites && RegionCounterMap) { +llvm::LLVMContext &Ctx = CGM.getLLVMContext(); +auto *I8PtrTy = llvm::Type::getInt8PtrTy(Ctx); +llvm::Value *Args[5] = { +llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy), +Builder.getInt64(FunctionHash), +Builder.CreatePtrToInt(ValuePtr, Builder.getInt64Ty()), +Builder.getInt32(ValueKind), +Builder.getInt32(NumValueSites[ValueKind]++) +}; +Builder.CreateCall( +CGM.getIntrinsic(llvm::Intrinsic::instrprof_value_profile), Args); +return; + } + + llvm::IndexedInstrProfReader *PGOReader = CGM.getPGOReader(); + if (PGOReader && haveRegionCounts()) { +// We record the top most called three functions at each call site. +// Profile metadata contains "VP" string identifying this metadata +// as value profiling data, then a uint32_t value for the value profiling +// kind, a uint64_t value for the total number of times the call is +// executed, followed by the function hash and execution count (uint64_t) +// pairs for each function. +if (NumValueSites[ValueKind] >= ProfRecord->getNumValueSites(ValueKind)) + return; +uint32_t NV = ProfRecord->getNumValueDataForSite(ValueKind, + NumValueSites[ValueKind]); +std::unique_ptr VD = +ProfRecord->getValueForSite(ValueKind, NumValueSites[ValueKind]); + +uint64_t Sum = 0; +for (uint32_t I = 0; I < NV; ++I) + Sum += VD[I].Count; + +llvm::LLVMContext &Ctx = CGM.getLLVMContext(); +llvm::MDBuilder MDHelper(Ctx); +SmallVector Vals; +Vals.push_back(MDHelper.createString("VP")); +Vals.push_back(MDHelper.createConstant( +llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx), ValueKind))); +Vals.push_back(MDHelper.createConstant( +llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), Sum))); + +uint32_t MDCount = 3; +for (uint32_t I = 0; I < NV; ++I) { + Vals.push_back(MDHelper.createConstant( + llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), VD[I].Value))); + Vals.push_back(MDHelper.createConstant( + llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), VD[I].Count))); + if (--MDCount == 0) +break; +} +ValueSite->setMetadata( +llvm::LLVMContext::MD_prof, llvm::MDNode::get(Ctx, Vals)); +NumValueSites[ValueKind]++; + } +} + void CodeGenPGO::loadRegionCounts(llvm::IndexedInstrProfReader *PGOReader, bool IsInMainFile) { CGM.getPGOStats().addVisited(IsInMainFile); RegionCounts.clear(
Re: [PATCH] D8940: Clang changes for indirect call target profiling
betulb added a comment. Committed in revision 258650. Repository: rL LLVM http://reviews.llvm.org/D8940 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r258652 - [PGO] Windows buildbot failure fix. [NFC]
Author: betulb Date: Sat Jan 23 18:56:19 2016 New Revision: 258652 URL: http://llvm.org/viewvc/llvm-project?rev=258652&view=rev Log: [PGO] Windows buildbot failure fix. [NFC] Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.h Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.h?rev=258652&r1=258651&r2=258652&view=diff == --- cfe/trunk/lib/CodeGen/CodeGenPGO.h (original) +++ cfe/trunk/lib/CodeGen/CodeGenPGO.h Sat Jan 23 18:56:19 2016 @@ -21,6 +21,7 @@ #include "llvm/ADT/StringMap.h" #include "llvm/ProfileData/InstrProfReader.h" #include "llvm/Support/MemoryBuffer.h" +#include #include namespace clang { @@ -33,7 +34,7 @@ private: std::string FuncName; llvm::GlobalVariable *FuncNameVar; - unsigned NumValueSites[llvm::IPVK_Last + 1]; + std::array NumValueSites; unsigned NumRegionCounters; uint64_t FunctionHash; std::unique_ptr> RegionCounterMap; @@ -47,7 +48,7 @@ private: public: CodeGenPGO(CodeGenModule &CGM) - : CGM(CGM), NumValueSites{0}, NumRegionCounters(0), + : CGM(CGM), NumValueSites({{0}}), NumRegionCounters(0), FunctionHash(0), CurrentRegionCount(0), SkipCoverageMapping(false) {} /// Whether or not we have PGO region data for the current function. This is ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
RE: [PATCH] D8940: Clang changes for indirect call target profiling
http://reviews.llvm.org/rL258652 should fix the issue. Please let me know if you continue to see failures. -Betul -Original Message- From: Oleksiy Vyalov [mailto:ovya...@google.com] Sent: Saturday, January 23, 2016 5:10 PM To: bet...@codeaurora.org; m...@justinbogner.com; dnovi...@google.com; x...@google.com; davi...@google.com Cc: ovya...@google.com; v...@apple.com; ib...@codeaurora.org; cfe-commits@lists.llvm.org Subject: Re: [PATCH] D8940: Clang changes for indirect call target profiling ovyalov added a subscriber: ovyalov. ovyalov added a comment. It seems this CL is causing Window build to fail - http://lab.llvm.org:8011/builders/lldb-windows7-android/builds/3885 Could you take a look? Repository: rL LLVM http://reviews.llvm.org/D8940 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r253404 - [PGO] Removed unused code. [NFC]
Author: betulb Date: Tue Nov 17 18:14:08 2015 New Revision: 253404 URL: http://llvm.org/viewvc/llvm-project?rev=253404&view=rev Log: [PGO] Removed unused code. [NFC] Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.h Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.h?rev=253404&r1=253403&r2=253404&view=diff == --- cfe/trunk/lib/CodeGen/CodeGenPGO.h (original) +++ cfe/trunk/lib/CodeGen/CodeGenPGO.h Tue Nov 17 18:14:08 2015 @@ -92,7 +92,6 @@ public: private: void setFuncName(llvm::Function *Fn); void setFuncName(StringRef Name, llvm::GlobalValue::LinkageTypes Linkage); - void createFuncNameVar(llvm::GlobalValue::LinkageTypes Linkage); void mapRegionCounters(const Decl *D); void computeRegionCounts(const Decl *D); void applyFunctionAttributes(llvm::IndexedInstrProfReader *PGOReader, ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r253485 - [PGO] Test update for revision 253484.
Author: betulb Date: Wed Nov 18 12:15:55 2015 New Revision: 253485 URL: http://llvm.org/viewvc/llvm-project?rev=253485&view=rev Log: [PGO] Test update for revision 253484. Modified: cfe/trunk/test/Profile/c-linkage-available_externally.c Modified: cfe/trunk/test/Profile/c-linkage-available_externally.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/c-linkage-available_externally.c?rev=253485&r1=253484&r2=253485&view=diff == --- cfe/trunk/test/Profile/c-linkage-available_externally.c (original) +++ cfe/trunk/test/Profile/c-linkage-available_externally.c Wed Nov 18 12:15:55 2015 @@ -5,7 +5,7 @@ // CHECK: @__llvm_profile_name_foo = linkonce_odr hidden constant [3 x i8] c"foo", section "__DATA,__llvm_prf_names", align 1 // CHECK: @__llvm_profile_counters_foo = linkonce_odr hidden global [1 x i64] zeroinitializer, section "__DATA,__llvm_prf_cnts", align 8 -// CHECK: @__llvm_profile_data_foo = linkonce_odr hidden constant { i32, i32, i64, i8*, i64* } { i32 3, i32 1, i64 {{[0-9]+}}, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__llvm_profile_name_foo, i32 0, i32 0), i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__llvm_profile_counters_foo, i32 0, i32 0) }, section "__DATA,__llvm_prf_data", align 8 +// CHECK: @__llvm_profile_data_foo = linkonce_odr hidden global { i32, i32, i64, i8*, i64*, i8*, i8*, [1 x i16] } { i32 3, i32 1, i64 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__llvm_profile_name_foo, i32 0, i32 0), i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__llvm_profile_counters_foo, i32 0, i32 0), i8* null, i8* null, [1 x i16] zeroinitializer }, section "__DATA,__llvm_prf_data", align 8 inline int foo(void) { return 1; } int main(void) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D8940: Clang changes for indirect call target profiling
betulb added a comment. No it's not. I need to replace the API's w/ the recent ones for retrieving the value profile data and add the flag definition for -fprofile-values. This was off the radar due to other commitments. I'll get back to this beginning of this week. -Betul http://reviews.llvm.org/D8940 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits