Go to the documentation of this file.
21 #include "llvm/Config/config.h"
52 #include <system_error>
53 #include <type_traits>
61 cl::desc(
"Use full module build paths in the profile counter names for "
62 "static functions."));
74 cl::desc(
"Strip specified level of directory name from source path in "
75 "the profile counter name for static functions."));
78 const std::string &ErrMsg =
"") {
90 OS <<
"unrecognized instrumentation profile encoding format";
93 OS <<
"invalid instrumentation profile data (bad magic)";
96 OS <<
"invalid instrumentation profile data (file header is corrupt)";
99 OS <<
"unsupported instrumentation profile format version";
102 OS <<
"unsupported instrumentation profile hash type";
105 OS <<
"too much profile data";
108 OS <<
"truncated profile data";
111 OS <<
"malformed instrumentation profile data";
114 OS <<
"debug info for correlation is required";
117 OS <<
"debug info for correlation is not necessary";
120 OS <<
"unable to correlate profile";
123 OS <<
"invalid profile created. Please file a bug "
124 "at: " BUG_REPORT_URL
125 " and include the profraw files that caused this error.";
128 OS <<
"no profile data available for function";
131 OS <<
"function control flow change detected (hash mismatch)";
134 OS <<
"function basic block count change detected (counter mismatch)";
137 OS <<
"counter overflow";
140 OS <<
"function value site count change detected (counter mismatch)";
143 OS <<
"failed to compress data (zlib)";
146 OS <<
"failed to uncompress data (zlib)";
149 OS <<
"empty raw profile file";
152 OS <<
"profile uses zlib compression but the profile reader was built "
153 "without zlib support";
159 OS <<
": " << ErrMsg;
169 class InstrProfErrorCategoryType :
public std::error_category {
170 const char *
name()
const noexcept
override {
return "llvm.instrprof"; }
172 std::string
message(
int IE)
const override {
180 static InstrProfErrorCategoryType ErrorCategory;
181 return ErrorCategory;
186 const char *InstrProfSectNameCommon[] = {
187 #define INSTR_PROF_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) \
192 const char *InstrProfSectNameCoff[] = {
193 #define INSTR_PROF_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) \
198 const char *InstrProfSectNamePrefix[] = {
199 #define INSTR_PROF_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) \
209 "enable-name-compression",
214 bool AddSegmentInfo) {
215 std::string SectName;
218 SectName = InstrProfSectNamePrefix[IPSK];
221 SectName += InstrProfSectNameCoff[IPSK];
223 SectName += InstrProfSectNameCommon[IPSK];
225 if (OF ==
Triple::MachO && IPSK == IPSK_data && AddSegmentInfo)
226 SectName +=
",regular,live_support";
243 ++NumCountMismatches;
246 ++NumCounterOverflows;
249 ++NumValueSiteCountMismatches;
275 for (
auto & CI : PathNameStr) {
284 return PathNameStr.substr(LastPos);
302 StringRef FileName(
F.getParent()->getSourceFileName());
313 StringRef S = cast<MDString>(MD->getOperand(0))->getString();
324 if (FileName.
empty())
343 const char *InvalidChars =
"-:<>/\"'";
344 size_t found =
VarName.find_first_of(InvalidChars);
345 while (found != std::string::npos) {
347 found =
VarName.find_first_of(InvalidChars, found + 1);
403 const std::string UniqSuffix =
".__uniq.";
404 auto pos = PGOFuncName.find(UniqSuffix);
407 if (pos != std::string::npos)
408 pos += UniqSuffix.length();
411 pos = PGOFuncName.find(
'.', pos);
412 if (pos != std::string::npos && pos != 0) {
413 const std::string &OtherFuncName = PGOFuncName.substr(0, pos);
426 auto It =
partition_point(AddrToMD5Map, [=](std::pair<uint64_t, uint64_t> A) {
427 return A.first < Address;
433 if (It != AddrToMD5Map.end() && It->first == Address)
439 bool doCompression, std::string &Result) {
440 assert(!NameStrs.
empty() &&
"No name data to emit");
442 uint8_t Header[16], *
P = Header;
443 std::string UncompressedNameStrings =
448 "PGO name is invalid (contains separator token)");
450 unsigned EncLen =
encodeULEB128(UncompressedNameStrings.length(),
P);
453 auto WriteStringToResult = [&](
size_t CompressedLen,
StringRef InputStr) {
456 char *HeaderStr =
reinterpret_cast<char *
>(&Header[0]);
457 unsigned HeaderLen =
P - &Header[0];
458 Result.append(HeaderStr, HeaderLen);
463 if (!doCompression) {
464 return WriteStringToResult(0, UncompressedNameStrings);
469 CompressedNameStrings,
472 return WriteStringToResult(CompressedNameStrings.size(),
479 Arr->isCString() ? Arr->getAsCString() : Arr->getAsString();
484 std::string &Result,
bool doCompression) {
485 std::vector<std::string> NameStrs;
486 for (
auto *NameVar : NameVars) {
495 const uint8_t *EndP = NameStrings.
bytes_end();
502 bool isCompressed = (CompressedSize != 0);
510 UncompressedNameStrings,
516 NameStrings =
toStringRef(UncompressedNameStrings);
519 StringRef(
reinterpret_cast<const char *
>(
P), UncompressedSize);
520 P += UncompressedSize;
529 while (
P < EndP && *
P == 0)
542 for (
uint32_t VK = IPVK_First; VK <= IPVK_Last; ++VK) {
545 for (
size_t I = 0;
I < NumValueSites; ++
I) {
549 KindSum += VD[V].Count;
561 double Score = 0.0f, FuncLevelScore = 0.0f;
566 while (
I !=
IE && J != JE) {
567 if (
I->Value == J->Value) {
575 }
else if (
I->Value < J->Value) {
592 if (!ThisNumValueSites)
595 std::vector<InstrProfValueSiteRecord> &ThisSiteRecords =
610 bool Mismatch = (
Counts.size() !=
Other.Counts.size());
614 for (
uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind) {
617 if (ThisNumValueSites != OtherNumValueSites) {
629 for (
uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
635 for (
size_t I = 0,
E =
Other.Counts.size();
I <
E; ++
I) {
643 if (MaxCount >= ValueCutoff) {
644 double FuncScore = 0.0;
645 for (
size_t I = 0,
E =
Other.Counts.size();
I <
E; ++
I)
651 FuncLevelOverlap.
Valid =
true;
662 for (
const InstrProfValueData &J : Input.
ValueData) {
663 while (
I !=
IE &&
I->Value < J.Value)
665 if (
I !=
IE &&
I->Value == J.Value) {
689 void InstrProfRecord::mergeValueProfData(
694 if (ThisNumValueSites != OtherNumValueSites) {
698 if (!ThisNumValueSites)
700 std::vector<InstrProfValueSiteRecord> &ThisSiteRecords =
705 ThisSiteRecords[
I].
merge(OtherSiteRecords[
I], Weight, Warn);
735 for (
size_t I = 0,
E =
Other.Counts.size();
I <
E; ++
I) {
748 for (
uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
749 mergeValueProfData(Kind,
Other, Weight, Warn);
752 void InstrProfRecord::scaleValueProfData(
755 for (
auto &R : getValueSitesForKind(
ValueKind))
761 assert(
D != 0 &&
"D cannot be 0");
762 for (
auto &Count : this->
Counts) {
772 for (
uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
773 scaleValueProfData(Kind,
N,
D, Warn);
782 if (
ValueKind == IPVK_IndirectCallTarget)
794 std::vector<InstrProfValueSiteRecord> &ValueSites =
797 ValueSites.emplace_back();
799 ValueSites.emplace_back(VData, VData +
N);
802 #define INSTR_PROF_COMMON_API_IMPL
816 ->getNumValueSites(VKind);
821 ->getNumValueData(VKind);
827 ->getNumValueDataForSite(VK,
S);
837 (ValueProfData *)(
new (::
operator new(TotalSizeInBytes)) ValueProfData());
838 memset(VD, 0, TotalSizeInBytes);
856 return getValueProfDataSize(&Closure);
860 std::unique_ptr<ValueProfData>
864 std::unique_ptr<ValueProfData> VPD(
871 Record.reserveSites(Kind, NumValueSites);
873 InstrProfValueData *ValueData = getValueProfRecordValueData(
this);
874 for (
uint64_t VSite = 0; VSite < NumValueSites; ++VSite) {
875 uint8_t ValueDataCount = this->SiteCountArray[VSite];
876 Record.addValueData(Kind, VSite, ValueData, ValueDataCount, SymTab);
877 ValueData += ValueDataCount;
892 sys::swapByteOrder<uint32_t>(NumValueSites);
893 sys::swapByteOrder<uint32_t>(Kind);
895 uint32_t ND = getValueProfRecordNumValueData(
this);
896 InstrProfValueData *VD = getValueProfRecordValueData(
this);
900 sys::swapByteOrder<uint64_t>(VD[
I].
Value);
901 sys::swapByteOrder<uint64_t>(VD[
I].Count);
904 sys::swapByteOrder<uint32_t>(NumValueSites);
905 sys::swapByteOrder<uint32_t>(Kind);
911 if (NumValueKinds == 0)
914 ValueProfRecord *VR = getFirstValueProfRecord(
this);
915 for (
uint32_t K = 0; K < NumValueKinds; K++) {
916 VR->deserializeTo(
Record, SymTab);
917 VR = getValueProfRecordNext(VR);
926 return endian::readNext<T, little, unaligned>(
D);
928 return endian::readNext<T, big, unaligned>(
D);
932 return std::unique_ptr<ValueProfData>(
new (::
operator new(TotalSize))
936 Error ValueProfData::checkIntegrity() {
937 if (NumValueKinds > IPVK_Last + 1)
938 return make_error<InstrProfError>(
942 return make_error<InstrProfError>(
945 ValueProfRecord *VR = getFirstValueProfRecord(
this);
946 for (
uint32_t K = 0; K < this->NumValueKinds; K++) {
947 if (VR->Kind > IPVK_Last)
949 "value kind is invalid");
950 VR = getValueProfRecordNext(VR);
951 if ((
char *)VR - (
char *)
this > (
ptrdiff_t)TotalSize)
952 return make_error<InstrProfError>(
954 "value profile address is greater than total size");
960 ValueProfData::getValueProfData(
const unsigned char *
D,
961 const unsigned char *
const BufferEnd,
965 if (
D +
sizeof(ValueProfData) > BufferEnd)
968 const unsigned char *Header =
D;
970 if (
D + TotalSize > BufferEnd)
974 memcpy(VPD.get(),
D, TotalSize);
978 Error E = VPD->checkIntegrity();
991 sys::swapByteOrder<uint32_t>(TotalSize);
992 sys::swapByteOrder<uint32_t>(NumValueKinds);
994 ValueProfRecord *VR = getFirstValueProfRecord(
this);
995 for (
uint32_t K = 0; K < NumValueKinds; K++) {
997 VR = getValueProfRecordNext(VR);
1007 ValueProfRecord *VR = getFirstValueProfRecord(
this);
1008 for (
uint32_t K = 0; K < NumValueKinds; K++) {
1009 ValueProfRecord *NVR = getValueProfRecordNext(VR);
1013 sys::swapByteOrder<uint32_t>(TotalSize);
1014 sys::swapByteOrder<uint32_t>(NumValueKinds);
1026 std::unique_ptr<InstrProfValueData[]> VD =
1051 for (
auto &VD : VDs) {
1065 InstrProfValueData ValueData[],
1067 bool GetNoICPValue) {
1082 if (!
Tag->getString().equals(
"VP"))
1098 ActualNumValueData = 0;
1100 for (
unsigned I = 3;
I < NOps;
I += 2) {
1101 if (ActualNumValueData >= MaxNumValueData)
1105 mdconst::dyn_extract<ConstantInt>(MD->
getOperand(
I + 1));
1106 if (!
Value || !Count)
1111 ValueData[ActualNumValueData].Value =
Value->getZExtValue();
1112 ValueData[ActualNumValueData].Count = CntValue;
1113 ActualNumValueData++;
1124 if (PGOFuncName ==
F.getName())
1162 M->getNamedGlobal(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));
1163 if (!IRInstrVar || IRInstrVar->hasLocalLinkage())
1168 if (IRInstrVar->isDeclaration())
1172 if (!IRInstrVar->hasInitializer())
1175 auto *InitVal = dyn_cast_or_null<ConstantInt>(IRInstrVar->getInitializer());
1178 return (InitVal->getZExtValue() & VARIANT_MASK_IR_PROF) != 0;
1183 if (
F.getName().empty())
1189 if (CheckAddressTaken &&
F.hasAddressTaken())
1197 if (!
F.hasComdat()) {
1206 if (InstrProfileOutput.
empty())
1212 ProfileNameConst, INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_NAME_VAR));
1214 Triple TT(
M.getTargetTriple());
1215 if (TT.supportsCOMDAT()) {
1217 ProfileNameVar->
setComdat(
M.getOrInsertComdat(
1218 StringRef(INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_NAME_VAR))));
1223 const std::string &TestFilename,
1225 auto getProfileSum = [IsCS](
const std::string &Filename,
1228 if (
Error E = ReaderOrErr.takeError()) {
1231 auto Reader =
std::move(ReaderOrErr.get());
1232 Reader->accumulateCounts(Sum, IsCS);
1250 for (
unsigned I = 0;
I < IPVK_Last - IPVK_First + 1;
I++) {
1260 for (
unsigned I = 0;
I < IPVK_Last - IPVK_First + 1;
I++) {
1270 const char *EntryName =
1273 OS <<
"Profile overlap infomation for base_profile: " << *
BaseFilename
1274 <<
" and test_profile: " << *
TestFilename <<
"\nProgram level:\n";
1276 OS <<
"Function level:\n"
1285 OS <<
" # of " << EntryName
1291 OS <<
" Mismatched count percentage (Edge): "
1294 OS <<
" Percentage of Edge profile only in test_profile: "
1301 for (
unsigned I = 0;
I < IPVK_Last - IPVK_First + 1;
I++) {
1304 char ProfileKindName[20];
1306 case IPVK_IndirectCallTarget:
1307 strncpy(ProfileKindName,
"IndirectCall", 19);
1309 case IPVK_MemOPSize:
1310 strncpy(ProfileKindName,
"MemOP", 19);
1313 snprintf(ProfileKindName, 19,
"VP[%d]",
I);
1316 OS <<
" " << ProfileKindName
1320 OS <<
" Mismatched count percentage (" << ProfileKindName
1323 OS <<
" Percentage of " << ProfileKindName
1324 <<
" profile only in test_profile: "
1326 OS <<
" " << ProfileKindName
1329 <<
" " << ProfileKindName
1335 namespace IndexedInstrProf {
1337 template <
typename T1,
typename T2>
1344 return *
reinterpret_cast<const uint64_t *
>(Buffer + Offset);
1349 return endian::byte_swap<uint64_t, little>(
Version);
1354 static_assert(std::is_standard_layout_v<Header>,
1355 "The header should be standard layout type since we use offset "
1356 "of fields to read.");
1367 if (GET_VERSION(
H.formatVersion()) >
1371 switch (GET_VERSION(
H.formatVersion())) {
1376 "Please update the reading code below if a new field has been added, "
1377 "if not add a case statement to fall through to the latest version.");
1398 "Please update the size computation below if a new field has "
1399 "been added to the header, if not add a case statement to "
1400 "fall through to the latest version.");
std::enable_if_t< std::is_unsigned< T >::value, T > SaturatingMultiply(T X, T Y, bool *ResultOverflowed=nullptr)
Multiply two unsigned integers, X and Y, of type T.
void createPGOFuncNameMetadata(Function &F, StringRef PGOFuncName)
Create the PGOFuncName meta data if PGOFuncName is different from function's raw name.
static double score(uint64_t Val1, uint64_t Val2, double Sum1, double Sum2)
static std::unique_ptr< ValueProfData > allocValueProfData(uint32_t TotalSize)
Error decompress(ArrayRef< uint8_t > Input, uint8_t *Output, size_t &UncompressedSize)
void setComdat(Comdat *C)
This is an optimization pass for GlobalISel generic memory operations.
ConstantAsMetadata * createConstant(Constant *C)
Return the given constant as metadata.
constexpr support::endianness Endianness
The endianness of all multi-byte encoded values in MessagePack.
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
std::string getGlobalIdentifier() const
Return the modified name for this global value suitable to be used as the key for a global lookup (e....
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
std::string message() const override
Return the error message as a string.
uint32_t getNumValueKindsInstrProf(const void *Record)
ValueProfRecordClosure Interface implementation for InstrProfRecord class.
CountPseudoKind getCountPseudoKind() const
@ HiddenVisibility
The GV is hidden.
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
constexpr size_t offsetOf(T1 T2::*Member)
A raw_ostream that writes to an std::string.
std::unique_ptr< InstrProfValueData[]> getValueForSite(uint32_t ValueKind, uint32_t Site, uint64_t *TotalC=nullptr) const
Return the array of profiled values at Site.
bool needsComdatForCounter(const Function &F, const Module &M)
Check if we can use Comdat for profile variables.
StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar)
Return the initializer in string of the PGO name var NameVar.
void setPseudoCount(CountPseudoKind Kind)
static bool isLocalLinkage(LinkageTypes Linkage)
std::string getPGOFuncName(const Function &F, bool InLTO=false, uint64_t Version=INSTR_PROF_INDEX_VERSION)
Return the modified name for function F suitable to be used the key for profile lookup.
Error create(object::SectionRef &Section)
Create InstrProfSymtab from an object file section which contains function PGO names.
void dump(raw_fd_ostream &OS) const
static ErrorSuccess success()
Create a success value.
StringRef getInstrProfNameSeparator()
Return the marker used to separate PGO names during serialization.
void getValueForSiteInstrProf(const void *R, InstrProfValueData *Dst, uint32_t K, uint32_t S)
Triple - Helper class for working with autoconf configuration names.
GlobalVariable * createPGOFuncNameVar(Function &F, StringRef PGOFuncName)
Create and return the global variable for function name used in PGO instrumentation.
static cl::opt< bool > StaticFuncFullModulePrefix("static-func-full-module-prefix", cl::init(true), cl::Hidden, cl::desc("Use full module build paths in the profile counter names for " "static functions."))
uint64_t getInstrMaxCountValue()
Return the max count value. We reserver a few large values for special use.
void scale(uint64_t N, uint64_t D, function_ref< void(instrprof_error)> Warn)
Scale up value profile data counts by N (Numerator) / D (Denominator).
void overlap(InstrProfRecord &Other, OverlapStats &Overlap, OverlapStats &FuncLevelOverlap, uint64_t ValueCutoff)
Compute the overlap b/w this IntrprofRecord and Other.
@ value_site_count_mismatch
DiagnosticInfoOptimizationBase::Argument NV
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Tagged union holding either a T or a Error.
LinkageTypes
An enumeration for the kinds of linkage for global values.
std::string getPGOFuncNameVarName(StringRef FuncName, GlobalValue::LinkageTypes Linkage)
Return the name of the global variable used to store a function name in PGO instrumentation.
void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput)
#define LLVM_ATTRIBUTE_UNUSED
bool isDiscardableIfUnused() const
void consumeError(Error Err)
Consume a Error without doing anything.
static IntegerType * getInt32Ty(LLVMContext &C)
bool empty() const
empty - Check if the array is empty.
Profiling information for a single function.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
void merge(InstrProfValueSiteRecord &Input, uint64_t Weight, function_ref< void(instrprof_error)> Warn)
Merge data from another InstrProfValueSiteRecord Optionally scale merged counts by Weight.
unsigned getNumOperands() const
Return number of MDNode operands.
@ unexpected_debug_info_for_correlation
const std::string * TestFilename
StringRef toStringRef(const std::optional< DWARFFormValue > &V, StringRef Default={})
Take an optional DWARFFormValue and try to extract a string value from it.
static std::string getInstrProfErrString(instrprof_error Err, const std::string &ErrMsg="")
This is the shared class of boolean and integer constants.
uint64_t decodeULEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a ULEB128 value.
constexpr int BestSizeCompression
uint32_t getNumValueDataForSite(uint32_t ValueKind, uint32_t Site) const
Return the number of value data collected for ValueKind at profiling site: Site.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
bool startswith(StringRef Prefix) const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
(vector float) vec_cmpeq(*A, *B) C
static ValueProfRecordClosure InstrProfRecordClosure
bool canRenameComdatFunc(const Function &F, bool CheckAddressTaken=false)
Check if we can safely rename this Comdat function.
uint32_t getNumValueSites(uint32_t ValueKind) const
Return the number of instrumented sites for ValueKind.
ValueProfData * allocValueProfDataInstrProf(size_t TotalSizeInBytes)
bool supportsCOMDAT() const
Tests whether the target supports comdat.
static StringRef stripDirPrefix(StringRef PathNameStr, uint32_t NumPrefix)
static T swapToHostOrder(const unsigned char *&D, support::endianness Orig)
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static cl::opt< unsigned > StaticFuncStripDirNamePrefix("static-func-strip-dirname-prefix", cl::init(0), cl::Hidden, cl::desc("Strip specified level of directory name from source path in " "the profile counter name for static functions."))
@ InternalLinkage
Rename collisions when linking (static functions).
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
An efficient, type-erasing, non-owning reference to a callable.
const MDOperand & getOperand(unsigned I) const
MDString * createString(StringRef Str)
Return the given string as metadata.
support::endianness getHostEndianness()
constexpr bool empty() const
empty - Check if the string is empty.
StringRef getInstrProfNameVarPrefix()
Return the name prefix of variables containing instrumented function names.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
This is an important base class in LLVM.
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
void addError(instrprof_error IE)
Track a soft error (IE) and increment its associated counter.
uint32_t getNumValueSitesInstrProf(const void *Record, uint32_t VKind)
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
This is an important class for using LLVM in a threaded context.
bool isIRPGOFlagSet(const Module *M)
Check if INSTR_PROF_RAW_VERSION_VAR is defined.
std::enable_if_t< std::is_unsigned< T >::value, T > SaturatingMultiplyAdd(T X, T Y, T A, bool *ResultOverflowed=nullptr)
Multiply two unsigned integers, X and Y, and add the unsigned integer, A to the product.
initializer< Ty > init(const Ty &Val)
void setLinkage(LinkageTypes LT)
static MDString * get(LLVMContext &Context, StringRef Str)
message(STATUS "Targeting ${t}") add_subdirectory($
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
<%struct.s * > cast struct s *S to sbyte *< sbyte * > sbyte uint cast struct s *agg result to sbyte *< sbyte * > sbyte uint cast struct s *memtmp to sbyte *< sbyte * > sbyte uint ret void llc ends up issuing two memcpy or custom lower memcpy(of small size) to be ldmia/stmia. I think option 2 is better but the current register allocator cannot allocate a chunk of registers at a time. A feasible temporary solution is to use specific physical registers at the lowering time for small(<
A Module instance is used to store all the information related to an LLVM module.
Error collectPGOFuncNameStrings(ArrayRef< std::string > NameStrs, bool doCompression, std::string &Result)
Given a vector of strings (function PGO names) NameStrs, the method generates a combined string Resul...
static unsigned getSize(unsigned Kind)
uint32_t getNumValueDataInstrProf(const void *Record, uint32_t VKind)
const unsigned char * bytes_begin() const
uint64_t getFunctionHashFromAddress(uint64_t Address)
Return a function's hash, or 0, if the function isn't in this SymTab.
void accumulateCounts(CountSumOrPercent &Sum) const
Compute the sums of all counts and store in Sum.
void addOneUnique(const CountSumOrPercent &UniqueFunc)
StringRef - Represent a constant reference to a string, i.e.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Type * getType() const
All values are typed, get the type of this value.
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
@ AvailableExternallyLinkage
Available for inspection, not emission.
std::list< InstrProfValueData > ValueData
Value profiling data pairs at a given value site.
A raw_ostream that writes to a file descriptor.
const std::error_category & instrprof_category()
void annotateValueSite(Module &M, Instruction &Inst, const InstrProfRecord &InstrProfR, InstrProfValueKind ValueKind, uint32_t SiteIndx, uint32_t MaxMDCount=3)
Get the value profile data for value site SiteIdx from InstrProfR and annotate the instruction Inst w...
const CustomOperand< const MCSubtargetInfo & > Msg[]
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
void merge(InstrProfRecord &Other, uint64_t Weight, function_ref< void(instrprof_error)> Warn)
Merge the counts in Other into this one.
cl::opt< bool > DoInstrProfNameCompression
void overlapValueProfData(uint32_t ValueKind, InstrProfRecord &Src, OverlapStats &Overlap, OverlapStats &FuncLevelOverlap)
Compute the overlap of value profile counts.
constexpr size_t size() const
size - Get the string size.
Error readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab)
NameStrings is a string composed of one of more sub-strings encoded in the format described above.
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
static IntegerType * getInt64Ty(LLVMContext &C)
A symbol table used for function PGO name look-up with keys (such as pointers, md5hash values) to the...
void overlap(InstrProfValueSiteRecord &Input, uint32_t ValueKind, OverlapStats &Overlap, OverlapStats &FuncLevelOverlap)
Compute the overlap b/w this record and Input record.
Lightweight error class with error context and mandatory checking.
void compress(ArrayRef< uint8_t > Input, SmallVectorImpl< uint8_t > &CompressedBuffer, int Level=DefaultCompression)
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
static Expected< std::unique_ptr< InstrProfReader > > create(const Twine &Path, const InstrProfCorrelator *Correlator=nullptr)
Factory method to create an appropriately typed reader for the given instrprof file.
const uint64_t NOMORE_ICP_MAGICNUM
Magic number in the value profile metadata showing a target has been promoted for the instruction and...
CountSumOrPercent Overlap
uint32_t getNumValueDataForSiteInstrProf(const void *R, uint32_t VK, uint32_t S)
CountSumOrPercent Mismatch
StringRef getPGOFuncNameMetadataName()
void addValueData(uint32_t ValueKind, uint32_t Site, InstrProfValueData *VData, uint32_t N, InstrProfSymtab *SymTab)
Add ValueData for ValueKind at value Site.
std::string getInstrProfSectionName(InstrProfSectKind IPSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)
Return the name of the profile section corresponding to IPSK.
@ ExternalLinkage
Externally visible function.
bool is_separator(char value, Style style=Style::native)
Check whether the given char is a path separator on the host OS.
Error addFuncName(StringRef FuncName)
Update the symtab by adding FuncName to the table.
@ PrivateLinkage
Like Internal, but omit from symbol table.
std::optional< std::vector< StOtherPiece > > Other
const std::string * BaseFilename
@ unable_to_correlate_profile
size_t size() const
size - Get the array size.
Reimplement select in terms of SEL *We would really like to support but we need to prove that the add doesn t need to overflow between the two bit chunks *Implement pre post increment support(e.g. PR935) *Implement smarter const ant generation for binops with large immediates. A few ARMv6T2 ops should be pattern matched
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
void sortByTargetValues()
Sort ValueData ascending by Value.
double ValueCounts[IPVK_Last - IPVK_First+1]
ArrayRef(const T &OneElt) -> ArrayRef< T >
StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, StringRef FileName="<unknown>")
Given a PGO function name, remove the filename prefix and return the original (static) function name.
Error accumulateCounts(const std::string &BaseFilename, const std::string &TestFilename, bool IsCS)
static uint64_t read(const unsigned char *Buffer, size_t Offset)
bool getValueProfDataFromInst(const Instruction &Inst, InstrProfValueKind ValueKind, uint32_t MaxNumValueData, InstrProfValueData ValueData[], uint32_t &ActualNumValueData, uint64_t &TotalC, bool GetNoICPValue=false)
Extract the value profile data from Inst which is annotated with value profile meta data.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
std::string & str()
Returns the string's reference.
void setVisibility(VisibilityTypes V)
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
LLVM Value Representation.
void addOneMismatch(const CountSumOrPercent &MismatchFunc)
std::vector< uint64_t > Counts
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
@ missing_debug_info_for_correlation
MDNode * getPGOFuncNameMetadata(const Function &F)
Return the PGOFuncName meta data associated with a function.
const unsigned char * bytes_end() const
void scale(uint64_t N, uint64_t D, function_ref< void(instrprof_error)> Warn)
Scale up profile counts (including value profile data) by a factor of (N / D).