| From ba72e3476bfd8f588c288f87048199a5e6f7a0ee Mon Sep 17 00:00:00 2001 |
| From: Pirama Arumuga Nainar <pirama@google.com> |
| Date: Wed, 12 Feb 2020 10:40:09 -0800 |
| Subject: [ANDROID] Do not record function addresses if value profiling is |
| disabled |
| |
| Temporary change until a proper fix is merged to upstream. |
| |
| Don't recording function addresses in __llvm_prf_data when value |
| profiling is turned off. This is safe for Android, where we don't use |
| value profiling. |
| |
| Functional change: needs -mllvm -enable-value-profiling to work with LTO |
| |
| The proper fix is to use associated metadata to link a __llvm_prf_data |
| of a function with the function itself so the linker can discard the |
| __llvm_prf_data if the function itself is discarded. See |
| http://lists.llvm.org/pipermail/llvm-dev/2019-December/137363.html for |
| more details. |
| |
| Change-Id: Ifcb04349e71e20ae3ef4bb82ebf8ac064fc59169 |
| --- |
| clang/lib/CodeGen/CodeGenPGO.cpp | 5 +---- |
| llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp | 8 ++++++++ |
| 2 files changed, 9 insertions(+), 4 deletions(-) |
| |
| diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp |
| index e525abe979e..fee33883ac0 100644 |
| --- a/clang/lib/CodeGen/CodeGenPGO.cpp |
| +++ b/clang/lib/CodeGen/CodeGenPGO.cpp |
| @@ -21,10 +21,7 @@ |
| #include "llvm/Support/FileSystem.h" |
| #include "llvm/Support/MD5.h" |
| |
| -static llvm::cl::opt<bool> |
| - EnableValueProfiling("enable-value-profiling", llvm::cl::ZeroOrMore, |
| - llvm::cl::desc("Enable value profiling"), |
| - llvm::cl::Hidden, llvm::cl::init(false)); |
| +extern llvm::cl::opt<bool> EnableValueProfiling; |
| |
| using namespace clang; |
| using namespace CodeGen; |
| diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp |
| index 63c2b807896..6aba06fbb65 100644 |
| --- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp |
| +++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp |
| @@ -71,6 +71,11 @@ cl::opt<unsigned> MemOPSizeLarge( |
| "Value of 0 disables the large value profiling."), |
| cl::init(8192)); |
| |
| +llvm::cl::opt<bool> |
| + EnableValueProfiling("enable-value-profiling", llvm::cl::ZeroOrMore, |
| + llvm::cl::desc("Enable value profiling"), |
| + llvm::cl::Hidden, llvm::cl::init(false)); |
| + |
| namespace { |
| |
| cl::opt<bool> DoNameCompression("enable-name-compression", |
| @@ -678,6 +683,9 @@ static std::string getVarName(InstrProfIncrementInst *Inc, StringRef Prefix) { |
| } |
| |
| static inline bool shouldRecordFunctionAddr(Function *F) { |
| + if (!EnableValueProfiling) |
| + return false; |
| + |
| // Check the linkage |
| bool HasAvailableExternallyLinkage = F->hasAvailableExternallyLinkage(); |
| if (!F->hasLinkOnceLinkage() && !F->hasLocalLinkage() && |
| -- |
| 2.25.0.225.g125e21ebc7-goog |
| |