diff options
author | Xinliang David Li <davidxl@google.com> | 2015-11-22 05:42:31 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2015-11-22 05:42:31 +0000 |
commit | 416b0b1dd8d918841bb78ab8b5d79c12b3ebf263 (patch) | |
tree | 1ebb6359614f6c0fa0db2731855c78c605494634 | |
parent | add2047b2c6055c76a403e4e989df35ca5ce68b0 (diff) |
[PGO] move names of runtime sections definitions to InstrProfData.inc
In profile runtime implementation for Darwin, Linux and FreeBSD, the
names of sections holding profile control/counter/naming data need
to be known by the runtime in order to locate the start/end of the
data. Moving the name definitions to the common file to specify the
connection.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253814 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/ProfileData/InstrProf.h | 15 | ||||
-rw-r--r-- | include/llvm/ProfileData/InstrProfData.inc | 41 | ||||
-rw-r--r-- | lib/Transforms/Instrumentation/InstrProfiling.cpp | 2 |
3 files changed, 51 insertions, 7 deletions
diff --git a/include/llvm/ProfileData/InstrProf.h b/include/llvm/ProfileData/InstrProf.h index 4cd4ef9ee8f..6eea531e589 100644 --- a/include/llvm/ProfileData/InstrProf.h +++ b/include/llvm/ProfileData/InstrProf.h @@ -37,19 +37,28 @@ class Module; /// Return the name of data section containing profile counter variables. inline StringRef getInstrProfCountersSectionName(bool AddSegment) { - return AddSegment ? "__DATA,__llvm_prf_cnts" : "__llvm_prf_cnts"; + return AddSegment ? "__DATA," INSTR_PROF_CNTS_SECT_NAME_STR + : INSTR_PROF_CNTS_SECT_NAME_STR; } /// Return the name of data section containing names of instrumented /// functions. inline StringRef getInstrProfNameSectionName(bool AddSegment) { - return AddSegment ? "__DATA,__llvm_prf_names" : "__llvm_prf_names"; + return AddSegment ? "__DATA," INSTR_PROF_NAME_SECT_NAME_STR + : INSTR_PROF_NAME_SECT_NAME_STR; } /// Return the name of the data section containing per-function control /// data. inline StringRef getInstrProfDataSectionName(bool AddSegment) { - return AddSegment ? "__DATA,__llvm_prf_data" : "__llvm_prf_data"; + return AddSegment ? "__DATA," INSTR_PROF_DATA_SECT_NAME_STR + : INSTR_PROF_DATA_SECT_NAME_STR; +} + +/// Return the name profile runtime entry point to do value profiling +/// for a given site. +inline StringRef getInstrProfValueProfFuncName() { + return INSTR_PROF_VALUE_PROF_FUNC_STR; } /// Return the name of the section containing function coverage mapping diff --git a/include/llvm/ProfileData/InstrProfData.inc b/include/llvm/ProfileData/InstrProfData.inc index 1452baeb06f..31173cb7ee6 100644 --- a/include/llvm/ProfileData/InstrProfData.inc +++ b/include/llvm/ProfileData/InstrProfData.inc @@ -14,9 +14,10 @@ * or both. * * The file has two identical copies. The master copy lives in LLVM and - * the other one sits in compiler-rt/lib/profile directory. Changes can only - * be made directly made in the master copy. Whenever the master copy changes, - * the compiler-rt copy needs to be kept in sync with the master. + * the other one sits in compiler-rt/lib/profile directory. To make changes + * in this file, first modify the master copy and copy it over to compiler-rt. + * Testing of any change in this file can start only after the two copies are + * synced up. * * The first part of the file includes macros that defines types, names, and * initializers for the member fields of the core data structures. The field @@ -176,6 +177,13 @@ COVMAP_FUNC_RECORD(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \ #ifndef INSTR_PROF_DATA_INC_ #define INSTR_PROF_DATA_INC_ +/* Helper macros. */ +#define INSTR_PROF_SIMPLE_QUOTE(x) #x +#define INSTR_PROF_QUOTE(x) INSTR_PROF_SIMPLE_QUOTE(x) +#define INSTR_PROF_SIMPLE_CONCAT(x,y) x ## y +#define INSTR_PROF_CONCAT(x,y) INSTR_PROF_SIMPLE_CONCAT(x,y) + + /* Magic number to detect file format and endianness. * Use 255 at one end, since no UTF-8 file can use that character. Avoid 0, * so that utilities, like strings, don't grab it as a string. 129 is also @@ -195,6 +203,33 @@ COVMAP_FUNC_RECORD(const uint64_t, llvm::Type::getInt64Ty(Ctx), FuncHash, \ /* Raw profile format version. */ #define INSTR_PROF_RAW_VERSION 2 +/* Runtime section names and name strings. */ +#define INSTR_PROF_DATA_SECT_NAME __llvm_prf_data +#define INSTR_PROF_NAME_SECT_NAME __llvm_prf_names +#define INSTR_PROF_CNTS_SECT_NAME __llvm_prf_cnts + +#define INSTR_PROF_DATA_SECT_NAME_STR \ + INSTR_PROF_QUOTE(INSTR_PROF_DATA_SECT_NAME) +#define INSTR_PROF_NAME_SECT_NAME_STR \ + INSTR_PROF_QUOTE(INSTR_PROF_NAME_SECT_NAME) +#define INSTR_PROF_CNTS_SECT_NAME_STR \ + INSTR_PROF_QUOTE(INSTR_PROF_CNTS_SECT_NAME) + +/* Macros to define start/stop section symbol for a given + * section on Linux. For instance + * INSTR_PROF_SECT_START(INSTR_PROF_DATA_SECT_NAME) will + * expand to __start___llvm_prof_data + */ +#define INSTR_PROF_SECT_START(Sect) \ + INSTR_PROF_CONCAT(__start_,Sect) +#define INSTR_PROF_SECT_STOP(Sect) \ + INSTR_PROF_CONCAT(__stop_,Sect) + +/* Value Profiling API linkage name. */ +#define INSTR_PROF_VALUE_PROF_FUNC __llvm_profile_instrument_target +#define INSTR_PROF_VALUE_PROF_FUNC_STR \ + INSTR_PROF_QUOTE(INSTR_PROF_VALUE_PROF_FUNC) + #endif /* INSTR_PROF_DATA_INC_ */ #else diff --git a/lib/Transforms/Instrumentation/InstrProfiling.cpp b/lib/Transforms/Instrumentation/InstrProfiling.cpp index a70bf27ed7b..03b404c1f3b 100644 --- a/lib/Transforms/Instrumentation/InstrProfiling.cpp +++ b/lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -181,7 +181,7 @@ static Constant *getOrInsertValueProfilingCall(Module &M) { }; auto *ValueProfilingCallTy = FunctionType::get(ReturnTy, makeArrayRef(ParamTypes), false); - return M.getOrInsertFunction("__llvm_profile_instrument_target", + return M.getOrInsertFunction(getInstrProfValueProfFuncName(), ValueProfilingCallTy); } |