InstrProf.h 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- InstrProf.h - Instrumented profiling format support ------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // Instrumentation-based profiling data is generated by instrumented
  15. // binaries through library functions in compiler-rt, and read by the clang
  16. // frontend to feed PGO.
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_PROFILEDATA_INSTRPROF_H
  20. #define LLVM_PROFILEDATA_INSTRPROF_H
  21. #include "llvm/ADT/ArrayRef.h"
  22. #include "llvm/ADT/STLExtras.h"
  23. #include "llvm/ADT/StringRef.h"
  24. #include "llvm/ADT/StringSet.h"
  25. #include "llvm/ADT/Triple.h"
  26. #include "llvm/IR/GlobalValue.h"
  27. #include "llvm/IR/ProfileSummary.h"
  28. #include "llvm/ProfileData/InstrProfData.inc"
  29. #include "llvm/Support/CommandLine.h"
  30. #include "llvm/Support/Compiler.h"
  31. #include "llvm/Support/Endian.h"
  32. #include "llvm/Support/Error.h"
  33. #include "llvm/Support/ErrorHandling.h"
  34. #include "llvm/Support/Host.h"
  35. #include "llvm/Support/MD5.h"
  36. #include "llvm/Support/MathExtras.h"
  37. #include "llvm/Support/raw_ostream.h"
  38. #include <algorithm>
  39. #include <cassert>
  40. #include <cstddef>
  41. #include <cstdint>
  42. #include <cstring>
  43. #include <list>
  44. #include <memory>
  45. #include <string>
  46. #include <system_error>
  47. #include <utility>
  48. #include <vector>
  49. namespace llvm {
  50. class Function;
  51. class GlobalVariable;
  52. struct InstrProfRecord;
  53. class InstrProfSymtab;
  54. class Instruction;
  55. class MDNode;
  56. class Module;
  57. enum InstrProfSectKind {
  58. #define INSTR_PROF_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) Kind,
  59. #include "llvm/ProfileData/InstrProfData.inc"
  60. };
  61. /// Return the name of the profile section corresponding to \p IPSK.
  62. ///
  63. /// The name of the section depends on the object format type \p OF. If
  64. /// \p AddSegmentInfo is true, a segment prefix and additional linker hints may
  65. /// be added to the section name (this is the default).
  66. std::string getInstrProfSectionName(InstrProfSectKind IPSK,
  67. Triple::ObjectFormatType OF,
  68. bool AddSegmentInfo = true);
  69. /// Return the name profile runtime entry point to do value profiling
  70. /// for a given site.
  71. inline StringRef getInstrProfValueProfFuncName() {
  72. return INSTR_PROF_VALUE_PROF_FUNC_STR;
  73. }
  74. /// Return the name profile runtime entry point to do memop size value
  75. /// profiling.
  76. inline StringRef getInstrProfValueProfMemOpFuncName() {
  77. return INSTR_PROF_VALUE_PROF_MEMOP_FUNC_STR;
  78. }
  79. /// Return the name prefix of variables containing instrumented function names.
  80. inline StringRef getInstrProfNameVarPrefix() { return "__profn_"; }
  81. /// Return the name prefix of variables containing per-function control data.
  82. inline StringRef getInstrProfDataVarPrefix() { return "__profd_"; }
  83. /// Return the name prefix of profile counter variables.
  84. inline StringRef getInstrProfCountersVarPrefix() { return "__profc_"; }
  85. /// Return the name prefix of value profile variables.
  86. inline StringRef getInstrProfValuesVarPrefix() { return "__profvp_"; }
  87. /// Return the name of value profile node array variables:
  88. inline StringRef getInstrProfVNodesVarName() { return "__llvm_prf_vnodes"; }
  89. /// Return the name of the variable holding the strings (possibly compressed)
  90. /// of all function's PGO names.
  91. inline StringRef getInstrProfNamesVarName() {
  92. return "__llvm_prf_nm";
  93. }
  94. /// Return the name of a covarage mapping variable (internal linkage)
  95. /// for each instrumented source module. Such variables are allocated
  96. /// in the __llvm_covmap section.
  97. inline StringRef getCoverageMappingVarName() {
  98. return "__llvm_coverage_mapping";
  99. }
  100. /// Return the name of the internal variable recording the array
  101. /// of PGO name vars referenced by the coverage mapping. The owning
  102. /// functions of those names are not emitted by FE (e.g, unused inline
  103. /// functions.)
  104. inline StringRef getCoverageUnusedNamesVarName() {
  105. return "__llvm_coverage_names";
  106. }
  107. /// Return the name of function that registers all the per-function control
  108. /// data at program startup time by calling __llvm_register_function. This
  109. /// function has internal linkage and is called by __llvm_profile_init
  110. /// runtime method. This function is not generated for these platforms:
  111. /// Darwin, Linux, and FreeBSD.
  112. inline StringRef getInstrProfRegFuncsName() {
  113. return "__llvm_profile_register_functions";
  114. }
  115. /// Return the name of the runtime interface that registers per-function control
  116. /// data for one instrumented function.
  117. inline StringRef getInstrProfRegFuncName() {
  118. return "__llvm_profile_register_function";
  119. }
  120. /// Return the name of the runtime interface that registers the PGO name strings.
  121. inline StringRef getInstrProfNamesRegFuncName() {
  122. return "__llvm_profile_register_names_function";
  123. }
  124. /// Return the name of the runtime initialization method that is generated by
  125. /// the compiler. The function calls __llvm_profile_register_functions and
  126. /// __llvm_profile_override_default_filename functions if needed. This function
  127. /// has internal linkage and invoked at startup time via init_array.
  128. inline StringRef getInstrProfInitFuncName() { return "__llvm_profile_init"; }
  129. /// Return the name of the hook variable defined in profile runtime library.
  130. /// A reference to the variable causes the linker to link in the runtime
  131. /// initialization module (which defines the hook variable).
  132. inline StringRef getInstrProfRuntimeHookVarName() {
  133. return INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_RUNTIME_VAR);
  134. }
  135. /// Return the name of the compiler generated function that references the
  136. /// runtime hook variable. The function is a weak global.
  137. inline StringRef getInstrProfRuntimeHookVarUseFuncName() {
  138. return "__llvm_profile_runtime_user";
  139. }
  140. inline StringRef getInstrProfCounterBiasVarName() {
  141. return "__llvm_profile_counter_bias";
  142. }
  143. /// Return the marker used to separate PGO names during serialization.
  144. inline StringRef getInstrProfNameSeparator() { return "\01"; }
  145. /// Return the modified name for function \c F suitable to be
  146. /// used the key for profile lookup. Variable \c InLTO indicates if this
  147. /// is called in LTO optimization passes.
  148. std::string getPGOFuncName(const Function &F, bool InLTO = false,
  149. uint64_t Version = INSTR_PROF_INDEX_VERSION);
  150. /// Return the modified name for a function suitable to be
  151. /// used the key for profile lookup. The function's original
  152. /// name is \c RawFuncName and has linkage of type \c Linkage.
  153. /// The function is defined in module \c FileName.
  154. std::string getPGOFuncName(StringRef RawFuncName,
  155. GlobalValue::LinkageTypes Linkage,
  156. StringRef FileName,
  157. uint64_t Version = INSTR_PROF_INDEX_VERSION);
  158. /// Return the name of the global variable used to store a function
  159. /// name in PGO instrumentation. \c FuncName is the name of the function
  160. /// returned by the \c getPGOFuncName call.
  161. std::string getPGOFuncNameVarName(StringRef FuncName,
  162. GlobalValue::LinkageTypes Linkage);
  163. /// Create and return the global variable for function name used in PGO
  164. /// instrumentation. \c FuncName is the name of the function returned
  165. /// by \c getPGOFuncName call.
  166. GlobalVariable *createPGOFuncNameVar(Function &F, StringRef PGOFuncName);
  167. /// Create and return the global variable for function name used in PGO
  168. /// instrumentation. /// \c FuncName is the name of the function
  169. /// returned by \c getPGOFuncName call, \c M is the owning module,
  170. /// and \c Linkage is the linkage of the instrumented function.
  171. GlobalVariable *createPGOFuncNameVar(Module &M,
  172. GlobalValue::LinkageTypes Linkage,
  173. StringRef PGOFuncName);
  174. /// Return the initializer in string of the PGO name var \c NameVar.
  175. StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar);
  176. /// Given a PGO function name, remove the filename prefix and return
  177. /// the original (static) function name.
  178. StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName,
  179. StringRef FileName = "<unknown>");
  180. /// Given a vector of strings (function PGO names) \c NameStrs, the
  181. /// method generates a combined string \c Result thatis ready to be
  182. /// serialized. The \c Result string is comprised of three fields:
  183. /// The first field is the legnth of the uncompressed strings, and the
  184. /// the second field is the length of the zlib-compressed string.
  185. /// Both fields are encoded in ULEB128. If \c doCompress is false, the
  186. /// third field is the uncompressed strings; otherwise it is the
  187. /// compressed string. When the string compression is off, the
  188. /// second field will have value zero.
  189. Error collectPGOFuncNameStrings(ArrayRef<std::string> NameStrs,
  190. bool doCompression, std::string &Result);
  191. /// Produce \c Result string with the same format described above. The input
  192. /// is vector of PGO function name variables that are referenced.
  193. Error collectPGOFuncNameStrings(ArrayRef<GlobalVariable *> NameVars,
  194. std::string &Result, bool doCompression = true);
  195. /// \c NameStrings is a string composed of one of more sub-strings encoded in
  196. /// the format described above. The substrings are separated by 0 or more zero
  197. /// bytes. This method decodes the string and populates the \c Symtab.
  198. Error readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab);
  199. /// Check if INSTR_PROF_RAW_VERSION_VAR is defined. This global is only being
  200. /// set in IR PGO compilation.
  201. bool isIRPGOFlagSet(const Module *M);
  202. /// Check if we can safely rename this Comdat function. Instances of the same
  203. /// comdat function may have different control flows thus can not share the
  204. /// same counter variable.
  205. bool canRenameComdatFunc(const Function &F, bool CheckAddressTaken = false);
  206. enum InstrProfValueKind : uint32_t {
  207. #define VALUE_PROF_KIND(Enumerator, Value, Descr) Enumerator = Value,
  208. #include "llvm/ProfileData/InstrProfData.inc"
  209. };
  210. /// Get the value profile data for value site \p SiteIdx from \p InstrProfR
  211. /// and annotate the instruction \p Inst with the value profile meta data.
  212. /// Annotate up to \p MaxMDCount (default 3) number of records per value site.
  213. void annotateValueSite(Module &M, Instruction &Inst,
  214. const InstrProfRecord &InstrProfR,
  215. InstrProfValueKind ValueKind, uint32_t SiteIndx,
  216. uint32_t MaxMDCount = 3);
  217. /// Same as the above interface but using an ArrayRef, as well as \p Sum.
  218. void annotateValueSite(Module &M, Instruction &Inst,
  219. ArrayRef<InstrProfValueData> VDs, uint64_t Sum,
  220. InstrProfValueKind ValueKind, uint32_t MaxMDCount);
  221. /// Extract the value profile data from \p Inst which is annotated with
  222. /// value profile meta data. Return false if there is no value data annotated,
  223. /// otherwise return true.
  224. bool getValueProfDataFromInst(const Instruction &Inst,
  225. InstrProfValueKind ValueKind,
  226. uint32_t MaxNumValueData,
  227. InstrProfValueData ValueData[],
  228. uint32_t &ActualNumValueData, uint64_t &TotalC);
  229. inline StringRef getPGOFuncNameMetadataName() { return "PGOFuncName"; }
  230. /// Return the PGOFuncName meta data associated with a function.
  231. MDNode *getPGOFuncNameMetadata(const Function &F);
  232. /// Create the PGOFuncName meta data if PGOFuncName is different from
  233. /// function's raw name. This should only apply to internal linkage functions
  234. /// declared by users only.
  235. void createPGOFuncNameMetadata(Function &F, StringRef PGOFuncName);
  236. /// Check if we can use Comdat for profile variables. This will eliminate
  237. /// the duplicated profile variables for Comdat functions.
  238. bool needsComdatForCounter(const Function &F, const Module &M);
  239. const std::error_category &instrprof_category();
  240. enum class instrprof_error {
  241. success = 0,
  242. eof,
  243. unrecognized_format,
  244. bad_magic,
  245. bad_header,
  246. unsupported_version,
  247. unsupported_hash_type,
  248. too_large,
  249. truncated,
  250. malformed,
  251. unknown_function,
  252. hash_mismatch,
  253. count_mismatch,
  254. counter_overflow,
  255. value_site_count_mismatch,
  256. compress_failed,
  257. uncompress_failed,
  258. empty_raw_profile,
  259. zlib_unavailable
  260. };
  261. inline std::error_code make_error_code(instrprof_error E) {
  262. return std::error_code(static_cast<int>(E), instrprof_category());
  263. }
  264. class InstrProfError : public ErrorInfo<InstrProfError> {
  265. public:
  266. InstrProfError(instrprof_error Err) : Err(Err) {
  267. assert(Err != instrprof_error::success && "Not an error");
  268. }
  269. std::string message() const override;
  270. void log(raw_ostream &OS) const override { OS << message(); }
  271. std::error_code convertToErrorCode() const override {
  272. return make_error_code(Err);
  273. }
  274. instrprof_error get() const { return Err; }
  275. /// Consume an Error and return the raw enum value contained within it. The
  276. /// Error must either be a success value, or contain a single InstrProfError.
  277. static instrprof_error take(Error E) {
  278. auto Err = instrprof_error::success;
  279. handleAllErrors(std::move(E), [&Err](const InstrProfError &IPE) {
  280. assert(Err == instrprof_error::success && "Multiple errors encountered");
  281. Err = IPE.get();
  282. });
  283. return Err;
  284. }
  285. static char ID;
  286. private:
  287. instrprof_error Err;
  288. };
  289. class SoftInstrProfErrors {
  290. /// Count the number of soft instrprof_errors encountered and keep track of
  291. /// the first such error for reporting purposes.
  292. /// The first soft error encountered.
  293. instrprof_error FirstError = instrprof_error::success;
  294. /// The number of hash mismatches.
  295. unsigned NumHashMismatches = 0;
  296. /// The number of count mismatches.
  297. unsigned NumCountMismatches = 0;
  298. /// The number of counter overflows.
  299. unsigned NumCounterOverflows = 0;
  300. /// The number of value site count mismatches.
  301. unsigned NumValueSiteCountMismatches = 0;
  302. public:
  303. SoftInstrProfErrors() = default;
  304. ~SoftInstrProfErrors() {
  305. assert(FirstError == instrprof_error::success &&
  306. "Unchecked soft error encountered");
  307. }
  308. /// Track a soft error (\p IE) and increment its associated counter.
  309. void addError(instrprof_error IE);
  310. /// Get the number of hash mismatches.
  311. unsigned getNumHashMismatches() const { return NumHashMismatches; }
  312. /// Get the number of count mismatches.
  313. unsigned getNumCountMismatches() const { return NumCountMismatches; }
  314. /// Get the number of counter overflows.
  315. unsigned getNumCounterOverflows() const { return NumCounterOverflows; }
  316. /// Get the number of value site count mismatches.
  317. unsigned getNumValueSiteCountMismatches() const {
  318. return NumValueSiteCountMismatches;
  319. }
  320. /// Return the first encountered error and reset FirstError to a success
  321. /// value.
  322. Error takeError() {
  323. if (FirstError == instrprof_error::success)
  324. return Error::success();
  325. auto E = make_error<InstrProfError>(FirstError);
  326. FirstError = instrprof_error::success;
  327. return E;
  328. }
  329. };
  330. namespace object {
  331. class SectionRef;
  332. } // end namespace object
  333. namespace IndexedInstrProf {
  334. uint64_t ComputeHash(StringRef K);
  335. } // end namespace IndexedInstrProf
  336. /// A symbol table used for function PGO name look-up with keys
  337. /// (such as pointers, md5hash values) to the function. A function's
  338. /// PGO name or name's md5hash are used in retrieving the profile
  339. /// data of the function. See \c getPGOFuncName() method for details
  340. /// on how PGO name is formed.
  341. class InstrProfSymtab {
  342. public:
  343. using AddrHashMap = std::vector<std::pair<uint64_t, uint64_t>>;
  344. private:
  345. StringRef Data;
  346. uint64_t Address = 0;
  347. // Unique name strings.
  348. StringSet<> NameTab;
  349. // A map from MD5 keys to function name strings.
  350. std::vector<std::pair<uint64_t, StringRef>> MD5NameMap;
  351. // A map from MD5 keys to function define. We only populate this map
  352. // when build the Symtab from a Module.
  353. std::vector<std::pair<uint64_t, Function *>> MD5FuncMap;
  354. // A map from function runtime address to function name MD5 hash.
  355. // This map is only populated and used by raw instr profile reader.
  356. AddrHashMap AddrToMD5Map;
  357. bool Sorted = false;
  358. static StringRef getExternalSymbol() {
  359. return "** External Symbol **";
  360. }
  361. // If the symtab is created by a series of calls to \c addFuncName, \c
  362. // finalizeSymtab needs to be called before looking up function names.
  363. // This is required because the underlying map is a vector (for space
  364. // efficiency) which needs to be sorted.
  365. inline void finalizeSymtab();
  366. public:
  367. InstrProfSymtab() = default;
  368. /// Create InstrProfSymtab from an object file section which
  369. /// contains function PGO names. When section may contain raw
  370. /// string data or string data in compressed form. This method
  371. /// only initialize the symtab with reference to the data and
  372. /// the section base address. The decompression will be delayed
  373. /// until before it is used. See also \c create(StringRef) method.
  374. Error create(object::SectionRef &Section);
  375. /// This interface is used by reader of CoverageMapping test
  376. /// format.
  377. inline Error create(StringRef D, uint64_t BaseAddr);
  378. /// \c NameStrings is a string composed of one of more sub-strings
  379. /// encoded in the format described in \c collectPGOFuncNameStrings.
  380. /// This method is a wrapper to \c readPGOFuncNameStrings method.
  381. inline Error create(StringRef NameStrings);
  382. /// A wrapper interface to populate the PGO symtab with functions
  383. /// decls from module \c M. This interface is used by transformation
  384. /// passes such as indirect function call promotion. Variable \c InLTO
  385. /// indicates if this is called from LTO optimization passes.
  386. Error create(Module &M, bool InLTO = false);
  387. /// Create InstrProfSymtab from a set of names iteratable from
  388. /// \p IterRange. This interface is used by IndexedProfReader.
  389. template <typename NameIterRange> Error create(const NameIterRange &IterRange);
  390. /// Update the symtab by adding \p FuncName to the table. This interface
  391. /// is used by the raw and text profile readers.
  392. Error addFuncName(StringRef FuncName) {
  393. if (FuncName.empty())
  394. return make_error<InstrProfError>(instrprof_error::malformed);
  395. auto Ins = NameTab.insert(FuncName);
  396. if (Ins.second) {
  397. MD5NameMap.push_back(std::make_pair(
  398. IndexedInstrProf::ComputeHash(FuncName), Ins.first->getKey()));
  399. Sorted = false;
  400. }
  401. return Error::success();
  402. }
  403. /// Map a function address to its name's MD5 hash. This interface
  404. /// is only used by the raw profiler reader.
  405. void mapAddress(uint64_t Addr, uint64_t MD5Val) {
  406. AddrToMD5Map.push_back(std::make_pair(Addr, MD5Val));
  407. }
  408. /// Return a function's hash, or 0, if the function isn't in this SymTab.
  409. uint64_t getFunctionHashFromAddress(uint64_t Address);
  410. /// Return function's PGO name from the function name's symbol
  411. /// address in the object file. If an error occurs, return
  412. /// an empty string.
  413. StringRef getFuncName(uint64_t FuncNameAddress, size_t NameSize);
  414. /// Return function's PGO name from the name's md5 hash value.
  415. /// If not found, return an empty string.
  416. inline StringRef getFuncName(uint64_t FuncMD5Hash);
  417. /// Just like getFuncName, except that it will return a non-empty StringRef
  418. /// if the function is external to this symbol table. All such cases
  419. /// will be represented using the same StringRef value.
  420. inline StringRef getFuncNameOrExternalSymbol(uint64_t FuncMD5Hash);
  421. /// True if Symbol is the value used to represent external symbols.
  422. static bool isExternalSymbol(const StringRef &Symbol) {
  423. return Symbol == InstrProfSymtab::getExternalSymbol();
  424. }
  425. /// Return function from the name's md5 hash. Return nullptr if not found.
  426. inline Function *getFunction(uint64_t FuncMD5Hash);
  427. /// Return the function's original assembly name by stripping off
  428. /// the prefix attached (to symbols with priviate linkage). For
  429. /// global functions, it returns the same string as getFuncName.
  430. inline StringRef getOrigFuncName(uint64_t FuncMD5Hash);
  431. /// Return the name section data.
  432. inline StringRef getNameData() const { return Data; }
  433. };
  434. Error InstrProfSymtab::create(StringRef D, uint64_t BaseAddr) {
  435. Data = D;
  436. Address = BaseAddr;
  437. return Error::success();
  438. }
  439. Error InstrProfSymtab::create(StringRef NameStrings) {
  440. return readPGOFuncNameStrings(NameStrings, *this);
  441. }
  442. template <typename NameIterRange>
  443. Error InstrProfSymtab::create(const NameIterRange &IterRange) {
  444. for (auto Name : IterRange)
  445. if (Error E = addFuncName(Name))
  446. return E;
  447. finalizeSymtab();
  448. return Error::success();
  449. }
  450. void InstrProfSymtab::finalizeSymtab() {
  451. if (Sorted)
  452. return;
  453. llvm::sort(MD5NameMap, less_first());
  454. llvm::sort(MD5FuncMap, less_first());
  455. llvm::sort(AddrToMD5Map, less_first());
  456. AddrToMD5Map.erase(std::unique(AddrToMD5Map.begin(), AddrToMD5Map.end()),
  457. AddrToMD5Map.end());
  458. Sorted = true;
  459. }
  460. StringRef InstrProfSymtab::getFuncNameOrExternalSymbol(uint64_t FuncMD5Hash) {
  461. StringRef ret = getFuncName(FuncMD5Hash);
  462. if (ret.empty())
  463. return InstrProfSymtab::getExternalSymbol();
  464. return ret;
  465. }
  466. StringRef InstrProfSymtab::getFuncName(uint64_t FuncMD5Hash) {
  467. finalizeSymtab();
  468. auto Result = llvm::lower_bound(MD5NameMap, FuncMD5Hash,
  469. [](const std::pair<uint64_t, StringRef> &LHS,
  470. uint64_t RHS) { return LHS.first < RHS; });
  471. if (Result != MD5NameMap.end() && Result->first == FuncMD5Hash)
  472. return Result->second;
  473. return StringRef();
  474. }
  475. Function* InstrProfSymtab::getFunction(uint64_t FuncMD5Hash) {
  476. finalizeSymtab();
  477. auto Result = llvm::lower_bound(MD5FuncMap, FuncMD5Hash,
  478. [](const std::pair<uint64_t, Function *> &LHS,
  479. uint64_t RHS) { return LHS.first < RHS; });
  480. if (Result != MD5FuncMap.end() && Result->first == FuncMD5Hash)
  481. return Result->second;
  482. return nullptr;
  483. }
  484. // See also getPGOFuncName implementation. These two need to be
  485. // matched.
  486. StringRef InstrProfSymtab::getOrigFuncName(uint64_t FuncMD5Hash) {
  487. StringRef PGOName = getFuncName(FuncMD5Hash);
  488. size_t S = PGOName.find_first_of(':');
  489. if (S == StringRef::npos)
  490. return PGOName;
  491. return PGOName.drop_front(S + 1);
  492. }
  493. // To store the sums of profile count values, or the percentage of
  494. // the sums of the total count values.
  495. struct CountSumOrPercent {
  496. uint64_t NumEntries;
  497. double CountSum;
  498. double ValueCounts[IPVK_Last - IPVK_First + 1];
  499. CountSumOrPercent() : NumEntries(0), CountSum(0.0f), ValueCounts() {}
  500. void reset() {
  501. NumEntries = 0;
  502. CountSum = 0.0f;
  503. for (unsigned I = 0; I < IPVK_Last - IPVK_First + 1; I++)
  504. ValueCounts[I] = 0.0f;
  505. }
  506. };
  507. // Function level or program level overlap information.
  508. struct OverlapStats {
  509. enum OverlapStatsLevel { ProgramLevel, FunctionLevel };
  510. // Sum of the total count values for the base profile.
  511. CountSumOrPercent Base;
  512. // Sum of the total count values for the test profile.
  513. CountSumOrPercent Test;
  514. // Overlap lap score. Should be in range of [0.0f to 1.0f].
  515. CountSumOrPercent Overlap;
  516. CountSumOrPercent Mismatch;
  517. CountSumOrPercent Unique;
  518. OverlapStatsLevel Level;
  519. const std::string *BaseFilename;
  520. const std::string *TestFilename;
  521. StringRef FuncName;
  522. uint64_t FuncHash;
  523. bool Valid;
  524. OverlapStats(OverlapStatsLevel L = ProgramLevel)
  525. : Level(L), BaseFilename(nullptr), TestFilename(nullptr), FuncHash(0),
  526. Valid(false) {}
  527. void dump(raw_fd_ostream &OS) const;
  528. void setFuncInfo(StringRef Name, uint64_t Hash) {
  529. FuncName = Name;
  530. FuncHash = Hash;
  531. }
  532. Error accumulateCounts(const std::string &BaseFilename,
  533. const std::string &TestFilename, bool IsCS);
  534. void addOneMismatch(const CountSumOrPercent &MismatchFunc);
  535. void addOneUnique(const CountSumOrPercent &UniqueFunc);
  536. static inline double score(uint64_t Val1, uint64_t Val2, double Sum1,
  537. double Sum2) {
  538. if (Sum1 < 1.0f || Sum2 < 1.0f)
  539. return 0.0f;
  540. return std::min(Val1 / Sum1, Val2 / Sum2);
  541. }
  542. };
  543. // This is used to filter the functions whose overlap information
  544. // to be output.
  545. struct OverlapFuncFilters {
  546. uint64_t ValueCutoff;
  547. const std::string NameFilter;
  548. };
  549. struct InstrProfValueSiteRecord {
  550. /// Value profiling data pairs at a given value site.
  551. std::list<InstrProfValueData> ValueData;
  552. InstrProfValueSiteRecord() { ValueData.clear(); }
  553. template <class InputIterator>
  554. InstrProfValueSiteRecord(InputIterator F, InputIterator L)
  555. : ValueData(F, L) {}
  556. /// Sort ValueData ascending by Value
  557. void sortByTargetValues() {
  558. ValueData.sort(
  559. [](const InstrProfValueData &left, const InstrProfValueData &right) {
  560. return left.Value < right.Value;
  561. });
  562. }
  563. /// Sort ValueData Descending by Count
  564. inline void sortByCount();
  565. /// Merge data from another InstrProfValueSiteRecord
  566. /// Optionally scale merged counts by \p Weight.
  567. void merge(InstrProfValueSiteRecord &Input, uint64_t Weight,
  568. function_ref<void(instrprof_error)> Warn);
  569. /// Scale up value profile data counts by N (Numerator) / D (Denominator).
  570. void scale(uint64_t N, uint64_t D, function_ref<void(instrprof_error)> Warn);
  571. /// Compute the overlap b/w this record and Input record.
  572. void overlap(InstrProfValueSiteRecord &Input, uint32_t ValueKind,
  573. OverlapStats &Overlap, OverlapStats &FuncLevelOverlap);
  574. };
  575. /// Profiling information for a single function.
  576. struct InstrProfRecord {
  577. std::vector<uint64_t> Counts;
  578. InstrProfRecord() = default;
  579. InstrProfRecord(std::vector<uint64_t> Counts) : Counts(std::move(Counts)) {}
  580. InstrProfRecord(InstrProfRecord &&) = default;
  581. InstrProfRecord(const InstrProfRecord &RHS)
  582. : Counts(RHS.Counts),
  583. ValueData(RHS.ValueData
  584. ? std::make_unique<ValueProfData>(*RHS.ValueData)
  585. : nullptr) {}
  586. InstrProfRecord &operator=(InstrProfRecord &&) = default;
  587. InstrProfRecord &operator=(const InstrProfRecord &RHS) {
  588. Counts = RHS.Counts;
  589. if (!RHS.ValueData) {
  590. ValueData = nullptr;
  591. return *this;
  592. }
  593. if (!ValueData)
  594. ValueData = std::make_unique<ValueProfData>(*RHS.ValueData);
  595. else
  596. *ValueData = *RHS.ValueData;
  597. return *this;
  598. }
  599. /// Return the number of value profile kinds with non-zero number
  600. /// of profile sites.
  601. inline uint32_t getNumValueKinds() const;
  602. /// Return the number of instrumented sites for ValueKind.
  603. inline uint32_t getNumValueSites(uint32_t ValueKind) const;
  604. /// Return the total number of ValueData for ValueKind.
  605. inline uint32_t getNumValueData(uint32_t ValueKind) const;
  606. /// Return the number of value data collected for ValueKind at profiling
  607. /// site: Site.
  608. inline uint32_t getNumValueDataForSite(uint32_t ValueKind,
  609. uint32_t Site) const;
  610. /// Return the array of profiled values at \p Site. If \p TotalC
  611. /// is not null, the total count of all target values at this site
  612. /// will be stored in \c *TotalC.
  613. inline std::unique_ptr<InstrProfValueData[]>
  614. getValueForSite(uint32_t ValueKind, uint32_t Site,
  615. uint64_t *TotalC = nullptr) const;
  616. /// Get the target value/counts of kind \p ValueKind collected at site
  617. /// \p Site and store the result in array \p Dest. Return the total
  618. /// counts of all target values at this site.
  619. inline uint64_t getValueForSite(InstrProfValueData Dest[], uint32_t ValueKind,
  620. uint32_t Site) const;
  621. /// Reserve space for NumValueSites sites.
  622. inline void reserveSites(uint32_t ValueKind, uint32_t NumValueSites);
  623. /// Add ValueData for ValueKind at value Site.
  624. void addValueData(uint32_t ValueKind, uint32_t Site,
  625. InstrProfValueData *VData, uint32_t N,
  626. InstrProfSymtab *SymTab);
  627. /// Merge the counts in \p Other into this one.
  628. /// Optionally scale merged counts by \p Weight.
  629. void merge(InstrProfRecord &Other, uint64_t Weight,
  630. function_ref<void(instrprof_error)> Warn);
  631. /// Scale up profile counts (including value profile data) by
  632. /// a factor of (N / D).
  633. void scale(uint64_t N, uint64_t D, function_ref<void(instrprof_error)> Warn);
  634. /// Sort value profile data (per site) by count.
  635. void sortValueData() {
  636. for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
  637. for (auto &SR : getValueSitesForKind(Kind))
  638. SR.sortByCount();
  639. }
  640. /// Clear value data entries and edge counters.
  641. void Clear() {
  642. Counts.clear();
  643. clearValueData();
  644. }
  645. /// Clear value data entries
  646. void clearValueData() { ValueData = nullptr; }
  647. /// Compute the sums of all counts and store in Sum.
  648. void accumulateCounts(CountSumOrPercent &Sum) const;
  649. /// Compute the overlap b/w this IntrprofRecord and Other.
  650. void overlap(InstrProfRecord &Other, OverlapStats &Overlap,
  651. OverlapStats &FuncLevelOverlap, uint64_t ValueCutoff);
  652. /// Compute the overlap of value profile counts.
  653. void overlapValueProfData(uint32_t ValueKind, InstrProfRecord &Src,
  654. OverlapStats &Overlap,
  655. OverlapStats &FuncLevelOverlap);
  656. private:
  657. struct ValueProfData {
  658. std::vector<InstrProfValueSiteRecord> IndirectCallSites;
  659. std::vector<InstrProfValueSiteRecord> MemOPSizes;
  660. };
  661. std::unique_ptr<ValueProfData> ValueData;
  662. MutableArrayRef<InstrProfValueSiteRecord>
  663. getValueSitesForKind(uint32_t ValueKind) {
  664. // Cast to /add/ const (should be an implicit_cast, ideally, if that's ever
  665. // implemented in LLVM) to call the const overload of this function, then
  666. // cast away the constness from the result.
  667. auto AR = const_cast<const InstrProfRecord *>(this)->getValueSitesForKind(
  668. ValueKind);
  669. return makeMutableArrayRef(
  670. const_cast<InstrProfValueSiteRecord *>(AR.data()), AR.size());
  671. }
  672. ArrayRef<InstrProfValueSiteRecord>
  673. getValueSitesForKind(uint32_t ValueKind) const {
  674. if (!ValueData)
  675. return None;
  676. switch (ValueKind) {
  677. case IPVK_IndirectCallTarget:
  678. return ValueData->IndirectCallSites;
  679. case IPVK_MemOPSize:
  680. return ValueData->MemOPSizes;
  681. default:
  682. llvm_unreachable("Unknown value kind!");
  683. }
  684. }
  685. std::vector<InstrProfValueSiteRecord> &
  686. getOrCreateValueSitesForKind(uint32_t ValueKind) {
  687. if (!ValueData)
  688. ValueData = std::make_unique<ValueProfData>();
  689. switch (ValueKind) {
  690. case IPVK_IndirectCallTarget:
  691. return ValueData->IndirectCallSites;
  692. case IPVK_MemOPSize:
  693. return ValueData->MemOPSizes;
  694. default:
  695. llvm_unreachable("Unknown value kind!");
  696. }
  697. }
  698. // Map indirect call target name hash to name string.
  699. uint64_t remapValue(uint64_t Value, uint32_t ValueKind,
  700. InstrProfSymtab *SymTab);
  701. // Merge Value Profile data from Src record to this record for ValueKind.
  702. // Scale merged value counts by \p Weight.
  703. void mergeValueProfData(uint32_t ValkeKind, InstrProfRecord &Src,
  704. uint64_t Weight,
  705. function_ref<void(instrprof_error)> Warn);
  706. // Scale up value profile data count by N (Numerator) / D (Denominator).
  707. void scaleValueProfData(uint32_t ValueKind, uint64_t N, uint64_t D,
  708. function_ref<void(instrprof_error)> Warn);
  709. };
  710. struct NamedInstrProfRecord : InstrProfRecord {
  711. StringRef Name;
  712. uint64_t Hash;
  713. // We reserve this bit as the flag for context sensitive profile record.
  714. static const int CS_FLAG_IN_FUNC_HASH = 60;
  715. NamedInstrProfRecord() = default;
  716. NamedInstrProfRecord(StringRef Name, uint64_t Hash,
  717. std::vector<uint64_t> Counts)
  718. : InstrProfRecord(std::move(Counts)), Name(Name), Hash(Hash) {}
  719. static bool hasCSFlagInHash(uint64_t FuncHash) {
  720. return ((FuncHash >> CS_FLAG_IN_FUNC_HASH) & 1);
  721. }
  722. static void setCSFlagInHash(uint64_t &FuncHash) {
  723. FuncHash |= ((uint64_t)1 << CS_FLAG_IN_FUNC_HASH);
  724. }
  725. };
  726. uint32_t InstrProfRecord::getNumValueKinds() const {
  727. uint32_t NumValueKinds = 0;
  728. for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
  729. NumValueKinds += !(getValueSitesForKind(Kind).empty());
  730. return NumValueKinds;
  731. }
  732. uint32_t InstrProfRecord::getNumValueData(uint32_t ValueKind) const {
  733. uint32_t N = 0;
  734. for (auto &SR : getValueSitesForKind(ValueKind))
  735. N += SR.ValueData.size();
  736. return N;
  737. }
  738. uint32_t InstrProfRecord::getNumValueSites(uint32_t ValueKind) const {
  739. return getValueSitesForKind(ValueKind).size();
  740. }
  741. uint32_t InstrProfRecord::getNumValueDataForSite(uint32_t ValueKind,
  742. uint32_t Site) const {
  743. return getValueSitesForKind(ValueKind)[Site].ValueData.size();
  744. }
  745. std::unique_ptr<InstrProfValueData[]>
  746. InstrProfRecord::getValueForSite(uint32_t ValueKind, uint32_t Site,
  747. uint64_t *TotalC) const {
  748. uint64_t Dummy = 0;
  749. uint64_t &TotalCount = (TotalC == nullptr ? Dummy : *TotalC);
  750. uint32_t N = getNumValueDataForSite(ValueKind, Site);
  751. if (N == 0) {
  752. TotalCount = 0;
  753. return std::unique_ptr<InstrProfValueData[]>(nullptr);
  754. }
  755. auto VD = std::make_unique<InstrProfValueData[]>(N);
  756. TotalCount = getValueForSite(VD.get(), ValueKind, Site);
  757. return VD;
  758. }
  759. uint64_t InstrProfRecord::getValueForSite(InstrProfValueData Dest[],
  760. uint32_t ValueKind,
  761. uint32_t Site) const {
  762. uint32_t I = 0;
  763. uint64_t TotalCount = 0;
  764. for (auto V : getValueSitesForKind(ValueKind)[Site].ValueData) {
  765. Dest[I].Value = V.Value;
  766. Dest[I].Count = V.Count;
  767. TotalCount = SaturatingAdd(TotalCount, V.Count);
  768. I++;
  769. }
  770. return TotalCount;
  771. }
  772. void InstrProfRecord::reserveSites(uint32_t ValueKind, uint32_t NumValueSites) {
  773. if (!NumValueSites)
  774. return;
  775. getOrCreateValueSitesForKind(ValueKind).reserve(NumValueSites);
  776. }
  777. inline support::endianness getHostEndianness() {
  778. return sys::IsLittleEndianHost ? support::little : support::big;
  779. }
  780. // Include definitions for value profile data
  781. #define INSTR_PROF_VALUE_PROF_DATA
  782. #include "llvm/ProfileData/InstrProfData.inc"
  783. void InstrProfValueSiteRecord::sortByCount() {
  784. ValueData.sort(
  785. [](const InstrProfValueData &left, const InstrProfValueData &right) {
  786. return left.Count > right.Count;
  787. });
  788. // Now truncate
  789. size_t max_s = INSTR_PROF_MAX_NUM_VAL_PER_SITE;
  790. if (ValueData.size() > max_s)
  791. ValueData.resize(max_s);
  792. }
  793. namespace IndexedInstrProf {
  794. enum class HashT : uint32_t {
  795. MD5,
  796. Last = MD5
  797. };
  798. inline uint64_t ComputeHash(HashT Type, StringRef K) {
  799. switch (Type) {
  800. case HashT::MD5:
  801. return MD5Hash(K);
  802. }
  803. llvm_unreachable("Unhandled hash type");
  804. }
  805. const uint64_t Magic = 0x8169666f72706cff; // "\xfflprofi\x81"
  806. enum ProfVersion {
  807. // Version 1 is the first version. In this version, the value of
  808. // a key/value pair can only include profile data of a single function.
  809. // Due to this restriction, the number of block counters for a given
  810. // function is not recorded but derived from the length of the value.
  811. Version1 = 1,
  812. // The version 2 format supports recording profile data of multiple
  813. // functions which share the same key in one value field. To support this,
  814. // the number block counters is recorded as an uint64_t field right after the
  815. // function structural hash.
  816. Version2 = 2,
  817. // Version 3 supports value profile data. The value profile data is expected
  818. // to follow the block counter profile data.
  819. Version3 = 3,
  820. // In this version, profile summary data \c IndexedInstrProf::Summary is
  821. // stored after the profile header.
  822. Version4 = 4,
  823. // In this version, the frontend PGO stable hash algorithm defaults to V2.
  824. Version5 = 5,
  825. // In this version, the frontend PGO stable hash algorithm got fixed and
  826. // may produce hashes different from Version5.
  827. Version6 = 6,
  828. // An additional counter is added around logical operators.
  829. Version7 = 7,
  830. // The current version is 7.
  831. CurrentVersion = INSTR_PROF_INDEX_VERSION
  832. };
  833. const uint64_t Version = ProfVersion::CurrentVersion;
  834. const HashT HashType = HashT::MD5;
  835. inline uint64_t ComputeHash(StringRef K) { return ComputeHash(HashType, K); }
  836. // This structure defines the file header of the LLVM profile
  837. // data file in indexed-format.
  838. struct Header {
  839. uint64_t Magic;
  840. uint64_t Version;
  841. uint64_t Unused; // Becomes unused since version 4
  842. uint64_t HashType;
  843. uint64_t HashOffset;
  844. };
  845. // Profile summary data recorded in the profile data file in indexed
  846. // format. It is introduced in version 4. The summary data follows
  847. // right after the profile file header.
  848. struct Summary {
  849. struct Entry {
  850. uint64_t Cutoff; ///< The required percentile of total execution count.
  851. uint64_t
  852. MinBlockCount; ///< The minimum execution count for this percentile.
  853. uint64_t NumBlocks; ///< Number of blocks >= the minumum execution count.
  854. };
  855. // The field kind enumerator to assigned value mapping should remain
  856. // unchanged when a new kind is added or an old kind gets deleted in
  857. // the future.
  858. enum SummaryFieldKind {
  859. /// The total number of functions instrumented.
  860. TotalNumFunctions = 0,
  861. /// Total number of instrumented blocks/edges.
  862. TotalNumBlocks = 1,
  863. /// The maximal execution count among all functions.
  864. /// This field does not exist for profile data from IR based
  865. /// instrumentation.
  866. MaxFunctionCount = 2,
  867. /// Max block count of the program.
  868. MaxBlockCount = 3,
  869. /// Max internal block count of the program (excluding entry blocks).
  870. MaxInternalBlockCount = 4,
  871. /// The sum of all instrumented block counts.
  872. TotalBlockCount = 5,
  873. NumKinds = TotalBlockCount + 1
  874. };
  875. // The number of summmary fields following the summary header.
  876. uint64_t NumSummaryFields;
  877. // The number of Cutoff Entries (Summary::Entry) following summary fields.
  878. uint64_t NumCutoffEntries;
  879. Summary() = delete;
  880. Summary(uint32_t Size) { memset(this, 0, Size); }
  881. void operator delete(void *ptr) { ::operator delete(ptr); }
  882. static uint32_t getSize(uint32_t NumSumFields, uint32_t NumCutoffEntries) {
  883. return sizeof(Summary) + NumCutoffEntries * sizeof(Entry) +
  884. NumSumFields * sizeof(uint64_t);
  885. }
  886. const uint64_t *getSummaryDataBase() const {
  887. return reinterpret_cast<const uint64_t *>(this + 1);
  888. }
  889. uint64_t *getSummaryDataBase() {
  890. return reinterpret_cast<uint64_t *>(this + 1);
  891. }
  892. const Entry *getCutoffEntryBase() const {
  893. return reinterpret_cast<const Entry *>(
  894. &getSummaryDataBase()[NumSummaryFields]);
  895. }
  896. Entry *getCutoffEntryBase() {
  897. return reinterpret_cast<Entry *>(&getSummaryDataBase()[NumSummaryFields]);
  898. }
  899. uint64_t get(SummaryFieldKind K) const {
  900. return getSummaryDataBase()[K];
  901. }
  902. void set(SummaryFieldKind K, uint64_t V) {
  903. getSummaryDataBase()[K] = V;
  904. }
  905. const Entry &getEntry(uint32_t I) const { return getCutoffEntryBase()[I]; }
  906. void setEntry(uint32_t I, const ProfileSummaryEntry &E) {
  907. Entry &ER = getCutoffEntryBase()[I];
  908. ER.Cutoff = E.Cutoff;
  909. ER.MinBlockCount = E.MinCount;
  910. ER.NumBlocks = E.NumCounts;
  911. }
  912. };
  913. inline std::unique_ptr<Summary> allocSummary(uint32_t TotalSize) {
  914. return std::unique_ptr<Summary>(new (::operator new(TotalSize))
  915. Summary(TotalSize));
  916. }
  917. } // end namespace IndexedInstrProf
  918. namespace RawInstrProf {
  919. // Version 1: First version
  920. // Version 2: Added value profile data section. Per-function control data
  921. // struct has more fields to describe value profile information.
  922. // Version 3: Compressed name section support. Function PGO name reference
  923. // from control data struct is changed from raw pointer to Name's MD5 value.
  924. // Version 4: ValueDataBegin and ValueDataSizes fields are removed from the
  925. // raw header.
  926. // Version 5: Bit 60 of FuncHash is reserved for the flag for the context
  927. // sensitive records.
  928. const uint64_t Version = INSTR_PROF_RAW_VERSION;
  929. template <class IntPtrT> inline uint64_t getMagic();
  930. template <> inline uint64_t getMagic<uint64_t>() {
  931. return INSTR_PROF_RAW_MAGIC_64;
  932. }
  933. template <> inline uint64_t getMagic<uint32_t>() {
  934. return INSTR_PROF_RAW_MAGIC_32;
  935. }
  936. // Per-function profile data header/control structure.
  937. // The definition should match the structure defined in
  938. // compiler-rt/lib/profile/InstrProfiling.h.
  939. // It should also match the synthesized type in
  940. // Transforms/Instrumentation/InstrProfiling.cpp:getOrCreateRegionCounters.
  941. template <class IntPtrT> struct alignas(8) ProfileData {
  942. #define INSTR_PROF_DATA(Type, LLVMType, Name, Init) Type Name;
  943. #include "llvm/ProfileData/InstrProfData.inc"
  944. };
  945. // File header structure of the LLVM profile data in raw format.
  946. // The definition should match the header referenced in
  947. // compiler-rt/lib/profile/InstrProfilingFile.c and
  948. // InstrProfilingBuffer.c.
  949. struct Header {
  950. #define INSTR_PROF_RAW_HEADER(Type, Name, Init) const Type Name;
  951. #include "llvm/ProfileData/InstrProfData.inc"
  952. };
  953. } // end namespace RawInstrProf
  954. // Parse MemOP Size range option.
  955. void getMemOPSizeRangeFromOption(StringRef Str, int64_t &RangeStart,
  956. int64_t &RangeLast);
  957. // Create a COMDAT variable INSTR_PROF_RAW_VERSION_VAR to make the runtime
  958. // aware this is an ir_level profile so it can set the version flag.
  959. void createIRLevelProfileFlagVar(Module &M, bool IsCS,
  960. bool InstrEntryBBEnabled);
  961. // Create the variable for the profile file name.
  962. void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput);
  963. // Whether to compress function names in profile records, and filenames in
  964. // code coverage mappings. Used by the Instrumentation library and unit tests.
  965. extern cl::opt<bool> DoInstrProfNameCompression;
  966. } // end namespace llvm
  967. #endif // LLVM_PROFILEDATA_INSTRPROF_H
  968. #ifdef __GNUC__
  969. #pragma GCC diagnostic pop
  970. #endif