InstrProf.h 41 KB

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